Skip to content

Commit

Permalink
test: add mineBlocks to node context.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Dec 18, 2023
1 parent 6102ad5 commit a2d7e3c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 84 deletions.
15 changes: 7 additions & 8 deletions test/node-http-test.js
Expand Up @@ -450,14 +450,13 @@ describe('Node HTTP', function() {

// take into account race conditions
async function mineBlocks(count, address) {
for (let i = 0; i < count; i++) {
const obj = { complete: false };
nodeCtx.node.once('block', () => {
obj.complete = true;
});
await nclient.execute('generatetoaddress', [1, address]);
await common.forValue(obj, 'complete', true);
}
const blockEvents = common.forEvent(
nodeCtx.nclient.socket.events,
'block connect',
count
);
await nodeCtx.mineBlocks(count, address);
await blockEvents;
}

before(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/node-rpc-test.js
Expand Up @@ -120,7 +120,7 @@ describe('RPC', function() {
const address = 'rs1qjjpnmnrzfvxgqlqf5j48j50jmq9pyqjz0a7ytz';

// Mine two blocks.
await nclient.execute('generatetoaddress', [2, address]);
await nodeCtx.mineBlocks(2, address);

const {chain} = await nclient.getInfo();
const info = await nclient.execute('getblock', [chain.tip]);
Expand Down
17 changes: 17 additions & 0 deletions test/util/node-context.js
Expand Up @@ -285,6 +285,23 @@ class NodeContext {

return client;
}

/**
* Mine blocks and wait for connect.
* @param {Number} count
* @param {Address} address
* @returns {Promise<Buffer[]>} - Block hashes
*/

async mineBlocks(count, address) {
assert(this.open);

const blockEvents = common.forEvent(this.node, 'block', count);
const hashes = await this.nodeRPC.generateToAddress([count, address]);
await blockEvents;

return hashes;
}
}

module.exports = NodeContext;

0 comments on commit a2d7e3c

Please sign in to comment.