Skip to content

Commit dac7a11

Browse files
committed
refactor: test: use _ variable for unused loop counters
substitutes "for x in range(N):" by "for _ in range(N):" indicates to the reader that a block is just repeated N times, and that the loop counter is not used in the body
1 parent 82127d2 commit dac7a11

35 files changed

+83
-83
lines changed

test/functional/example_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def run_test(self):
166166

167167
height = self.nodes[0].getblockcount()
168168

169-
for i in range(10):
169+
for _ in range(10):
170170
# Use the mininode and blocktools functionality to manually build a block
171171
# Calling the generate() rpc is easier, but this allows us to exactly
172172
# control the blocks and transactions.

test/functional/feature_assumevalid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def run_test(self):
123123
height += 1
124124

125125
# Bury the block 100 deep so the coinbase output is spendable
126-
for i in range(100):
126+
for _ in range(100):
127127
block = create_block(self.tip, create_coinbase(height), self.block_time)
128128
block.solve()
129129
self.blocks.append(block)
@@ -149,7 +149,7 @@ def run_test(self):
149149
height += 1
150150

151151
# Bury the assumed valid block 2100 deep
152-
for i in range(2100):
152+
for _ in range(2100):
153153
block = create_block(self.tip, create_coinbase(height), self.block_time)
154154
block.nVersion = 4
155155
block.solve()

test/functional/feature_bip68_sequence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_sequence_lock_confirmed_inputs(self):
141141
# some of those inputs to be sequence locked (and randomly choose
142142
# between height/time locking). Small random chance of making the locks
143143
# all pass.
144-
for i in range(400):
144+
for _ in range(400):
145145
# Randomly choose up to 10 inputs
146146
num_inputs = random.randint(1, 10)
147147
random.shuffle(utxos)
@@ -260,7 +260,7 @@ def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
260260
# Use prioritisetransaction to lower the effective feerate to 0
261261
self.nodes[0].prioritisetransaction(txid=tx2.hash, fee_delta=int(-self.relayfee*COIN))
262262
cur_time = int(time.time())
263-
for i in range(10):
263+
for _ in range(10):
264264
self.nodes[0].setmocktime(cur_time + 600)
265265
self.nodes[0].generate(1)
266266
cur_time += 600

test/functional/feature_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def run_test(self):
125125

126126
# collect spendable outputs now to avoid cluttering the code later on
127127
out = []
128-
for i in range(NUM_OUTPUTS_TO_COLLECT):
128+
for _ in range(NUM_OUTPUTS_TO_COLLECT):
129129
out.append(self.get_spendable_output())
130130

131131
# Start by building a couple of blocks on top (which output is spent is

test/functional/feature_csv_activation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def skip_test_if_missing_module(self):
161161

162162
def generate_blocks(self, number):
163163
test_blocks = []
164-
for i in range(number):
164+
for _ in range(number):
165165
block = self.create_test_block([])
166166
test_blocks.append(block)
167167
self.last_block_time += 600
@@ -209,22 +209,22 @@ def run_test(self):
209209
# Note we reuse inputs for v1 and v2 txs so must test these separately
210210
# 16 normal inputs
211211
bip68inputs = []
212-
for i in range(16):
212+
for _ in range(16):
213213
bip68inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
214214

215215
# 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
216216
bip112basicinputs = []
217-
for j in range(2):
217+
for _ in range(2):
218218
inputs = []
219-
for i in range(16):
219+
for _ in range(16):
220220
inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
221221
bip112basicinputs.append(inputs)
222222

223223
# 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
224224
bip112diverseinputs = []
225-
for j in range(2):
225+
for _ in range(2):
226226
inputs = []
227-
for i in range(16):
227+
for _ in range(16):
228228
inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
229229
bip112diverseinputs.append(inputs)
230230

test/functional/feature_dbcrash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def generate_small_transactions(self, node, count, utxo_list):
195195
while len(utxo_list) >= 2 and num_transactions < count:
196196
tx = CTransaction()
197197
input_amount = 0
198-
for i in range(2):
198+
for _ in range(2):
199199
utxo = utxo_list.pop()
200200
tx.vin.append(CTxIn(COutPoint(int(utxo['txid'], 16), utxo['vout'])))
201201
input_amount += int(utxo['amount'] * COIN)
@@ -205,7 +205,7 @@ def generate_small_transactions(self, node, count, utxo_list):
205205
# Sanity check -- if we chose inputs that are too small, skip
206206
continue
207207

208-
for i in range(3):
208+
for _ in range(3):
209209
tx.vout.append(CTxOut(output_amount, hex_str_to_bytes(utxo['scriptPubKey'])))
210210

211211
# Sign and send the transaction to get into the mempool

test/functional/feature_fee_estimation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def transact_and_mine(self, numblocks, mining_node):
176176
# We shuffle our confirmed txout set before each set of transactions
177177
# small_txpuzzle_randfee will use the transactions that have inputs already in the chain when possible
178178
# resorting to tx's that depend on the mempool when those run out
179-
for i in range(numblocks):
179+
for _ in range(numblocks):
180180
random.shuffle(self.confutxo)
181-
for j in range(random.randrange(100 - 50, 100 + 50)):
181+
for _ in range(random.randrange(100 - 50, 100 + 50)):
182182
from_index = random.randint(1, 2)
183183
(txhex, fee) = small_txpuzzle_randfee(self.nodes[from_index], self.confutxo,
184184
self.memutxo, Decimal("0.005"), min_fee, min_fee)
@@ -243,7 +243,7 @@ def run_test(self):
243243
self.confutxo = self.txouts # Start with the set of confirmed txouts after splitting
244244
self.log.info("Will output estimates for 1/2/3/6/15/25 blocks")
245245

246-
for i in range(2):
246+
for _ in range(2):
247247
self.log.info("Creating transactions and mining them with a block size that can't keep up")
248248
# Create transactions and mine 10 small blocks with node 2, but create txs faster than we can mine
249249
self.transact_and_mine(10, self.nodes[2])

test/functional/feature_maxuploadtarget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def run_test(self):
104104
assert_equal(len(self.nodes[0].getpeerinfo()), 3)
105105
# At most a couple more tries should succeed (depending on how long
106106
# the test has been running so far).
107-
for i in range(3):
107+
for _ in range(3):
108108
p2p_conns[0].send_message(getdata_request)
109109
p2p_conns[0].wait_for_disconnect()
110110
assert_equal(len(self.nodes[0].getpeerinfo()), 2)

test/functional/feature_pruning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def create_chain_with_staleblocks(self):
147147
# Create stale blocks in manageable sized chunks
148148
self.log.info("Mine 24 (stale) blocks on Node 1, followed by 25 (main chain) block reorg from Node 0, for 12 rounds")
149149

150-
for j in range(12):
150+
for _ in range(12):
151151
# Disconnect node 0 so it can mine a longer reorg chain without knowing about node 1's soon-to-be-stale chain
152152
# Node 2 stays connected, so it hears about the stale blocks and then reorg's when node0 reconnects
153153
disconnect_nodes(self.nodes[0], 1)

test/functional/feature_rbf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def test_too_many_replacements(self):
376376
split_value = int((initial_nValue-fee)/(MAX_REPLACEMENT_LIMIT+1))
377377

378378
outputs = []
379-
for i in range(MAX_REPLACEMENT_LIMIT+1):
379+
for _ in range(MAX_REPLACEMENT_LIMIT+1):
380380
outputs.append(CTxOut(split_value, CScript([1])))
381381

382382
splitting_tx = CTransaction()

0 commit comments

Comments
 (0)