fix variable names

This commit is contained in:
Matias Alejo Garcia 2014-03-15 18:21:59 -03:00
parent 97209540b6
commit b6e6ad28eb
4 changed files with 54 additions and 18 deletions

View File

@ -0,0 +1,34 @@
{
"unspent": [
{
"address": "n4g2TFaQo8UgedwpkYdcQFF6xE2Ei9Czvy",
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
"scriptPubKey": "76a9146ce4e1163eb18939b1440c42844d5f0261c0338288ac",
"vout": 1,
"amount": 1.01,
"confirmations":7
},
{
"address": "mhNCT9TwZAGF1tLPpZdqfkTmtBkY282YDW",
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc2",
"scriptPubKey": "76a9146ce4e1163eb18939b1440c42844d5f0261c0338288ad",
"vout": 0,
"confirmations": 1,
"amount": 10
},
{
"address": "n44hn28zAooZpn8mpWKzATbabqaHDK9oNJ",
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc3",
"scriptPubKey": "76a9146ce4e1163eb18939b1440c42844d5f0261c0338288ae",
"vout": 3,
"confirmations": 0,
"amount": 5
}
],
"keyStrings": [
"cSq7yo4fvsbMyWVN945VUGUWMaSazZPWqBVJZyoGsHmNq6W4HVBV",
"cPa87VgwZfowGZYaEenoQeJgRfKW6PhZ1R65EHTkN1K19cSvc92G",
"cPQ9DSbBRLva9av5nqeF5AGrh3dsdW8p2E5jS4P8bDWZAoQTeeKB"
]
}

View File

@ -35,17 +35,17 @@ describe('Transaction', function() {
it('#_selectUnspent should be able to select utxos', function() {
var u = Transaction._selectUnspent(testdata.dataUnspends,1.0);
var u = Transaction._selectUnspent(testdata.dataUnspent,1.0);
u.length.should.equal(3);
u = Transaction._selectUnspent(testdata.dataUnspends,0.5);
u = Transaction._selectUnspent(testdata.dataUnspent,0.5);
u.length.should.equal(3);
u = Transaction._selectUnspent(testdata.dataUnspends,0.1);
u = Transaction._selectUnspent(testdata.dataUnspent,0.1);
u.length.should.equal(2);
u = Transaction._selectUnspent(testdata.dataUnspends,0.05);
u = Transaction._selectUnspent(testdata.dataUnspent,0.05);
u.length.should.equal(2);
u = Transaction._selectUnspent(testdata.dataUnspends,0.015);
u = Transaction._selectUnspent(testdata.dataUnspent,0.015);
u.length.should.equal(2);
u = Transaction._selectUnspent(testdata.dataUnspends,0.01);
u = Transaction._selectUnspent(testdata.dataUnspent,0.01);
u.length.should.equal(1);
should.exist(u[0].amount);
should.exist(u[0].txid);
@ -54,27 +54,27 @@ describe('Transaction', function() {
});
it('#selectUnspent should return null if not enough utxos', function() {
var u = Transaction.selectUnspent(testdata.dataUnspends,1.12);
var u = Transaction.selectUnspent(testdata.dataUnspent,1.12);
u.length.should.equal(0);
});
it('#selectUnspent should check confirmations', function() {
var u = Transaction.selectUnspent(testdata.dataUnspends,0.9);
var u = Transaction.selectUnspent(testdata.dataUnspent,0.9);
u.length.should.equal(0);
var u = Transaction.selectUnspent(testdata.dataUnspends,0.9,true);
var u = Transaction.selectUnspent(testdata.dataUnspent,0.9,true);
u.length.should.equal(3);
var u = Transaction.selectUnspent(testdata.dataUnspends,0.11);
var u = Transaction.selectUnspent(testdata.dataUnspent,0.11);
u.length.should.equal(2);
var u = Transaction.selectUnspent(testdata.dataUnspends,0.111);
var u = Transaction.selectUnspent(testdata.dataUnspent,0.111);
u.length.should.equal(0);
});
var opts = {remainderAddress: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'};
it('#create should be able to create instance', function() {
var utxos = Transaction.selectUnspent(testdata.dataUnspends,0.1);
var utxos = Transaction.selectUnspent(testdata.dataUnspent,0.1);
var outs = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.08}];
var tx = Transaction.create(utxos, outs, opts);
should.exist(tx);
@ -83,13 +83,13 @@ describe('Transaction', function() {
tx.ins.length.should.equal(2);
tx.outs.length.should.equal(2);
util.valueToBigInt(tx.outs[0].v).cmp(8000000).should.equal(0);
// remainder is 0.0299 here because unspend select utxos in order
// remainder is 0.0299 here because unspent select utxos in order
util.valueToBigInt(tx.outs[1].v).cmp(2990000).should.equal(0);
});
it('#create should fail if not enough inputs ', function() {
var utxos = Transaction.selectUnspent(testdata.dataUnspends,1);
var utxos = Transaction.selectUnspent(testdata.dataUnspent,1);
var outs = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.08}];
Transaction
.create
@ -99,7 +99,7 @@ describe('Transaction', function() {
it('#create should create same output as bitcoind createrawtransaction ', function() {
var utxos = Transaction.selectUnspent(testdata.dataUnspends,0.1);
var utxos = Transaction.selectUnspent(testdata.dataUnspent,0.1);
var outs = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.08}];
var tx = Transaction.create(utxos, outs, opts);
@ -117,7 +117,7 @@ describe('Transaction', function() {
});
it.skip('#sign should sign a tx', function() {
var utxos = Transaction.selectUnspent(testdata.dataUnspends,0.1);
var utxos = Transaction.selectUnspent(testdata.dataUnspentign.unspent,0.1);
var outs = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.08}];
var tx = Transaction.create(utxos, outs, opts);
});

View File

@ -7,7 +7,8 @@ var dataTxValid = JSON.parse(fs.readFileSync('test/data/tx_valid.json'));
var dataTxInvalid = JSON.parse(fs.readFileSync('test/data/tx_invalid.json'));
var dataScriptValid = JSON.parse(fs.readFileSync('test/data/script_valid.json'));
var dataScriptInvalid = JSON.parse(fs.readFileSync('test/data/script_invalid.json'));
var dataUnspends = JSON.parse(fs.readFileSync('test/data/unspends.json'));
var dataUnspent = JSON.parse(fs.readFileSync('test/data/unspent.json'));
var dataUnspentSign = JSON.parse(fs.readFileSync('test/data/unspentSign.json'));
module.exports.dataValid = dataValid;
@ -18,4 +19,5 @@ module.exports.dataTxInvalid = dataTxInvalid;
module.exports.dataScriptValid = dataScriptValid;
module.exports.dataScriptInvalid = dataScriptInvalid;
module.exports.dataScriptAll = dataScriptValid.concat(dataScriptInvalid);
module.exports.dataUnspends = dataUnspends;
module.exports.dataUnspent = dataUnspent;
module.exports.dataUnspentSign = dataUnspentSign;