diff --git a/packages/testcontainers/README.md b/packages/testcontainers/README.md index 2af850e57c..8c178c1fb5 100644 --- a/packages/testcontainers/README.md +++ b/packages/testcontainers/README.md @@ -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 diff --git a/packages/testcontainers/src/chains/container.ts b/packages/testcontainers/src/chains/container.ts index cc32d1f487..997618ed5a 100644 --- a/packages/testcontainers/src/chains/container.ts +++ b/packages/testcontainers/src/chains/container.ts @@ -269,8 +269,9 @@ export abstract class DeFiDContainer { /** * @param {() => Promise} 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, timeout: number): Promise { + async waitForCondition (condition: () => Promise, timeout: number, interval: number = 200): Promise { const expiredAt = Date.now() + timeout return await new Promise((resolve, reject) => { @@ -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) } } diff --git a/packages/testcontainers/src/chains/reg_test_container/masternode.ts b/packages/testcontainers/src/chains/reg_test_container/masternode.ts index 6e439d9b68..c9b35b0712 100644 --- a/packages/testcontainers/src/chains/reg_test_container/masternode.ts +++ b/packages/testcontainers/src/chains/reg_test_container/masternode.ts @@ -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 { - await this.generate(100) + async waitForWalletCoinbaseMaturity (timeout = 90000): Promise { + return await this.waitForCondition(async () => { + await this.generate(1) + const count = await this.getBlockCount() + return count > 100 + }, timeout, 100) } /**