From 5e6600162afe609dde19c9fff2b8d6b6c0fdf529 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 22 Apr 2016 12:48:16 -0400 Subject: [PATCH] test: add unit test for getaddressunspentoutputs with mempool --- lib/services/bitcoind.js | 1 + test/services/bitcoind.unit.js | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index c952f9b3..bc45a1b8 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -840,6 +840,7 @@ Bitcoin.prototype.getAddressUnspentOutputs = function(addressArg, options, callb } function updateWithMempool(confirmedUtxos, mempoolDeltas) { + /* jshint maxstatements: 20 */ if (!mempoolDeltas || !mempoolDeltas.length) { return confirmedUtxos; } diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index e5532a06..d030cf8b 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -1465,6 +1465,84 @@ describe('Bitcoin Service', function() { }); }); }); + it('will update with mempool results', function(done) { + var deltas = [ + { + txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce', + satoshis: -7679241, + address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo', + index: 0, + timestamp: 1461342707725, + prevtxid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0', + prevout: 1 + }, + { + txid: 'f637384e9f81f18767ea50e00bce58fc9848b6588a1130529eebba22a410155f', + satoshis: 100000, + address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo', + index: 0, + timestamp: 1461342833133 + }, + { + txid: 'f71bccef3a8f5609c7f016154922adbfe0194a96fb17a798c24077c18d0a9345', + satoshis: 400000, + address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo', + index: 1, + timestamp: 1461342954813 + } + ]; + var bitcoind = new BitcoinService(baseConfig); + var confirmedUtxos = [ + { + address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo', + txid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0', + outputIndex: 1, + script: '76a914f399b4b8894f1153b96fce29f05e6e116eb4c21788ac', + satoshis: 7679241, + height: 207111 + } + ]; + var expectedUtxos = [ + { + address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo', + outputIndex: 1, + satoshis: 400000, + script: '76a914809dc14496f99b6deb722cf46d89d22f4beb8efd88ac', + timestamp: 1461342954813, + txid: 'f71bccef3a8f5609c7f016154922adbfe0194a96fb17a798c24077c18d0a9345' + }, + { + address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo', + outputIndex: 0, + satoshis: 100000, + script: '76a914809dc14496f99b6deb722cf46d89d22f4beb8efd88ac', + timestamp: 1461342833133, + txid: 'f637384e9f81f18767ea50e00bce58fc9848b6588a1130529eebba22a410155f' + } + ]; + bitcoind.nodes.push({ + client: { + getAddressUtxos: sinon.stub().callsArgWith(1, null, { + result: confirmedUtxos + }), + getAddressMempool: sinon.stub().callsArgWith(1, null, { + result: deltas + }) + } + }); + var options = { + queryMempool: true + }; + var address = '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo'; + bitcoind.getAddressUnspentOutputs(address, options, function(err, utxos) { + if (err) { + return done(err); + } + utxos.length.should.equal(2); + utxos.should.deep.equal(expectedUtxos); + done(); + }); + }); }); describe('#_getBalanceFromMempool', function() {