diff --git a/packages/localnet/src/handleOnZEVMCalled.ts b/packages/localnet/src/handleOnZEVMCalled.ts index ba7de4a..d4ae7af 100644 --- a/packages/localnet/src/handleOnZEVMCalled.ts +++ b/packages/localnet/src/handleOnZEVMCalled.ts @@ -43,6 +43,16 @@ export const handleOnZEVMCalled = async ({ }; log(chainID, `Calling ${receiver} with message ${message}`); + if (isArbitraryCall) { + const selector = message.slice(0, 10); + const code = await provider.getCode(receiver); + if (!code.includes(selector.slice(2))) { + throw new Error( + `Receiver contract does not contain function with selector ${selector}` + ); + } + } + const executeTx = await evmContracts[chainID].gatewayEVM .connect(tss) .execute(messageContext, receiver, message, deployOpts); diff --git a/packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts b/packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts index f823df8..e567a2c 100644 --- a/packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts +++ b/packages/localnet/src/handleOnZEVMWithdrawnAndCalled.ts @@ -56,7 +56,17 @@ export const handleOnZEVMWithdrawnAndCalled = async ({ const zrc20Contract = new ethers.Contract(zrc20, ZRC20.abi, deployer); const coinType = await zrc20Contract.COIN_TYPE(); const isGasToken = coinType === 1n; - const isERC20orZETA = coinType === 2n; + + if (isArbitraryCall) { + const selector = message.slice(0, 10); + const code = await provider.getCode(receiver); + if (!code.includes(selector.slice(2))) { + throw new Error( + `Receiver contract does not contain function with selector ${selector}` + ); + } + } + log(chainID, `Calling ${receiver} with message ${message}`); if (isGasToken) { const executeTx = await evmContracts[chainID].gatewayEVM