better txitem test
This commit is contained in:
parent
5e68c8c7ed
commit
c1d5296618
|
@ -96,6 +96,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, cb) {
|
||||||
this.fromIdWithInfo(txid, function(err, t) {
|
this.fromIdWithInfo(txid, function(err, t) {
|
||||||
if (err || !t) return cb(err);
|
if (err || !t) return cb(err);
|
||||||
|
|
||||||
|
var index=0;
|
||||||
async.each(t.info.vin, function(i, next_in) {
|
async.each(t.info.vin, function(i, next_in) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -107,7 +108,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, cb) {
|
||||||
txid : t.txid,
|
txid : t.txid,
|
||||||
value : -1 * i.value,
|
value : -1 * i.value,
|
||||||
addr : i.addr,
|
addr : i.addr,
|
||||||
index : i.n,
|
index : index++,
|
||||||
}, next_in);
|
}, next_in);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -130,7 +131,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, cb) {
|
||||||
TransactionItem.create({
|
TransactionItem.create({
|
||||||
txid : t.txid,
|
txid : t.txid,
|
||||||
value : o.value,
|
value : o.value,
|
||||||
addr : o.scriptPubKey.addresses[0],
|
addr : o.scriptPubKey.addresses[0],
|
||||||
index : o.n,
|
index : o.n,
|
||||||
}, next_out);
|
}, next_out);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ var TransactionItemSchema = new Schema({
|
||||||
type: String,
|
type: String,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
// >0 is Input <0 is Output
|
// <0 is Input >0 is Output
|
||||||
value: Number,
|
value: Number,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ var
|
||||||
config = require('../../config/config'),
|
config = require('../../config/config'),
|
||||||
Transaction = require('../../app/models/Transaction'),
|
Transaction = require('../../app/models/Transaction'),
|
||||||
TransactionItem = require('../../app/models/TransactionItem'),
|
TransactionItem = require('../../app/models/TransactionItem'),
|
||||||
fs = require('fs');
|
fs = require('fs'),
|
||||||
|
util = require('util');
|
||||||
|
|
||||||
|
|
||||||
var txItemsValid = JSON.parse(fs.readFileSync('test/model/txitems.json'));
|
var txItemsValid = JSON.parse(fs.readFileSync('test/model/txitems.json'));
|
||||||
|
@ -86,18 +87,21 @@ describe('Transaction', function(){
|
||||||
|
|
||||||
TransactionItem.find({txid: v.txid}).sort({ index:1 }).exec(function(err, readItems) {
|
TransactionItem.find({txid: v.txid}).sort({ index:1 }).exec(function(err, readItems) {
|
||||||
|
|
||||||
var match=0;
|
var unmatch={};
|
||||||
|
|
||||||
|
v.items.forEach(function(validItem){
|
||||||
|
unmatch[validItem.addr] =1;
|
||||||
|
});
|
||||||
v.items.forEach(function(validItem){
|
v.items.forEach(function(validItem){
|
||||||
readItems.forEach(function(readItem){
|
readItems.forEach(function(readItem){
|
||||||
if ( readItem.addr === validItem.addr &&
|
if ( readItem.addr === validItem.addr &&
|
||||||
parseInt(readItem.index) === parseInt(validItem.index) &&
|
parseInt(readItem.index) == parseInt(validItem.index) &&
|
||||||
parseFloat(readItem.value) === parseFloat(validItem.value) ) {
|
parseFloat(readItem.value) == parseFloat(validItem.value) )
|
||||||
}
|
delete unmatch[validItem.addr];
|
||||||
match=1;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var all = v.items.toString();
|
var valid = util.inspect(v.items, { depth: null });
|
||||||
assert(match, "Testing..." + readItems + "vs." + all);
|
assert(!Object.keys(unmatch).length, '\n\tmatched:' + Object.keys(unmatch) + "\n\n" +valid + '\nvs.\n' + readItems);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,18 +3,18 @@
|
||||||
"txid": "21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237",
|
"txid": "21798ddc9664ac0ef618f52b151dda82dafaf2e26d2bbef6cdaf55a6957ca237",
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"addr": "mwcFwXv2Yquy4vJA4nnNLAbHVjrPdC8Q1Z",
|
"addr": "mwcFwXv2Yquy4vJA4nnNLAbHVjrPdC8Q1Z",
|
||||||
"value": 1.66224,
|
"value": -1.66224,
|
||||||
"index": 0
|
"index": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"addr": "mzjLe62faUqCSjkwQkwPAL5nYyR8K132fA",
|
"addr": "mzjLe62faUqCSjkwQkwPAL5nYyR8K132fA",
|
||||||
"value": -1.34574,
|
"value": 1.34574,
|
||||||
"index": 0
|
"index": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"addr": "n28wb1cRGxPtfmsenYKFfsvnZ6kRapx3jF",
|
"addr": "n28wb1cRGxPtfmsenYKFfsvnZ6kRapx3jF",
|
||||||
"value": -0.316,
|
"value": 0.316,
|
||||||
"index": 1
|
"index": 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -24,17 +24,17 @@
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"addr": "mzjLe62faUqCSjkwQkwPAL5nYyR8K132fA",
|
"addr": "mzjLe62faUqCSjkwQkwPAL5nYyR8K132fA",
|
||||||
"value": 0.40790667,
|
"value": -0.40790667,
|
||||||
"index": 0
|
"index": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"addr": "mhfQJUSissP6nLM5pz6DxHfctukrrLct2T",
|
"addr": "mhfQJUSissP6nLM5pz6DxHfctukrrLct2T",
|
||||||
"value": -0.193,
|
"value": 0.193,
|
||||||
"index": 0
|
"index": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"addr": "mzcDhbL877ES3MGftWnc3EuTSXs3WXDDML",
|
"addr": "mzcDhbL877ES3MGftWnc3EuTSXs3WXDDML",
|
||||||
"value": -0.21440667,
|
"value": 0.21440667,
|
||||||
"index": 1
|
"index": 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue