Skip to content

Commit

Permalink
[stylebot] Fixes for code style
Browse files Browse the repository at this point in the history
  • Loading branch information
robotoer authored and github-actions[bot] committed Sep 24, 2024
1 parent d1dec59 commit f8060c2
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 83 deletions.
128 changes: 63 additions & 65 deletions src/compat/waffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,98 +15,98 @@ import { PublicClient, WalletClient } from "viem";

export const doppelgangerAbi = [
{
"stateMutability": "payable",
"type": "fallback"
stateMutability: "payable",
type: "fallback",
},
{
"inputs": [
inputs: [
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
internalType: "bytes",
name: "data",
type: "bytes",
},
{
"internalType": "bytes",
"name": "value",
"type": "bytes"
}
internalType: "bytes",
name: "value",
type: "bytes",
},
],
"name": "__doppelganger__mockReturns",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
name: "__doppelganger__mockReturns",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
"inputs": [
inputs: [
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
internalType: "bytes",
name: "data",
type: "bytes",
},
{
"internalType": "string",
"name": "reason",
"type": "string"
}
internalType: "string",
name: "reason",
type: "string",
},
],
"name": "__doppelganger__mockReverts",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
name: "__doppelganger__mockReverts",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
"inputs": [
inputs: [
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
internalType: "bytes",
name: "data",
type: "bytes",
},
{
"internalType": "bytes",
"name": "value",
"type": "bytes"
}
internalType: "bytes",
name: "value",
type: "bytes",
},
],
"name": "__doppelganger__queueReturn",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
name: "__doppelganger__queueReturn",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
"inputs": [
inputs: [
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
internalType: "bytes",
name: "data",
type: "bytes",
},
{
"internalType": "string",
"name": "reason",
"type": "string"
}
internalType: "string",
name: "reason",
type: "string",
},
],
"name": "__doppelganger__queueRevert",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
name: "__doppelganger__queueRevert",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
"inputs": [
inputs: [
{
"internalType": "string",
"name": "reason",
"type": "string"
}
internalType: "string",
name: "reason",
type: "string",
},
],
"name": "__doppelganger__receiveReverts",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
name: "__doppelganger__receiveReverts",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
"stateMutability": "payable",
"type": "receive"
}
stateMutability: "payable",
type: "receive",
},
] as const;

interface StubInterface extends Pick<Promise<void>, "then"> {
Expand Down Expand Up @@ -229,9 +229,7 @@ function createMock<T extends Abi>(
mockContractInstance: MockContractController,
// wallet: WalletClient,
): MockContract<T>["mock"] {
const functions = abi.filter(
(f) => f.type === "function",
) as AbiFunction[];
const functions = abi.filter((f) => f.type === "function") as AbiFunction[];
const mockedAbi = Object.values(functions).reduce(
(acc, func) => {
const stubbed = new Stub(mockContractInstance, func);
Expand Down
62 changes: 44 additions & 18 deletions test/waffle-compat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,33 @@ describe("waffle", function () {
it("Should allow for the mocking of read calls", async function () {
const reader = await hre.viem.getPublicClient();
const [signer] = await hre.viem.getWalletClients();
const mock = await deployMockContract<typeof erc20ABI>(signer, reader, erc20ABI);
const mock = await deployMockContract<typeof erc20ABI>(
signer,
reader,
erc20ABI,
);
console.log(`Deployed mock at ${mock.address}`);

await mock.mock.balanceOf.withArgs(zeroAddress).returns(100n);

expect(await reader.readContract({
address: mock.address,
abi: erc20ABI,
functionName: "balanceOf",
args: [zeroAddress],
})).to.equal(100n);
expect(
await reader.readContract({
address: mock.address,
abi: erc20ABI,
functionName: "balanceOf",
args: [zeroAddress],
}),
).to.equal(100n);
});

it("Should allow for the mocking of write calls", async function () {
const reader = await hre.viem.getPublicClient();
const [signer] = await hre.viem.getWalletClients();
const mock = await deployMockContract<typeof erc20ABI>(signer, reader, erc20ABI);
const mock = await deployMockContract<typeof erc20ABI>(
signer,
reader,
erc20ABI,
);

await mock.mock.transfer.withArgs(zeroAddress, 100n);

Expand All @@ -69,9 +79,15 @@ describe("waffle", function () {
it("Should allow for the mocking of reverts on read calls", async function () {
const reader = await hre.viem.getPublicClient();
const [signer] = await hre.viem.getWalletClients();
const mock = await deployMockContract<typeof erc20ABI>(signer, reader, erc20ABI);
const mock = await deployMockContract<typeof erc20ABI>(
signer,
reader,
erc20ABI,
);

await mock.mock.balanceOf.withArgs(zeroAddress).revertsWithReason("Custom reason");
await mock.mock.balanceOf
.withArgs(zeroAddress)
.revertsWithReason("Custom reason");

try {
await reader.readContract({
Expand All @@ -88,7 +104,11 @@ describe("waffle", function () {
it("Should fail if the mock is not set up", async function () {
const reader = await hre.viem.getPublicClient();
const [signer] = await hre.viem.getWalletClients();
const mock = await deployMockContract<typeof erc20ABI>(signer, reader, erc20ABI);
const mock = await deployMockContract<typeof erc20ABI>(
signer,
reader,
erc20ABI,
);

try {
await reader.readContract({
Expand All @@ -107,16 +127,22 @@ describe("waffle", function () {
it("Should allow undefined call.inputs for read calls", async function () {
const reader = await hre.viem.getPublicClient();
const [signer] = await hre.viem.getWalletClients();
const mock = await deployMockContract<typeof erc20ABI>(signer, reader, erc20ABI);
const mock = await deployMockContract<typeof erc20ABI>(
signer,
reader,
erc20ABI,
);

await mock.mock.balanceOf.returns(20998n);

expect(await reader.readContract({
address: mock.address,
abi: erc20ABI,
functionName: "balanceOf",
args: [zeroAddress],
})).to.equal(20998n);
expect(
await reader.readContract({
address: mock.address,
abi: erc20ABI,
functionName: "balanceOf",
args: [zeroAddress],
}),
).to.equal(20998n);
});
});
});

0 comments on commit f8060c2

Please sign in to comment.