diff --git a/test/mock-contract.test.ts b/test/mock-contract.test.ts index f3d7ec4..24f0291 100644 --- a/test/mock-contract.test.ts +++ b/test/mock-contract.test.ts @@ -59,9 +59,26 @@ describe("Doppelganger", function () { ).to.equal(100n); }); - it.skip("Should allow for the mocking of write calls", async function () {}); + it("Should allow for the mocking of write 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: "write", + abi: erc20ABI[2], + inputs: [zeroAddress, 100n], + }); + + await signer.writeContract({ + address: mock.address, + abi: erc20ABI, + functionName: "transfer", + args: [zeroAddress, 100n], + }); + }); - it("Should allow for the mocking of reverts on read calls", async function () { + it("Should allow for the mocking of reverts on calls", async function () { const [signer] = await hre.viem.getWalletClients(); const reader = await hre.viem.getPublicClient(); @@ -85,6 +102,24 @@ describe("Doppelganger", function () { } }); + it("Should fail if the mock is not set up", async function () { + const [signer] = await hre.viem.getWalletClients(); + const reader = await hre.viem.getPublicClient(); + + const mock = await deployMock(signer, reader); + + try { + await reader.readContract({ + address: mock.address, + abi: erc20ABI, + functionName: "balanceOf", + args: [zeroAddress], + }); + } catch (error) { + expect(error.message).to.contain("Mock on the method is not initialized"); + } + }); + // TODO: it.skip("Should allow for the mocking of events", async function () {}); });