addr tests work from simple txs
This commit is contained in:
parent
d6e2415822
commit
f957a57de8
|
@ -28,13 +28,21 @@ function spec() {
|
|||
|
||||
|
||||
Address.prototype.__defineGetter__('balance', function(){
|
||||
|
||||
console.log('#################### '+this.balanceSat);
|
||||
|
||||
|
||||
return this.balanceSat / BitcoreUtil.COIN;
|
||||
return parseFloat(this.balanceSat) / parseFloat(BitcoreUtil.COIN);
|
||||
});
|
||||
|
||||
|
||||
Address.prototype.__defineGetter__('totalReceived', function(){
|
||||
return parseFloat(this.totalReceivedSat) / parseFloat(BitcoreUtil.COIN);
|
||||
});
|
||||
|
||||
|
||||
Address.prototype.__defineGetter__('totalSent', function(){
|
||||
return parseFloat(this.totalSentSat) / parseFloat(BitcoreUtil.COIN);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Address.prototype.update = function(next) {
|
||||
|
||||
if (! this.addrStr) {
|
||||
|
@ -58,9 +66,9 @@ console.log('#################### '+this.balanceSat);
|
|||
that.transactions.push(txItem.txid);
|
||||
|
||||
if (txItem.value_sat > 0)
|
||||
that.totalSentSat += txItem.value_sat;
|
||||
that.totalReceivedSat += txItem.value_sat;
|
||||
else
|
||||
that.totalReceivedSat += Math.abs(txItem.value_sat);
|
||||
that.totalSentSat += Math.abs(txItem.value_sat);
|
||||
});
|
||||
return cb();
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ var
|
|||
mongoose= require('mongoose'),
|
||||
addrValid = JSON.parse(fs.readFileSync('test/model/addr.json'));
|
||||
|
||||
describe('Address update', function(){
|
||||
describe('Address balances', function(){
|
||||
|
||||
before(function(done) {
|
||||
mongoose.connect(config.db);
|
||||
|
@ -27,21 +27,22 @@ describe('Address update', function(){
|
|||
console.log(v.addr + " => disabled in JSON");
|
||||
}
|
||||
else {
|
||||
it('should retrieve the correct info for:' + v.addr, function(done) {
|
||||
it('Info for:' + v.addr, function(done) {
|
||||
this.timeout(5000);
|
||||
|
||||
var a = new Address(v.addr);
|
||||
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
|
||||
assert.equal(v.addr, a.addrStr);
|
||||
console.log("TX count:" + a.transactions.length);
|
||||
|
||||
if (v.balance) assert.equal(v.balance, a.balance);
|
||||
if (v.totalReceived) assert.equal(v.totalReceived, a.totalReceived);
|
||||
if (v.totalSent) assert.equal(v.totalSent, a.totalSent);
|
||||
if (v.transactions) {
|
||||
v.transactions.forEach( function(tx) {
|
||||
assert(tx in a.inTransactions);
|
||||
assert(tx in a.transactions);
|
||||
});
|
||||
}
|
||||
done();
|
||||
|
|
|
@ -1,17 +1,31 @@
|
|||
[
|
||||
{
|
||||
"addr": "mjRmkmYzvZN3cA3aBKJgYJ65epn3WCG84H"
|
||||
"addr": "mgqvRGJMwR9JU5VhJ3x9uX9MTkzTsmmDgQ",
|
||||
"balance": 43.1
|
||||
},
|
||||
{
|
||||
"addr": "mp3Rzxx9s1A21SY3sjJ3CQoa2Xjph7e5eS",
|
||||
"balance": 0,
|
||||
"totalReceived": 50,
|
||||
"totalSent": 50.0
|
||||
}
|
||||
,
|
||||
},
|
||||
{
|
||||
"addr": "mgqvRGJMwR9JU5VhJ3x9uX9MTkzTsmmDgQ",
|
||||
"balance": 43.1
|
||||
"addr": "muyg1K5WsHkfMVCkUXU2y7Xp5ZD6RGzCeH",
|
||||
"balance": 0.38571339,
|
||||
"totalReceived": 0.38571339,
|
||||
"totalSent": 0
|
||||
},
|
||||
{
|
||||
"addr": "mhPEfAmeKVwT7arwMYbhwnL2TfwuWbP4r4",
|
||||
"balance": 1065,
|
||||
"totalReceived": 1069,
|
||||
"totalSent": 4
|
||||
},
|
||||
{
|
||||
"addr": "n47CfqnKWdNwqY1UWxTmNJAqYutFxdH3zY",
|
||||
"balance": 0,
|
||||
"totalReceived":26.4245,
|
||||
"totalSent": 26.4245
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
|
@ -19,11 +33,7 @@
|
|||
"balance": 910.39522682,
|
||||
"totalReceived": 910.39522682,
|
||||
"totalSent": 0
|
||||
}
|
||||
,
|
||||
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
"disabled":1,
|
||||
"addr": "mjRmkmYzvZN3cA3aBKJgYJ65epn3WCG84H",
|
||||
|
|
Loading…
Reference in New Issue