Skip to content

Commit

Permalink
Improves function call input encoding errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
robotoer committed Aug 22, 2024
1 parent d0f618e commit e77b6c6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/mock-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ export const calculateFnSigHash = (
| MockReadCallExpectation<FunctionFragment>
| MockWriteCallExpectation<FunctionFragment>,
) => {
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 <C extends BaseContract>(
Expand Down

0 comments on commit e77b6c6

Please sign in to comment.