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