difftreelog
Merge pull request #486 from UniqueNetwork/fix/no-error-on-calling-non-existing-function
in: master
5 files changed
Cargo.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",
pallets/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
pallets/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"
pallets/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,8 @@
let (selector, mut reader) = AbiReader::new_call(input)?;
let call = C::parse(selector, &mut reader)?;
if call.is_none() {
- return Ok(None);
+ let selector = u32::from_be_bytes(selector);
+ return Err(format!("unrecognized selector: 0x{selector:0<8x}").into());
}
let call = call.unwrap();
tests/src/evmCoder.test.tsdiffbeforeafterboth1// 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 function test3() public {59 ITest(${collectionAddress}).ztestzzzzzzz();60 }61 }62 `,63 },64 },65 settings: {66 outputSelection: {67 '*': {68 '*': ['*'],69 },70 },71 },72 };73 const json = JSON.parse(solc.compile(JSON.stringify(input)));74 const out = json.contracts['Test.sol']['Test'];7576 return {77 abi: out.abi,78 object: '0x' + out.evm.bytecode.object,79 };80}8182async function deployTestContract(web3: Web3, owner: string, collectionAddress: string, contractAddress: string) {83 const compiled = await compileTestContract(collectionAddress, contractAddress);84 const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {85 data: compiled.object,86 from: owner,87 ...GAS_ARGS,88 });89 return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});90}9192describe('Evm Coder tests', () => {93 itWeb3('Call non-existing function', async ({api, web3, privateKeyWrapper}) => {94 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);95 const {collectionIdAddress} = await createRefungibleCollection(api, web3, owner);96 const contract = await deployTestContract(web3, owner, collectionIdAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c');97 const testContract = await deployTestContract(web3, owner, collectionIdAddress, contract.options.address);98 {99 const result = await testContract.methods.test1().send();100 expect(result.events.Result.returnValues).to.deep.equal({101 '0': false,102 '1': '0',103 });104 }105 {106 const result = await testContract.methods.test2().send();107 expect(result.events.Result.returnValues).to.deep.equal({108 '0': false,109 '1': '0',110 });111 }112 {113 await expect(testContract.methods.test3().call())114 .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);115 }116 });117});