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