Skip to content

Commit 79309a8

Browse files
authored
fix wait for wallet coinbase maturity should use getBlockCount (#174)
* wait for wallet coinbase maturity should use getBlockCount instead as it checks block count instead of generating 100 blocks * added this.generate to waitForWalletCoinbaseMaturity
1 parent 34856ea commit 79309a8

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

packages/testcontainers/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[![npm](https://img.shields.io/npm/v/@defichain/testcontainer)](https://www.npmjs.com/package/@defichain/testcontainer/v/latest)
2-
[![npm@next](https://img.shields.io/npm/v/@defichain/testcontainer/next)](https://www.npmjs.com/package/@defichain/testcontainer/v/next)
1+
[![npm](https://img.shields.io/npm/v/@defichain/testcontainers)](https://www.npmjs.com/package/@defichain/testcontainers/v/latest)
2+
[![npm@next](https://img.shields.io/npm/v/@defichain/testcontainers/next)](https://www.npmjs.com/package/@defichain/testcontainers/v/next)
33

44
# @defichain/testcontainers
55

packages/testcontainers/src/chains/container.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,9 @@ export abstract class DeFiDContainer {
269269
/**
270270
* @param {() => Promise<boolean>} condition to wait for true
271271
* @param {number} timeout duration when condition is not met
272+
* @param {number} [interval=200] duration in ms
272273
*/
273-
async waitForCondition (condition: () => Promise<boolean>, timeout: number): Promise<void> {
274+
async waitForCondition (condition: () => Promise<boolean>, timeout: number, interval: number = 200): Promise<void> {
274275
const expiredAt = Date.now() + timeout
275276

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

packages/testcontainers/src/chains/reg_test_container/masternode.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,15 @@ export class MasterNodeRegTestContainer extends RegTestContainer {
8989
*
9090
* A coinbase transaction must be 100 blocks deep before you can spend its outputs.
9191
* This is a safeguard to prevent outputs that originate
92-
* from the coinbase transaction from becoming unspendable
93-
* (in the event the mined block moves out of the active chaindue to a fork).
92+
* from the coinbase transaction from becoming un-spendable
93+
* (in the event the mined block moves out of the active chain due to a fork).
9494
*/
95-
async waitForWalletCoinbaseMaturity (): Promise<void> {
96-
await this.generate(100)
95+
async waitForWalletCoinbaseMaturity (timeout = 90000): Promise<void> {
96+
return await this.waitForCondition(async () => {
97+
await this.generate(1)
98+
const count = await this.getBlockCount()
99+
return count > 100
100+
}, timeout, 100)
97101
}
98102

99103
/**

0 commit comments

Comments
 (0)