diff --git a/src/mock-contract.ts b/src/mock-contract.ts index 8de72a4..fc9434d 100644 --- a/src/mock-contract.ts +++ b/src/mock-contract.ts @@ -3,7 +3,7 @@ import { encodeFunctionData, encodeFunctionResult, PublicClient, - toFunctionHash, + toFunctionSelector, WalletClient, } from "viem"; import { @@ -48,7 +48,7 @@ export const calculateFnSigHash = ( | MockWriteCallExpectation, ) => { if (call.inputs === undefined || call.inputs === null) { - return toFunctionHash(call.abi); + return toFunctionSelector(call.abi); } return encodeFunctionData({ abi: [call.abi as AbiFunction], diff --git a/test/mock-contract.test.ts b/test/mock-contract.test.ts index 0990bea..49f92e2 100644 --- a/test/mock-contract.test.ts +++ b/test/mock-contract.test.ts @@ -122,6 +122,27 @@ describe("Doppelganger", function () { } }); + it("Should allow undefined call.inputs for read calls", async function () { + const [signer] = await hre.viem.getWalletClients(); + const reader = await hre.viem.getPublicClient(); + + const mock = await deployMock(signer, reader); + await mock.setup>({ + kind: "read", + abi: erc20ABI[0], + outputs: [100n], + }); + + expect( + await reader.readContract({ + address: mock.address, + abi: erc20ABI, + functionName: "balanceOf", + args: [zeroAddress], + }), + ).to.equal(100n); + }); + // TODO: it.skip("Should allow for the mocking of events", async function () {}); });