Skip to content

Commit 6fc2cd3

Browse files
committed
test: introduce helper to create random P2WPKH scriptPubKeys
1 parent aa26797 commit 6fc2cd3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

test/functional/test_framework/wallet.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
OP_NOP,
2929
SIGHASH_ALL,
3030
)
31+
from test_framework.script_util import key_to_p2wpkh_script
3132
from test_framework.util import (
3233
assert_equal,
3334
assert_greater_than_or_equal,
@@ -207,6 +208,14 @@ def sendrawtransaction(self, *, from_node, tx_hex):
207208
return txid
208209

209210

211+
def random_p2wpkh():
212+
"""Generate a random P2WPKH scriptPubKey. Can be used when a random destination is needed,
213+
but no compiled wallet is available (e.g. as replacement to the getnewaddress RPC)."""
214+
key = ECKey()
215+
key.generate()
216+
return key_to_p2wpkh_script(key.get_pubkey().get_bytes())
217+
218+
210219
def make_chain(node, address, privkeys, parent_txid, parent_value, n=0, parent_locking_script=None, fee=DEFAULT_FEE):
211220
"""Build a transaction that spends parent_txid.vout[n] and produces one output with
212221
amount = parent_value with a fee deducted.

0 commit comments

Comments
 (0)