From e6258963f0533c702a35ab205ca494f54876162a Mon Sep 17 00:00:00 2001 From: Grigoriy Simonov Date: Fri, 12 Aug 2022 12:21:20 +0000 Subject: [PATCH] chore: add selector to error message --- --- 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 Err("Function not found".into()); + let selector = u32::from_be_bytes(selector); + return Err(format!("unrecognized selector: 0x{selector:0<8x}").into()); } let call = call.unwrap(); --- a/tests/src/evmCoder.test.ts +++ b/tests/src/evmCoder.test.ts @@ -31,30 +31,33 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface ITest { - function ztestzzzzzzz() external returns (uint256 n); + function ztestzzzzzzz() external returns (uint256 n); } contract Test { - event Result(bool, uint256); - function test1() public { - try - ITest(${collectionAddress}).ztestzzzzzzz() - returns (uint256 n) { - // enters - emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }] - } catch { - emit Result(false, 0); - } - } - function test2() public { - try - ITest(${contractAddress}).ztestzzzzzzz() - returns (uint256 n) { - emit Result(true, n); - } catch { - // enters - emit Result(false, 0); // => [ false, BigNumber { value: "0" } ] - } - } + event Result(bool, uint256); + function test1() public { + try + ITest(${collectionAddress}).ztestzzzzzzz() + returns (uint256 n) { + // enters + emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }] + } catch { + emit Result(false, 0); + } + } + function test2() public { + try + ITest(${contractAddress}).ztestzzzzzzz() + returns (uint256 n) { + emit Result(true, n); + } catch { + // enters + emit Result(false, 0); // => [ false, BigNumber { value: "0" } ] + } + } + function test3() public { + ITest(${collectionAddress}).ztestzzzzzzz(); + } } `, }, @@ -106,5 +109,9 @@ '1': '0', }); } + { + await expect(testContract.methods.test3().call()) + .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g); + } }); }); \ No newline at end of file -- gitstuff