better txitem test

This commit is contained in:
Matias Alejo Garcia 2014-01-12 01:16:22 -03:00
parent 5e68c8c7ed
commit c1d5296618
4 changed files with 24 additions and 19 deletions

View File

@ -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 {

View File

@ -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,
});

View File

@ -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();
});
});

View File

@ -4,17 +4,17 @@
"items": [
{
"addr": "mwcFwXv2Yquy4vJA4nnNLAbHVjrPdC8Q1Z",
"value": 1.66224,
"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
}
]