From 5e1cd6e995f2945263da6c6fec6b1f29c536bbed Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 27 Jan 2015 17:26:34 +1100 Subject: [PATCH 1/2] integration: avoid looking up all address transactions each time --- test/integration/advanced.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/integration/advanced.js b/test/integration/advanced.js index b4effbb..dd3b8e2 100644 --- a/test/integration/advanced.js +++ b/test/integration/advanced.js @@ -31,30 +31,27 @@ describe('bitcoinjs-lib (advanced)', function() { blockchain.addresses.unspents(address, function(err, unspents) { if (err) return done(err) - // filter small unspents - unspents = unspents.filter(function(unspent) { return unspent.value > 1e4 }) - - // use the oldest unspent - var unspent = unspents.pop() - var tx = new bitcoin.TransactionBuilder() - var data = new Buffer('cafedeadbeef', 'hex') var dataScript = bitcoin.scripts.nullDataOutput(data) + var unspent = unspents.pop() + tx.addInput(unspent.txId, unspent.vout) tx.addOutput(dataScript, 1000) tx.sign(0, key) - blockchain.transactions.propagate(tx.build().toHex(), function(err) { + var txBuilt = tx.build() + + blockchain.transactions.propagate(txBuilt.toHex(), function(err) { if (err) return done(err) // check that the message was propagated - blockchain.addresses.transactions(address, function(err, transactions) { + blockchain.transactions.get(txBuilt.getId(), function(err, transaction) { if (err) return done(err) - var transaction = bitcoin.Transaction.fromHex(transactions[0].txHex) - var dataScript2 = transaction.outs[0].script + var actual = bitcoin.Transaction.fromHex(transaction.txHex) + var dataScript2 = actual.outs[0].script var data2 = dataScript2.chunks[1] assert.deepEqual(dataScript, dataScript2) From 234ae84b86b646b874887e1aa447c611c671e71c Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 27 Jan 2015 17:32:20 +1100 Subject: [PATCH 2/2] integration: use 'bitcoinjs-lib' as OP_RETURN constant --- test/integration/advanced.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/advanced.js b/test/integration/advanced.js index dd3b8e2..482d316 100644 --- a/test/integration/advanced.js +++ b/test/integration/advanced.js @@ -32,7 +32,7 @@ describe('bitcoinjs-lib (advanced)', function() { if (err) return done(err) var tx = new bitcoin.TransactionBuilder() - var data = new Buffer('cafedeadbeef', 'hex') + var data = new Buffer('bitcoinjs-lib') var dataScript = bitcoin.scripts.nullDataOutput(data) var unspent = unspents.pop()