Browse Source

improve robustness & tests

feat/estimateFee-limit
Ivan Socolsky 8 years ago
parent
commit
785fc4676e
No known key found for this signature in database GPG Key ID: FAECE6A05FAA4F56
  1. 4
      lib/server.js
  2. 75
      test/integration/server.js

4
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;

75
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() {

Loading…
Cancel
Save