|
|
@ -94,8 +94,9 @@ describe('Transaction', function() { |
|
|
|
tx.outs.length.should.equal(2); |
|
|
|
|
|
|
|
util.valueToBigInt(tx.outs[0].v).cmp(8000000).should.equal(0); |
|
|
|
|
|
|
|
// remainder is 0.0299 here because unspent select utxos in order
|
|
|
|
util.valueToBigInt(tx.outs[1].v).cmp(2900000).should.equal(0); |
|
|
|
util.valueToBigInt(tx.outs[1].v).cmp(2990000).should.equal(0); |
|
|
|
tx.isComplete().should.equal(false); |
|
|
|
}); |
|
|
|
|
|
|
@ -106,6 +107,12 @@ describe('Transaction', function() { |
|
|
|
.create |
|
|
|
.bind(utxos, outs, null, opts) |
|
|
|
.should.throw(); |
|
|
|
|
|
|
|
var outs2 = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.5}]; |
|
|
|
should.exist( Transaction.create(utxos, outs2, null, opts)); |
|
|
|
|
|
|
|
// do not allow unconfirmed
|
|
|
|
Transaction.create.bind(utxos, outs2).should.throw(); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -116,7 +123,7 @@ describe('Transaction', function() { |
|
|
|
|
|
|
|
|
|
|
|
// string output generated from: bitcoind createrawtransaction '[{"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1","vout":1},{"txid":"2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc2","vout":0} ]' '{"mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE":0.08,"mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd":0.0299}'
|
|
|
|
tx.serialize().toString('hex').should.equal('0100000002c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a0100000000ffffffffc2cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a0000000000ffffffff0200127a00000000001976a914774e603bafb717bd3f070e68bbcccfd907c77d1388ac20402c00000000001976a914b00127584485a7cff0949ef0f6bc5575f06ce00d88ac00000000'); |
|
|
|
tx.serialize().toString('hex').should.equal('0100000002c1cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a0100000000ffffffffc2cf12ab89729d19d3cdec8ae531b5038d56c741006a105d532b3a7afa65c12a0000000000ffffffff0200127a00000000001976a914774e603bafb717bd3f070e68bbcccfd907c77d1388acb09f2d00000000001976a914b00127584485a7cff0949ef0f6bc5575f06ce00d88ac00000000'); |
|
|
|
|
|
|
|
// no remainder
|
|
|
|
outs = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.08}]; |
|
|
@ -132,10 +139,14 @@ describe('Transaction', function() { |
|
|
|
var outs = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.08}]; |
|
|
|
var tx = Transaction.create(utxos, outs, testdata.dataUnspentSign.keyStrings, opts); |
|
|
|
tx.isComplete().should.equal(true); |
|
|
|
tx.ins.length.should.equal(1); |
|
|
|
tx.outs.length.should.equal(2); |
|
|
|
|
|
|
|
var outs2 = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:16}]; |
|
|
|
var tx2 = Transaction.create(utxos, outs2, testdata.dataUnspentSign.keyStrings, opts); |
|
|
|
tx2.isComplete().should.equal(true); |
|
|
|
tx2.ins.length.should.equal(3); |
|
|
|
tx2.outs.length.should.equal(2); |
|
|
|
}); |
|
|
|
|
|
|
|
it('#sign should sign an incomplete tx ', function() { |
|
|
@ -143,6 +154,8 @@ describe('Transaction', function() { |
|
|
|
var utxos =testdata.dataUnspentSign.unspent; |
|
|
|
var outs = [{address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.08}]; |
|
|
|
var tx = Transaction.create(utxos, outs, keys, opts); |
|
|
|
tx.ins.length.should.equal(1); |
|
|
|
tx.outs.length.should.equal(2); |
|
|
|
tx.isComplete().should.equal(false); |
|
|
|
}); |
|
|
|
it('#sign should sign a tx in multiple steps', function() { |
|
|
@ -165,6 +178,51 @@ describe('Transaction', function() { |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
it('#create: should generate dynamic fee and readjust (and not) the selected UTXOs', function() { |
|
|
|
//this cases exceeds the input by 1mbtc AFTEr calculating the dynamic fee,
|
|
|
|
//so, it should trigger adding a new 10BTC utxo
|
|
|
|
var utxos =testdata.dataUnspentSign.unspent; |
|
|
|
var outs = []; |
|
|
|
var n =101; |
|
|
|
for (var i=0; i<n; i++) { |
|
|
|
outs.push({address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.01}); |
|
|
|
} |
|
|
|
|
|
|
|
var tx = Transaction.create(utxos, outs, testdata.dataUnspentSign.keyStrings, opts); |
|
|
|
tx.getSize().should.equal(3560); |
|
|
|
|
|
|
|
// ins = 11.0101 BTC (2 inputs: 1.0101 + 10 );
|
|
|
|
tx.ins.length.should.equal(2); |
|
|
|
// outs = 101 outs:
|
|
|
|
// 101 * 0.01 = 1.01BTC; + 0.0004 fee = 1.0104btc
|
|
|
|
// remainder = 11.0101-1.0104 = 9.9997
|
|
|
|
tx.outs.length.should.equal(102); |
|
|
|
util.valueToBigInt(tx.outs[n].v).cmp(999970000).should.equal(0); |
|
|
|
tx.isComplete().should.equal(true); |
|
|
|
|
|
|
|
|
|
|
|
//this is the complementary case, it does not trigger a new utxo
|
|
|
|
var utxos =testdata.dataUnspentSign.unspent; |
|
|
|
var outs = []; |
|
|
|
var n =100; |
|
|
|
for (var i=0; i<n; i++) { |
|
|
|
outs.push({address:'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE', amount:0.01}); |
|
|
|
} |
|
|
|
|
|
|
|
var tx = Transaction.create(utxos, outs, testdata.dataUnspentSign.keyStrings, opts); |
|
|
|
tx.getSize().should.equal(3485); |
|
|
|
|
|
|
|
// ins = 1.0101 BTC (1 inputs: 1.0101);
|
|
|
|
tx.ins.length.should.equal(1); |
|
|
|
// outs = 100 outs:
|
|
|
|
// 100 * 0.01 = 1BTC; + 0.0004 fee = 1.0004btc
|
|
|
|
// remainder = 1.0101-1.0004 = 0.0097
|
|
|
|
tx.outs.length.should.equal(101); |
|
|
|
util.valueToBigInt(tx.outs[n].v).cmp(970000).should.equal(0); |
|
|
|
tx.isComplete().should.equal(true); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Read tests from test/data/tx_valid.json
|
|
|
|
// Format is an array of arrays
|
|
|
|
// Inner arrays are either [ "comment" ]
|
|
|
|