git.delta.rocks / unique-network / refs/commits / aea35c0d7499

difftreelog

source

js-packages/tests/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 type {IKeyringPair} from '@polkadot/types/types';18import {itEth, expect, usingEthPlaygrounds} from './util/index.js';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});