commit
ec181e2c9e
@ -1,174 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
|
||||
|
||||
var should = require('chai');
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
util = require('util'),
|
||||
TransactionDb = require('../../lib/TransactionDb').default();
|
||||
|
||||
var txItemsValid = JSON.parse(fs.readFileSync('test/integration/txitems.json'));
|
||||
var txDb;
|
||||
|
||||
describe.skip('TransactionDb fromIdWithInfo', function(){
|
||||
|
||||
before(function(c) {
|
||||
txDb = TransactionDb;
|
||||
return c();
|
||||
});
|
||||
|
||||
|
||||
var txid = '7e621eeb02874ab039a8566fd36f4591e65eca65313875221842c53de6907d6c';
|
||||
it('tx info ' + txid, function(done) {
|
||||
txDb.fromIdWithInfo(txid, function(err, tx) {
|
||||
|
||||
if (err) done(err);
|
||||
assert.equal(tx.txid, txid);
|
||||
assert(!tx.info.isCoinBase);
|
||||
|
||||
for(var i=0; i<20; i++) {
|
||||
assert(parseFloat(tx.info.vin[i].value) === parseFloat(50), 'input '+i);
|
||||
}
|
||||
|
||||
|
||||
tx.info.vin[0].addr.should.equal('msGKGCy2i8wbKS5Fo1LbWUTJnf1GoFFG59');
|
||||
tx.info.vin[1].addr.should.equal('mfye7oHsdrHbydtj4coPXCasKad2eYSv5P');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('tx info', function(done) {
|
||||
var txid = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237';
|
||||
txDb.fromIdWithInfo(txid, function(err, tx) {
|
||||
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';
|
||||
txDb.fromIdWithInfo(txid, function(err, tx) {
|
||||
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) {
|
||||
txDb.fromIdWithInfo(txid1, function(err, tx) {
|
||||
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) {
|
||||
txDb.fromIdWithInfo(txid22, function(err, tx) {
|
||||
if (err && err.message.match(/must.be.hexadecimal/)) {
|
||||
return done();
|
||||
}
|
||||
else {
|
||||
return done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var txid23 = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca227';
|
||||
it('test unexisting TX ' + txid23, function(done) {
|
||||
|
||||
txDb.fromIdWithInfo(txid23, function(err, tx) {
|
||||
assert(!err);
|
||||
assert(!tx);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
var txid2 = '64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608';
|
||||
it('create TX on the fly ' + txid2, function(done) {
|
||||
txDb.fromIdWithInfo(txid2, function(err, tx) {
|
||||
if (err) return done(err);
|
||||
assert.equal(tx.info.txid, txid2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
txid2 = '64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608';
|
||||
it('test a broken TX ' + txid2, function(done) {
|
||||
txDb.fromIdWithInfo(txid2, function(err, tx) {
|
||||
if (err) return done(err);
|
||||
assert.equal(tx.info.txid, txid2);
|
||||
assert.equal(tx.info.vin[0].addr, 'n1JagbRWBDi6VMvG7HfZmXX74dB9eiHJzU');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('TransactionDb Outs', function(){
|
||||
|
||||
before(function(c) {
|
||||
txDb = TransactionDb;
|
||||
return c();
|
||||
});
|
||||
|
||||
txItemsValid.forEach( function(v) {
|
||||
if (v.disabled) return;
|
||||
it('test a processing tx ' + v.txid, function(done) {
|
||||
this.timeout(60000);
|
||||
|
||||
// Remove first
|
||||
txDb.removeFromTxId(v.txid, function() {
|
||||
|
||||
txDb.fromTxId( v.txid, function(err, readItems) {
|
||||
assert.equal(readItems.length,0);
|
||||
|
||||
var unmatch=[];
|
||||
txDb.addMany([v.txid], function(err) {
|
||||
if (err) return done(err);
|
||||
|
||||
txDb.fromTxId( v.txid, function(err, readItems) {
|
||||
|
||||
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();
|
||||
|
||||
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];
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,59 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
|
||||
|
||||
var
|
||||
assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
util = require('util'),
|
||||
async = require('async'),
|
||||
config = require('../../config/config'),
|
||||
TransactionDb = require('../../lib/TransactionDb').default();
|
||||
|
||||
var spentValid = JSON.parse(fs.readFileSync('test/integration/spent.json'));
|
||||
|
||||
var txDb;
|
||||
|
||||
describe.skip('TransactionDb Expenses', function(){
|
||||
|
||||
before(function(c) {
|
||||
txDb = TransactionDb;
|
||||
|
||||
// lets spend!
|
||||
async.each(Object.keys(spentValid),
|
||||
function(txid,c_out) {
|
||||
async.each(spentValid[txid],
|
||||
function(i,c_in) {
|
||||
txDb.addMany([i.txid], function(err) {
|
||||
return c_in();
|
||||
});
|
||||
},
|
||||
function(err) {
|
||||
return c_out();
|
||||
}
|
||||
);
|
||||
},
|
||||
function(err) {
|
||||
return c();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Object.keys(spentValid).forEach( function(txid) {
|
||||
it('test result of spending tx ' + txid, function(done) {
|
||||
var s = spentValid[txid];
|
||||
var c=0;
|
||||
txDb.fromTxId( txid, function(err, readItems) {
|
||||
s.forEach( function(v) {
|
||||
assert.equal(readItems[c].spentTxId,v.txid);
|
||||
assert.equal(readItems[c].spentIndex,v.n);
|
||||
c++;
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,366 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var should = require('chai');
|
||||
|
||||
var
|
||||
assert = require('assert'),
|
||||
async = require('async'),
|
||||
HistoricSync = require('../../lib/HistoricSync');
|
||||
|
||||
var s;
|
||||
var b = [
|
||||
'00000000c4cbd75af741f3a2b2ff72d9ed4d83a048462c1efe331be31ccf006b', //0 B#16
|
||||
'00000000fe198cce4c8abf9dca0fee1182cb130df966cc428ad2a230df8da743', //1
|
||||
'000000008d55c3e978639f70af1d2bf1fe6f09cb3143e104405a599215c89a48', //2
|
||||
'000000009b3bca4909f38313f2746120129cce4a699a1f552390955da470c5a9', //3
|
||||
'00000000ede57f31cc598dc241d129ccb4d8168ef112afbdc870dc60a85f5dd3', //4 B#20
|
||||
'000000001a29aff8154de6230a4909a3a971c52ae590006e00fddff33f9e3773', //5 B#21
|
||||
];
|
||||
var t = [
|
||||
'd08582d3711f75d085c618874fb0d049ae09d5ec95ec6f5abd289f4b54712c54', // TX from B#16
|
||||
'1729001087e0cebea8d14de1653d5cf59628d9746bc1ae65f776f1cbaff7ebad', //1
|
||||
'cf53d7ccd83a099acfbc319ee10c1e3b10e3d42ba675b569fdd6b69cb8d2db4e', //2
|
||||
'73a4988adf462b6540cfa59097804174b298cfa439f73c1a072c2c6fbdbe57c7', //3
|
||||
'd45f9da73619799e9d7bd03cc290e70875ea4cbad56b8bffa15135fbbb3df9ea', //4 Tx from B20
|
||||
];
|
||||
|
||||
var initialTest = function(cb) {
|
||||
async.each([2,3,4], function(i,c) {
|
||||
s.sync.bDb.getPrev(b[i], function(err, p) {
|
||||
assert.equal(p,b[i-1]);
|
||||
return c();
|
||||
});
|
||||
}, function() {
|
||||
async.each([0,1,2,3,4], function(i,c) {
|
||||
s.sync.bDb.has(b[i], function(err, p) {
|
||||
assert(p);
|
||||
return c();
|
||||
});
|
||||
}, function() {
|
||||
async.each([0,1,2,3], function(i,c) {
|
||||
s.sync.bDb.getNext(b[i], function(err, p) {
|
||||
assert.equal(p,b[i+1]);
|
||||
return c();
|
||||
});
|
||||
}, function() {
|
||||
async.each([0,1,2,3], function(i,c) {
|
||||
s.sync.bDb.getHeight(b[i], function(err, h) {
|
||||
assert.equal(h,16+i);
|
||||
return c();
|
||||
});
|
||||
}, function() {
|
||||
async.each([0,1,2,3], function(i,c) {
|
||||
s.sync.bDb.getDepth(b[i], function(err, d) {
|
||||
assert.equal(d,4-i);
|
||||
return c();
|
||||
});
|
||||
}, cb);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* TEST CASES
|
||||
*
|
||||
* b0 height = 16;
|
||||
*
|
||||
* Blocks: 0-1-2-3-4
|
||||
* case 1)
|
||||
* 0-1-2-3-4
|
||||
* \
|
||||
* C1* (height should be 19)
|
||||
*
|
||||
* case 2)
|
||||
* 0-1-2---3-4
|
||||
* \ \
|
||||
* C1 C2*
|
||||
*
|
||||
* case 2b)
|
||||
* 0-1-2---3-4
|
||||
* \ \
|
||||
* C1 C2-C2b(TX=C1.TX)*
|
||||
* case 2c)
|
||||
* 0-1-2---3-4
|
||||
* \ \
|
||||
* C1 C2-C2b(TX=C1.TX)
|
||||
* \
|
||||
* C2c(TX=C2.TX)*
|
||||
*
|
||||
*/
|
||||
|
||||
var checkTxs = function(txs,heights){
|
||||
var i=0;
|
||||
txs.forEach(function(tx){
|
||||
var v=heights[i++];
|
||||
it('tx height:'+tx+' #'+v,function(done){
|
||||
s.sync.bDb.getBlockForTx(tx, function(err,hash,height) {
|
||||
assert(!err,err);
|
||||
if (v>=0) {
|
||||
assert(hash);
|
||||
height.should.equal(v);
|
||||
} else {
|
||||
assert(!hash);
|
||||
assert(!height);
|
||||
}
|
||||
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
//heights is optional
|
||||
var checkBlocks = function(hashes,heights){
|
||||
var i=0;
|
||||
hashes.forEach(function(hash){
|
||||
var v = heights[i++];
|
||||
it('block height:'+hash+' #'+v,function(done){
|
||||
s.sync.bDb.getHeight(hash, function(err,height) {
|
||||
assert(!err,err);
|
||||
height.should.equal(v);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
describe.skip('Sync Reorgs', function(){
|
||||
var opts = {
|
||||
forceRPC: true,
|
||||
stopAt: b[5],
|
||||
};
|
||||
|
||||
before(function(done) {
|
||||
s = new HistoricSync();
|
||||
s.sync.destroy(done);
|
||||
});
|
||||
|
||||
it('simple RPC forward syncing', function(done) {
|
||||
s.start(opts, function(err) {
|
||||
if (err) return done(err);
|
||||
initialTest(done);
|
||||
});
|
||||
});
|
||||
|
||||
var case1 = {
|
||||
hash: '0000000042d3db6c529dd8f1b085367cb6d907b534f5b1a5dfdd3a34a3459886',
|
||||
tx: [ '2dc27c8d4b98f5e2ed009cfc164ac4990f18e03c4d5b71e780f9c8b7b2c5f151' ],
|
||||
time: 1296690099,
|
||||
previousblockhash: b[2],
|
||||
};
|
||||
|
||||
|
||||
describe.skip('reorg, case 1', function() {
|
||||
checkTxs([t[0], t[1], t[2], t[3], t[4]],[16,17,18,19,20]);
|
||||
checkBlocks([b[0], b[1], b[2], b[3], b[4]],[16,17,18,19,20]);
|
||||
it('trigger reorg case 1', function(done1){
|
||||
s.sync.storeTipBlock(case1, function(err) {
|
||||
assert(!err, 'shouldnt return error' + err);
|
||||
done1();
|
||||
});
|
||||
});
|
||||
checkTxs([t[0], t[1], t[2], t[3], t[4],case1.tx],[16,17,18,-1,-1,19]);
|
||||
checkBlocks([b[0], b[1], b[2],b[3],b[4],case1.hash],[16,17,18,-1,-1,19]);
|
||||
|
||||
it('reorg, case 1 (repeat)', function(done) {
|
||||
s.sync.storeTipBlock(case1, function(err) {
|
||||
assert(!err, 'shouldnt return error' + err);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var case2 = {
|
||||
hash: '00000000c262f9428bb84407780bb0bd008b74941d651111ab2500cf649fa45d',
|
||||
tx: [ '3fa6fce216e91c9dc9a6267168e9d8bfb4ae57aec0d26590442cfec6e8233682' ],
|
||||
time: 1296690099,
|
||||
previousblockhash: b[3],
|
||||
};
|
||||
|
||||
|
||||
// * case 2)
|
||||
// * 0-1-2---3-4
|
||||
// * \ \
|
||||
// * C1 C2*
|
||||
|
||||
|
||||
describe('reorg, case 2', function() {
|
||||
checkTxs([t[0], t[1], t[2], t[3], t[4],case1.tx[0]],[16,17,18,-1,-1,19]);
|
||||
checkBlocks([b[0], b[1], b[2],b[3],b[4],case1.hash],[16,17,18,-1,-1,19]);
|
||||
it('trigger reorg case 2', function(done1){
|
||||
s.sync.storeTipBlock(case2, function(err) {
|
||||
assert(!err, 'shouldnt return error' + err);
|
||||
return done1();
|
||||
});
|
||||
});
|
||||
checkBlocks([b[0], b[1], b[2],b[3],b[4],case2.hash],[16,17,18,19,-1,20]);
|
||||
checkTxs([t[0], t[1], t[2],t[3],t[4],case2.tx[0]],[16,17,18,19,-1,20]);
|
||||
it('next from block 2', function(done1){
|
||||
s.sync.bDb.getNext(b[2], function(err, val) {
|
||||
assert(!err);
|
||||
assert.equal(val,b[3]);
|
||||
return done1();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// * case 2b)
|
||||
// * 0-1-2---3-4
|
||||
// * \ \
|
||||
// * C1 C2-C2b(TX=C1.TX)*
|
||||
|
||||
|
||||
var case2b = {
|
||||
hash: '0000000022bb34bc09f8d8d0ae26b86c87f8483e54b9c3addfe6f30b12bc656a',
|
||||
tx: case1.tx,
|
||||
time: 1296690099,
|
||||
previousblockhash: case2.hash,
|
||||
};
|
||||
|
||||
describe('reorg, case 2', function() {
|
||||
it('reorg case 2b', function(done1){
|
||||
s.sync.storeTipBlock(case2b, function(err) {
|
||||
assert(!err, 'shouldnt return error' + err);
|
||||
return done1();
|
||||
});
|
||||
});
|
||||
checkBlocks([b[0], b[1], b[2],b[3],b[4],case2.hash, case2b.hash, case1.hash],[16,17,18,19,-1,20, 21, -1]);
|
||||
checkTxs([t[0], t[1], t[2],t[3],t[4],case2.tx[0], case1.tx],[16,17,18,19,-1,20, 21]);
|
||||
});
|
||||
|
||||
var case2c = {
|
||||
hash: '0000000000000000000000000000000000000000000000000000000000000004',
|
||||
tx: case2.tx,
|
||||
time: 1296690099,
|
||||
previousblockhash: case1.hash,
|
||||
};
|
||||
|
||||
// * case 2c)
|
||||
// * 0-1-2---3-4
|
||||
// * \ \
|
||||
// * C1 C2-C2b(TX=C1.TX)
|
||||
// * \
|
||||
// * C2c(TX=C2.TX)*
|
||||
|
||||
describe.skip('reorg, case 2c', function() {
|
||||
it('trigger reorg case 2c', function(done1){
|
||||
s.sync.storeTipBlock(case2c, function(err) {
|
||||
assert(!err, 'shouldnt return error' + err);
|
||||
return done1();
|
||||
});
|
||||
});
|
||||
checkBlocks([b[0], b[1], b[2],
|
||||
b[3],b[4],case2.hash, case2b.hash,
|
||||
case1.hash, case2c.hash],
|
||||
[16,17,18,
|
||||
-1,-1,-1, -1,
|
||||
19, 20
|
||||
]);
|
||||
checkTxs(
|
||||
[t[0], t[1], t[2],
|
||||
t[3],t[4], case2.tx[0],
|
||||
case1.tx, case2c.tx[0]],
|
||||
[16,17,18,
|
||||
-1,-1, 20,
|
||||
19, 20]);
|
||||
});
|
||||
|
||||
|
||||
// * case 3)
|
||||
// * 0-1-2---3-4
|
||||
// * \ \
|
||||
// * C1 C2-C2b(TX=C1.TX)
|
||||
// * \
|
||||
// * C2c(TX=C2.TX)
|
||||
//
|
||||
// (orphan)-C3*
|
||||
// -> returns error
|
||||
|
||||
var case3 = {
|
||||
hash: '0000000000000000000000000000000000000000000000000000000000000005',
|
||||
tx: case2.tx,
|
||||
time: 1296690099,
|
||||
previousblockhash: '666',
|
||||
};
|
||||
|
||||
describe.skip('reorg, case 3)', function() {
|
||||
it('case 3). Should return an error', function(done1){
|
||||
s.sync.storeTipBlock(case3, function(err) {
|
||||
assert(err, 'should return error' + err);
|
||||
return done1();
|
||||
});
|
||||
});
|
||||
//shoudnt change anything
|
||||
checkBlocks([b[0], b[1], b[2],
|
||||
b[3],b[4],case2.hash, case2b.hash,
|
||||
case1.hash, case2c.hash],
|
||||
[16,17,18,
|
||||
-1,-1,-1, -1,
|
||||
19, 20
|
||||
]);
|
||||
checkTxs(
|
||||
[t[0], t[1], t[2],
|
||||
t[3],t[4], case2.tx[0],
|
||||
case1.tx, case2c.tx[0]],
|
||||
[16,17,18,
|
||||
-1,-1, 20,
|
||||
19, 20]);
|
||||
});
|
||||
|
||||
var p2p = {
|
||||
hash: '0000000000000000000000000000000000000000000000000000000000000006',
|
||||
tx: ['f6c2901f39fd07f2f2e503183d76f73ecc1aee9ac9216fde58e867bc29ce674e'],
|
||||
time: 1296690099,
|
||||
previousblockhash: '111',
|
||||
};
|
||||
|
||||
describe.skip('p2p sync. no reorgs', function() {
|
||||
it('Should return an error', function(done1){
|
||||
s.sync.storeTipBlock(p2p, false, function(err) {
|
||||
assert(!err, 'shouldnt return error' + err);
|
||||
return done1();
|
||||
});
|
||||
it('Block should be stored', function(done1){
|
||||
s.sync.bDb.has(p2p.hash, function(err,is) {
|
||||
assert(!err);
|
||||
assert(is);
|
||||
return done1();
|
||||
});
|
||||
});
|
||||
//shoudnt change anything
|
||||
checkBlocks([b[0], b[1], b[2],
|
||||
b[3],b[4],case2.hash, case2b.hash,
|
||||
case1.hash, case2c.hash,
|
||||
p2p.hash],
|
||||
[16,17,18,
|
||||
-1,-1,-1, -1,
|
||||
19, 20,
|
||||
-1
|
||||
]);
|
||||
});
|
||||
it('next Block should be stored', function(done1){
|
||||
s.sync.bDb.getNext(p2p.hash, function(err,v) {
|
||||
assert(!err);
|
||||
assert.equal(v,p2p.nextblockhash);
|
||||
return done1();
|
||||
});
|
||||
});
|
||||
it('next Block should be stored', function(done1){
|
||||
s.sync.bDb.getNext(p2p.previousblockhash, function(err,v) {
|
||||
assert(!err);
|
||||
assert.equal(v,p2p.hash);
|
||||
return done1();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,146 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
Address = require('../../app/models/Address'),
|
||||
TransactionDb = require('../../lib/TransactionDb').default(),
|
||||
addrValid = JSON.parse(fs.readFileSync('test/integration/addr.json')),
|
||||
utxoValid = JSON.parse(fs.readFileSync('test/integration/utxo.json'));
|
||||
|
||||
var should = require('chai');
|
||||
|
||||
var txDb;
|
||||
describe.skip('Address balances', function() {
|
||||
this.timeout(5000);
|
||||
|
||||
before(function(c) {
|
||||
txDb = TransactionDb;
|
||||
|
||||
var l =addrValid.length;
|
||||
var i =0;
|
||||
addrValid.forEach(function(v) {
|
||||
TransactionDb.deleteCacheForAddress(v.addr, function() {
|
||||
if (++i===l) return c();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
addrValid.forEach(function(v) {
|
||||
if (v.disabled) {
|
||||
console.log(v.addr + ' => disabled in JSON');
|
||||
} else {
|
||||
it('Address info 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);
|
||||
|
||||
if (v.unconfirmedTxApperances)
|
||||
a.unconfirmedTxApperances.should.equal(v.unconfirmedTxApperances || 0, 'unconfirmedTxApperances');
|
||||
if (v.unconfirmedBalanceSat)
|
||||
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);
|
||||
|
||||
if (v.transactions) {
|
||||
|
||||
v.transactions.forEach(function(tx) {
|
||||
a.transactions.should.include(tx);
|
||||
});
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
},{txLimit:0});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
//tested against https://api.biteasy.com/testnet/v1/addresses/2N1pLkosf6o8Ciqs573iwwgVpuFS6NbNKx5/unspent-outputs?per_page=40
|
||||
describe.skip('Address unspent', function() {
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
utxoValid.forEach(function(v) {
|
||||
if (v.disabled) {
|
||||
console.log(v.addr + ' => disabled in JSON');
|
||||
} else {
|
||||
it('Address unspent for: ' + v.addr, function(done) {
|
||||
this.timeout(2000);
|
||||
var a = new Address(v.addr, txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
assert.equal(v.addr, a.addrStr);
|
||||
if (v.length) a.unspent.length.should.equal(v.length, 'Unspent count');
|
||||
if (v.tx0id) {
|
||||
var x=a.unspent.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();
|
||||
}, {onlyUnspent:1});
|
||||
});
|
||||
it('Address unspent (cached) for: ' + v.addr, function(done) {
|
||||
this.timeout(2000);
|
||||
var a = new Address(v.addr, txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
assert.equal(v.addr, a.addrStr);
|
||||
if (v.length) a.unspent.length.should.equal(v.length, 'Unspent count');
|
||||
if (v.tx0id) {
|
||||
var x=a.unspent.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();
|
||||
}, {onlyUnspent:1});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1,199 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
Address = require('../../app/models/Address'),
|
||||
TransactionDb = require('../../lib/TransactionDb').default(),
|
||||
addrValid = JSON.parse(fs.readFileSync('test/integration/addr.json')),
|
||||
utxoValid = JSON.parse(fs.readFileSync('test/integration/utxo.json'));
|
||||
|
||||
var should = require('chai');
|
||||
|
||||
var txDb;
|
||||
|
||||
|
||||
describe.skip('Address cache ', function() {
|
||||
this.timeout(5000);
|
||||
|
||||
before(function(c) {
|
||||
txDb = TransactionDb;
|
||||
txDb.deleteCacheForAddress('muAt5RRqDarPFCe6qDXGZc54xJjXYUyepG',function(){
|
||||
txDb.deleteCacheForAddress('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3',function(){
|
||||
txDb.deleteCacheForAddress('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk',c);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('cache case 1 w/o cache', function(done) {
|
||||
var a = new Address('muAt5RRqDarPFCe6qDXGZc54xJjXYUyepG', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0, 'balance');
|
||||
a.totalReceived.should.equal(19175, 'totalReceived');
|
||||
a.txApperances.should.equal(2, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
it('cache case 1 w cache', function(done) {
|
||||
var a = new Address('muAt5RRqDarPFCe6qDXGZc54xJjXYUyepG', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0, 'balance');
|
||||
a.totalReceived.should.equal(19175, 'totalReceived');
|
||||
a.txApperances.should.equal(2, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('cache case 2 w/o cache', function(done) {
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cache case 2 w cache', function(done) {
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('cache case 2 unspent wo cache', function(done) {
|
||||
txDb.deleteCacheForAddress('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk',function() {
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.unspent.length.should.equal(1);
|
||||
a.unspent[0].scriptPubKey.should.equal('a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87');
|
||||
a.unspent[0].confirmations.should.be.above(15000);
|
||||
a.unspent[0].confirmationsFromCache.should.equal(false);
|
||||
a.update(function(err) {
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
}, {onlyUnspent:1});
|
||||
});
|
||||
});
|
||||
|
||||
it('cache case 2 unspent w cache', function(done) {
|
||||
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.unspent.length.should.equal(1);
|
||||
a.unspent[0].confirmationsFromCache.should.equal(true);
|
||||
a.unspent[0].confirmations.should.equal(6);
|
||||
a.unspent[0].scriptPubKey.should.equal('a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87');
|
||||
a.update(function(err) {
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
|
||||
}, {onlyUnspent:1});
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('cache case 3 w/o cache', function(done) {
|
||||
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0, 'balance');
|
||||
a.totalReceived.should.equal(1376000, 'totalReceived');
|
||||
a.txApperances.should.equal(8003, 'txApperances');
|
||||
return done();
|
||||
});
|
||||
},1);
|
||||
it('cache case 4 w cache', function(done) {
|
||||
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0, 'balance');
|
||||
a.totalReceived.should.equal(1376000, 'totalReceived');
|
||||
a.txApperances.should.equal(8003, 'txApperances');
|
||||
return done();
|
||||
},{txLimit:0});
|
||||
});
|
||||
it('cache case 4 w ignore cache', function(done) {
|
||||
var a = new Address('mt2AzeCorSf7yFckj19HFiXJgh9aNyc4h3', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0, 'balance');
|
||||
a.totalReceived.should.equal(1376000, 'totalReceived');
|
||||
a.txApperances.should.equal(8003, 'txApperances');
|
||||
return done();
|
||||
},{txLimit:0, ignoreCache:1});
|
||||
});
|
||||
|
||||
it('cache case 5 unspent w cache', function(done) {
|
||||
var a = new Address('2NBuTjjZrURxLaMyPUu2sJwNrtpt7GtPX2p', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.unspent.length.should.equal(1);
|
||||
a.unspent[0].confirmationsFromCache.should.equal(true);
|
||||
a.unspent[0].confirmations.should.equal(6);
|
||||
return done();
|
||||
}, {onlyUnspent:1});
|
||||
});
|
||||
|
||||
it('cache fix broken cases', function(done) {
|
||||
txDb._db.put('txa2-2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk-9998599199253-16c0287dbea7e323431caff7f7e490da6de66530717f86f8dae9549b3355301a-0', '23000000:1399232338:0:a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87', function(){
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.balance.should.equal(0.23, 'balance');
|
||||
a.totalReceived.should.equal(0.23, 'totalReceived');
|
||||
a.txApperances.should.equal(1, 'txApperances');
|
||||
a.transactions.length.should.equal(1);
|
||||
a.transactions[0].should.equal('16c0287dbea7e323431caff7f7e490da6de66530717f86f8dae9549b3355301a');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('cache fix broken cases 2)', function(done) {
|
||||
txDb._db.put('txa2-2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk-9998599199253-16c0287dbea7e323431caff7f7e490da6de66530717f86f8dae9549b3355301a-0', '23000000:1399232338:0:a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87', function(){
|
||||
var a = new Address('2N7zvqQTUYFfhYvFs1NEzureMLvhwk5FSsk', txDb);
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.unspent.length.should.equal(1);
|
||||
a.unspent[0].confirmationsFromCache.should.equal(false);
|
||||
a.unspent[0].confirmations.should.above(6);
|
||||
a.unspent[0].scriptPubKey.should.equal('a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87');
|
||||
a.update(function(err) {
|
||||
if (err) done(err);
|
||||
a.unspent.length.should.equal(1);
|
||||
a.unspent[0].confirmationsFromCache.should.equal(true);
|
||||
a.unspent[0].confirmations.should.equal(6);
|
||||
a.unspent[0].scriptPubKey.should.equal('a914a1d5be9f72224b5e83d00d7f5b9b674d456c573f87');
|
||||
return done();
|
||||
}, {onlyUnspent:1});
|
||||
}, {onlyUnspent:1});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
|
||||
var TESTING_BLOCK = '000000000185678d3d7ecc9962c96418174431f93fe20bf216d5565272423f74';
|
||||
|
||||
var
|
||||
assert = require('assert'),
|
||||
// config = require('../../config/config'),
|
||||
BlockDb = require('../../lib/BlockDb').default();
|
||||
|
||||
var bDb;
|
||||
|
||||
describe.skip('BlockDb fromHashWithInfo', function() {
|
||||
|
||||
before(function(c) {
|
||||
bDb = BlockDb;
|
||||
return c();
|
||||
});
|
||||
|
||||
it('should poll block\'s info from bitcoind', function(done) {
|
||||
bDb.fromHashWithInfo(TESTING_BLOCK, function(err, b2) {
|
||||
if (err) done(err);
|
||||
assert.equal(b2.hash, TESTING_BLOCK, 'hash');
|
||||
assert.equal(b2.info.hash, TESTING_BLOCK, 'info.hash');
|
||||
assert.equal(b2.info.height, 71619);
|
||||
assert.equal(b2.info.nonce, 3960980741);
|
||||
assert.equal(b2.info.bits, '1c018c14');
|
||||
assert.equal(b2.info.merkleroot, '9a326cb524aa2e5bc926b8c1f6de5b01257929ee02158054b55aae93a55ec9dd');
|
||||
assert.equal(b2.info.nextblockhash, '000000000121941b3b10d76fbe67b35993df91eb3398e9153e140b4f6213cb84');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('return true in has', function(done) {
|
||||
bDb.has(TESTING_BLOCK, function(err, has) {
|
||||
assert.equal(has, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,75 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
|
||||
|
||||
var assert = require('assert'),
|
||||
config = require('../../config/config'),
|
||||
BlockExtractor = require('../../lib/BlockExtractor'),
|
||||
networks = require('bitcore/networks'),
|
||||
util = require('bitcore/util/util');
|
||||
|
||||
var should = require('chai');
|
||||
//var txItemsValid = JSON.parse(fs.readFileSync('test/model/txitems.json'));
|
||||
|
||||
describe.skip('BlockExtractor', function(){
|
||||
|
||||
var be = new BlockExtractor(config.bitcoind.dataDir, config.network);
|
||||
|
||||
var network = config.network === 'testnet' ? networks.testnet: networks.livenet;
|
||||
|
||||
it('should glob block files ', function(done) {
|
||||
assert(be.files.length>0);
|
||||
done();
|
||||
});
|
||||
|
||||
var lastTs;
|
||||
|
||||
it('should read genesis block ', function(done) {
|
||||
be.getNextBlock(function(err,b) {
|
||||
assert(!err);
|
||||
var genesisHashReversed = new Buffer(32);
|
||||
network.genesisBlock.hash.copy(genesisHashReversed);
|
||||
var genesis = util.formatHashFull(network.genesisBlock.hash);
|
||||
|
||||
assert.equal(util.formatHashFull(b.hash),genesis);
|
||||
assert.equal(b.nounce,network.genesisBlock.nounce);
|
||||
assert.equal(b.timestamp,network.genesisBlock.timestamp);
|
||||
assert.equal(b.merkle_root.toString('hex'),network.genesisBlock.merkle_root.toString('hex'));
|
||||
|
||||
lastTs = b.timestamp;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should read next '+config.network+' block ', function(done) {
|
||||
be.getNextBlock(function(err,b) {
|
||||
assert(!err);
|
||||
// 2nd block of testnet3
|
||||
util.formatHashFull(b.hash).should.equal('00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206');
|
||||
assert(b.timestamp > lastTs, 'timestamp > genesis_ts');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should read 100000 blocks with no error ', function(done) {
|
||||
|
||||
var i=0;
|
||||
while(i++<100000) {
|
||||
be.getNextBlock(function(err,b) {
|
||||
assert(!err,err);
|
||||
assert(lastTs < b.timestamp, 'genesisTS < b.timestamp: ' + lastTs + '<' + b.timestamp + ":" + i);
|
||||
if(i % 1000 === 1) process.stdout.write('.');
|
||||
if(i === 100000) done();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var TESTING_BLOCK0 = '00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206';
|
||||
var TESTING_BLOCK1 = '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943';
|
||||
var START_TS = 1;
|
||||
var END_TS = '1296688928~'; // 2/2/2011 23:23PM
|
||||
|
||||
var assert = require('assert'),
|
||||
BlockDb = require('../../lib/BlockDb').default();
|
||||
|
||||
var bDb;
|
||||
|
||||
describe.skip('BlockDb getBlocksByDate', function(){
|
||||
|
||||
|
||||
before(function(c) {
|
||||
bDb = BlockDb;
|
||||
return c();
|
||||
});
|
||||
|
||||
it('Get Hash by Date', function(done) {
|
||||
|
||||
bDb.getBlocksByDate(START_TS, END_TS, 2, function(err, list) {
|
||||
if (err) done(err);
|
||||
assert(list, 'returns list');
|
||||
assert.equal(list.length,2, 'list has 2 items');
|
||||
assert.equal(list[1].hash, TESTING_BLOCK0);
|
||||
assert.equal(list[0].hash, TESTING_BLOCK1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,90 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var assert = require('assert'),
|
||||
config = require('../../config/config'),
|
||||
messages = require('../../app/controllers/messages'),
|
||||
correctMessage = 'test2',
|
||||
correctAddress,
|
||||
correctSignature;
|
||||
|
||||
if(config.network === 'livenet') {
|
||||
correctAddress = '16Q7eRty2LrpAWvP3VTtaXXCMZj2v4xm57',
|
||||
correctSignature = 'HERpcxkyOezkBPPwvUUAaxYXR/9X/8eyVjp8WKGYl7Aw8'
|
||||
+ 'pMsiMXDWXf8G1t/SOUEWy94I+KA/SrBKYs2LfIHA0Q=';
|
||||
} else {
|
||||
correctAddress = 'mhtJo5nZLcreM5Arrf8EDABpCevp2MfmCW',
|
||||
correctSignature = 'G/y2UhjZ4qBPLQGmOhl/4p/EIwTHIO1iq95kPxDk9RjYr'
|
||||
+ '1JKL6dsCSuhXat7VLTGwAM3PdgRh/jwGxi6x6dNeSE=';
|
||||
}
|
||||
|
||||
function createMockReq(body) {
|
||||
// create a simplified mock of express' request object, suitable for the
|
||||
// needs of test cases in this file
|
||||
return {
|
||||
body: body,
|
||||
param: function(name) {
|
||||
return this.body[name];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
describe.skip('messages.verify', function() {
|
||||
|
||||
it('should return true with correct message', function(done) {
|
||||
var mockReq = createMockReq({
|
||||
address: correctAddress,
|
||||
signature: correctSignature,
|
||||
message: correctMessage
|
||||
});
|
||||
var mockRes = {
|
||||
json: function(data) {
|
||||
assert.deepEqual(data, {
|
||||
result: true,
|
||||
});
|
||||
done();
|
||||
}
|
||||
};
|
||||
messages.verify(mockReq, mockRes);
|
||||
});
|
||||
|
||||
it('should return false with incorrect message', function(done) {
|
||||
var mockReq = createMockReq({
|
||||
address: correctAddress,
|
||||
signature: correctSignature,
|
||||
message: 'NOPE'
|
||||
});
|
||||
var mockRes = {
|
||||
json: function(data) {
|
||||
assert.deepEqual(data, {
|
||||
result: false,
|
||||
});
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
messages.verify(mockReq, mockRes);
|
||||
});
|
||||
|
||||
it('should return error with incorrect parameters', function(done) {
|
||||
var mockReq = createMockReq({
|
||||
address: correctAddress,
|
||||
message: correctMessage
|
||||
});
|
||||
var mockRes = {
|
||||
status: function(code) {
|
||||
assert.equal(code, 400);
|
||||
return this;
|
||||
},
|
||||
send: function(data) {
|
||||
assert.ok(data.match(/^Missing parameters/),
|
||||
"Match not found, got '" + data + "' instead")
|
||||
done();
|
||||
}
|
||||
};
|
||||
messages.verify(mockReq, mockRes);
|
||||
});
|
||||
|
||||
});
|
||||
@ -1,17 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var BlockDb = require('../../lib/BlockDb').default();
|
||||
var height_needed = 180000;
|
||||
var bDb = BlockDb;
|
||||
|
||||
var expect = require('chai').expect;
|
||||
|
||||
describe.skip('Node check', function() {
|
||||
it('should contain block ' + height_needed, function(done) {
|
||||
bDb.blockIndex(height_needed, function(err, b) {
|
||||
expect(err).to.equal(null);
|
||||
expect(b).to.not.equal(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var assert = require('assert'),
|
||||
Status = require('../../app/models/Status');
|
||||
|
||||
describe.skip('Status', function(){
|
||||
|
||||
it('getInfo', function(done) {
|
||||
var d = new Status();
|
||||
|
||||
d.getInfo(function(err) {
|
||||
if (err) done(err);
|
||||
assert.equal('number', typeof d.info.difficulty);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getDifficulty', function(done) {
|
||||
var d = new Status();
|
||||
|
||||
d.getDifficulty(function(err) {
|
||||
if (err) done(err);
|
||||
assert.equal('number', typeof d.difficulty);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('getLastBlockHash', function(done) {
|
||||
var d = new Status();
|
||||
|
||||
d.getLastBlockHash(function(err) {
|
||||
if (err) done(err);
|
||||
assert.equal('string', typeof d.lastblockhash);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
@ -1,69 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var fs = require('fs');
|
||||
var Address = require('../../app/models/Address');
|
||||
var addresses = require('../../app/controllers/addresses');
|
||||
var TransactionDb = require('../../lib/TransactionDb').default();
|
||||
var fixture = JSON.parse(fs.readFileSync('test/integration/txs.json'));
|
||||
var should = require('chai');
|
||||
var sinon = require('sinon');
|
||||
|
||||
var txDb;
|
||||
describe.skip('Transactions for multiple addresses', function() {
|
||||
this.timeout(5000);
|
||||
|
||||
var req, res;
|
||||
before(function(c) {
|
||||
txDb = TransactionDb;
|
||||
|
||||
var i = 0;
|
||||
_.each(_.flatten(_.pluck(fixture, 'addrs')), function(addr) {
|
||||
TransactionDb.deleteCacheForAddress(addr, function() {
|
||||
if (++i === fixture.length) return c();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(function(c) {
|
||||
req = {};
|
||||
res = {};
|
||||
return c();
|
||||
});
|
||||
|
||||
describe('Transactions from multiple addresses', function () {
|
||||
_.each(fixture, function (f) {
|
||||
it(f.test, function (done) {
|
||||
var checkResult = function(txs) {
|
||||
var paginated = !_.isUndefined(f.from) || !_.isUndefined(f.to);
|
||||
txs.should.exist;
|
||||
if (paginated) {
|
||||
txs.totalItems.should.equal(f.totalTransactions);
|
||||
txs.items.length.should.equal(f.returnedTransactions);
|
||||
if (f.transactions) {
|
||||
JSON.stringify(_.pluck(txs.items, 'txid')).should.equal(JSON.stringify(f.transactions));
|
||||
}
|
||||
} else {
|
||||
txs.should.be.instanceof(Array);
|
||||
txs.length.should.equal(f.returnedTransactions);
|
||||
}
|
||||
done();
|
||||
};
|
||||
|
||||
res.jsonp = checkResult;
|
||||
req.param = sinon.stub();
|
||||
req.param.withArgs('addrs').returns(f.addrs.join(','));
|
||||
req.param.withArgs('from').returns(f.from);
|
||||
req.param.withArgs('to').returns(f.to);
|
||||
|
||||
addresses.multitxs(req, res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user