aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
authorConor Scott <conor.r.scott.88@gmail.com>2018-07-30 10:16:40 +0200
committerConor Scott <conor.r.scott.88@gmail.com>2018-08-09 12:58:36 +0200
commit736f9414246f2a855e7b6fc57c8f903e60530540 (patch)
tree4a2ff2b6cc647e36d1c4ec96523950047c2c25c2 /test/functional/test_framework
parent157651855f91c3c093c27290a349a231ac5ba740 (diff)
downloadbitcoin-736f9414246f2a855e7b6fc57c8f903e60530540.tar.xz
[Tests] Cleanup extra instances of create_transaction
Diffstat (limited to 'test/functional/test_framework')
-rw-r--r--test/functional/test_framework/blocktools.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py
index c2d20d27b5..56f70d9833 100644
--- a/test/functional/test_framework/blocktools.py
+++ b/test/functional/test_framework/blocktools.py
@@ -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