2014-01-09 15:21:16 -08:00
|
|
|
#!/usr/bin/env node
|
2014-02-11 08:02:28 -08:00
|
|
|
|
2014-02-04 22:34:46 -08:00
|
|
|
'use strict';
|
2014-01-09 15:21:16 -08:00
|
|
|
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
2014-02-11 08:02:28 -08:00
|
|
|
var assert = require('assert'),
|
|
|
|
fs = require('fs'),
|
2014-03-10 11:06:10 -07:00
|
|
|
Address = require('../../app/models/Address'),
|
|
|
|
TransactionDb = require('../../lib/TransactionDb').default(),
|
2014-02-20 11:10:10 -08:00
|
|
|
addrValid = JSON.parse(fs.readFileSync('test/integration/addr.json')),
|
|
|
|
utxoValid = JSON.parse(fs.readFileSync('test/integration/utxo.json'));
|
2014-01-09 15:21:16 -08:00
|
|
|
|
2014-05-25 13:34:49 -07:00
|
|
|
var should = require('chai');
|
|
|
|
|
2014-02-11 08:02:28 -08:00
|
|
|
var txDb;
|
|
|
|
describe('Address balances', function() {
|
2014-05-25 13:34:49 -07:00
|
|
|
this.timeout(5000);
|
2014-01-09 15:21:16 -08:00
|
|
|
|
2014-02-04 22:34:46 -08:00
|
|
|
before(function(c) {
|
2014-03-10 11:06:10 -07:00
|
|
|
txDb = TransactionDb;
|
2014-02-04 22:34:46 -08:00
|
|
|
return c();
|
|
|
|
});
|
|
|
|
|
2014-02-11 08:02:28 -08:00
|
|
|
addrValid.forEach(function(v) {
|
2014-01-12 18:37:36 -08:00
|
|
|
if (v.disabled) {
|
2014-02-11 08:02:28 -08:00
|
|
|
console.log(v.addr + ' => disabled in JSON');
|
|
|
|
} else {
|
2014-02-11 12:06:34 -08:00
|
|
|
it('Address info for: ' + v.addr, function(done) {
|
2014-02-04 22:34:46 -08:00
|
|
|
var a = new Address(v.addr, txDb);
|
2014-01-12 18:37:36 -08:00
|
|
|
a.update(function(err) {
|
|
|
|
if (err) done(err);
|
2014-05-25 13:34:49 -07:00
|
|
|
v.addr.should.equal(a.addrStr);
|
2014-05-26 12:58:44 -07:00
|
|
|
|
|
|
|
if (v.unconfirmedTxApperances)
|
|
|
|
a.unconfirmedTxApperances.should.equal(v.unconfirmedTxApperances || 0, 'unconfirmedTxApperances');
|
|
|
|
if (v.unconfirmedBalanceSat)
|
|
|
|
a.unconfirmedBalanceSat.should.equal(v.unconfirmedBalanceSat || 0, 'unconfirmedBalanceSat');
|
2014-02-11 08:02:28 -08:00
|
|
|
if (v.txApperances)
|
2014-05-25 13:34:49 -07:00
|
|
|
a.txApperances.should.equal(v.txApperances, 'txApperances');
|
|
|
|
|
|
|
|
if (v.totalReceived) a.totalReceived.should.equal(v.totalReceived,'totalReceived');
|
2014-02-11 08:02:28 -08:00
|
|
|
if (v.totalSent) assert.equal(v.totalSent, a.totalSent, 'send: ' + a.totalSent);
|
2014-01-14 07:58:45 -08:00
|
|
|
|
2014-02-05 10:08:39 -08:00
|
|
|
if (v.balance) assert.equal(v.balance, a.balance, 'balance: ' + a.balance);
|
2014-01-14 07:58:45 -08:00
|
|
|
|
2014-01-12 18:37:36 -08:00
|
|
|
if (v.transactions) {
|
2014-01-13 15:38:51 -08:00
|
|
|
|
2014-02-11 08:02:28 -08:00
|
|
|
v.transactions.forEach(function(tx) {
|
|
|
|
assert(a.transactions.indexOf(tx) > -1, 'have tx ' + tx);
|
2014-01-12 18:37:36 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
2014-02-11 08:02:28 -08:00
|
|
|
});
|
2014-05-25 13:34:49 -07:00
|
|
|
|
|
|
|
it('Address info (cache) for: ' + v.addr, function(done) {
|
|
|
|
var a = new Address(v.addr, txDb);
|
|
|
|
a.update(function(err) {
|
|
|
|
if (err) done(err);
|
|
|
|
v.addr.should.equal(a.addrStr);
|
|
|
|
a.unconfirmedTxApperances.should.equal(v.unconfirmedTxApperances || 0, 'unconfirmedTxApperances');
|
|
|
|
a.unconfirmedBalanceSat.should.equal(v.unconfirmedBalanceSat || 0, 'unconfirmedBalanceSat');
|
|
|
|
if (v.txApperances)
|
|
|
|
a.txApperances.should.equal(v.txApperances, 'txApperances');
|
|
|
|
|
|
|
|
if (v.totalReceived) a.totalReceived.should.equal(v.totalReceived,'totalReceived');
|
|
|
|
if (v.totalSent) assert.equal(v.totalSent, a.totalSent, 'send: ' + a.totalSent);
|
|
|
|
if (v.balance) assert.equal(v.balance, a.balance, 'balance: ' + a.balance);
|
|
|
|
done();
|
|
|
|
},1);
|
|
|
|
});
|
2014-01-12 18:37:36 -08:00
|
|
|
}
|
2014-01-09 15:21:16 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2014-02-20 11:10:10 -08:00
|
|
|
|
2014-05-25 13:34:49 -07:00
|
|
|
//tested against https://api.biteasy.com/testnet/v1/addresses/2N1pLkosf6o8Ciqs573iwwgVpuFS6NbNKx5/unspent-outputs?per_page=40
|
2014-02-20 11:10:10 -08:00
|
|
|
describe('Address utxo', function() {
|
2014-05-25 13:34:49 -07:00
|
|
|
|
|
|
|
before(function(c) {
|
|
|
|
txDb = TransactionDb;
|
|
|
|
var l = utxoValid.length;
|
|
|
|
var d=0;
|
|
|
|
|
|
|
|
utxoValid.forEach(function(v) {
|
|
|
|
//console.log('Deleting cache for', v.addr); //TODO
|
|
|
|
txDb.deleteCacheForAddress(v.addr,function(){
|
|
|
|
if (d++ == l-1) return c();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-02-20 11:10:10 -08:00
|
|
|
utxoValid.forEach(function(v) {
|
|
|
|
if (v.disabled) {
|
|
|
|
console.log(v.addr + ' => disabled in JSON');
|
|
|
|
} else {
|
|
|
|
it('Address utxo for: ' + v.addr, function(done) {
|
2014-05-25 13:34:49 -07:00
|
|
|
this.timeout(2000);
|
2014-02-20 11:10:10 -08:00
|
|
|
var a = new Address(v.addr, txDb);
|
|
|
|
a.getUtxo(function(err, utxo) {
|
|
|
|
if (err) done(err);
|
|
|
|
assert.equal(v.addr, a.addrStr);
|
2014-05-25 13:34:49 -07:00
|
|
|
if (v.length) utxo.length.should.equal(v.length, 'Unspent count');
|
|
|
|
if (v.tx0id) {
|
|
|
|
var x=utxo.filter(function(x){
|
|
|
|
return x.txid === v.tx0id;
|
|
|
|
});
|
|
|
|
assert(x,'found output');
|
|
|
|
x.length.should.equal(1,'found output');
|
|
|
|
x[0].scriptPubKey.should.equal(v.tx0scriptPubKey,'scriptPubKey');
|
|
|
|
x[0].amount.should.equal(v.tx0amount,'amount');
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('Address utxo (cached) for: ' + v.addr, function(done) {
|
|
|
|
this.timeout(2000);
|
|
|
|
var a = new Address(v.addr, txDb);
|
|
|
|
a.getUtxo(function(err, utxo) {
|
|
|
|
if (err) done(err);
|
|
|
|
assert.equal(v.addr, a.addrStr);
|
|
|
|
if (v.length) utxo.length.should.equal(v.length, 'Unspent count');
|
|
|
|
if (v.tx0id) {
|
|
|
|
var x=utxo.filter(function(x){
|
|
|
|
return x.txid === v.tx0id;
|
|
|
|
});
|
|
|
|
assert(x,'found output');
|
|
|
|
x.length.should.equal(1,'found output');
|
|
|
|
x[0].scriptPubKey.should.equal(v.tx0scriptPubKey,'scriptPubKey');
|
|
|
|
x[0].amount.should.equal(v.tx0amount,'amount');
|
|
|
|
}
|
2014-02-20 11:10:10 -08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|