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