Skip to content

Commit

Permalink
Couple more tests, fixme
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Oct 7, 2024
1 parent 18038a8 commit 3776977
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/drift/src/adapter/MockAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class MockAdapter implements ReadWriteAdapter {
onEncodeFunctionData<
TAbi extends Abi,
TFunctionName extends FunctionName<TAbi>,
// FIXME: The `fn` prop is getting typed as a generic `string`.
>(params: Partial<AdapterEncodeFunctionDataParams<TAbi, TFunctionName>>) {
return this.mocks
.get<[AdapterEncodeFunctionDataParams], Bytes>({
Expand Down
37 changes: 37 additions & 0 deletions packages/drift/src/client/Contract/MockContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ describe("MockContract", () => {
await contract.getEvents("Transfer", { filter: { from: "0x2" } }),
).toBe(events2);
});

it("Inherits stubbed values from the adapter", async () => {
const contract = new MockContract({ abi });
const events: ContractEvent<Erc20Abi, "Transfer">[] = [
{
eventName: "Transfer",
args: {
from: "0x",
to: "0x",
value: 123n,
},
},
];
contract.adapter
.onGetEvents({
abi: contract.abi,
address: contract.address,
event: "Transfer",
})
.resolves(events);
expect(await contract.getEvents("Transfer")).toBe(events);
});
});

describe("read", () => {
Expand Down Expand Up @@ -163,6 +185,21 @@ describe("MockContract", () => {
await contract.simulateWrite("transfer", { to: "0x2", value: 123n }),
).toBe(false);
});

it("Inherits stubbed values from the adapter", async () => {
const contract = new MockContract({ abi });
contract.adapter
.onSimulateWrite({
abi: contract.abi,
address: contract.address,
fn: "transfer",
args: { to: "0x", value: 123n },
})
.resolves(true);
expect(
await contract.simulateWrite("transfer", { to: "0x", value: 123n }),
).toBe(true);
});
});

describe("encodeFunctionData", () => {
Expand Down

0 comments on commit 3776977

Please sign in to comment.