From f7e3c037e79a30f3ce15e42eec8cbc1db125cfa6 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 1 Oct 2014 11:47:49 -0300 Subject: [PATCH] add test for uxtos containing dust --- test/data/unspentDust.json | 46 +++++++++++++++++++++++++++++++++ test/test.TransactionBuilder.js | 43 ++++++++++++++++++++++++++++++ test/testdata.js | 2 ++ 3 files changed, 91 insertions(+) create mode 100644 test/data/unspentDust.json diff --git a/test/data/unspentDust.json b/test/data/unspentDust.json new file mode 100644 index 000000000..2e0ee1b0d --- /dev/null +++ b/test/data/unspentDust.json @@ -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 + } +] diff --git a/test/test.TransactionBuilder.js b/test/test.TransactionBuilder.js index 418c34825..0885e1229 100644 --- a/test/test.TransactionBuilder.js +++ b/test/test.TransactionBuilder.js @@ -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() { @@ -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(); diff --git a/test/testdata.js b/test/testdata.js index a86183e11..58b087bd3 100644 --- a/test/testdata.js +++ b/test/testdata.js @@ -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')); @@ -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;