Skip to content

Commit fa54efd

Browse files
author
MarcoFalke
committed
test: pep-8 touched test
Can be reviewed with "--word-diff-regex=.".
1 parent fa46768 commit fa54efd

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

test/functional/test_framework/script_util.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Useful Script constants and utils."""
6-
from test_framework.script import CScript, hash160, sha256, OP_0, OP_DUP, OP_HASH160, OP_CHECKSIG, OP_EQUAL, OP_EQUALVERIFY
6+
from test_framework.script import (
7+
CScript,
8+
hash160,
9+
sha256,
10+
OP_0,
11+
OP_DUP,
12+
OP_HASH160,
13+
OP_CHECKSIG,
14+
OP_EQUAL,
15+
OP_EQUALVERIFY,
16+
)
717

818
# To prevent a "tx-size-small" policy rule error, a transaction has to have a
919
# non-witness size of at least 82 bytes (MIN_STANDARD_TX_NONWITNESS_SIZE in
@@ -25,27 +35,33 @@
2535
DUMMY_P2WPKH_SCRIPT = CScript([b'a' * 21])
2636
DUMMY_2_P2WPKH_SCRIPT = CScript([b'b' * 21])
2737

38+
2839
def keyhash_to_p2pkh_script(hash):
2940
assert len(hash) == 20
3041
return CScript([OP_DUP, OP_HASH160, hash, OP_EQUALVERIFY, OP_CHECKSIG])
3142

43+
3244
def scripthash_to_p2sh_script(hash):
3345
assert len(hash) == 20
3446
return CScript([OP_HASH160, hash, OP_EQUAL])
3547

48+
3649
def key_to_p2pkh_script(key):
3750
key = check_key(key)
3851
return keyhash_to_p2pkh_script(hash160(key))
3952

53+
4054
def script_to_p2sh_script(script):
4155
script = check_script(script)
4256
return scripthash_to_p2sh_script(hash160(script))
4357

58+
4459
def key_to_p2sh_p2wpkh_script(key):
4560
key = check_key(key)
4661
p2shscript = CScript([OP_0, hash160(key)])
4762
return script_to_p2sh_script(p2shscript)
4863

64+
4965
def program_to_witness_script(version, program):
5066
if isinstance(program, str):
5167
program = bytes.fromhex(program)
@@ -54,29 +70,34 @@ def program_to_witness_script(version, program):
5470
assert version > 0 or len(program) in [20, 32]
5571
return CScript([version, program])
5672

73+
5774
def script_to_p2wsh_script(script):
5875
script = check_script(script)
5976
return program_to_witness_script(0, sha256(script))
6077

78+
6179
def key_to_p2wpkh_script(key):
6280
key = check_key(key)
6381
return program_to_witness_script(0, hash160(key))
6482

83+
6584
def script_to_p2sh_p2wsh_script(script):
6685
script = check_script(script)
6786
p2shscript = CScript([OP_0, sha256(script)])
6887
return script_to_p2sh_script(p2shscript)
6988

89+
7090
def check_key(key):
7191
if isinstance(key, str):
72-
key = bytes.fromhex(key) # Assuming this is hex string
92+
key = bytes.fromhex(key) # Assuming this is hex string
7393
if isinstance(key, bytes) and (len(key) == 33 or len(key) == 65):
7494
return key
7595
assert False
7696

97+
7798
def check_script(script):
7899
if isinstance(script, str):
79-
script = bytes.fromhex(script) # Assuming this is hex string
100+
script = bytes.fromhex(script) # Assuming this is hex string
80101
if isinstance(script, bytes) or isinstance(script, CScript):
81102
return script
82103
assert False

0 commit comments

Comments
 (0)