From f3199b6fcef68ea543a8c33200c20c37a3e29c8d Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Fri, 25 Jul 2014 16:18:13 +1000 Subject: [PATCH] tests: integration test to use TxBuilder --- test/integration/p2sh.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/test/integration/p2sh.js b/test/integration/p2sh.js index ff7946c..3d47406 100644 --- a/test/integration/p2sh.js +++ b/test/integration/p2sh.js @@ -1,14 +1,12 @@ var assert = require('assert') var bitcoin = require('../../') -var crypto = bitcoin.crypto var networks = bitcoin.networks var scripts = bitcoin.scripts var Address = bitcoin.Address var ECKey = bitcoin.ECKey -var Transaction = bitcoin.Transaction -var Script = bitcoin.Script +var TransactionBuilder = bitcoin.TransactionBuilder var helloblock = require('helloblock-js')({ network: 'testnet' @@ -43,35 +41,31 @@ describe('Bitcoin-js', function() { var targetAddress = ECKey.makeRandom().pub.getAddress(networks.testnet).toString() // get latest unspents from the multisigAddress - helloblock.addresses.getUnspents(multisigAddress, function(err, resp, resource) { + helloblock.addresses.getUnspents(multisigAddress, function(err, res, unspents) { if (err) return done(err) // use the oldest unspent - var unspent = resource[resource.length - 1] + var unspent = unspents[unspents.length - 1] var spendAmount = Math.min(unspent.value, outputAmount) - var tx = new Transaction() - tx.addInput(unspent.txHash, unspent.index) - tx.addOutput(targetAddress, spendAmount) + var txb = new TransactionBuilder() + txb.addInput(unspent.txHash, unspent.index) + txb.addOutput(targetAddress, spendAmount) - var signatures = privKeys.map(function(privKey) { - return tx.signInput(0, redeemScript, privKey) + privKeys.forEach(function(privKey) { + txb.sign(0, privKey, redeemScript) }) - var redeemScriptSig = scripts.multisigInput(signatures) - var scriptSig = scripts.scriptHashInput(redeemScriptSig, redeemScript) - tx.setInputScript(0, scriptSig) - // broadcast our transaction - helloblock.transactions.propagate(tx.toHex(), function(err, resp, resource) { + helloblock.transactions.propagate(txb.build().toHex(), function(err, res) { // no err means that the transaction has been successfully propagated if (err) return done(err) // Check that the funds (spendAmount Satoshis) indeed arrived at the intended address - helloblock.addresses.get(targetAddress, function(err, resp, resource) { + helloblock.addresses.get(targetAddress, function(err, res, addrInfo) { if (err) return done(err) - assert.equal(resource.balance, spendAmount) + assert.equal(addrInfo.balance, spendAmount) done() }) })