From d178082996dc3000f42816f89afcf3fa4d31e159 Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Thu, 23 Mar 2023 12:00:54 +0100 Subject: [PATCH] test: add bech32 decoding support to address_to_scriptpubkey() This permits functional tests to decode bech32 addresses to scriptpubkeys. --- test/functional/test_framework/wallet.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py index f3253630c46..eab8fbda470 100644 --- a/test/functional/test_framework/wallet.py +++ b/test/functional/test_framework/wallet.py @@ -14,6 +14,7 @@ from typing import ( ) from test_framework.address import ( base58_to_byte, + bech32_to_bytes, create_deterministic_address_bcrt1_p2tr_op_true, key_to_p2pkh, key_to_p2sh_p2wpkh, @@ -49,6 +50,7 @@ from test_framework.script_util import ( key_to_p2sh_p2wpkh_script, key_to_p2wpkh_script, keyhash_to_p2pkh_script, + program_to_witness_script, scripthash_to_p2sh_script, ) from test_framework.util import ( @@ -414,6 +416,9 @@ def getnewdestination(address_type='bech32m'): def address_to_scriptpubkey(address): """Converts a given address to the corresponding output script (scriptPubKey).""" + version, payload = bech32_to_bytes(address) + if version is not None: + return program_to_witness_script(version, payload) # testnet segwit scriptpubkey payload, version = base58_to_byte(address) if version == 111: # testnet pubkey hash return keyhash_to_p2pkh_script(payload)