aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/blocktools.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/test_framework/blocktools.py')
-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