Skip to content

Commit

Permalink
Adds test for undefined call.inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
robotoer committed Sep 24, 2024
1 parent da48409 commit 484d102
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mock-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
encodeFunctionData,
encodeFunctionResult,
PublicClient,
toFunctionHash,
toFunctionSelector,
WalletClient,
} from "viem";
import {
Expand Down Expand Up @@ -48,7 +48,7 @@ export const calculateFnSigHash = (
| MockWriteCallExpectation<AbiFunction>,
) => {
if (call.inputs === undefined || call.inputs === null) {
return toFunctionHash(call.abi);
return toFunctionSelector(call.abi);
}
return encodeFunctionData({
abi: [call.abi as AbiFunction],
Expand Down
21 changes: 21 additions & 0 deletions test/mock-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtractAbiFunction<typeof erc20ABI, "balanceOf">>({
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 () {});
});
Expand Down

0 comments on commit 484d102

Please sign in to comment.