Skip to content

Commit

Permalink
Use options in stub lookup (#38)
Browse files Browse the repository at this point in the history
* Use options in stub lookup

* Add changeset
  • Loading branch information
DannyDelott authored Feb 16, 2024
1 parent bdd14d3 commit 1098f69
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thin-papayas-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/evm-client": patch
---

Fix bug causing stub lookups to fail
28 changes: 28 additions & 0 deletions packages/evm-client/src/contract/stubs/ReadContractStub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@ import { describe, expect, it } from 'vitest';
const ERC20ABI = IERC20.abi;

describe('ReadContractStub', () => {
it('stubs the read function without args, but with options', async () => {
const contract = new ReadContractStub(IERC20.abi);

// stub total supply
contract.stubRead({
functionName: 'totalSupply',
value: 30n,
// options can be specfied as well
options: { blockNumber: 12n },
});
contract.stubRead({
functionName: 'totalSupply',
value: 40n,
// options can be specfied as well
options: { blockNumber: 16n },
});
// Now try and read them based on their args
const totalSupplyAtBlock12 = await contract.read('totalSupply', undefined, {
blockNumber: 12n,
});
expect(totalSupplyAtBlock12).toBe(30n);

const totalSupplyAtBlock16 = await contract.read('totalSupply', undefined, {
blockNumber: 16n,
});
expect(totalSupplyAtBlock16).toBe(40n);
});

it('stubs the read function', async () => {
const contract = new ReadContractStub(IERC20.abi);

Expand Down
2 changes: 1 addition & 1 deletion packages/evm-client/src/contract/stubs/ReadContractStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ReadContractStub<TAbi extends Abi = Abi>
}

// Account for dynamic args if provided
if (args) {
if (args || options) {
readStub.withArgs(args, options).resolves(value);
return;
}
Expand Down

0 comments on commit 1098f69

Please sign in to comment.