From e77b6c60c6e4b21a5a75dfe779107d92c5e03073 Mon Sep 17 00:00:00 2001 From: Robert Chu Date: Thu, 22 Aug 2024 14:10:41 -0700 Subject: [PATCH] Improves function call input encoding errors. --- src/mock-contract.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/mock-contract.ts b/src/mock-contract.ts index 40cd158..9e54fc8 100644 --- a/src/mock-contract.ts +++ b/src/mock-contract.ts @@ -47,15 +47,21 @@ export const calculateFnSigHash = ( | MockReadCallExpectation | MockWriteCallExpectation, ) => { + try { const iface = new Interface([call.abi]); - if (call.inputs === undefined || call.inputs === null) { - const selector = iface.getFunction(call.abi.name)?.selector; - if (!selector) { - throw new Error("Could not find function selector"); + if (call.inputs === undefined || call.inputs === null) { + const selector = iface.getFunction(call.abi.name)?.selector; + if (!selector) { + throw new Error("Could not find function selector"); + } + return selector; } - return selector; + return iface.encodeFunctionData(call.abi, call.inputs); + } catch (e) { + const err = e as Error; + err.message = `[${call.abi.format("minimal")}]: ${err.message}`; + throw err; } - return iface.encodeFunctionData(call.abi, call.inputs); }; export const deployMock = async (