git.delta.rocks / unique-network / refs/commits / 6a7ab3b81055

difftreelog

source

tests/src/eth/evmCoder.test.ts3.1 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {itEth, expect, usingEthPlaygrounds} from './util';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 = await privateKey({filename: __filename});63    });64  });6566  itEth('Call non-existing function', async ({helper}) => {67    const owner = await helper.eth.createAccountWithBalance(donor);68    const collection = await helper.eth.createNFTCollection(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});