TxBuilder: move param coercion from Transaction to TxBuilder
This commit is contained in:
parent
5beee20038
commit
7f3b4c93ba
4 changed files with 60 additions and 103 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
var assert = require('assert')
|
||||
|
||||
var Address = require('../src/address')
|
||||
var BigInteger = require('bigi')
|
||||
var ECKey = require('../src/eckey')
|
||||
var Script = require('../src/script')
|
||||
|
@ -62,8 +63,8 @@ describe('TransactionBuilder', function () {
|
|||
txb = new TransactionBuilder()
|
||||
|
||||
prevTx = new Transaction()
|
||||
prevTx.addOutput('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH', 0)
|
||||
prevTx.addOutput('1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP', 1)
|
||||
prevTx.addOutput(Address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH').toOutputScript(), 0)
|
||||
prevTx.addOutput(Address.fromBase58Check('1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP').toOutputScript(), 1)
|
||||
prevTxHash = prevTx.getHash()
|
||||
|
||||
privKey = new ECKey(BigInteger.ONE, false)
|
||||
|
@ -121,6 +122,33 @@ describe('TransactionBuilder', function () {
|
|||
})
|
||||
|
||||
describe('addOutput', function () {
|
||||
it('accepts an address string and value', function () {
|
||||
var vout = txb.addOutput(privAddress.toBase58Check(), 1000)
|
||||
assert.equal(vout, 0)
|
||||
|
||||
var txout = txb.tx.outs[0]
|
||||
assert.deepEqual(txout.script, privScript)
|
||||
assert.equal(txout.value, 1000)
|
||||
})
|
||||
|
||||
it('accepts an Address object and value', function () {
|
||||
var vout = txb.addOutput(privAddress, 1000)
|
||||
assert.equal(vout, 0)
|
||||
|
||||
var txout = txb.tx.outs[0]
|
||||
assert.deepEqual(txout.script, privScript)
|
||||
assert.equal(txout.value, 1000)
|
||||
})
|
||||
|
||||
it('accepts a ScriptPubKey and value', function () {
|
||||
var vout = txb.addOutput(privScript, 1000)
|
||||
assert.equal(vout, 0)
|
||||
|
||||
var txout = txb.tx.outs[0]
|
||||
assert.deepEqual(txout.script, privScript)
|
||||
assert.equal(txout.value, 1000)
|
||||
})
|
||||
|
||||
it('throws if SIGHASH_ALL has been used to sign any existing scriptSigs', function () {
|
||||
txb.addInput(prevTxHash, 0)
|
||||
txb.addOutput(privScript, 2000)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue