From f957a57de848e4c3916e2ca9487b38312c656b5e Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 13 Jan 2014 19:57:13 -0300 Subject: [PATCH] addr tests work from simple txs --- app/models/Address.js | 22 +++++++++++++++------- test/model/addr.js | 9 +++++---- test/model/addr.json | 30 ++++++++++++++++++++---------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/app/models/Address.js b/app/models/Address.js index 05414886..ce6cccb6 100644 --- a/app/models/Address.js +++ b/app/models/Address.js @@ -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(); }); diff --git a/test/model/addr.js b/test/model/addr.js index 2a59f616..c19988e5 100644 --- a/test/model/addr.js +++ b/test/model/addr.js @@ -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(); diff --git a/test/model/addr.json b/test/model/addr.json index 22f42558..e669a1dd 100644 --- a/test/model/addr.json +++ b/test/model/addr.json @@ -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",