Skip to content

Commit

Permalink
test: add node sendTX test case for "tx" event
Browse files Browse the repository at this point in the history
  • Loading branch information
OrfeasLitos committed Nov 16, 2019
1 parent fcccef7 commit 518be85
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,29 @@ describe('Node', function() {
assert.strictEqual(meta.tx.txid(), tx2.txid());
});

it('should wake listeners of \'tx\' when sending', async () => {
let notified = false;
const notifier = () => {
notified = true;
};
node.on('tx', notifier);

const addr = Address.fromString(
'17SXrfEbhsLme7HSspiLSoWGMGTchMMr3P');
const mtx = await wallet.createTX({
outputs: [{
value: 10 * 1e8,
address: addr.toString(node.network)
}]
}, false);
await wallet.sign(mtx);

await node.sendTX(mtx.toTX());

assert(notified);
node.removeListener('tx', notifier);
});

it('should cleanup', async () => {
consensus.COINBASE_MATURITY = 100;
await node.close();
Expand Down
61 changes: 61 additions & 0 deletions test/spvnode-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-env mocha */
/* eslint prefer-arrow-callback: "off" */

'use strict';

const assert = require('bsert');
const SPVNode = require('../lib/node/spvnode');
const Input = require('../lib/primitives/input');
const Outpoint = require('../lib/primitives/outpoint');
const MTX = require('../lib/primitives/mtx');
const random = require('bcrypto/lib/random');

function dummyInput() {
const hash = random.randomBytes(32);
return Input.fromOutpoint(new Outpoint(hash, 0));
}

const node = new SPVNode({
network: 'regtest',
plugins: [require('../lib/wallet/plugin')]
});

const {wdb} = node.require('walletdb');

let wallet = null;

describe.only('SPV Node', function() {
this.timeout(process.browser ? 20000 : 5000);

if (process.browser)
return;

it('should open node', async () => {
await node.open();
});

it('should open walletdb', async () => {
wallet = await wdb.create();
});

it('should wake listeners of \'tx\' when sending', async () => {
let notified = false;
const notifier = () => {
notified = true;
};
node.on('tx', notifier);

const mtx = new MTX();
mtx.addInput(dummyInput());
mtx.addOutput(await wallet.receiveAddress(), 5460);

await node.sendTX(mtx.toTX());

assert(notified);
node.removeListener('tx', notifier);
});

it('should cleanup', async () => {
await node.close();
});
});

0 comments on commit 518be85

Please sign in to comment.