Skip to content

Commit

Permalink
Add chain id mock
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Dec 18, 2023
1 parent eff766e commit 8d7e125
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assembly/vm-mock/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
@external("massa", "assembly_script_mock_call")
export declare function mockScCall(value: StaticArray<u8>): void;

@external("massa", "assembly_script_set_chain_id")
export declare function mockSetChainId(value: number): void;

/**
* Add a new smart contract address to the ledger
*
Expand Down
12 changes: 12 additions & 0 deletions vm-mock/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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".`,
);
},
},
};

Expand Down

0 comments on commit 8d7e125

Please sign in to comment.