Skip to content

Commit

Permalink
refactor(task/withdraw): wait for transaction receipt (#147)
Browse files Browse the repository at this point in the history
* refactor(task/withdraw): wait for transaction receipt

* chore: print transaction hash before waiting

---------

Co-authored-by: Antonio Morrone <antonio@iovlabs.org>
  • Loading branch information
franciscotobar and antomor authored Nov 22, 2023
1 parent 020db49 commit b997131
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion tasks/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ export const withdraw = async (
);

try {
tokenAddress
const transaction = tokenAddress
? await collector.withdrawToken(tokenAddress, { gasLimit })
: await collector.withdraw({ gasLimit });

console.log(`Waiting for transaction ${transaction.hash}...`);
await transaction.wait();
} catch (error) {
console.error(
`Error withdrawing funds from collector with address ${collectorAddress}: ${
Expand Down
10 changes: 7 additions & 3 deletions test/tasks/withdraw.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { BigNumber, Contract, Wallet } from 'ethers';
import { BigNumber, Contract, ContractTransaction, Wallet } from 'ethers';
import * as hre from 'hardhat';
import { ethers } from 'hardhat';
import {
Expand Down Expand Up @@ -36,14 +36,18 @@ describe('Withdraw Script', function () {
let stubbedCollector: SinonStubbedInstance<Contract>;
let withdrawSpy: SinonSpy;
let withdrawTokenSpy: SinonSpy;
let stubbedContractTransaction: SinonStubbedInstance<ContractTransaction>;

beforeEach(function () {
stubbedContractTransaction = {
wait: sinon.stub(),
} as typeof stubbedContractTransaction;
stubbedERC20 = sinon.createStubInstance(Contract);
stubbedERC20['balanceOf'] = () => BigNumber.from(300000000);

stubbedCollector = sinon.createStubInstance(Contract);
stubbedCollector['withdraw'] = () => undefined;
stubbedCollector['withdrawToken'] = () => undefined;
stubbedCollector['withdraw'] = () => stubbedContractTransaction;
stubbedCollector['withdrawToken'] = () => stubbedContractTransaction;
stubbedCollector['getPartners'] = () => PARTNERS_CONFIG;
stubbedCollector['getTokens'] = () => ALLOWED_TOKENS;

Expand Down

0 comments on commit b997131

Please sign in to comment.