[Tests] Cleanup extra instances of create_transaction

This commit is contained in:
Conor Scott
2018-07-30 10:16:40 +02:00
parent 157651855f
commit 736f941424
9 changed files with 46 additions and 73 deletions

View File

@ -39,6 +39,7 @@ from .script import (
hash160,
)
from .util import assert_equal
from io import BytesIO
# From BIP141
WITNESS_COMMITMENT_HEADER = b"\xaa\x21\xa9\xed"
@ -117,17 +118,30 @@ def create_coinbase(height, pubkey=None):
coinbase.calc_sha256()
return coinbase
def create_transaction(prevtx, n, sig, value, script_pub_key=CScript()):
"""Create a transaction.
def create_tx_with_script(prevtx, n, script_sig=b"", amount=1, script_pub_key=CScript()):
"""Return one-input, one-output transaction object
spending the prevtx's n-th output with the given amount.
If the script_pub_key is not specified, make it anyone-can-spend."""
Can optionally pass scriptPubKey and scriptSig, default is anyone-can-spend ouput.
"""
tx = CTransaction()
assert(n < len(prevtx.vout))
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff))
tx.vout.append(CTxOut(value, script_pub_key))
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), script_sig, 0xffffffff))
tx.vout.append(CTxOut(amount, script_pub_key))
tx.calc_sha256()
return tx
def create_transaction(node, txid, to_address, amount):
""" Return signed transaction spending the first output of the
input txid. Note that the node must be able to sign for the
output that is being spent, and the node must not be running
multiple wallets.
"""
raw_tx = create_raw_transaction(node, txid, to_address, amount)
tx = CTransaction()
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx)))
return tx
def create_raw_transaction(node, txid, to_address, amount):
""" Return raw signed transaction spending the first output of the
input txid. Note that the node must be able to sign for the