Expose the hash field from contract wasm (#3267)

This commit is contained in:
Jaco Greeff
2021-03-05 13:25:00 +01:00
committed by GitHub
parent 9295349886
commit 108b49ea03
4 changed files with 28 additions and 2 deletions
+22
View File
@@ -1,10 +1,18 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { blake2AsHex } from '@polkadot/util-crypto';
import abis from '../test/contracts';
import { Abi } from '.';
interface JSONAbi {
source: {
compiler: string,
hash: string,
language: string,
wasm: string
},
spec: {
messages: {
name: string[] | string
@@ -27,4 +35,18 @@ describe('Abi', (): void => {
}
});
});
it('has the correct hash for the source', (): void => {
const bundle = abis.ink_flipperBundle as JSONAbi;
const abi = new Abi(bundle as any);
// manual
expect(bundle.source.hash).toEqual(blake2AsHex(bundle.source.wasm));
// the Codec hash
expect(bundle.source.hash).toEqual(abi.project.source.wasm.hash.toHex());
// the hash as per the actual Abi
expect(bundle.source.hash).toEqual(abi.project.source.wasmHash.toHex());
});
});
@@ -6,5 +6,6 @@ export { default as dns } from './dns.json';
export { default as erc20 } from './erc20.json';
export { default as erc721 } from './erc721.json';
export { default as flipper } from './flipper.json';
export { default as flipperBundle } from './flipper.contract.json';
export { default as incrementer } from './incrementer.json';
export { default as multisigPlain } from './multisig_plain.json';
@@ -126,7 +126,10 @@ export default {
license: 'Option<Text>'
},
ContractProjectSource: {
hash: '[u8; 32]',
_alias: {
wasmHash: 'hash'
},
wasmHash: '[u8; 32]',
language: 'Text',
compiler: 'Text',
wasm: 'Raw'
@@ -136,7 +136,7 @@ export interface ContractProjectContract extends Struct {
/** @name ContractProjectSource */
export interface ContractProjectSource extends Struct {
readonly hash: U8aFixed;
readonly wasmHash: U8aFixed;
readonly language: Text;
readonly compiler: Text;
readonly wasm: Raw;