Skip to content

Commit

Permalink
Merge pull request bitpay#520 from matiu/test/dust
Browse files Browse the repository at this point in the history
add test for uxtos containing dust
  • Loading branch information
maraoz committed Oct 1, 2014
2 parents 85b55de + f7e3c03 commit a4ea349
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/data/unspentDust.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[{
"address": "3M9KXMPSVmiGi3hMn8uLCfGpvL4uDVxesf",
"txid": "a81dee966f2c9e8b0dfed79e2cece5f75a8381717521e60d4c67bd3cb47bfc4a",
"vout": 12,
"ts": 1411839163,
"scriptPubKey": "a914d563e5922bb15a5564a69e1b98202ec086eaf5ab87",
"amount": 1e-8,
"confirmations": 6,
"confirmationsFromCache": true
},


{
"address": "3M9KXMPSVmiGi3hMn8uLCfGpvL4uDVxesf",
"txid": "183861109cf81ea2305873957a3c2619a8a299b580bbb613880f99bf7c4d4e81",
"vout": 1,
"ts": 1411765691,
"scriptPubKey": "a914d563e5922bb15a5564a69e1b98202ec086eaf5ab87",
"amount": 0.06407,
"confirmations": 6,
"confirmationsFromCache": true
},

{
"address": "3QfLBMCLsjWRgJBbze7ebsRq46YHmbWnkd",
"txid": "a84dd7361ad406c13a13499167397cc68da221aaadec3669475df58ba4127d30",
"vout": 45,
"ts": 1411839163,
"scriptPubKey": "a914fbf94cc1a14da52761e4704ac371f87b2b4e475187",
"amount": 1e-8,
"confirmations": 6,
"confirmationsFromCache": true
},


{
"address": "3QfLBMCLsjWRgJBbze7ebsRq46YHmbWnkd",
"txid": "fe017b836ece3b1ab11d42409632fc6bc9757d116e12d80f74f7982d0c247ece",
"vout": 0,
"ts": 1411765691,
"scriptPubKey": "a914fbf94cc1a14da52761e4704ac371f87b2b4e475187",
"amount": 3.5348,
"confirmations": 6,
"confirmationsFromCache": true
}
]
43 changes: 43 additions & 0 deletions test/test.TransactionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ describe('TransactionBuilder', function() {
.setOutputs(outs);
};


var getBuilderDust = function() {
var opts = {
remainderOut: {
address: 'mwZabyZXg8JzUtFX1pkGygsMJjnuqiNhgd'
},
spendUnconfirmed: true,
};

var outs = [{
address: 'mrPnbY1yKDBsdgbHbS7kJ8GVm8F66hWHLE',
amount: 3.27585303,
}];

return new TransactionBuilder(opts)
.setUnspent(testdata.dataUnspentDust)
.setOutputs(outs);
};



it('should fail to create tx', function() {

(function() {
Expand Down Expand Up @@ -213,6 +234,28 @@ describe('TransactionBuilder', function() {
});


it('should be able to create a tx with dust UTXOs', function() {
var b = getBuilderDust();

b.isFullySigned().should.equal(false);
b.getSelectedUnspent().length.should.equal(4);

var tx = b.build();
should.exist(tx);

tx.version.should.equal(1);
tx.ins.length.should.equal(4);
tx.outs.length.should.equal(2);
util.valueToBigInt(tx.outs[0].v).cmp(327585303).should.equal(0);


// remainder is ( 0.06407+ 3.5348 + 1-e8 + 1-e8 ) * 100000000 - fee - 359877002
util.valueToBigInt(tx.outs[1].v).cmp(32291699).should.equal(0);
});




it('should create same output as bitcoind createrawtransaction ', function() {
var tx = getBuilder2().build();

Expand Down
2 changes: 2 additions & 0 deletions test/testdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var dataScriptValid = JSON.parse(fs.readFileSync('test/data/script_valid.json'))
var dataScriptInvalid = JSON.parse(fs.readFileSync('test/data/script_invalid.json'));
var dataUnspent = JSON.parse(fs.readFileSync('test/data/unspent.json'));
var dataUnspentSign = JSON.parse(fs.readFileSync('test/data/unspentSign.json'));
var dataUnspentDust = JSON.parse(fs.readFileSync('test/data/unspentDust.json'));
var dataSigCanonical = JSON.parse(fs.readFileSync('test/data/sig_canonical.json'));
var dataSigNonCanonical = JSON.parse(fs.readFileSync('test/data/sig_noncanonical.json'));
var dataBase58KeysValid = JSON.parse(fs.readFileSync('test/data/base58_keys_valid.json'));
Expand All @@ -26,6 +27,7 @@ module.exports.dataScriptInvalid = dataScriptInvalid;
module.exports.dataScriptAll = dataScriptValid.concat(dataScriptInvalid);
module.exports.dataUnspent = dataUnspent;
module.exports.dataUnspentSign = dataUnspentSign;
module.exports.dataUnspentDust = dataUnspentDust;
module.exports.dataSigCanonical = dataSigCanonical;
module.exports.dataSigNonCanonical = dataSigNonCanonical;
module.exports.dataBase58KeysValid = dataBase58KeysValid;
Expand Down

0 comments on commit a4ea349

Please sign in to comment.