Skip to content

Commit

Permalink
test: isolate mempool event listeners in wallet-http-test
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
pinheadmz committed Jan 18, 2021
1 parent 1a086e4 commit 61ee99c
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions test/wallet-http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 () => {
Expand Down

0 comments on commit 61ee99c

Please sign in to comment.