mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 07:22:33 +02:00
test: pep-8 touched test
Can be reviewed with "--word-diff-regex=.".
This commit is contained in:
parent
fa46768059
commit
fa54efda9b
@ -3,7 +3,17 @@
|
|||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Useful Script constants and utils."""
|
"""Useful Script constants and utils."""
|
||||||
from test_framework.script import CScript, hash160, sha256, OP_0, OP_DUP, OP_HASH160, OP_CHECKSIG, OP_EQUAL, OP_EQUALVERIFY
|
from test_framework.script import (
|
||||||
|
CScript,
|
||||||
|
hash160,
|
||||||
|
sha256,
|
||||||
|
OP_0,
|
||||||
|
OP_DUP,
|
||||||
|
OP_HASH160,
|
||||||
|
OP_CHECKSIG,
|
||||||
|
OP_EQUAL,
|
||||||
|
OP_EQUALVERIFY,
|
||||||
|
)
|
||||||
|
|
||||||
# To prevent a "tx-size-small" policy rule error, a transaction has to have a
|
# To prevent a "tx-size-small" policy rule error, a transaction has to have a
|
||||||
# non-witness size of at least 82 bytes (MIN_STANDARD_TX_NONWITNESS_SIZE in
|
# non-witness size of at least 82 bytes (MIN_STANDARD_TX_NONWITNESS_SIZE in
|
||||||
@ -25,27 +35,33 @@ from test_framework.script import CScript, hash160, sha256, OP_0, OP_DUP, OP_HAS
|
|||||||
DUMMY_P2WPKH_SCRIPT = CScript([b'a' * 21])
|
DUMMY_P2WPKH_SCRIPT = CScript([b'a' * 21])
|
||||||
DUMMY_2_P2WPKH_SCRIPT = CScript([b'b' * 21])
|
DUMMY_2_P2WPKH_SCRIPT = CScript([b'b' * 21])
|
||||||
|
|
||||||
|
|
||||||
def keyhash_to_p2pkh_script(hash):
|
def keyhash_to_p2pkh_script(hash):
|
||||||
assert len(hash) == 20
|
assert len(hash) == 20
|
||||||
return CScript([OP_DUP, OP_HASH160, hash, OP_EQUALVERIFY, OP_CHECKSIG])
|
return CScript([OP_DUP, OP_HASH160, hash, OP_EQUALVERIFY, OP_CHECKSIG])
|
||||||
|
|
||||||
|
|
||||||
def scripthash_to_p2sh_script(hash):
|
def scripthash_to_p2sh_script(hash):
|
||||||
assert len(hash) == 20
|
assert len(hash) == 20
|
||||||
return CScript([OP_HASH160, hash, OP_EQUAL])
|
return CScript([OP_HASH160, hash, OP_EQUAL])
|
||||||
|
|
||||||
|
|
||||||
def key_to_p2pkh_script(key):
|
def key_to_p2pkh_script(key):
|
||||||
key = check_key(key)
|
key = check_key(key)
|
||||||
return keyhash_to_p2pkh_script(hash160(key))
|
return keyhash_to_p2pkh_script(hash160(key))
|
||||||
|
|
||||||
|
|
||||||
def script_to_p2sh_script(script):
|
def script_to_p2sh_script(script):
|
||||||
script = check_script(script)
|
script = check_script(script)
|
||||||
return scripthash_to_p2sh_script(hash160(script))
|
return scripthash_to_p2sh_script(hash160(script))
|
||||||
|
|
||||||
|
|
||||||
def key_to_p2sh_p2wpkh_script(key):
|
def key_to_p2sh_p2wpkh_script(key):
|
||||||
key = check_key(key)
|
key = check_key(key)
|
||||||
p2shscript = CScript([OP_0, hash160(key)])
|
p2shscript = CScript([OP_0, hash160(key)])
|
||||||
return script_to_p2sh_script(p2shscript)
|
return script_to_p2sh_script(p2shscript)
|
||||||
|
|
||||||
|
|
||||||
def program_to_witness_script(version, program):
|
def program_to_witness_script(version, program):
|
||||||
if isinstance(program, str):
|
if isinstance(program, str):
|
||||||
program = bytes.fromhex(program)
|
program = bytes.fromhex(program)
|
||||||
@ -54,29 +70,34 @@ def program_to_witness_script(version, program):
|
|||||||
assert version > 0 or len(program) in [20, 32]
|
assert version > 0 or len(program) in [20, 32]
|
||||||
return CScript([version, program])
|
return CScript([version, program])
|
||||||
|
|
||||||
|
|
||||||
def script_to_p2wsh_script(script):
|
def script_to_p2wsh_script(script):
|
||||||
script = check_script(script)
|
script = check_script(script)
|
||||||
return program_to_witness_script(0, sha256(script))
|
return program_to_witness_script(0, sha256(script))
|
||||||
|
|
||||||
|
|
||||||
def key_to_p2wpkh_script(key):
|
def key_to_p2wpkh_script(key):
|
||||||
key = check_key(key)
|
key = check_key(key)
|
||||||
return program_to_witness_script(0, hash160(key))
|
return program_to_witness_script(0, hash160(key))
|
||||||
|
|
||||||
|
|
||||||
def script_to_p2sh_p2wsh_script(script):
|
def script_to_p2sh_p2wsh_script(script):
|
||||||
script = check_script(script)
|
script = check_script(script)
|
||||||
p2shscript = CScript([OP_0, sha256(script)])
|
p2shscript = CScript([OP_0, sha256(script)])
|
||||||
return script_to_p2sh_script(p2shscript)
|
return script_to_p2sh_script(p2shscript)
|
||||||
|
|
||||||
|
|
||||||
def check_key(key):
|
def check_key(key):
|
||||||
if isinstance(key, str):
|
if isinstance(key, str):
|
||||||
key = bytes.fromhex(key) # Assuming this is hex string
|
key = bytes.fromhex(key) # Assuming this is hex string
|
||||||
if isinstance(key, bytes) and (len(key) == 33 or len(key) == 65):
|
if isinstance(key, bytes) and (len(key) == 33 or len(key) == 65):
|
||||||
return key
|
return key
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|
||||||
def check_script(script):
|
def check_script(script):
|
||||||
if isinstance(script, str):
|
if isinstance(script, str):
|
||||||
script = bytes.fromhex(script) # Assuming this is hex string
|
script = bytes.fromhex(script) # Assuming this is hex string
|
||||||
if isinstance(script, bytes) or isinstance(script, CScript):
|
if isinstance(script, bytes) or isinstance(script, CScript):
|
||||||
return script
|
return script
|
||||||
assert False
|
assert False
|
||||||
|
Loading…
Reference in New Issue
Block a user