commit
106e00e6f1
10 changed files with 730 additions and 49 deletions
test
|
@ -183,7 +183,7 @@ describe('Bitcoin-core', function() {
|
|||
|
||||
var actualHash
|
||||
try {
|
||||
actualHash = transaction.hashForSignature(script, inIndex, hashType)
|
||||
actualHash = transaction.hashForSignature(inIndex, script, hashType)
|
||||
} catch (e) {
|
||||
// don't fail if we don't support it yet, TODO
|
||||
if (!e.message.match(/not yet supported/)) throw e
|
||||
|
|
152
test/fixtures/transaction_builder.json
vendored
Normal file
152
test/fixtures/transaction_builder.json
vendored
Normal file
|
@ -0,0 +1,152 @@
|
|||
{
|
||||
"valid": {
|
||||
"build": [
|
||||
{
|
||||
"description": "pubKeyHash->pubKeyHash 1:1 transaction",
|
||||
"txid": "bd641f4b0aa8bd70189ab45e935c4762f0e1c49f294b4779d79887937b7cf42e",
|
||||
"txhex": "0100000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000006b483045022100a3b254e1c10b5d039f36c05f323995d6e5a367d98dd78a13d5bbc3991b35720e022022fccea3897d594de0689601fbd486588d5bfa6915be2386db0397ee9a6e80b601210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ffffffff0110270000000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00000000",
|
||||
"inputs": [
|
||||
{
|
||||
"index": 0,
|
||||
"prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"privKeys": [
|
||||
"KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"value": 10000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "pubKey->pubKeyHash 1:1 transaction",
|
||||
"txid": "a900dea133a3c51e9fe55d82bf4a4f50a4c3ac6e380c841f93651a076573320c",
|
||||
"txhex": "0100000001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000494830450221009833abb3ab49d7004c06bcc79eafd6905ada3eee91f3376ad388548034acd9a702202e84dda6ef2678c82256afcfc459aaa68e179b2bb0e6b2dc3f1410e132c5e6c301ffffffff0100f90295000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00000000",
|
||||
"inputs": [
|
||||
{
|
||||
"index": 0,
|
||||
"prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"prevTxScript": "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 OP_CHECKSIG",
|
||||
"privKeys": [
|
||||
"KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"value": 2500000000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "2-of-2 P2SH multisig -> pubKeyHash 1:1 Transaction",
|
||||
"txid": "8c500ce6eef6c78a10de923b68394cf31120151bdc4600e4b12de865defa9d24",
|
||||
"txhex": "0100000001cff58855426469d0ef16442ee9c644c4fb13832467bcbc3173168a7916f0714900000000fd1a0100473044022040039a3d0a806d6c2c0ac8a62f2467c979c897c945f3f11905b9c5ea76b4a88002200976f187f852f7d186e8e8aa39332092aa8a504b63a7ae3d0eca09ebea1497fd0147304402205522d1949d13347054bd5ea86cdcad2344f49628a935faaee8f5e744bd3ef87e022063a28ab077817222ccd7d5a70e77ed7274840b9ba8db5dd93a33bdd41813d548014c8752410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a52aeffffffff0110270000000000001976a914faf1d99bf040ea9c7f8cc9f14ac6733ad75ce24688ac00000000",
|
||||
"inputs": [
|
||||
{
|
||||
"index": 0,
|
||||
"prevTx": "4971f016798a167331bcbc67248313fbc444c6e92e4416efd06964425588f5cf",
|
||||
"privKeys": [
|
||||
"91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgwmaKkrx",
|
||||
"91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgww7vXtT"
|
||||
],
|
||||
"redeemScript": "OP_2 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a OP_2 OP_CHECKMULTISIG"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"script": "OP_DUP OP_HASH160 faf1d99bf040ea9c7f8cc9f14ac6733ad75ce246 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"value": 10000
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"invalid": {
|
||||
"build": [
|
||||
{
|
||||
"exception": "Transaction has no inputs",
|
||||
"inputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"value": 1000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"exception": "Transaction has no outputs",
|
||||
"inputs": [
|
||||
{
|
||||
"index": 0,
|
||||
"prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"privKeys": []
|
||||
}
|
||||
],
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"exception": "Transaction has no signatures",
|
||||
"inputs": [
|
||||
{
|
||||
"index": 0,
|
||||
"prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"privKeys": []
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"value": 1000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"exception": "Transaction is missing signatures",
|
||||
"inputs": [
|
||||
{
|
||||
"index": 0,
|
||||
"prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"privKeys": [
|
||||
"KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn"
|
||||
]
|
||||
},
|
||||
{
|
||||
"index": 1,
|
||||
"prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"privKeys": []
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"value": 1000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"exception": "nulldata not supported",
|
||||
"inputs": [
|
||||
{
|
||||
"index": 0,
|
||||
"prevTx": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"prevTxScript": "OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474",
|
||||
"privKeys": [
|
||||
"KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"value": 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
})
|
||||
})
|
||||
|
|
|
@ -221,7 +221,7 @@ describe('Transaction', function() {
|
|||
// TODO:
|
||||
// hashForSignature: [Function],
|
||||
|
||||
// FIXME: could be better
|
||||
// FIXME: remove in 2.x.y
|
||||
describe('signInput/validateInput', function() {
|
||||
it('works for multi-sig redeem script', function() {
|
||||
var tx = new Transaction()
|
||||
|
|
262
test/transaction_builder.js
Normal file
262
test/transaction_builder.js
Normal file
|
@ -0,0 +1,262 @@
|
|||
var assert = require('assert')
|
||||
var ecdsa = require('../src/ecdsa')
|
||||
var scripts = require('../src/scripts')
|
||||
|
||||
var Address = require('../src/address')
|
||||
var BigInteger = require('bigi')
|
||||
var ECKey = require('../src/eckey')
|
||||
var Script = require('../src/script')
|
||||
var Transaction = require('../src/transaction')
|
||||
var TransactionBuilder = require('../src/transaction_builder')
|
||||
|
||||
var fixtures = require('./fixtures/transaction_builder')
|
||||
|
||||
describe('TransactionBuilder', function() {
|
||||
var privAddress, privScript
|
||||
var prevTx, prevTxHash
|
||||
var privKey
|
||||
var txb
|
||||
|
||||
beforeEach(function() {
|
||||
txb = new TransactionBuilder()
|
||||
|
||||
prevTx = new Transaction()
|
||||
prevTx.addOutput('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH', 0)
|
||||
prevTx.addOutput('1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP', 1)
|
||||
prevTxHash = prevTx.getHash()
|
||||
prevTxId = prevTx.getId()
|
||||
|
||||
privKey = new ECKey(BigInteger.ONE, false)
|
||||
privAddress = privKey.pub.getAddress()
|
||||
privScript = privAddress.toOutputScript()
|
||||
value = 10000
|
||||
})
|
||||
|
||||
describe('addInput', function() {
|
||||
it('accepts a txHash, index [and sequence number]', function() {
|
||||
var vin = txb.addInput(prevTxHash, 1, 54)
|
||||
assert.equal(vin, 0)
|
||||
|
||||
var txin = txb.tx.ins[0]
|
||||
assert.equal(txin.hash, prevTxHash)
|
||||
assert.equal(txin.index, 1)
|
||||
assert.equal(txin.sequence, 54)
|
||||
assert.equal(txb.prevOutScripts[0], undefined)
|
||||
})
|
||||
|
||||
it('accepts a txHash, index [, sequence number and scriptPubKey]', function() {
|
||||
var vin = txb.addInput(prevTxHash, 1, 54, prevTx.outs[1].script)
|
||||
assert.equal(vin, 0)
|
||||
|
||||
var txin = txb.tx.ins[0]
|
||||
assert.equal(txin.hash, prevTxHash)
|
||||
assert.equal(txin.index, 1)
|
||||
assert.equal(txin.sequence, 54)
|
||||
assert.equal(txb.prevOutScripts[0], prevTx.outs[1].script)
|
||||
})
|
||||
|
||||
it('accepts a prevTx, index [and sequence number]', function() {
|
||||
var vin = txb.addInput(prevTx, 1, 54)
|
||||
assert.equal(vin, 0)
|
||||
|
||||
var txin = txb.tx.ins[0]
|
||||
assert.deepEqual(txin.hash, prevTxHash)
|
||||
assert.equal(txin.index, 1)
|
||||
assert.equal(txin.sequence, 54)
|
||||
assert.equal(txb.prevOutScripts[0], prevTx.outs[1].script)
|
||||
})
|
||||
|
||||
it('returns the input index', function() {
|
||||
assert.equal(txb.addInput(prevTxHash, 0), 0)
|
||||
assert.equal(txb.addInput(prevTxHash, 1), 1)
|
||||
})
|
||||
|
||||
it('throws if prevOutScript is not supported', function() {
|
||||
assert.throws(function() {
|
||||
txb.addInput(prevTxHash, 0, undefined, Script.EMPTY)
|
||||
}, /PrevOutScript not supported \(nonstandard\)/)
|
||||
})
|
||||
|
||||
it('throws if SIGHASH_ALL has been used to sign any existing scriptSigs', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
txb.sign(0, privKey)
|
||||
|
||||
assert.throws(function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
}, /No, this would invalidate signatures/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('addOutput', function() {
|
||||
it('throws if SIGHASH_ALL has been used to sign any existing scriptSigs', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
txb.addOutput(privScript, value)
|
||||
txb.sign(0, privKey)
|
||||
|
||||
assert.throws(function() {
|
||||
txb.addOutput(privScript, 9000)
|
||||
}, /No, this would invalidate signatures/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('sign', function() {
|
||||
describe('when prevOutScript is undefined', function() {
|
||||
it('assumes pubKeyHash', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
txb.sign(0, privKey)
|
||||
|
||||
assert.strictEqual(txb.signatures[0].redeemScript, undefined)
|
||||
assert.equal(txb.signatures[0].scriptType, 'pubkeyhash')
|
||||
})
|
||||
})
|
||||
|
||||
describe('when redeemScript is defined', function() {
|
||||
it('assumes scriptHash', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
txb.sign(0, privKey, privScript)
|
||||
|
||||
assert.equal(txb.signatures[0].redeemScript, privScript)
|
||||
})
|
||||
|
||||
it('throws if prevOutScript is not P2SH', function() {
|
||||
txb.addInput(prevTx, 0)
|
||||
|
||||
assert.throws(function() {
|
||||
txb.sign(0, privKey, privScript)
|
||||
}, /PrevOutScript must be P2SH/)
|
||||
})
|
||||
|
||||
it('throws if redeemScript is P2SH', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
|
||||
var privScriptP2SH = scripts.scriptHashOutput(privScript.getHash())
|
||||
|
||||
assert.throws(function() {
|
||||
txb.sign(0, privKey, privScriptP2SH)
|
||||
}, /RedeemScript can\'t be P2SH/)
|
||||
})
|
||||
|
||||
it('throws if redeemScript not supported', function() {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
|
||||
assert.throws(function() {
|
||||
txb.sign(0, privKey, Script.EMPTY)
|
||||
}, /RedeemScript not supported \(nonstandard\)/)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('build', function() {
|
||||
fixtures.valid.build.forEach(function(f) {
|
||||
it('builds the correct transaction', function() {
|
||||
f.inputs.forEach(function(input) {
|
||||
var prevTxScript
|
||||
|
||||
if (input.prevTxScript) {
|
||||
prevTxScript = Script.fromASM(input.prevTxScript)
|
||||
}
|
||||
|
||||
txb.addInput(input.prevTx, input.index, input.sequence, prevTxScript)
|
||||
})
|
||||
|
||||
f.outputs.forEach(function(output) {
|
||||
var script = Script.fromASM(output.script)
|
||||
|
||||
txb.addOutput(script, output.value)
|
||||
})
|
||||
|
||||
f.inputs.forEach(function(input, index) {
|
||||
var redeemScript
|
||||
|
||||
if (input.redeemScript) {
|
||||
redeemScript = Script.fromASM(input.redeemScript)
|
||||
}
|
||||
|
||||
input.privKeys.forEach(function(wif) {
|
||||
var privKey = ECKey.fromWIF(wif)
|
||||
|
||||
txb.sign(index, privKey, redeemScript)
|
||||
})
|
||||
})
|
||||
|
||||
var tx = txb.build()
|
||||
|
||||
assert.equal(tx.getId(), f.txid)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.build.forEach(function(f) {
|
||||
it('throws on ' + f.exception, function() {
|
||||
f.inputs.forEach(function(input) {
|
||||
var prevTxScript
|
||||
|
||||
if (input.prevTxScript) {
|
||||
prevTxScript = Script.fromASM(input.prevTxScript)
|
||||
}
|
||||
|
||||
txb.addInput(input.prevTx, input.index, input.sequence, prevTxScript)
|
||||
})
|
||||
|
||||
f.outputs.forEach(function(output) {
|
||||
var script = Script.fromASM(output.script)
|
||||
|
||||
txb.addOutput(script, output.value)
|
||||
})
|
||||
|
||||
f.inputs.forEach(function(input, index) {
|
||||
var redeemScript
|
||||
|
||||
if (input.redeemScript) {
|
||||
redeemScript = Script.fromASM(input.redeemScript)
|
||||
}
|
||||
|
||||
input.privKeys.forEach(function(wif) {
|
||||
var privKey = ECKey.fromWIF(wif)
|
||||
|
||||
txb.sign(index, privKey, redeemScript)
|
||||
})
|
||||
})
|
||||
|
||||
assert.throws(function() {
|
||||
txb.build()
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('fromTransaction', function() {
|
||||
fixtures.valid.build.forEach(function(f) {
|
||||
it('builds the correct TransactionBuilder for ' + f.description, function() {
|
||||
var tx = Transaction.fromHex(f.txhex)
|
||||
var txb = TransactionBuilder.fromTransaction(tx)
|
||||
|
||||
assert.equal(txb.build().toHex(), f.txhex)
|
||||
})
|
||||
})
|
||||
|
||||
it('works for the P2SH multisig case', function() {
|
||||
var privKeys = [
|
||||
"91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgwmaKkrx",
|
||||
"91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgww7vXtT"
|
||||
].map(function(wif) { return ECKey.fromWIF(wif) })
|
||||
var redeemScript = Script.fromASM("OP_2 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a OP_2 OP_CHECKMULTISIG")
|
||||
|
||||
txb.addInput("4971f016798a167331bcbc67248313fbc444c6e92e4416efd06964425588f5cf", 0)
|
||||
txb.addOutput("1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH", 10000)
|
||||
txb.sign(0, privKeys[0], redeemScript)
|
||||
|
||||
var tx = txb.buildIncomplete()
|
||||
|
||||
// in another galaxy...
|
||||
// ... far, far away
|
||||
var txb2 = TransactionBuilder.fromTransaction(tx)
|
||||
|
||||
// [you should] verify that Transaction is what you want...
|
||||
// ... then sign it
|
||||
txb2.sign(0, privKeys[1], redeemScript)
|
||||
var tx2 = txb2.build()
|
||||
|
||||
assert.equal(tx2.toHex(), '0100000001cff58855426469d0ef16442ee9c644c4fb13832467bcbc3173168a7916f0714900000000fd1c01004830450221009c92c1ae1767ac04e424da7f6db045d979b08cde86b1ddba48621d59a109d818022004f5bb21ad72255177270abaeb2d7940ac18f1e5ca1f53db4f3fd1045647a8a8014830450221009418caa5bc18da87b188a180125c0cf06dce6092f75b2d3c01a29493466800fd02206ead65e7ca6e0f17eefe6f78457c084eab59af7c9882be1437de2e7116358eb9014c8752410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a52aeffffffff0110270000000000001976a914751e76e8199196d454941c45d1b3a323f1433bd688ac00000000')
|
||||
})
|
||||
})
|
||||
})
|
|
@ -7,6 +7,7 @@ var scripts = require('../src/scripts')
|
|||
var Address = require('../src/address')
|
||||
var HDNode = require('../src/hdnode')
|
||||
var Transaction = require('../src/transaction')
|
||||
var TransactionBuilder = require('../src/transaction_builder')
|
||||
var Wallet = require('../src/wallet')
|
||||
|
||||
var fixtureTxes = require('./fixtures/mainnet_tx')
|
||||
|
@ -623,17 +624,17 @@ describe('Wallet', function() {
|
|||
|
||||
describe('signing', function(){
|
||||
afterEach(function(){
|
||||
Transaction.prototype.sign.restore()
|
||||
TransactionBuilder.prototype.sign.restore()
|
||||
})
|
||||
|
||||
it('signs the inputs with respective keys', function(){
|
||||
var fee = 30000
|
||||
sinon.stub(Transaction.prototype, "sign")
|
||||
sinon.spy(TransactionBuilder.prototype, "sign")
|
||||
|
||||
var tx = wallet.createTx(to, value, fee)
|
||||
|
||||
assert(Transaction.prototype.sign.calledWith(0, wallet.getPrivateKeyForAddress(address2)))
|
||||
assert(Transaction.prototype.sign.calledWith(1, wallet.getPrivateKeyForAddress(address1)))
|
||||
assert(TransactionBuilder.prototype.sign.calledWith(0, wallet.getPrivateKeyForAddress(address2)))
|
||||
assert(TransactionBuilder.prototype.sign.calledWith(1, wallet.getPrivateKeyForAddress(address1)))
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue