From 6fc2cd3f09d023b2e971dcdf8472956259f94c1d Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Fri, 24 Sep 2021 17:26:27 +0200 Subject: [PATCH] test: introduce helper to create random P2WPKH scriptPubKeys --- test/functional/test_framework/wallet.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index 0fa31e68b64..ef27cb3221f 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -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.