add tests to _updateAddressIndex
This commit is contained in:
parent
02f2234004
commit
1a68ca4fae
@ -276,14 +276,14 @@ AddressService.prototype.transactionHandler = function(txInfo, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
AddressService.prototype._updateAddressIndex = function(key, add) {
|
AddressService.prototype._updateAddressIndex = function(key, add) {
|
||||||
|
|
||||||
var currentValue = this.mempoolAddressIndex[key] || 0;
|
var currentValue = this.mempoolAddressIndex[key] || 0;
|
||||||
|
|
||||||
if(add) {
|
if(add) {
|
||||||
if (currentValue > 0)
|
if (currentValue > 0) {
|
||||||
this.mempoolAddressIndex[key] = currentValue + 1;
|
this.mempoolAddressIndex[key] = currentValue + 1;
|
||||||
else
|
} else {
|
||||||
this.mempoolAddressIndex[key] = 1;
|
this.mempoolAddressIndex[key] = 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (currentValue < 1) {
|
if (currentValue < 1) {
|
||||||
delete this.mempoolAddressIndex[key];
|
delete this.mempoolAddressIndex[key];
|
||||||
|
|||||||
@ -2433,6 +2433,56 @@ describe('Address Service', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe.only('#_updateAddressIndex', function() {
|
||||||
|
var as;
|
||||||
|
beforeEach(function(){
|
||||||
|
var testnode = {
|
||||||
|
services: {
|
||||||
|
bitcoind: {
|
||||||
|
on: sinon.stub()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
datadir: 'testdir'
|
||||||
|
};
|
||||||
|
as = new AddressService({
|
||||||
|
mempoolMemoryIndex: true,
|
||||||
|
node: testnode
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should add using 2 keys', function() {
|
||||||
|
_.values(as.mempoolAddressIndex).should.deep.equal([]);
|
||||||
|
as._updateAddressIndex('index1', true);
|
||||||
|
as._updateAddressIndex('index1', true);
|
||||||
|
as._updateAddressIndex('index1', true);
|
||||||
|
as._updateAddressIndex('index1', true);
|
||||||
|
as._updateAddressIndex('index2', true);
|
||||||
|
as._updateAddressIndex('index2', true);
|
||||||
|
as.mempoolAddressIndex.should.deep.equal({
|
||||||
|
"index1": 4,
|
||||||
|
"index2": 2
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should add/remove using 2 keys', function() {
|
||||||
|
_.values(as.mempoolAddressIndex).should.deep.equal([]);
|
||||||
|
as._updateAddressIndex('index1', true);
|
||||||
|
as._updateAddressIndex('index1', true);
|
||||||
|
as._updateAddressIndex('index1', true);
|
||||||
|
as._updateAddressIndex('index1', true);
|
||||||
|
as._updateAddressIndex('index1', false);
|
||||||
|
|
||||||
|
as._updateAddressIndex('index2', true);
|
||||||
|
as._updateAddressIndex('index2', true);
|
||||||
|
as._updateAddressIndex('index2', false);
|
||||||
|
as._updateAddressIndex('index2', false);
|
||||||
|
as._updateAddressIndex('index2', false);
|
||||||
|
as.mempoolAddressIndex.should.deep.equal({
|
||||||
|
"index1": 3
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('#_getAddressMempoolSummary', function() {
|
describe('#_getAddressMempoolSummary', function() {
|
||||||
it('skip if options not enabled', function(done) {
|
it('skip if options not enabled', function(done) {
|
||||||
var testnode = {
|
var testnode = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user