Skip to content

Commit cab8be5

Browse files
committed
[tests] Fix flake8 warnings in blocktools.py
1 parent b184127 commit cab8be5

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

test/functional/test_framework/blocktools.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,24 @@
1010
script_to_p2sh_p2wsh,
1111
script_to_p2wsh,
1212
)
13-
from .mininode import *
13+
from .messages import (
14+
CBlock,
15+
COIN,
16+
COutPoint,
17+
CTransaction,
18+
CTxIn,
19+
CTxInWitness,
20+
CTxOut,
21+
FromHex,
22+
ToHex,
23+
bytes_to_hex_str,
24+
hash256,
25+
hex_str_to_bytes,
26+
ser_string,
27+
ser_uint256,
28+
sha256,
29+
uint256_from_str,
30+
)
1431
from .script import (
1532
CScript,
1633
OP_0,
@@ -24,15 +41,15 @@
2441
from .util import assert_equal
2542

2643
# Create a block (with regtest difficulty)
27-
def create_block(hashprev, coinbase, nTime=None):
44+
def create_block(hashprev, coinbase, ntime=None):
2845
block = CBlock()
29-
if nTime is None:
46+
if ntime is None:
3047
import time
31-
block.nTime = int(time.time()+600)
48+
block.nTime = int(time.time() + 600)
3249
else:
33-
block.nTime = nTime
50+
block.nTime = ntime
3451
block.hashPrevBlock = hashprev
35-
block.nBits = 0x207fffff # difficulty retargeting is disabled in REGTEST chainparams
52+
block.nBits = 0x207fffff # difficulty retargeting is disabled in REGTEST chainparams
3653
block.vtx.append(coinbase)
3754
block.hashMerkleRoot = block.calc_merkle_root()
3855
block.calc_sha256()
@@ -43,7 +60,7 @@ def create_block(hashprev, coinbase, nTime=None):
4360

4461

4562
def get_witness_script(witness_root, witness_nonce):
46-
witness_commitment = uint256_from_str(hash256(ser_uint256(witness_root)+ser_uint256(witness_nonce)))
63+
witness_commitment = uint256_from_str(hash256(ser_uint256(witness_root) + ser_uint256(witness_nonce)))
4764
output_data = WITNESS_COMMITMENT_HEADER + ser_uint256(witness_commitment)
4865
return CScript([OP_RETURN, output_data])
4966

@@ -84,52 +101,52 @@ def serialize_script_num(value):
84101
# Create a coinbase transaction, assuming no miner fees.
85102
# If pubkey is passed in, the coinbase output will be a P2PK output;
86103
# otherwise an anyone-can-spend output.
87-
def create_coinbase(height, pubkey = None):
104+
def create_coinbase(height, pubkey=None):
88105
coinbase = CTransaction()
89106
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
90-
ser_string(serialize_script_num(height)), 0xffffffff))
107+
ser_string(serialize_script_num(height)), 0xffffffff))
91108
coinbaseoutput = CTxOut()
92109
coinbaseoutput.nValue = 50 * COIN
93-
halvings = int(height/150) # regtest
110+
halvings = int(height / 150) # regtest
94111
coinbaseoutput.nValue >>= halvings
95-
if (pubkey != None):
112+
if (pubkey is not None):
96113
coinbaseoutput.scriptPubKey = CScript([pubkey, OP_CHECKSIG])
97114
else:
98115
coinbaseoutput.scriptPubKey = CScript([OP_TRUE])
99-
coinbase.vout = [ coinbaseoutput ]
116+
coinbase.vout = [coinbaseoutput]
100117
coinbase.calc_sha256()
101118
return coinbase
102119

103120
# Create a transaction.
104-
# If the scriptPubKey is not specified, make it anyone-can-spend.
105-
def create_transaction(prevtx, n, sig, value, scriptPubKey=CScript()):
121+
# If the script_pub_key is not specified, make it anyone-can-spend.
122+
def create_transaction(prevtx, n, sig, value, script_pub_key=CScript()):
106123
tx = CTransaction()
107124
assert(n < len(prevtx.vout))
108125
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff))
109-
tx.vout.append(CTxOut(value, scriptPubKey))
126+
tx.vout.append(CTxOut(value, script_pub_key))
110127
tx.calc_sha256()
111128
return tx
112129

113-
def get_legacy_sigopcount_block(block, fAccurate=True):
130+
def get_legacy_sigopcount_block(block, accurate=True):
114131
count = 0
115132
for tx in block.vtx:
116-
count += get_legacy_sigopcount_tx(tx, fAccurate)
133+
count += get_legacy_sigopcount_tx(tx, accurate)
117134
return count
118135

119-
def get_legacy_sigopcount_tx(tx, fAccurate=True):
136+
def get_legacy_sigopcount_tx(tx, accurate=True):
120137
count = 0
121138
for i in tx.vout:
122-
count += i.scriptPubKey.GetSigOpCount(fAccurate)
139+
count += i.scriptPubKey.GetSigOpCount(accurate)
123140
for j in tx.vin:
124141
# scriptSig might be of type bytes, so convert to CScript for the moment
125-
count += CScript(j.scriptSig).GetSigOpCount(fAccurate)
142+
count += CScript(j.scriptSig).GetSigOpCount(accurate)
126143
return count
127144

128145
# Create a scriptPubKey corresponding to either a P2WPKH output for the
129146
# given pubkey, or a P2WSH output of a 1-of-1 multisig for the given
130147
# pubkey. Returns the hex encoding of the scriptPubKey.
131148
def witness_script(use_p2wsh, pubkey):
132-
if (use_p2wsh == False):
149+
if not use_p2wsh:
133150
# P2WPKH instead
134151
pubkeyhash = hash160(hex_str_to_bytes(pubkey))
135152
pkscript = CScript([OP_0, pubkeyhash])

0 commit comments

Comments
 (0)