test for txitem explode
This commit is contained in:
parent
28e082b53b
commit
9193ae1746
@ -8,12 +8,15 @@ var
|
|||||||
mongoose= require('mongoose'),
|
mongoose= require('mongoose'),
|
||||||
assert = require('assert'),
|
assert = require('assert'),
|
||||||
config = require('../../config/config'),
|
config = require('../../config/config'),
|
||||||
Transaction = require('../../app/models/Transaction');
|
Transaction = require('../../app/models/Transaction'),
|
||||||
|
TransactionItem = require('../../app/models/TransactionItem'),
|
||||||
|
fs = require('fs');
|
||||||
|
|
||||||
|
|
||||||
|
var txItemsValid = JSON.parse(fs.readFileSync('test/model/txitems.json'));
|
||||||
mongoose.connection.on('error', function(err) { console.log(err); });
|
mongoose.connection.on('error', function(err) { console.log(err); });
|
||||||
|
|
||||||
describe('Transaction fromIdWithInfo', function(){
|
describe('Transaction', function(){
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
mongoose.connect(config.db);
|
mongoose.connect(config.db);
|
||||||
@ -26,20 +29,20 @@ describe('Transaction fromIdWithInfo', function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should pool tx\'s object from mongoose', function(done) {
|
it('should pool tx\'s object from mongoose', function(done) {
|
||||||
var test_txid = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237';
|
var txid = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237';
|
||||||
Transaction.fromIdWithInfo(test_txid, function(err, tx) {
|
Transaction.fromIdWithInfo(txid, function(err, tx) {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
assert.equal(tx.txid, test_txid);
|
assert.equal(tx.txid, txid);
|
||||||
assert(!tx.info.isCoinBase);
|
assert(!tx.info.isCoinBase);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should pool tx\'s info from bitcoind', function(done) {
|
it('should pool tx\'s info from bitcoind', function(done) {
|
||||||
var test_txid = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237';
|
var txid = '21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237';
|
||||||
Transaction.fromIdWithInfo(test_txid, function(err, tx) {
|
Transaction.fromIdWithInfo(txid, function(err, tx) {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
assert.equal(tx.info.txid, test_txid);
|
assert.equal(tx.info.txid, txid);
|
||||||
assert.equal(tx.info.blockhash, '000000000185678d3d7ecc9962c96418174431f93fe20bf216d5565272423f74');
|
assert.equal(tx.info.blockhash, '000000000185678d3d7ecc9962c96418174431f93fe20bf216d5565272423f74');
|
||||||
assert.equal(tx.info.valueOut, 1.66174);
|
assert.equal(tx.info.valueOut, 1.66174);
|
||||||
assert.equal(tx.info.feeds, 0.0005 );
|
assert.equal(tx.info.feeds, 0.0005 );
|
||||||
@ -49,28 +52,57 @@ describe('Transaction fromIdWithInfo', function(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test a coinbase TX 2a104bab1782e9b6445583296d4a0ecc8af304e4769ceb64b890e8219c562399', function(done) {
|
var txid1 = '2a104bab1782e9b6445583296d4a0ecc8af304e4769ceb64b890e8219c562399';
|
||||||
var test_txid2 = '2a104bab1782e9b6445583296d4a0ecc8af304e4769ceb64b890e8219c562399';
|
it('test a coinbase TX ' + txid1, function(done) {
|
||||||
Transaction.fromIdWithInfo(test_txid2, function(err, tx) {
|
Transaction.fromIdWithInfo(txid1, function(err, tx) {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
assert(tx.info.isCoinBase);
|
assert(tx.info.isCoinBase);
|
||||||
assert.equal(tx.info.txid, test_txid2);
|
assert.equal(tx.info.txid, txid1);
|
||||||
assert(!tx.info.feeds);
|
assert(!tx.info.feeds);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('test a broken TX 64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608', function(done) {
|
var txid2 = '64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608';
|
||||||
var test_txid2 = '64496d005faee77ac5a18866f50af6b8dd1f60107d6795df34c402747af98608';
|
it('test a broken TX ' + txid2, function(done) {
|
||||||
Transaction.fromIdWithInfo(test_txid2, function(err, tx) {
|
Transaction.fromIdWithInfo(txid2, function(err, tx) {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
assert.equal(tx.info.txid, test_txid2);
|
assert.equal(tx.info.txid, txid2);
|
||||||
assert.equal(tx.info.vin[0].addr, null);
|
assert.equal(tx.info.vin[0].addr, null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
txItemsValid.forEach( function(v) {
|
||||||
|
it('test a exploding TX ' + v.txid, function(done) {
|
||||||
|
|
||||||
|
// Remove first
|
||||||
|
TransactionItem.remove({txid: v.txid}, function(err) {
|
||||||
|
|
||||||
|
Transaction.explodeTransactionItems(v.txid, function(err, tx) {
|
||||||
|
if (err) done(err);
|
||||||
|
|
||||||
|
TransactionItem.find({txid: v.txid}).sort({ index:1 }).exec(function(err, readItems) {
|
||||||
|
|
||||||
|
var match=0;
|
||||||
|
v.items.forEach(function(validItem){
|
||||||
|
readItems.forEach(function(readItem){
|
||||||
|
if ( readItem.addr === validItem.addr &&
|
||||||
|
parseInt(readItem.index) === parseInt(validItem.index) &&
|
||||||
|
parseFloat(readItem.value) === parseFloat(validItem.value) ) {
|
||||||
|
}
|
||||||
|
match=1;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var all = v.items.toString();
|
||||||
|
assert(match, "Testing..." + readItems + "vs." + all);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
22
test/model/txitems.json
Normal file
22
test/model/txitems.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"txid": "21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"addr": "mwcFwXv2Yquy4vJA4nnNLAbHVjrPdC8Q1Z",
|
||||||
|
"value": 1.66224,
|
||||||
|
"index": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"addr": "mzjLe62faUqCSjkwQkwPAL5nYyR8K132fA",
|
||||||
|
"value": -1.34574,
|
||||||
|
"index": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"addr": "n28wb1cRGxPtfmsenYKFfsvnZ6kRapx3jF",
|
||||||
|
"value": -0.316,
|
||||||
|
"index": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
Loading…
Reference in New Issue
Block a user