aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-09-24 17:26:27 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-09-27 13:55:25 +0200
commit6fc2cd3f09d023b2e971dcdf8472956259f94c1d (patch)
tree2e997c82cf2b00c5e46ee5fde50f52e58e0de45b /test
parentaa26797f69e6ed10efcad9fb07be7f5b3b0ee513 (diff)
downloadbitcoin-6fc2cd3f09d023b2e971dcdf8472956259f94c1d.tar.xz
test: introduce helper to create random P2WPKH scriptPubKeys
Diffstat (limited to 'test')
-rw-r--r--test/functional/test_framework/wallet.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py
index 0fa31e68b6..ef27cb3221 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.