git.delta.rocks / unique-network / refs/commits / 909792523ad1

difftreelog

fix(evm-coder-substrate-pallet) add error when non existing function is called on collection contract

Grigoriy Simonov2022-08-12parent: #e4268af.patch.diff
in: master

5 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5871,7 +5871,7 @@
 
 [[package]]
 name = "pallet-evm-coder-substrate"
-version = "0.1.1"
+version = "0.1.2"
 dependencies = [
  "ethereum",
  "evm-coder",
addedpallets/evm-coder-substrate/CHANGELOG.mddiffbeforeafterboth
--- /dev/null
+++ b/pallets/evm-coder-substrate/CHANGELOG.md
@@ -0,0 +1,12 @@
+# Change Log
+
+All notable changes to this project will be documented in this file.
+
+## [0.1.2] - 2022-08-12
+
+### Fixed
+
+ - Issue with error not being thrown when non existing function is called on collection contract
+    
+ 
+ 
\ No newline at end of file
modifiedpallets/evm-coder-substrate/Cargo.tomldiffbeforeafterboth
--- a/pallets/evm-coder-substrate/Cargo.toml
+++ b/pallets/evm-coder-substrate/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-evm-coder-substrate"
-version = "0.1.1"
+version = "0.1.2"
 license = "GPLv3"
 edition = "2021"
 
modifiedpallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-coder-substrate/src/lib.rs
+++ b/pallets/evm-coder-substrate/src/lib.rs
@@ -261,7 +261,7 @@
 	let (selector, mut reader) = AbiReader::new_call(input)?;
 	let call = C::parse(selector, &mut reader)?;
 	if call.is_none() {
-		return Ok(None);
+		return Err("Function not found".into());
 	}
 	let call = call.unwrap();
 
addedtests/src/evmCoder.test.tsdiffbeforeafterboth
after · tests/src/evmCoder.test.ts
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 Web3 from 'web3';18import {createEthAccountWithBalance, createRefungibleCollection, GAS_ARGS, itWeb3} from './eth/util/helpers';19import * as solc from 'solc';2021import chai from 'chai';22const expect = chai.expect;2324async function compileTestContract(collectionAddress: string, contractAddress: string) {25  const input = {26    language: 'Solidity',27    sources: {28      ['Test.sol']: {29        content: 30        `31        // SPDX-License-Identifier: MIT32        pragma solidity ^0.8.0;33        interface ITest {34            function ztestzzzzzzz() external returns (uint256 n);35        }36        contract Test {37            event Result(bool, uint256);38            function test1() public {39                try40                    ITest(${collectionAddress}).ztestzzzzzzz()41                returns (uint256 n) {42                    // enters43                    emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }]44                } catch {45                    emit Result(false, 0);46                }47            }48            function test2() public {49                try50                    ITest(${contractAddress}).ztestzzzzzzz()51                returns (uint256 n) {52                    emit Result(true, n);53                } catch {54                    // enters55                    emit Result(false, 0); // => [ false, BigNumber { value: "0" } ]56                }57            }58        }59        `,60      },61    },62    settings: {63      outputSelection: {64        '*': {65          '*': ['*'],66        },67      },68    },69  };70  const json = JSON.parse(solc.compile(JSON.stringify(input)));71  const out = json.contracts['Test.sol']['Test'];7273  return  {74    abi: out.abi,75    object: '0x' + out.evm.bytecode.object,76  };77}7879async function deployTestContract(web3: Web3, owner: string, collectionAddress: string, contractAddress: string) {80  const compiled = await compileTestContract(collectionAddress, contractAddress);81  const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {82    data: compiled.object,83    from: owner,84    ...GAS_ARGS,85  });86  return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});87}8889describe('Evm Coder tests', () => {90  itWeb3('Call non-existing function', async ({api, web3, privateKeyWrapper}) => {91    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);92    const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);93    const contract = await deployTestContract(web3, owner, collectionIdAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c');94    const testContract = await deployTestContract(web3, owner, collectionIdAddress, contract.options.address);95    {96      const result = await testContract.methods.test1().send();97      expect(result.events.Result.returnValues).to.deep.equal({98        '0': false,99        '1': '0',100      });101    }102    {103      const result = await testContract.methods.test2().send();104      expect(result.events.Result.returnValues).to.deep.equal({105        '0': false,106        '1': '0',107      });108    }109  });110});