add tests
This commit is contained in:
parent
bc39a5e480
commit
b11ab97739
@ -293,6 +293,25 @@ describe('Node Functionality', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('correctly give the summary for the address', function(done) {
|
||||||
|
var options = {
|
||||||
|
queryMempool: false
|
||||||
|
};
|
||||||
|
node.services.address.getAddressSummary(address, options, function(err, results) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
results.totalReceived.should.equal(1000000000);
|
||||||
|
results.totalSpent.should.equal(0);
|
||||||
|
results.balance.should.equal(1000000000);
|
||||||
|
results.unconfirmedBalance.should.equal(1000000000);
|
||||||
|
results.appearances.should.equal(1);
|
||||||
|
results.unconfirmedAppearances.should.equal(0);
|
||||||
|
results.txids.length.should.equal(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('History', function() {
|
describe('History', function() {
|
||||||
|
|
||||||
this.timeout(20000);
|
this.timeout(20000);
|
||||||
|
|||||||
@ -890,6 +890,8 @@ AddressService.prototype.getAddressHistory = function(addresses, options, callba
|
|||||||
* txids - list of txids (unless noTxList is set)
|
* txids - list of txids (unless noTxList is set)
|
||||||
*
|
*
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
|
* @param {Object} options
|
||||||
|
* @param {Boolean} options.noTxList - if set, txid array will not be included
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
AddressService.prototype.getAddressSummary = function(address, options, callback) {
|
AddressService.prototype.getAddressSummary = function(address, options, callback) {
|
||||||
|
|||||||
@ -31,7 +31,7 @@ describe('Address Service', function() {
|
|||||||
it('should return the correct methods', function() {
|
it('should return the correct methods', function() {
|
||||||
var am = new AddressService({node: mocknode});
|
var am = new AddressService({node: mocknode});
|
||||||
var methods = am.getAPIMethods();
|
var methods = am.getAPIMethods();
|
||||||
methods.length.should.equal(5);
|
methods.length.should.equal(6);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -954,4 +954,81 @@ describe('Address Service', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('#getAddressSummary', function() {
|
||||||
|
var node = {
|
||||||
|
services: {
|
||||||
|
bitcoind: {
|
||||||
|
isSpent: sinon.stub().returns(false),
|
||||||
|
on: sinon.spy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var inputs = [
|
||||||
|
{
|
||||||
|
"txid": "9f183412de12a6c1943fc86c390174c1cde38d709217fdb59dcf540230fa58a6",
|
||||||
|
"height": -1,
|
||||||
|
"confirmations": 0,
|
||||||
|
"addresses": {
|
||||||
|
"mpkDdnLq26djg17s6cYknjnysAm3QwRzu2": {
|
||||||
|
"outputIndexes": [],
|
||||||
|
"inputIndexes": [
|
||||||
|
3
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"address": "mpkDdnLq26djg17s6cYknjnysAm3QwRzu2"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var outputs = [
|
||||||
|
{
|
||||||
|
"address": "mpkDdnLq26djg17s6cYknjnysAm3QwRzu2",
|
||||||
|
"txid": "689e9f543fa4aa5b2daa3b5bb65f9a00ad5aa1a2e9e1fc4e11061d85f2aa9bc5",
|
||||||
|
"outputIndex": 0,
|
||||||
|
"height": 556351,
|
||||||
|
"satoshis": 3487110,
|
||||||
|
"script": "76a914653b58493c2208481e0902a8ffb97b8112b13fe188ac",
|
||||||
|
"confirmations": 13190
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var as = new AddressService({node: node});
|
||||||
|
as.getInputs = sinon.stub().callsArgWith(2, null, inputs);
|
||||||
|
as.getOutputs = sinon.stub().callsArgWith(2, null, outputs);
|
||||||
|
as.mempoolSpentIndex = {
|
||||||
|
'689e9f543fa4aa5b2daa3b5bb65f9a00ad5aa1a2e9e1fc4e11061d85f2aa9bc5-0': true
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should handle unconfirmed and confirmed outputs and inputs', function(done) {
|
||||||
|
as.getAddressSummary('mpkDdnLq26djg17s6cYknjnysAm3QwRzu2', {}, function(err, summary) {
|
||||||
|
should.not.exist(err);
|
||||||
|
summary.totalReceived.should.equal(3487110);
|
||||||
|
summary.totalSpent.should.equal(0);
|
||||||
|
summary.balance.should.equal(3487110);
|
||||||
|
summary.unconfirmedBalance.should.equal(0);
|
||||||
|
summary.appearances.should.equal(1);
|
||||||
|
summary.unconfirmedAppearances.should.equal(1);
|
||||||
|
summary.txids.should.deep.equal(
|
||||||
|
[
|
||||||
|
'9f183412de12a6c1943fc86c390174c1cde38d709217fdb59dcf540230fa58a6',
|
||||||
|
'689e9f543fa4aa5b2daa3b5bb65f9a00ad5aa1a2e9e1fc4e11061d85f2aa9bc5'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('noTxList should not include txids array', function(done) {
|
||||||
|
as.getAddressSummary('mpkDdnLq26djg17s6cYknjnysAm3QwRzu2', {noTxList: true}, function(err, summary) {
|
||||||
|
should.not.exist(err);
|
||||||
|
summary.totalReceived.should.equal(3487110);
|
||||||
|
summary.totalSpent.should.equal(0);
|
||||||
|
summary.balance.should.equal(3487110);
|
||||||
|
summary.unconfirmedBalance.should.equal(0);
|
||||||
|
summary.appearances.should.equal(1);
|
||||||
|
summary.unconfirmedAppearances.should.equal(1);
|
||||||
|
should.not.exist(summary.txids);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user