Skip to content

Commit

Permalink
2512 add estimate/transact to withdrawal manager completeQueuedWithdr…
Browse files Browse the repository at this point in the history
…awal
  • Loading branch information
guestn committed Sep 19, 2024
1 parent cbae81a commit 33560ba
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
30 changes: 29 additions & 1 deletion lib/contracts/handlers/puffer-withdrawal-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ describe('PufferWithdrawalHandler', () => {
});

const withdrawalIdx = BigInt(5);
await handler.completeQueueWithdrawal(mockAddress, withdrawalIdx);
const { transact } = await handler.completeQueueWithdrawal(
mockAddress,
withdrawalIdx,
);

await transact();

expect(
handler['getContract']().write.completeQueuedWithdrawal,
Expand All @@ -190,6 +195,29 @@ describe('PufferWithdrawalHandler', () => {
);
});

it('should estimate gas for a queued withdrawal', async () => {
jest.spyOn(handler as any, 'getContract').mockReturnValue({
estimateGas: {
completeQueuedWithdrawal: jest.fn().mockResolvedValue(BigInt(100000)),
},
});

const withdrawalIdx = BigInt(5);
const { estimate } = await handler.completeQueueWithdrawal(
mockAddress,
withdrawalIdx,
);

await estimate();

expect(
handler['getContract']().estimateGas.completeQueuedWithdrawal,
).toHaveBeenCalledWith(
expect.arrayContaining([withdrawalIdx]),
expect.any(Object),
);
});

it('should get a withdrawal by its index', async () => {
const withdrawalIdx = BigInt(1);
const mockWithdrawal = { amount: '10', recipient: mockAddress };
Expand Down
16 changes: 11 additions & 5 deletions lib/contracts/handlers/puffer-withdrawal-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,19 @@ export class PufferWithdrawalHandler {
walletAddress: Address,
withdrawalIdx: bigint,
) {
return await this.getContract().write.completeQueuedWithdrawal(
[withdrawalIdx],
{
const transact = async () =>
await this.getContract().write.completeQueuedWithdrawal([withdrawalIdx], {
account: walletAddress,
chain: this.viemChain,
},
);
});

const estimate = async () =>
await this.getContract().estimateGas.completeQueuedWithdrawal(
[withdrawalIdx],
{ account: walletAddress },
);

return { transact, estimate };
}

/**
Expand Down

0 comments on commit 33560ba

Please sign in to comment.