Fixed tests for altered getAddressHistory and getAddressSummary calls.
This commit is contained in:
parent
a4cffe3bae
commit
678cb83d61
@ -9,7 +9,6 @@ var bitcore = require('bitcore-lib');
|
|||||||
var Unit = bitcore.Unit;
|
var Unit = bitcore.Unit;
|
||||||
var _ = bitcore.deps._;
|
var _ = bitcore.deps._;
|
||||||
var Encoding = require('./encoding');
|
var Encoding = require('./encoding');
|
||||||
var utils = require('../../utils');
|
|
||||||
var Transform = require('stream').Transform;
|
var Transform = require('stream').Transform;
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
@ -56,9 +55,7 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
|
|||||||
var txList = _.flatten(txLists);
|
var txList = _.flatten(txLists);
|
||||||
|
|
||||||
var results = {
|
var results = {
|
||||||
totalItems: txList.length,
|
totalCount: txList.length,
|
||||||
from: options.from,
|
|
||||||
to: options.to,
|
|
||||||
items: txList
|
items: txList
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -350,9 +347,33 @@ AddressService.prototype._getAddressHistory = function(address, options, callbac
|
|||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push(tx);
|
assert(tx.__height >- 0, 'tx must have a height');
|
||||||
|
self._header.getHeaderHash(tx.__height, function(err, hash) {
|
||||||
|
|
||||||
callback();
|
if(err) {
|
||||||
|
log.error(err);
|
||||||
|
txStream.emit('error', err);
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.__blockhash = hash;
|
||||||
|
|
||||||
|
var outputSatoshis = 0;
|
||||||
|
tx.outputs.forEach(function(output) {
|
||||||
|
outputSatoshis += output.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
var inputSatoshis = 0;
|
||||||
|
tx.__inputValues.forEach(function(value) {
|
||||||
|
inputSatoshis += value;
|
||||||
|
});
|
||||||
|
|
||||||
|
tx.__outputSatoshis = outputSatoshis;
|
||||||
|
tx.__inputSatoshis = inputSatoshis;
|
||||||
|
results.push(tx);
|
||||||
|
callback();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@ Encoding.prototype.decodeTransactionKey = function(buffer) {
|
|||||||
return buffer.slice(2).toString('hex');
|
return buffer.slice(2).toString('hex');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: maybe we should be storing the block hash here too.
|
||||||
Encoding.prototype.encodeTransactionValue = function(transaction) {
|
Encoding.prototype.encodeTransactionValue = function(transaction) {
|
||||||
var heightBuffer = new Buffer(4);
|
var heightBuffer = new Buffer(4);
|
||||||
heightBuffer.writeUInt32BE(transaction.__height);
|
heightBuffer.writeUInt32BE(transaction.__height);
|
||||||
|
|||||||
@ -38,7 +38,33 @@ TransactionService.prototype.getAPIMethods = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TransactionService.prototype.getDetailedTransaction = function(txid, options, callback) {
|
TransactionService.prototype.getDetailedTransaction = function(txid, options, callback) {
|
||||||
this.getTransaction(txid, options, callback);
|
var self = this;
|
||||||
|
|
||||||
|
this.getTransaction(txid, options, function(err, tx) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tx) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
self._header.getHeaderHash(tx.__height, function(err, hash) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(hash, 'Tx must have a hash entry in header db for given height.');
|
||||||
|
|
||||||
|
tx.__blockhash = hash;
|
||||||
|
|
||||||
|
callback(null, tx);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionService.prototype.getTransaction = function(txid, options, callback) {
|
TransactionService.prototype.getTransaction = function(txid, options, callback) {
|
||||||
|
|||||||
@ -64,9 +64,7 @@ describe('Address Service', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(res).to.be.deep.equal({
|
expect(res).to.be.deep.equal({
|
||||||
totalItems: 3,
|
totalCount: 3,
|
||||||
from: 12,
|
|
||||||
to: 14,
|
|
||||||
items: [ {}, {}, {} ]
|
items: [ {}, {}, {} ]
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -76,22 +74,24 @@ describe('Address Service', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#_getAddresHistory', function() {
|
describe('#_getAddressHistory', function() {
|
||||||
it('should get the address history', function(done) {
|
it('should get the address history', function(done) {
|
||||||
var encoding = new Encoding(new Buffer('0001', 'hex'));
|
var encoding = new Encoding(new Buffer('0001', 'hex'));
|
||||||
addressService._encoding = encoding;
|
addressService._encoding = encoding;
|
||||||
|
var getHeaderHash = sandbox.stub().callsArgWith(1, null, 'aa');
|
||||||
|
addressService._header = { getHeaderHash: getHeaderHash };
|
||||||
var address = 'a';
|
var address = 'a';
|
||||||
var opts = { from: 12, to: 14 };
|
var opts = { from: 12, to: 14 };
|
||||||
var txid = '1c6ea4a55a3edaac0a05e93b52908f607376a8fdc5387c492042f8baa6c05085';
|
var txid = '1c6ea4a55a3edaac0a05e93b52908f607376a8fdc5387c492042f8baa6c05085';
|
||||||
var data = [ null, encoding.encodeAddressIndexKey(address, 123, txid, 1, 1) ];
|
var data = [ null, encoding.encodeAddressIndexKey(address, 123, txid, 1, 1) ];
|
||||||
var getTransaction = sandbox.stub().callsArgWith(2, null, {});
|
var getTransaction = sandbox.stub().callsArgWith(2, null, { __height: 123, outputs: [ { value: 1 } ], __inputValues: [ 1 ] });
|
||||||
addressService._tx = { getTransaction: getTransaction };
|
addressService._tx = { getTransaction: getTransaction };
|
||||||
|
|
||||||
var txidStream = new Readable();
|
var txidStream = new Readable();
|
||||||
|
|
||||||
txidStream._read = function() {
|
txidStream._read = function() {
|
||||||
txidStream.push(data.pop());
|
txidStream.push(data.pop());
|
||||||
}
|
};
|
||||||
|
|
||||||
var createReadStream = sandbox.stub().returns(txidStream);
|
var createReadStream = sandbox.stub().returns(txidStream);
|
||||||
addressService._db = { createKeyStream: createReadStream };
|
addressService._db = { createKeyStream: createReadStream };
|
||||||
@ -101,7 +101,22 @@ describe('Address Service', function() {
|
|||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
expect(getTransaction.calledOnce).to.be.true;
|
expect(getTransaction.calledOnce).to.be.true;
|
||||||
expect(res).to.deep.equal([{}]);
|
expect(res).to.deep.equal([
|
||||||
|
{
|
||||||
|
__blockhash: 'aa',
|
||||||
|
__height: 123,
|
||||||
|
__inputSatoshis: 1,
|
||||||
|
__inputValues: [
|
||||||
|
1
|
||||||
|
],
|
||||||
|
__outputSatoshis: 1,
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
value: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -125,7 +140,7 @@ describe('Address Service', function() {
|
|||||||
|
|
||||||
txidStream._read = function() {
|
txidStream._read = function() {
|
||||||
txidStream.push(data.pop());
|
txidStream.push(data.pop());
|
||||||
}
|
};
|
||||||
|
|
||||||
var createReadStream = sandbox.stub().returns(txidStream);
|
var createReadStream = sandbox.stub().returns(txidStream);
|
||||||
addressService._db = { createKeyStream: createReadStream };
|
addressService._db = { createKeyStream: createReadStream };
|
||||||
@ -181,14 +196,14 @@ describe('Address Service', function() {
|
|||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
expect(res[0]).to.deep.equal({
|
expect(res[0]).to.deep.equal({
|
||||||
address: "a",
|
address: 'a',
|
||||||
amount: 0.0012,
|
amount: 0.0012,
|
||||||
confirmations: 27,
|
confirmations: 27,
|
||||||
confirmationsFromCache: true,
|
confirmationsFromCache: true,
|
||||||
satoshis: 120000,
|
satoshis: 120000,
|
||||||
scriptPubKey: "76a91449f8c749a9960dc29b5cbe7d2397cea7d26611bb88ac",
|
scriptPubKey: '76a91449f8c749a9960dc29b5cbe7d2397cea7d26611bb88ac',
|
||||||
ts: 1546300800,
|
ts: 1546300800,
|
||||||
txid: "25e28f9fb0ada5353b7d98d85af5524b2f8df5b0b0e2d188f05968bceca603eb",
|
txid: '25e28f9fb0ada5353b7d98d85af5524b2f8df5b0b0e2d188f05968bceca603eb',
|
||||||
vout: 1
|
vout: 1
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user