From 61ee99c0484b1a1361d40cd08470ef43633d6ce8 Mon Sep 17 00:00:00 2001 From: Matthew Zipkin Date: Mon, 18 Jan 2021 15:01:12 -0500 Subject: [PATCH] test: isolate mempool event listeners in wallet-http-test Also removed `assert.ok(false)` in these handlers since those assertion errors would be swallowed by the mempool event emitter and would not be caught by the test suite anyway. These test modifications can be tested themselves by reviewers by setting `broadcast: true` --- test/wallet-http-test.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/wallet-http-test.js b/test/wallet-http-test.js index 0fb0e44f4..79667d063 100644 --- a/test/wallet-http-test.js +++ b/test/wallet-http-test.js @@ -252,13 +252,14 @@ describe('Wallet HTTP', function() { }); it('should create an open and broadcast the tx', async () => { + let entered = false; + const handler = () => entered = true; + node.mempool.on('tx', handler); + const json = await wallet.createOpen({ name: name }); - let entered = false; - node.mempool.on('tx', () => entered = true); - // wait for tx event on mempool await common.event(node.mempool, 'tx'); @@ -269,20 +270,21 @@ describe('Wallet HTTP', function() { const opens = json.outputs.filter(output => output.covenant.type === types.OPEN); assert.equal(opens.length, 1); + + // reset for next test + node.mempool.removeListener('tx', handler); }); it('should create an open and not broadcast the transaction', async () => { + let entered = false; + const handler = () => entered = true; + node.mempool.on('tx', handler); + const json = await wallet.createOpen({ name: name, broadcast: false }); - let entered = false; - node.mempool.on('tx', () => { - entered = true; - assert.ok(false); - }); - await sleep(500); // tx is not in the mempool @@ -305,21 +307,22 @@ describe('Wallet HTTP', function() { const opens = mtx.outputs.filter(output => output.covenant.type === types.OPEN); assert.equal(opens.length, 1); + + // reset for next test + node.mempool.removeListener('tx', handler); }); it('should create an open and not sign the transaction', async () => { + let entered = false; + const handler = () => entered = true; + node.mempool.on('tx', handler); + const json = await wallet.createOpen({ name: name, broadcast: false, sign: false }); - let entered = false; - node.mempool.on('tx', () => { - entered = true; - assert.ok(false); - }); - await sleep(500); // tx is not in the mempool @@ -341,6 +344,9 @@ describe('Wallet HTTP', function() { // transaction not valid assert.equal(mtx.verify(), false); + + // reset for next test + node.mempool.removeListener('tx', handler); }); it('should throw error with incompatible broadcast and sign options', async () => {