mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-09 18:00:13 +02:00
test: refactor: remove hex_str_to_bytes
helper
Use the built-in class method bytes.fromhex() instead, which is available since Python 3.0.
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user