test: introduce helper to create random P2WPKH scriptPubKeys

This commit is contained in:
Sebastian Falbesoner committed 2021-09-27 13:55:25 +02:00
1 parent aa26797f69
commit 6fc2cd3f09
1 file changed
+9
+9
View File
@@ -28,6 +28,7 @@ from test_framework.script import (
OP_NOP,
SIGHASH_ALL,
)
from test_framework.script_util import key_to_p2wpkh_script
from test_framework.util import (
assert_equal,
assert_greater_than_or_equal,
@@ -207,6 +208,14 @@ class MiniWallet:
return txid
def random_p2wpkh():
"""Generate a random P2WPKH scriptPubKey. Can be used when a random destination is needed,
but no compiled wallet is available (e.g. as replacement to the getnewaddress RPC)."""
key = ECKey()
key.generate()
return key_to_p2wpkh_script(key.get_pubkey().get_bytes())
def make_chain(node, address, privkeys, parent_txid, parent_value, n=0, parent_locking_script=None, fee=DEFAULT_FEE):
"""Build a transaction that spends parent_txid.vout[n] and produces one output with
amount = parent_value with a fee deducted.