diff --git a/test/indexer-test.js b/test/indexer-test.js index 9256134d4..f87eef502 100644 --- a/test/indexer-test.js +++ b/test/indexer-test.js @@ -17,6 +17,7 @@ const FullNode = require('../lib/node/fullnode'); const Network = require('../lib/protocol/network'); const network = Network.get('regtest'); const {NodeClient, WalletClient} = require('bclient'); +const {forValue} = require('./util/common'); const workers = new WorkerPool({ enabled: true @@ -298,6 +299,8 @@ describe('Indexer', function() { assert.equal(blocks.length, 1); } + await forValue(node.chain, 'height', 160); + // Send unconfirmed to the vector addresses. for (let i = 0; i < 3; i++) { for (const v of vectors) { @@ -307,6 +310,8 @@ describe('Indexer', function() { unconfirmed.push(txid); } } + + await forValue(node.mempool.map, 'size', 6); }); after(async () => { diff --git a/test/util/common.js b/test/util/common.js index 39177fc52..3fd9f501a 100644 --- a/test/util/common.js +++ b/test/util/common.js @@ -102,6 +102,27 @@ common.rimraf = async function(p) { return await fs.rimraf(p); }; +common.forValue = async function(obj, key, val, timeout = 60000) { + assert(typeof obj === 'object'); + assert(typeof key === 'string'); + + const ms = 10; + let interval = null; + let count = 0; + return new Promise((resolve, reject) => { + interval = setInterval(() => { + if (obj[key] === val) { + clearInterval(interval); + resolve(); + } else if (count * ms >= timeout) { + clearInterval(interval); + reject(new Error('Timeout waiting for value.')); + } + count += 1; + }, ms); + }); +}; + function parseUndo(data) { const br = bio.read(data); const items = [];