diff --git a/assembly/vm-mock/env.ts b/assembly/vm-mock/env.ts index eb238e96..614b16a0 100644 --- a/assembly/vm-mock/env.ts +++ b/assembly/vm-mock/env.ts @@ -19,6 +19,9 @@ @external("massa", "assembly_script_mock_call") export declare function mockScCall(value: StaticArray): void; +@external("massa", "assembly_script_set_chain_id") +export declare function mockSetChainId(value: number): void; + /** * Add a new smart contract address to the ledger * diff --git a/vm-mock/vm.js b/vm-mock/vm.js index 97b6aef5..43aa62ad 100644 --- a/vm-mock/vm.js +++ b/vm-mock/vm.js @@ -87,6 +87,7 @@ function resetLedger() { let webModule; const scCallMockStack = []; +const chainIdMockStack = []; /** * Create a mock vm to simulate calls and responses of Massa WebAssembly sdk. @@ -774,6 +775,17 @@ export default function createMockedABI( const hash = sha3.keccak256.arrayBuffer(data); return newArrayBuffer(hash); }, + assembly_script_set_chain_id(value) { + chainIdMockStack.push(value); + }, + assembly_script_chain_id() { + if (chainIdMockStack.length) { + return chainIdMockStack.shift(); + } + throw new Error( + `No mock defined for chain id".`, + ); + }, }, };