aboutsummaryrefslogtreecommitdiff
path: root/test/functional/feature_segwit.py
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-07-31 21:23:16 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-08-01 19:26:51 +0200
commitca6c154ef116e8d2e0484cdb1af13b34a0c86c17 (patch)
tree4b38a878a5b2fd0f49a2cc0b0e1948b8119b40e9 /test/functional/feature_segwit.py
parentf2e41d11097dde1c841bcaa8615886c984f71632 (diff)
downloadbitcoin-ca6c154ef116e8d2e0484cdb1af13b34a0c86c17.tar.xz
test: refactor: remove `hex_str_to_bytes` helper
Use the built-in class method bytes.fromhex() instead, which is available since Python 3.0.
Diffstat (limited to 'test/functional/feature_segwit.py')
-rwxr-xr-xtest/functional/feature_segwit.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/test/functional/feature_segwit.py b/test/functional/feature_segwit.py
index 9cf46d9d11..f36575627e 100755
--- a/test/functional/feature_segwit.py
+++ b/test/functional/feature_segwit.py
@@ -46,7 +46,6 @@ from test_framework.util import (
assert_equal,
assert_is_hex_string,
assert_raises_rpc_error,
- hex_str_to_bytes,
try_rpc,
)
@@ -140,7 +139,7 @@ class SegWitTest(BitcoinTestFramework):
for i in range(3):
newaddress = self.nodes[i].getnewaddress()
self.pubkey.append(self.nodes[i].getaddressinfo(newaddress)["pubkey"])
- multiscript = CScript([OP_1, hex_str_to_bytes(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
+ multiscript = CScript([OP_1, bytes.fromhex(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
p2sh_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'p2sh-segwit')['address']
bip173_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'bech32')['address']
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
@@ -352,7 +351,7 @@ class SegWitTest(BitcoinTestFramework):
# Money sent to P2SH of multisig of this should only be seen after importaddress with the BASE58 P2SH address.
multisig_without_privkey_address = self.nodes[0].addmultisigaddress(2, [pubkeys[3], pubkeys[4]])['address']
- script = CScript([OP_2, hex_str_to_bytes(pubkeys[3]), hex_str_to_bytes(pubkeys[4]), OP_2, OP_CHECKMULTISIG])
+ script = CScript([OP_2, bytes.fromhex(pubkeys[3]), bytes.fromhex(pubkeys[4]), OP_2, OP_CHECKMULTISIG])
solvable_after_importaddress.append(script_to_p2sh_script(script))
for i in compressed_spendable_address:
@@ -426,7 +425,7 @@ class SegWitTest(BitcoinTestFramework):
op1 = CScript([OP_1])
op0 = CScript([OP_0])
# 2N7MGY19ti4KDMSzRfPAssP6Pxyuxoi6jLe is the P2SH(P2PKH) version of mjoE3sSrb8ByYEvgnC3Aox86u1CHnfJA4V
- unsolvable_address_key = hex_str_to_bytes("02341AEC7587A51CDE5279E0630A531AEA2615A9F80B17E8D9376327BAEAA59E3D")
+ unsolvable_address_key = bytes.fromhex("02341AEC7587A51CDE5279E0630A531AEA2615A9F80B17E8D9376327BAEAA59E3D")
unsolvablep2pkh = key_to_p2pkh_script(unsolvable_address_key)
unsolvablep2wshp2pkh = script_to_p2wsh_script(unsolvablep2pkh)
p2shop0 = script_to_p2sh_script(op0)
@@ -448,11 +447,11 @@ class SegWitTest(BitcoinTestFramework):
for i in compressed_spendable_address + uncompressed_spendable_address + compressed_solvable_address + uncompressed_solvable_address:
v = self.nodes[0].getaddressinfo(i)
if (v['isscript']):
- bare = hex_str_to_bytes(v['hex'])
+ bare = bytes.fromhex(v['hex'])
importlist.append(bare.hex())
importlist.append(script_to_p2wsh_script(bare).hex())
else:
- pubkey = hex_str_to_bytes(v['pubkey'])
+ pubkey = bytes.fromhex(v['pubkey'])
p2pk = CScript([pubkey, OP_CHECKSIG])
p2pkh = key_to_p2pkh_script(pubkey)
importlist.append(p2pk.hex())
@@ -612,18 +611,18 @@ class SegWitTest(BitcoinTestFramework):
return txid
def p2sh_address_to_script(self, v):
- bare = CScript(hex_str_to_bytes(v['hex']))
- p2sh = CScript(hex_str_to_bytes(v['scriptPubKey']))
+ bare = CScript(bytes.fromhex(v['hex']))
+ p2sh = CScript(bytes.fromhex(v['scriptPubKey']))
p2wsh = script_to_p2wsh_script(bare)
p2sh_p2wsh = script_to_p2sh_script(p2wsh)
return([bare, p2sh, p2wsh, p2sh_p2wsh])
def p2pkh_address_to_script(self, v):
- pubkey = hex_str_to_bytes(v['pubkey'])
+ pubkey = bytes.fromhex(v['pubkey'])
p2wpkh = key_to_p2wpkh_script(pubkey)
p2sh_p2wpkh = script_to_p2sh_script(p2wpkh)
p2pk = CScript([pubkey, OP_CHECKSIG])
- p2pkh = CScript(hex_str_to_bytes(v['scriptPubKey']))
+ p2pkh = CScript(bytes.fromhex(v['scriptPubKey']))
p2sh_p2pk = script_to_p2sh_script(p2pk)
p2sh_p2pkh = script_to_p2sh_script(p2pkh)
p2wsh_p2pk = script_to_p2wsh_script(p2pk)