Skip to content

Commit

Permalink
Fixes tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
robotoer committed Aug 1, 2024
1 parent 015568a commit 55f016f
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions test/mock-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtractAbiFunction<typeof erc20ABI, "transfer">>({
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();

Expand All @@ -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 () {});
});
Expand Down

0 comments on commit 55f016f

Please sign in to comment.