From f8060c2ef3112d47b36a006d53c977602d7ce6ef Mon Sep 17 00:00:00 2001 From: robotoer <1199079+robotoer@users.noreply.github.com> Date: Tue, 24 Sep 2024 21:19:49 +0000 Subject: [PATCH] [stylebot] Fixes for code style --- src/compat/waffle.ts | 128 ++++++++++++++++++------------------- test/waffle-compat.test.ts | 62 ++++++++++++------ 2 files changed, 107 insertions(+), 83 deletions(-) diff --git a/src/compat/waffle.ts b/src/compat/waffle.ts index 89b2447..4422ee9 100644 --- a/src/compat/waffle.ts +++ b/src/compat/waffle.ts @@ -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, "then"> { @@ -229,9 +229,7 @@ function createMock( mockContractInstance: MockContractController, // wallet: WalletClient, ): MockContract["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); diff --git a/test/waffle-compat.test.ts b/test/waffle-compat.test.ts index f3fc58a..040787e 100644 --- a/test/waffle-compat.test.ts +++ b/test/waffle-compat.test.ts @@ -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(signer, reader, erc20ABI); + const mock = await deployMockContract( + 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(signer, reader, erc20ABI); + const mock = await deployMockContract( + signer, + reader, + erc20ABI, + ); await mock.mock.transfer.withArgs(zeroAddress, 100n); @@ -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(signer, reader, erc20ABI); + const mock = await deployMockContract( + 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({ @@ -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(signer, reader, erc20ABI); + const mock = await deployMockContract( + signer, + reader, + erc20ABI, + ); try { await reader.readContract({ @@ -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(signer, reader, erc20ABI); + const mock = await deployMockContract( + 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); }); }); });