1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itEth, expect, usingEthPlaygrounds} from './util/playgrounds';1920const getContractSource = (collectionAddress: string, contractAddress: string): string => {21 return `22 // SPDX-License-Identifier: MIT23 pragma solidity ^0.8.0;24 interface ITest {25 function ztestzzzzzzz() external returns (uint256 n);26 }27 contract Test {28 event Result(bool, uint256);29 function test1() public {30 try31 ITest(${collectionAddress}).ztestzzzzzzz()32 returns (uint256 n) {33 // enters34 emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }]35 } catch {36 emit Result(false, 0);37 }38 }39 function test2() public {40 try41 ITest(${contractAddress}).ztestzzzzzzz()42 returns (uint256 n) {43 emit Result(true, n);44 } catch {45 // enters46 emit Result(false, 0); // => [ false, BigNumber { value: "0" } ]47 }48 }49 function test3() public {50 ITest(${collectionAddress}).ztestzzzzzzz();51 }52 }53 `;54};555657describe('Evm Coder tests', () => {58 let donor: IKeyringPair;5960 before(async function() {61 await usingEthPlaygrounds(async (_helper, privateKey) => {62 donor = privateKey('//Alice');63 });64 });65 66 itEth('Call non-existing function', async ({helper}) => {67 const owner = await helper.eth.createAccountWithBalance(donor);68 const collection = await helper.eth.createNonfungibleCollection(owner, 'EVMCODER', '', 'TEST');69 const contract = await helper.ethContract.deployByCode(owner, 'Test', getContractSource(collection.collectionAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c'));70 const testContract = await helper.ethContract.deployByCode(owner, 'Test', getContractSource(collection.collectionAddress, contract.options.address));71 {72 const result = await testContract.methods.test1().send();73 expect(result.events.Result.returnValues).to.deep.equal({74 '0': false,75 '1': '0',76 });77 }78 {79 const result = await testContract.methods.test2().send();80 expect(result.events.Result.returnValues).to.deep.equal({81 '0': false,82 '1': '0',83 });84 }85 {86 await expect(testContract.methods.test3().call())87 .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);88 }89 });90});