Skip to content

Commit

Permalink
fix wait for wallet coinbase maturity should use getBlockCount (#174)
Browse files Browse the repository at this point in the history
* wait for wallet coinbase maturity should use getBlockCount instead as it checks block count instead of generating 100 blocks

* added this.generate to waitForWalletCoinbaseMaturity
  • Loading branch information
fuxingloh authored Apr 30, 2021
1 parent 34856ea commit 79309a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/testcontainers/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![npm](https://img.shields.io/npm/v/@defichain/testcontainer)](https://www.npmjs.com/package/@defichain/testcontainer/v/latest)
[![npm@next](https://img.shields.io/npm/v/@defichain/testcontainer/next)](https://www.npmjs.com/package/@defichain/testcontainer/v/next)
[![npm](https://img.shields.io/npm/v/@defichain/testcontainers)](https://www.npmjs.com/package/@defichain/testcontainers/v/latest)
[![npm@next](https://img.shields.io/npm/v/@defichain/testcontainers/next)](https://www.npmjs.com/package/@defichain/testcontainers/v/next)

# @defichain/testcontainers

Expand Down
5 changes: 3 additions & 2 deletions packages/testcontainers/src/chains/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ export abstract class DeFiDContainer {
/**
* @param {() => Promise<boolean>} condition to wait for true
* @param {number} timeout duration when condition is not met
* @param {number} [interval=200] duration in ms
*/
async waitForCondition (condition: () => Promise<boolean>, timeout: number): Promise<void> {
async waitForCondition (condition: () => Promise<boolean>, timeout: number, interval: number = 200): Promise<void> {
const expiredAt = Date.now() + timeout

return await new Promise((resolve, reject) => {
Expand All @@ -281,7 +282,7 @@ export abstract class DeFiDContainer {
} else if (expiredAt < Date.now()) {
reject(new Error(`waitForCondition is not ready within given timeout of ${timeout}ms.`))
} else {
setTimeout(() => void checkCondition(), 200)
setTimeout(() => void checkCondition(), interval)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ export class MasterNodeRegTestContainer extends RegTestContainer {
*
* A coinbase transaction must be 100 blocks deep before you can spend its outputs.
* This is a safeguard to prevent outputs that originate
* from the coinbase transaction from becoming unspendable
* (in the event the mined block moves out of the active chaindue to a fork).
* from the coinbase transaction from becoming un-spendable
* (in the event the mined block moves out of the active chain due to a fork).
*/
async waitForWalletCoinbaseMaturity (): Promise<void> {
await this.generate(100)
async waitForWalletCoinbaseMaturity (timeout = 90000): Promise<void> {
return await this.waitForCondition(async () => {
await this.generate(1)
const count = await this.getBlockCount()
return count > 100
}, timeout, 100)
}

/**
Expand Down

0 comments on commit 79309a8

Please sign in to comment.