Skip to content

Commit

Permalink
update test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
snogcel committed Jan 9, 2017
1 parent 37b3380 commit 96e6cdf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions regtest/bitcoind.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ describe('Bitcoind Functionality', function() {
tx.outputs[0].spentIndex.should.equal(0);
tx.outputs[0].spentHeight.should.be.a('number');
tx.outputs[0].address.should.be.a('string');
tx.txlock.should.equal(false);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion regtest/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('Node Functionality', function() {
var address;
var unspentOutput;
before(function(done) {
this.timeout(200000);
this.timeout(300000);
address = testKey.toAddress(regtest).toString();
var startHeight = node.services.bitcoind.height;
node.services.bitcoind.on('tip', function(height) {
Expand Down
50 changes: 50 additions & 0 deletions test/services/bitcoind.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,56 @@ describe('Bitcoin Service', function() {
});
});

// TODO: transaction lock test coverage
describe('#_zmqTransactionLockHandler', function() {
it('will emit to subscribers', function(done) {
var bitcoind = new BitcoinService(baseConfig);
var expectedBuffer = new Buffer(txhex, 'hex');
var emitter = new EventEmitter();
bitcoind.subscriptions.transactionlock.push(emitter);
emitter.on('bitcoind/transactionlock', function(hex) {
hex.should.be.a('string');
hex.should.equal(expectedBuffer.toString('hex'));
done();
});
var node = {};
bitcoind._zmqTransactionLockHandler(node, expectedBuffer);
});
it('will NOT emit to subscribers more than once for the same tx', function(done) {
var bitcoind = new BitcoinService(baseConfig);
var expectedBuffer = new Buffer(txhex, 'hex');
var emitter = new EventEmitter();
bitcoind.subscriptions.transactionlock.push(emitter);
emitter.on('bitcoind/transactionlock', function() {
done();
});
var node = {};
bitcoind._zmqTransactionLockHandler(node, expectedBuffer);
bitcoind._zmqTransactionLockHandler(node, expectedBuffer);
});
it('will emit "tx" event', function(done) {
var bitcoind = new BitcoinService(baseConfig);
var expectedBuffer = new Buffer(txhex, 'hex');
bitcoind.on('txlock', function(buffer) {
buffer.should.be.instanceof(Buffer);
buffer.toString('hex').should.equal(expectedBuffer.toString('hex'));
done();
});
var node = {};
bitcoind._zmqTransactionLockHandler(node, expectedBuffer);
});
it('will NOT emit "tx" event more than once for the same tx', function(done) {
var bitcoind = new BitcoinService(baseConfig);
var expectedBuffer = new Buffer(txhex, 'hex');
bitcoind.on('txlock', function() {
done();
});
var node = {};
bitcoind._zmqTransactionLockHandler(node, expectedBuffer);
bitcoind._zmqTransactionLockHandler(node, expectedBuffer);
});
});

describe('#_checkSyncedAndSubscribeZmqEvents', function() {
var sandbox = sinon.sandbox.create();
before(function() {
Expand Down

0 comments on commit 96e6cdf

Please sign in to comment.