1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itEth, expect, usingEthPlaygrounds} from './util';1920const getContractSource = (collectionAddress: string, contractAddress: string): string => `21 // SPDX-License-Identifier: MIT22 pragma solidity ^0.8.0;23 interface ITest {24 function ztestzzzzzzz() external returns (uint256 n);25 }26 contract Test {27 event Result(bool, uint256);28 function test1() public {29 try30 ITest(${collectionAddress}).ztestzzzzzzz()31 returns (uint256 n) {32 // enters33 emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }]34 } catch {35 emit Result(false, 0);36 }37 }38 function test2() public {39 try40 ITest(${contractAddress}).ztestzzzzzzz()41 returns (uint256 n) {42 emit Result(true, n);43 } catch {44 // enters45 emit Result(false, 0); // => [ false, BigNumber { value: "0" } ]46 }47 }48 function test3() public {49 ITest(${collectionAddress}).ztestzzzzzzz();50 }51 }52 `;535455describe('Evm Coder tests', () => {56 let donor: IKeyringPair;5758 before(async function() {59 await usingEthPlaygrounds(async (_helper, privateKey) => {60 donor = await privateKey({url: import.meta.url});61 });62 });6364 itEth('Call non-existing function', async ({helper}) => {65 const owner = await helper.eth.createAccountWithBalance(donor);66 const collection = await helper.eth.createNFTCollection(owner, 'EVMCODER', '', 'TEST');67 const contract = await helper.ethContract.deployByCode(owner, 'Test', getContractSource(collection.collectionAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c'));68 const testContract = await helper.ethContract.deployByCode(owner, 'Test', getContractSource(collection.collectionAddress, contract.options.address));69 {70 const result = await testContract.methods.test1().send();71 expect(result.events.Result.returnValues).to.deep.equal({72 '0': false,73 '1': '0',74 });75 }76 {77 const result = await testContract.methods.test2().send();78 expect(result.events.Result.returnValues).to.deep.equal({79 '0': false,80 '1': '0',81 });82 }83 {84 await expect(testContract.methods.test3().call())85 .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);86 }87 });88});