Skip to content

Commit

Permalink
Properly switch between read/write modes in waffle compat mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
robotoer committed Oct 25, 2024
1 parent df0c7d3 commit 00a5580
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/compat/waffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class Stub<T extends AbiFunction> implements StubInterface {
argsSet = false;

constructor(
private mockContract: MockContractController,
private func: T,
private readonly mockContract: MockContractController,
private readonly func: T,
) {}

private err(reason: string): never {
Expand All @@ -146,8 +146,14 @@ class Stub<T extends AbiFunction> implements StubInterface {
if (!this.func.outputs)
this.err("Cannot mock return values from a void function");

const kind =
this.func.stateMutability === "view" ||
this.func.stateMutability === "pure"
? "read"
: "write";

this.calls.push({
kind: "read",
kind,
abi: this.func,
inputs: this.inputs,
outputs: args,
Expand Down Expand Up @@ -229,7 +235,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");
const mockedAbi = Object.values(functions).reduce(
(acc, func) => {
const stubbed = new Stub(mockContractInstance, func);
Expand Down
6 changes: 3 additions & 3 deletions src/mock-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const calculateFnSigHash = (
return toFunctionSelector(call.abi);
}
return encodeFunctionData({
abi: [call.abi as AbiFunction],
abi: [call.abi],
args: call.inputs,
functionName: call.abi.name,
});
Expand Down Expand Up @@ -150,7 +150,7 @@ export const deployMock = async (
account: signer.account,
abi: abi,
functionName: "__doppelganger__mockReverts",
args: [fnSigHash, call.reason || ""],
args: [fnSigHash, call.reason ?? ""],
});
firstCall = false;
} else {
Expand All @@ -160,7 +160,7 @@ export const deployMock = async (
account: signer.account,
abi: abi,
functionName: "__doppelganger__queueRevert",
args: [fnSigHash, call.reason || ""],
args: [fnSigHash, call.reason ?? ""],
});
}
break;
Expand Down

0 comments on commit 00a5580

Please sign in to comment.