fix tests

This commit is contained in:
Matias Alejo Garcia 2016-02-09 10:57:40 -05:00
parent 9f87156adc
commit d0c2fa61d8
4 changed files with 23 additions and 11 deletions

View File

@ -19,6 +19,15 @@ exports.encodeSpentIndexSyncKey = function(txidBuffer, outputIndex) {
return key.toString('binary'); return key.toString('binary');
}; };
exports.encodeMempoolAddressIndexKey = function(hashBuffer, hashTypeBuffer) {
var key = Buffer.concat([
hashBuffer,
hashTypeBuffer,
]);
return key;
};
exports.encodeOutputKey = function(hashBuffer, hashTypeBuffer, height, txidBuffer, outputIndex) { exports.encodeOutputKey = function(hashBuffer, hashTypeBuffer, height, txidBuffer, outputIndex) {
var heightBuffer = new Buffer(4); var heightBuffer = new Buffer(4);
heightBuffer.writeUInt32BE(height); heightBuffer.writeUInt32BE(height);

View File

@ -307,12 +307,12 @@ AddressService.prototype.updateMempoolIndex = function(tx, add, callback) {
continue; continue;
} }
var hashBufferHex = addressInfo.hashBuffer.toString('hex'); var addressIndexKey = encoding.encodeMempoolAddressIndexKey(addressInfo.hashBuffer, addressInfo.hashTypeBuffer);
if(add) { if(add) {
this.mempoolAddressIndex[hashBufferHex] = true; this.mempoolAddressIndex[addressIndexKey] = true;
} else { } else {
delete this.mempoolAddressIndex[hashBufferHex]; delete this.mempoolAddressIndex[addressIndexKey];
} }
// Update output index // Update output index
@ -407,11 +407,12 @@ AddressService.prototype.updateMempoolIndex = function(tx, add, callback) {
value: inputValue value: inputValue
}); });
var inputHashBufferHex = inputHashBuffer.toString('hex'); var addressIndexKey = encoding.encodeMempoolAddressIndexKey(inputHashBuffer, inputHashType);
if(add) { if(add) {
this.mempoolAddressIndex[inputHashBufferHex] = true; this.mempoolAddressIndex[addressIndexKey] = true;
} else { } else {
delete this.mempoolAddressIndex[inputHashBufferHex]; delete this.mempoolAddressIndex[addressIndexKey];
} }
} }
@ -1523,9 +1524,9 @@ AddressService.prototype._getAddressMempoolSummary = function(address, options,
var addressStr = address.toString(); var addressStr = address.toString();
var hashBuffer = address.hashBuffer; var hashBuffer = address.hashBuffer;
var hashTypeBuffer = constants.HASH_TYPES_MAP[address.type]; var hashTypeBuffer = constants.HASH_TYPES_MAP[address.type];
var hashBufferHex = hashBuffer.toString('hex'); var addressIndexKey = encoding.encodeMempoolAddressIndexKey(hashBuffer, hashTypeBuffer);
if(!this.mempoolAddressIndex[hashBufferHex]) { if(!this.mempoolAddressIndex[addressIndexKey]) {
return callback(null, result); return callback(null, result);
} }

View File

@ -122,7 +122,7 @@ describe('Address Service History', function() {
history.get(function() { history.get(function() {
history.node.services.address.getAddressSummary.callCount.should.equal(1); history.node.services.address.getAddressSummary.callCount.should.equal(1);
history.node.services.address.getAddressSummary.args[0][0].should.equal(address); history.node.services.address.getAddressSummary.args[0][0].should.equal(address);
history.node.services.address.getAddressSummary.args[0][1].should.equal({ history.node.services.address.getAddressSummary.args[0][1].should.deep.equal({
noBalance: true, noBalance: true,
}); });
history._paginateWithDetails.callCount.should.equal(1); history._paginateWithDetails.callCount.should.equal(1);
@ -157,6 +157,7 @@ describe('Address Service History', function() {
history.node.services.address.getAddressSummary.args[0][0].should.equal(address); history.node.services.address.getAddressSummary.args[0][0].should.equal(address);
history.node.services.address.getAddressSummary.args[0][1].should.deep.equal({ history.node.services.address.getAddressSummary.args[0][1].should.deep.equal({
fullTxList: true, fullTxList: true,
noBalance: true,
}); });
history._paginateWithDetails.callCount.should.equal(1); history._paginateWithDetails.callCount.should.equal(1);
history._paginateWithDetails.args[0][0].should.equal(txids); history._paginateWithDetails.args[0][0].should.equal(txids);

View File

@ -2521,8 +2521,9 @@ describe('Address Service', function() {
); );
as.mempoolSpentIndex[spentIndexSyncKey] = true; as.mempoolSpentIndex[spentIndexSyncKey] = true;
var hashBufferHex = address.hashBuffer.toString('hex'); var hashTypeBuffer = constants.HASH_TYPES_MAP[address.type];
as.mempoolAddressIndex[hashBufferHex] = true; var addressIndex = encoding.encodeMempoolAddressIndexKey(address.hashBuffer, hashTypeBuffer);
as.mempoolAddressIndex[addressIndex] = true;
as._getInputsMempool = sinon.stub().callsArgWith(3, null, mempoolInputs); as._getInputsMempool = sinon.stub().callsArgWith(3, null, mempoolInputs);
as._getOutputsMempool = sinon.stub().callsArgWith(3, null, mempoolOutputs); as._getOutputsMempool = sinon.stub().callsArgWith(3, null, mempoolOutputs);