diff --git a/lib/server.js b/lib/server.js index 7a0d471..207a036 100644 --- a/lib/server.js +++ b/lib/server.js @@ -2921,7 +2921,9 @@ WalletService.prototype.getTxHistory = function(opts, cb) { var level = _.find(levels, { level: 'superEconomy' }); - if (level) { + if (!level || !level.nbBlocks) { + log.debug('Cannot compute super economy fee level from blockchain'); + } else { var minFeePerKb = level.feePerKb; _.each(finalTxs, function(tx) { tx.lowFees = tx.feePerKb < minFeePerKb; diff --git a/test/integration/server.js b/test/integration/server.js index c372f5c..110dbf0 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -6027,7 +6027,6 @@ describe('Wallet service', function() { address: mainAddresses[0].address, amount: 200, }], - size: 500, }]; helpers.stubHistory(txs); server.getTxHistory({}, function(err, txs) { @@ -6039,7 +6038,6 @@ describe('Wallet service', function() { tx.amount.should.equal(200); tx.fees.should.equal(100); tx.time.should.equal(20); - tx.lowFees.should.be.true; done(); }); }); @@ -6307,6 +6305,79 @@ describe('Wallet service', function() { done(); }); }); + it('should set lowFees atribute for sub-superEconomy level fees', function(done) { + helpers.stubFeeLevels({ + 24: 10000, + }); + server._normalizeTxHistory = sinon.stub().returnsArg(0); + var txs = [{ + txid: '1', + confirmations: 1, + fees: 100, + time: 20, + inputs: [{ + address: 'external', + amount: 500, + }], + outputs: [{ + address: mainAddresses[0].address, + amount: 200, + }], + size: 500, + }, { + txid: '2', + confirmations: 1, + fees: 6000, + time: 20, + inputs: [{ + address: 'external', + amount: 500, + }], + outputs: [{ + address: mainAddresses[0].address, + amount: 200, + }], + size: 500, + }]; + helpers.stubHistory(txs); + server.getTxHistory({}, function(err, txs) { + should.not.exist(err); + var tx = txs[0]; + tx.feePerKb.should.equal(200); + tx.lowFees.should.be.true; + var tx = txs[1]; + tx.feePerKb.should.equal(12000); + tx.lowFees.should.be.false; + done(); + }); + }); + it('should get tx history even if fee levels are unavailable', function(done) { + blockchainExplorer.estimateFee = sinon.stub().yields('dummy error'); + server._normalizeTxHistory = sinon.stub().returnsArg(0); + var txs = [{ + txid: '1', + confirmations: 1, + fees: 100, + time: 20, + inputs: [{ + address: 'external', + amount: 500, + }], + outputs: [{ + address: mainAddresses[0].address, + amount: 200, + }], + size: 500, + }]; + helpers.stubHistory(txs); + server.getTxHistory({}, function(err, txs) { + should.not.exist(err); + var tx = txs[0]; + tx.feePerKb.should.equal(200); + should.not.exist(tx.lowFees); + done(); + }); + }); }); describe('#getTxHistory cache', function() {