2014-01-27 07:51:11 -08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-25 13:34:49 -07:00
|
|
|
var should = require('chai');
|
2014-02-04 18:50:18 -08:00
|
|
|
var assert = require('assert'),
|
2014-01-27 07:51:11 -08:00
|
|
|
fs = require('fs'),
|
|
|
|
util = require('util'),
|
2014-03-10 11:06:10 -07:00
|
|
|
TransactionDb = require('../../lib/TransactionDb').default();
|
2014-01-27 07:51:11 -08:00
|
|
|
|
2014-02-03 22:22:58 -08:00
|
|
|
var txItemsValid = JSON.parse(fs.readFileSync('test/integration/txitems.json'));
|
2014-02-04 21:48:54 -08:00
|
|
|
var txDb;
|
2014-01-27 07:51:11 -08:00
|
|
|
|
2014-02-04 18:50:18 -08:00
|
|
|
describe('TransactionDb fromIdWithInfo', function(){
|
|
|
|
|
|
|
|
before(function(c) {
|
2014-03-10 11:06:10 -07:00
|
|
|
txDb = TransactionDb;
|
2014-02-04 18:50:18 -08:00
|
|
|
return c();
|
|
|
|
});
|
|
|
|
|
2014-02-05 06:23:41 -08:00
|
|
|
|
2014-02-04 18:50:18 -08:00
|
|
|
var txid = '7e621eeb02874ab039a8566fd36f4591e65eca65313875221842c53de6907d6c';
|
|
|
|
it('tx info ' + txid, function(done) {
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromIdWithInfo(txid, function(err, tx) {
|
2014-02-04 18:50:18 -08:00
|
|
|
|
|
|
|
if (err) done(err);
|
|
|
|
assert.equal(tx.txid, txid);
|
|
|
|
assert(!tx.info.isCoinBase);
|
|
|
|
|
2014-05-23 17:23:44 -07:00
|
|
|
for(var i=0; i<20; i++) {
|
2014-02-04 18:50:18 -08:00
|
|
|
assert(parseFloat(tx.info.vin[i].value) === parseFloat(50), 'input '+i);
|
2014-05-23 17:23:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-25 13:34:49 -07:00
|
|
|
tx.info.vin[0].addr.should.equal('msGKGCy2i8wbKS5Fo1LbWUTJnf1GoFFG59');
|
|
|
|
tx.info.vin[1].addr.should.equal('mfye7oHsdrHbydtj4coPXCasKad2eYSv5P');
|
2014-02-04 18:50:18 -08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tx info', function(done) {
|
|
|
|
var txid = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237';
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromIdWithInfo(txid, function(err, tx) {
|
2014-02-04 18:50:18 -08:00
|
|
|
if (err) done(err);
|
|
|
|
assert.equal(tx.txid, txid);
|
|
|
|
assert(!tx.info.isCoinBase);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should pool tx\'s info from bitcoind', function(done) {
|
|
|
|
var txid = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237';
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromIdWithInfo(txid, function(err, tx) {
|
2014-02-04 18:50:18 -08:00
|
|
|
if (err) done(err);
|
|
|
|
assert.equal(tx.info.txid, txid);
|
|
|
|
assert.equal(tx.info.blockhash, '000000000185678d3d7ecc9962c96418174431f93fe20bf216d5565272423f74');
|
|
|
|
assert.equal(tx.info.valueOut, 1.66174);
|
|
|
|
assert.equal(tx.info.fees, 0.0005 );
|
|
|
|
assert.equal(tx.info.size, 226 );
|
|
|
|
assert(!tx.info.isCoinBase);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var txid1 = '2a104bab1782e9b6445583296d4a0ecc8af304e4769ceb64b890e8219c562399';
|
|
|
|
it('test a coinbase TX ' + txid1, function(done) {
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromIdWithInfo(txid1, function(err, tx) {
|
2014-02-04 18:50:18 -08:00
|
|
|
if (err) done(err);
|
|
|
|
assert(tx.info.isCoinBase);
|
|
|
|
assert.equal(tx.info.txid, txid1);
|
|
|
|
assert(!tx.info.feeds);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var txid22 = '666';
|
|
|
|
it('test invalid TX ' + txid22, function(done) {
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromIdWithInfo(txid22, function(err, tx) {
|
2014-02-04 18:50:18 -08:00
|
|
|
if (err && err.message.match(/must.be.hexadecimal/)) {
|
|
|
|
return done();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var txid23 = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca227';
|
|
|
|
it('test unexisting TX ' + txid23, function(done) {
|
|
|
|
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromIdWithInfo(txid23, function(err, tx) {
|
2014-02-04 18:50:18 -08:00
|
|
|
assert(!err);
|
|
|
|
assert(!tx);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var txid2 = '64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608';
|
|
|
|
it('create TX on the fly ' + txid2, function(done) {
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromIdWithInfo(txid2, function(err, tx) {
|
2014-02-04 18:50:18 -08:00
|
|
|
if (err) return done(err);
|
|
|
|
assert.equal(tx.info.txid, txid2);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
txid2 = '64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608';
|
|
|
|
it('test a broken TX ' + txid2, function(done) {
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromIdWithInfo(txid2, function(err, tx) {
|
2014-02-04 18:50:18 -08:00
|
|
|
if (err) return done(err);
|
|
|
|
assert.equal(tx.info.txid, txid2);
|
|
|
|
assert.equal(tx.info.vin[0].addr, 'n1JagbRWBDi6VMvG7HfZmXX74dB9eiHJzU');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TransactionDb Outs', function(){
|
2014-01-27 07:51:11 -08:00
|
|
|
|
2014-02-05 06:23:41 -08:00
|
|
|
before(function(c) {
|
2014-03-10 11:06:10 -07:00
|
|
|
txDb = TransactionDb;
|
2014-02-05 06:23:41 -08:00
|
|
|
return c();
|
|
|
|
});
|
|
|
|
|
2014-01-27 07:51:11 -08:00
|
|
|
txItemsValid.forEach( function(v) {
|
|
|
|
if (v.disabled) return;
|
2014-02-03 22:22:58 -08:00
|
|
|
it('test a processing tx ' + v.txid, function(done) {
|
|
|
|
this.timeout(60000);
|
2014-01-27 07:51:11 -08:00
|
|
|
|
|
|
|
// Remove first
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.removeFromTxId(v.txid, function() {
|
2014-01-27 07:51:11 -08:00
|
|
|
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromTxId( v.txid, function(err, readItems) {
|
2014-02-03 22:22:58 -08:00
|
|
|
assert.equal(readItems.length,0);
|
2014-01-27 07:51:11 -08:00
|
|
|
|
2014-02-03 22:22:58 -08:00
|
|
|
var unmatch=[];
|
2014-05-23 17:23:44 -07:00
|
|
|
txDb.addMany([v.txid], function(err) {
|
2014-02-03 22:22:58 -08:00
|
|
|
if (err) return done(err);
|
2014-01-27 07:51:11 -08:00
|
|
|
|
2014-02-04 21:48:54 -08:00
|
|
|
txDb.fromTxId( v.txid, function(err, readItems) {
|
2014-02-03 22:22:58 -08:00
|
|
|
|
|
|
|
v.items.forEach(function(validItem){
|
|
|
|
unmatch[validItem.addr] =1;
|
|
|
|
});
|
|
|
|
assert.equal(readItems.length,v.items.length);
|
|
|
|
|
|
|
|
v.items.forEach(function(validItem){
|
|
|
|
var readItem = readItems.shift();
|
2014-01-27 07:51:11 -08:00
|
|
|
|
2014-02-03 22:22:58 -08:00
|
|
|
assert.equal(readItem.addr,validItem.addr);
|
|
|
|
assert.equal(readItem.value_sat,validItem.value_sat);
|
|
|
|
assert.equal(readItem.index,validItem.index);
|
|
|
|
assert.equal(readItem.spendIndex, null);
|
|
|
|
assert.equal(readItem.spendTxIdBuf, null);
|
|
|
|
delete unmatch[validItem.addr];
|
|
|
|
});
|
2014-01-29 10:10:36 -08:00
|
|
|
|
2014-02-03 22:22:58 -08:00
|
|
|
var valid = util.inspect(v.items, { depth: null });
|
|
|
|
assert(!Object.keys(unmatch).length,'\n\tUnmatchs:' + Object.keys(unmatch) + "\n\n" +valid + '\nvs.\n' + readItems);
|
|
|
|
return done();
|
|
|
|
|
|
|
|
});
|
2014-01-27 07:51:11 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-29 10:10:36 -08:00
|
|
|
|