mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
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
This commit is contained in:
parent
82127d27c9
commit
dac7a111bd
35 changed files with 83 additions and 83 deletions
|
@ -166,7 +166,7 @@ class ExampleTest(BitcoinTestFramework):
|
|||
|
||||
height = self.nodes[0].getblockcount()
|
||||
|
||||
for i in range(10):
|
||||
for _ in range(10):
|
||||
# Use the mininode and blocktools functionality to manually build a block
|
||||
# Calling the generate() rpc is easier, but this allows us to exactly
|
||||
# control the blocks and transactions.
|
||||
|
|
|
@ -123,7 +123,7 @@ class AssumeValidTest(BitcoinTestFramework):
|
|||
height += 1
|
||||
|
||||
# Bury the block 100 deep so the coinbase output is spendable
|
||||
for i in range(100):
|
||||
for _ in range(100):
|
||||
block = create_block(self.tip, create_coinbase(height), self.block_time)
|
||||
block.solve()
|
||||
self.blocks.append(block)
|
||||
|
@ -149,7 +149,7 @@ class AssumeValidTest(BitcoinTestFramework):
|
|||
height += 1
|
||||
|
||||
# Bury the assumed valid block 2100 deep
|
||||
for i in range(2100):
|
||||
for _ in range(2100):
|
||||
block = create_block(self.tip, create_coinbase(height), self.block_time)
|
||||
block.nVersion = 4
|
||||
block.solve()
|
||||
|
|
|
@ -141,7 +141,7 @@ class BIP68Test(BitcoinTestFramework):
|
|||
# some of those inputs to be sequence locked (and randomly choose
|
||||
# between height/time locking). Small random chance of making the locks
|
||||
# all pass.
|
||||
for i in range(400):
|
||||
for _ in range(400):
|
||||
# Randomly choose up to 10 inputs
|
||||
num_inputs = random.randint(1, 10)
|
||||
random.shuffle(utxos)
|
||||
|
@ -260,7 +260,7 @@ class BIP68Test(BitcoinTestFramework):
|
|||
# Use prioritisetransaction to lower the effective feerate to 0
|
||||
self.nodes[0].prioritisetransaction(txid=tx2.hash, fee_delta=int(-self.relayfee*COIN))
|
||||
cur_time = int(time.time())
|
||||
for i in range(10):
|
||||
for _ in range(10):
|
||||
self.nodes[0].setmocktime(cur_time + 600)
|
||||
self.nodes[0].generate(1)
|
||||
cur_time += 600
|
||||
|
|
|
@ -125,7 +125,7 @@ class FullBlockTest(BitcoinTestFramework):
|
|||
|
||||
# collect spendable outputs now to avoid cluttering the code later on
|
||||
out = []
|
||||
for i in range(NUM_OUTPUTS_TO_COLLECT):
|
||||
for _ in range(NUM_OUTPUTS_TO_COLLECT):
|
||||
out.append(self.get_spendable_output())
|
||||
|
||||
# Start by building a couple of blocks on top (which output is spent is
|
||||
|
|
|
@ -161,7 +161,7 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
|||
|
||||
def generate_blocks(self, number):
|
||||
test_blocks = []
|
||||
for i in range(number):
|
||||
for _ in range(number):
|
||||
block = self.create_test_block([])
|
||||
test_blocks.append(block)
|
||||
self.last_block_time += 600
|
||||
|
@ -209,22 +209,22 @@ class BIP68_112_113Test(BitcoinTestFramework):
|
|||
# Note we reuse inputs for v1 and v2 txs so must test these separately
|
||||
# 16 normal inputs
|
||||
bip68inputs = []
|
||||
for i in range(16):
|
||||
for _ in range(16):
|
||||
bip68inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
|
||||
|
||||
# 2 sets of 16 inputs with 10 OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
|
||||
bip112basicinputs = []
|
||||
for j in range(2):
|
||||
for _ in range(2):
|
||||
inputs = []
|
||||
for i in range(16):
|
||||
for _ in range(16):
|
||||
inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
|
||||
bip112basicinputs.append(inputs)
|
||||
|
||||
# 2 sets of 16 varied inputs with (relative_lock_time) OP_CSV OP_DROP (actually will be prepended to spending scriptSig)
|
||||
bip112diverseinputs = []
|
||||
for j in range(2):
|
||||
for _ in range(2):
|
||||
inputs = []
|
||||
for i in range(16):
|
||||
for _ in range(16):
|
||||
inputs.append(send_generic_input_tx(self.nodes[0], self.coinbase_blocks, self.nodeaddress))
|
||||
bip112diverseinputs.append(inputs)
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
|
|||
while len(utxo_list) >= 2 and num_transactions < count:
|
||||
tx = CTransaction()
|
||||
input_amount = 0
|
||||
for i in range(2):
|
||||
for _ in range(2):
|
||||
utxo = utxo_list.pop()
|
||||
tx.vin.append(CTxIn(COutPoint(int(utxo['txid'], 16), utxo['vout'])))
|
||||
input_amount += int(utxo['amount'] * COIN)
|
||||
|
@ -205,7 +205,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
|
|||
# Sanity check -- if we chose inputs that are too small, skip
|
||||
continue
|
||||
|
||||
for i in range(3):
|
||||
for _ in range(3):
|
||||
tx.vout.append(CTxOut(output_amount, hex_str_to_bytes(utxo['scriptPubKey'])))
|
||||
|
||||
# Sign and send the transaction to get into the mempool
|
||||
|
|
|
@ -176,9 +176,9 @@ class EstimateFeeTest(BitcoinTestFramework):
|
|||
# We shuffle our confirmed txout set before each set of transactions
|
||||
# small_txpuzzle_randfee will use the transactions that have inputs already in the chain when possible
|
||||
# resorting to tx's that depend on the mempool when those run out
|
||||
for i in range(numblocks):
|
||||
for _ in range(numblocks):
|
||||
random.shuffle(self.confutxo)
|
||||
for j in range(random.randrange(100 - 50, 100 + 50)):
|
||||
for _ in range(random.randrange(100 - 50, 100 + 50)):
|
||||
from_index = random.randint(1, 2)
|
||||
(txhex, fee) = small_txpuzzle_randfee(self.nodes[from_index], self.confutxo,
|
||||
self.memutxo, Decimal("0.005"), min_fee, min_fee)
|
||||
|
@ -243,7 +243,7 @@ class EstimateFeeTest(BitcoinTestFramework):
|
|||
self.confutxo = self.txouts # Start with the set of confirmed txouts after splitting
|
||||
self.log.info("Will output estimates for 1/2/3/6/15/25 blocks")
|
||||
|
||||
for i in range(2):
|
||||
for _ in range(2):
|
||||
self.log.info("Creating transactions and mining them with a block size that can't keep up")
|
||||
# Create transactions and mine 10 small blocks with node 2, but create txs faster than we can mine
|
||||
self.transact_and_mine(10, self.nodes[2])
|
||||
|
|
|
@ -104,7 +104,7 @@ class MaxUploadTest(BitcoinTestFramework):
|
|||
assert_equal(len(self.nodes[0].getpeerinfo()), 3)
|
||||
# At most a couple more tries should succeed (depending on how long
|
||||
# the test has been running so far).
|
||||
for i in range(3):
|
||||
for _ in range(3):
|
||||
p2p_conns[0].send_message(getdata_request)
|
||||
p2p_conns[0].wait_for_disconnect()
|
||||
assert_equal(len(self.nodes[0].getpeerinfo()), 2)
|
||||
|
|
|
@ -147,7 +147,7 @@ class PruneTest(BitcoinTestFramework):
|
|||
# Create stale blocks in manageable sized chunks
|
||||
self.log.info("Mine 24 (stale) blocks on Node 1, followed by 25 (main chain) block reorg from Node 0, for 12 rounds")
|
||||
|
||||
for j in range(12):
|
||||
for _ in range(12):
|
||||
# Disconnect node 0 so it can mine a longer reorg chain without knowing about node 1's soon-to-be-stale chain
|
||||
# Node 2 stays connected, so it hears about the stale blocks and then reorg's when node0 reconnects
|
||||
disconnect_nodes(self.nodes[0], 1)
|
||||
|
|
|
@ -376,7 +376,7 @@ class ReplaceByFeeTest(BitcoinTestFramework):
|
|||
split_value = int((initial_nValue-fee)/(MAX_REPLACEMENT_LIMIT+1))
|
||||
|
||||
outputs = []
|
||||
for i in range(MAX_REPLACEMENT_LIMIT+1):
|
||||
for _ in range(MAX_REPLACEMENT_LIMIT+1):
|
||||
outputs.append(CTxOut(split_value, CScript([1])))
|
||||
|
||||
splitting_tx = CTransaction()
|
||||
|
|
|
@ -126,11 +126,11 @@ class SegWitTest(BitcoinTestFramework):
|
|||
assert_equal(bip173_ms_addr, script_to_p2wsh(multiscript))
|
||||
p2sh_ids.append([])
|
||||
wit_ids.append([])
|
||||
for v in range(2):
|
||||
for _ in range(2):
|
||||
p2sh_ids[i].append([])
|
||||
wit_ids[i].append([])
|
||||
|
||||
for i in range(5):
|
||||
for _ in range(5):
|
||||
for n in range(3):
|
||||
for v in range(2):
|
||||
wit_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], False, Decimal("49.999")))
|
||||
|
|
|
@ -31,7 +31,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
|
|||
for (txid, vout) in zip(parent_txids, vouts):
|
||||
inputs.append({'txid' : txid, 'vout' : vout})
|
||||
outputs = {}
|
||||
for i in range(num_outputs):
|
||||
for _ in range(num_outputs):
|
||||
outputs[node.getnewaddress()] = send_value
|
||||
rawtx = node.createrawtransaction(inputs, outputs, 0, True)
|
||||
signedtx = node.signrawtransactionwithwallet(rawtx)
|
||||
|
|
|
@ -48,7 +48,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
|
|||
send_value = satoshi_round((value - fee)/num_outputs)
|
||||
inputs = [ {'txid' : parent_txid, 'vout' : vout} ]
|
||||
outputs = {}
|
||||
for i in range(num_outputs):
|
||||
for _ in range(num_outputs):
|
||||
outputs[node.getnewaddress()] = send_value
|
||||
rawtx = node.createrawtransaction(inputs, outputs)
|
||||
signedtx = node.signrawtransactionwithwallet(rawtx)
|
||||
|
@ -70,7 +70,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
|
|||
# MAX_ANCESTORS transactions off a confirmed tx should be fine
|
||||
chain = []
|
||||
witness_chain = []
|
||||
for i in range(MAX_ANCESTORS):
|
||||
for _ in range(MAX_ANCESTORS):
|
||||
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, 0, value, fee, 1)
|
||||
value = sent_value
|
||||
chain.append(txid)
|
||||
|
@ -245,7 +245,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
|
|||
|
||||
# Sign and send up to MAX_DESCENDANT transactions chained off the parent tx
|
||||
chain = [] # save sent txs for the purpose of checking node1's mempool later (see below)
|
||||
for i in range(MAX_DESCENDANTS - 1):
|
||||
for _ in range(MAX_DESCENDANTS - 1):
|
||||
utxo = transaction_package.pop(0)
|
||||
(txid, sent_value) = self.chain_transaction(self.nodes[0], utxo['txid'], utxo['vout'], utxo['amount'], fee, 10)
|
||||
chain.append(txid)
|
||||
|
@ -312,7 +312,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
|
|||
send_value = satoshi_round((value - fee)/2)
|
||||
inputs = [ {'txid' : txid, 'vout' : vout} ]
|
||||
outputs = {}
|
||||
for i in range(2):
|
||||
for _ in range(2):
|
||||
outputs[self.nodes[0].getnewaddress()] = send_value
|
||||
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
|
||||
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
|
||||
|
@ -326,7 +326,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
|
|||
# Create tx2-7
|
||||
vout = 1
|
||||
txid = tx0_id
|
||||
for i in range(6):
|
||||
for _ in range(6):
|
||||
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, vout, value, fee, 1)
|
||||
vout = 0
|
||||
value = sent_value
|
||||
|
|
|
@ -62,7 +62,7 @@ class MempoolPersistTest(BitcoinTestFramework):
|
|||
def run_test(self):
|
||||
self.log.debug("Send 5 transactions from node2 (to its own address)")
|
||||
tx_creation_time_lower = int(time.time())
|
||||
for i in range(5):
|
||||
for _ in range(5):
|
||||
last_txid = self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10"))
|
||||
node2_balance = self.nodes[2].getbalance()
|
||||
self.sync_all()
|
||||
|
|
|
@ -73,7 +73,7 @@ class MempoolUpdateFromBlockTest(BitcoinTestFramework):
|
|||
n_outputs = size - tx_count
|
||||
output_value = ((inputs_value - fee) / Decimal(n_outputs)).quantize(Decimal('0.00000001'))
|
||||
outputs = {}
|
||||
for n in range(0, n_outputs):
|
||||
for _ in range(n_outputs):
|
||||
outputs[self.nodes[0].getnewaddress()] = output_value
|
||||
else:
|
||||
output_value = (inputs_value - fee).quantize(Decimal('0.00000001'))
|
||||
|
|
|
@ -125,7 +125,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||
out_value = total_value // 10
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(block.vtx[0].sha256, 0), b''))
|
||||
for i in range(10):
|
||||
for _ in range(10):
|
||||
tx.vout.append(CTxOut(out_value, CScript([OP_TRUE])))
|
||||
tx.rehash()
|
||||
|
||||
|
@ -266,7 +266,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||
address = node.getnewaddress()
|
||||
|
||||
segwit_tx_generated = False
|
||||
for i in range(num_transactions):
|
||||
for _ in range(num_transactions):
|
||||
txid = node.sendtoaddress(address, 0.1)
|
||||
hex_tx = node.gettransaction(txid)["hex"]
|
||||
tx = FromHex(CTransaction(), hex_tx)
|
||||
|
@ -418,7 +418,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||
def build_block_with_transactions(self, node, utxo, num_transactions):
|
||||
block = self.build_block_on_tip(node)
|
||||
|
||||
for i in range(num_transactions):
|
||||
for _ in range(num_transactions):
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(utxo[0], utxo[1]), b''))
|
||||
tx.vout.append(CTxOut(utxo[2] - 1000, CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
|
||||
|
@ -627,7 +627,7 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||
# Test that requesting old compactblocks doesn't work.
|
||||
MAX_CMPCTBLOCK_DEPTH = 5
|
||||
new_blocks = []
|
||||
for i in range(MAX_CMPCTBLOCK_DEPTH + 1):
|
||||
for _ in range(MAX_CMPCTBLOCK_DEPTH + 1):
|
||||
test_node.clear_block_announcement()
|
||||
new_blocks.append(node.generate(1)[0])
|
||||
wait_until(test_node.received_block_announcement, timeout=30, lock=mininode_lock)
|
||||
|
|
|
@ -19,7 +19,7 @@ def hashToHex(hash):
|
|||
|
||||
# Wait up to 60 secs to see if the testnode has received all the expected invs
|
||||
def allInvsMatch(invsExpected, testnode):
|
||||
for x in range(60):
|
||||
for _ in range(60):
|
||||
with mininode_lock:
|
||||
if (sorted(invsExpected) == sorted(testnode.txinvs)):
|
||||
return True
|
||||
|
@ -91,7 +91,7 @@ class FeeFilterTest(BitcoinTestFramework):
|
|||
# Test that invs are received by test connection for all txs at
|
||||
# feerate of .2 sat/byte
|
||||
node1.settxfee(Decimal("0.00000200"))
|
||||
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
|
||||
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for _ in range(3)]
|
||||
assert allInvsMatch(txids, conn)
|
||||
conn.clear_invs()
|
||||
|
||||
|
@ -100,14 +100,14 @@ class FeeFilterTest(BitcoinTestFramework):
|
|||
|
||||
# Test that txs are still being received by test connection (paying .15 sat/byte)
|
||||
node1.settxfee(Decimal("0.00000150"))
|
||||
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
|
||||
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for _ in range(3)]
|
||||
assert allInvsMatch(txids, conn)
|
||||
conn.clear_invs()
|
||||
|
||||
# Change tx fee rate to .1 sat/byte and test they are no longer received
|
||||
# by the test connection
|
||||
node1.settxfee(Decimal("0.00000100"))
|
||||
[node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
|
||||
[node1.sendtoaddress(node1.getnewaddress(), 1) for _ in range(3)]
|
||||
self.sync_mempools() # must be sure node 0 has received all txs
|
||||
|
||||
# Send one transaction from node0 that should be received, so that we
|
||||
|
@ -124,7 +124,7 @@ class FeeFilterTest(BitcoinTestFramework):
|
|||
|
||||
# Remove fee filter and check that txs are received again
|
||||
conn.send_and_ping(msg_feefilter(0))
|
||||
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for x in range(3)]
|
||||
txids = [node1.sendtoaddress(node1.getnewaddress(), 1) for _ in range(3)]
|
||||
assert allInvsMatch(txids, conn)
|
||||
conn.clear_invs()
|
||||
|
||||
|
|
|
@ -942,7 +942,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
parent_tx = CTransaction()
|
||||
parent_tx.vin.append(CTxIn(prevout, b""))
|
||||
child_value = int(value / NUM_OUTPUTS)
|
||||
for i in range(NUM_OUTPUTS):
|
||||
for _ in range(NUM_OUTPUTS):
|
||||
parent_tx.vout.append(CTxOut(child_value, script_pubkey))
|
||||
parent_tx.vout[0].nValue -= 50000
|
||||
assert parent_tx.vout[0].nValue > 0
|
||||
|
@ -952,7 +952,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
for i in range(NUM_OUTPUTS):
|
||||
child_tx.vin.append(CTxIn(COutPoint(parent_tx.sha256, i), b""))
|
||||
child_tx.vout = [CTxOut(value - 100000, CScript([OP_TRUE]))]
|
||||
for i in range(NUM_OUTPUTS):
|
||||
for _ in range(NUM_OUTPUTS):
|
||||
child_tx.wit.vtxinwit.append(CTxInWitness())
|
||||
child_tx.wit.vtxinwit[-1].scriptWitness.stack = [b'a' * 195] * (2 * NUM_DROPS) + [witness_program]
|
||||
child_tx.rehash()
|
||||
|
@ -1199,7 +1199,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
value = self.utxo[0].nValue
|
||||
for i in range(10):
|
||||
for _ in range(10):
|
||||
tx.vout.append(CTxOut(int(value / 10), script_pubkey))
|
||||
tx.vout[0].nValue -= 1000
|
||||
assert tx.vout[0].nValue >= 0
|
||||
|
@ -1372,7 +1372,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
split_value = (self.utxo[0].nValue - 4000) // NUM_SEGWIT_VERSIONS
|
||||
for i in range(NUM_SEGWIT_VERSIONS):
|
||||
for _ in range(NUM_SEGWIT_VERSIONS):
|
||||
tx.vout.append(CTxOut(split_value, CScript([OP_TRUE])))
|
||||
tx.rehash()
|
||||
block = self.build_next_block()
|
||||
|
@ -1646,7 +1646,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(prev_utxo.sha256, prev_utxo.n), b""))
|
||||
split_value = prev_utxo.nValue // NUM_SIGHASH_TESTS
|
||||
for i in range(NUM_SIGHASH_TESTS):
|
||||
for _ in range(NUM_SIGHASH_TESTS):
|
||||
tx.vout.append(CTxOut(split_value, script_pubkey))
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
sign_p2pk_witness_input(witness_program, tx, 0, SIGHASH_ALL, prev_utxo.nValue, key)
|
||||
|
@ -1676,7 +1676,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
total_value += temp_utxos[i].nValue
|
||||
split_value = total_value // num_outputs
|
||||
for i in range(num_outputs):
|
||||
for _ in range(num_outputs):
|
||||
tx.vout.append(CTxOut(split_value, script_pubkey))
|
||||
for i in range(num_inputs):
|
||||
# Now try to sign each input, using a random hashtype.
|
||||
|
@ -1974,7 +1974,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
split_value = self.utxo[0].nValue // outputs
|
||||
tx = CTransaction()
|
||||
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))
|
||||
for i in range(outputs):
|
||||
for _ in range(outputs):
|
||||
tx.vout.append(CTxOut(split_value, script_pubkey))
|
||||
tx.vout[-2].scriptPubKey = script_pubkey_toomany
|
||||
tx.vout[-1].scriptPubKey = script_pubkey_justright
|
||||
|
@ -2060,7 +2060,7 @@ class SegWitTest(BitcoinTestFramework):
|
|||
if (len(tx.wit.vtxinwit) != len(tx.vin)):
|
||||
# vtxinwit must have the same length as vin
|
||||
tx.wit.vtxinwit = tx.wit.vtxinwit[:len(tx.vin)]
|
||||
for i in range(len(tx.wit.vtxinwit), len(tx.vin)):
|
||||
for _ in range(len(tx.wit.vtxinwit), len(tx.vin)):
|
||||
tx.wit.vtxinwit.append(CTxInWitness())
|
||||
r += tx.wit.serialize()
|
||||
r += struct.pack("<I", tx.nLockTime)
|
||||
|
|
|
@ -328,7 +328,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
|||
for j in range(2):
|
||||
self.log.debug("Part 2.{}.{}: starting...".format(i, j))
|
||||
blocks = []
|
||||
for b in range(i + 1):
|
||||
for _ in range(i + 1):
|
||||
blocks.append(create_block(tip, create_coinbase(height), block_time))
|
||||
blocks[-1].solve()
|
||||
tip = blocks[-1].sha256
|
||||
|
@ -443,7 +443,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
|||
|
||||
# Create 2 blocks. Send the blocks, then send the headers.
|
||||
blocks = []
|
||||
for b in range(2):
|
||||
for _ in range(2):
|
||||
blocks.append(create_block(tip, create_coinbase(height), block_time))
|
||||
blocks[-1].solve()
|
||||
tip = blocks[-1].sha256
|
||||
|
@ -461,7 +461,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
|||
|
||||
# This time, direct fetch should work
|
||||
blocks = []
|
||||
for b in range(3):
|
||||
for _ in range(3):
|
||||
blocks.append(create_block(tip, create_coinbase(height), block_time))
|
||||
blocks[-1].solve()
|
||||
tip = blocks[-1].sha256
|
||||
|
@ -482,7 +482,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
|||
blocks = []
|
||||
|
||||
# Create extra blocks for later
|
||||
for b in range(20):
|
||||
for _ in range(20):
|
||||
blocks.append(create_block(tip, create_coinbase(height), block_time))
|
||||
blocks[-1].solve()
|
||||
tip = blocks[-1].sha256
|
||||
|
@ -529,7 +529,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
|||
test_node.last_message.pop("getdata", None)
|
||||
blocks = []
|
||||
# Create two more blocks.
|
||||
for j in range(2):
|
||||
for _ in range(2):
|
||||
blocks.append(create_block(tip, create_coinbase(height), block_time))
|
||||
blocks[-1].solve()
|
||||
tip = blocks[-1].sha256
|
||||
|
@ -550,7 +550,7 @@ class SendHeadersTest(BitcoinTestFramework):
|
|||
# Now we test that if we repeatedly don't send connecting headers, we
|
||||
# don't go into an infinite loop trying to get them to connect.
|
||||
MAX_UNCONNECTING_HEADERS = 10
|
||||
for j in range(MAX_UNCONNECTING_HEADERS + 1):
|
||||
for _ in range(MAX_UNCONNECTING_HEADERS + 1):
|
||||
blocks.append(create_block(tip, create_coinbase(height), block_time))
|
||||
blocks[-1].solve()
|
||||
tip = blocks[-1].sha256
|
||||
|
|
|
@ -162,7 +162,7 @@ class TxDownloadTest(BitcoinTestFramework):
|
|||
# Setup the p2p connections
|
||||
self.peers = []
|
||||
for node in self.nodes:
|
||||
for i in range(NUM_INBOUND):
|
||||
for _ in range(NUM_INBOUND):
|
||||
self.peers.append(node.add_p2p_connection(TestP2PConn()))
|
||||
|
||||
self.log.info("Nodes are setup with {} incoming connections each".format(NUM_INBOUND))
|
||||
|
|
|
@ -554,7 +554,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
self.nodes[1].generate(1)
|
||||
self.sync_all()
|
||||
|
||||
for i in range(0,20):
|
||||
for _ in range(20):
|
||||
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.01)
|
||||
self.nodes[0].generate(1)
|
||||
self.sync_all()
|
||||
|
@ -582,7 +582,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
self.nodes[1].generate(1)
|
||||
self.sync_all()
|
||||
|
||||
for i in range(0,20):
|
||||
for _ in range(20):
|
||||
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.01)
|
||||
self.nodes[0].generate(1)
|
||||
self.sync_all()
|
||||
|
|
|
@ -55,7 +55,7 @@ class GenerateBlockTest(BitcoinTestFramework):
|
|||
node.generatetoaddress(110, address)
|
||||
|
||||
# Generate some extra mempool transactions to verify they don't get mined
|
||||
for i in range(10):
|
||||
for _ in range(10):
|
||||
node.sendtoaddress(address, 0.001)
|
||||
|
||||
self.log.info('Generate block with txid')
|
||||
|
|
|
@ -430,7 +430,7 @@ class PSBTTest(BitcoinTestFramework):
|
|||
# Check that joining shuffles the inputs and outputs
|
||||
# 10 attempts should be enough to get a shuffled join
|
||||
shuffled = False
|
||||
for i in range(0, 10):
|
||||
for _ in range(10):
|
||||
shuffled_joined = self.nodes[0].joinpsbts([psbt, psbt2])
|
||||
shuffled |= joined != shuffled_joined
|
||||
if shuffled:
|
||||
|
|
|
@ -111,7 +111,7 @@ def deser_uint256(f):
|
|||
|
||||
def ser_uint256(u):
|
||||
rs = b""
|
||||
for i in range(8):
|
||||
for _ in range(8):
|
||||
rs += struct.pack("<I", u & 0xFFFFFFFF)
|
||||
u >>= 32
|
||||
return rs
|
||||
|
@ -134,7 +134,7 @@ def uint256_from_compact(c):
|
|||
def deser_vector(f, c):
|
||||
nit = deser_compact_size(f)
|
||||
r = []
|
||||
for i in range(nit):
|
||||
for _ in range(nit):
|
||||
t = c()
|
||||
t.deserialize(f)
|
||||
r.append(t)
|
||||
|
@ -157,7 +157,7 @@ def ser_vector(l, ser_function_name=None):
|
|||
def deser_uint256_vector(f):
|
||||
nit = deser_compact_size(f)
|
||||
r = []
|
||||
for i in range(nit):
|
||||
for _ in range(nit):
|
||||
t = deser_uint256(f)
|
||||
r.append(t)
|
||||
return r
|
||||
|
@ -173,7 +173,7 @@ def ser_uint256_vector(l):
|
|||
def deser_string_vector(f):
|
||||
nit = deser_compact_size(f)
|
||||
r = []
|
||||
for i in range(nit):
|
||||
for _ in range(nit):
|
||||
t = deser_string(f)
|
||||
r.append(t)
|
||||
return r
|
||||
|
@ -467,7 +467,7 @@ class CTransaction:
|
|||
else:
|
||||
self.vout = deser_vector(f, CTxOut)
|
||||
if flags != 0:
|
||||
self.wit.vtxinwit = [CTxInWitness() for i in range(len(self.vin))]
|
||||
self.wit.vtxinwit = [CTxInWitness() for _ in range(len(self.vin))]
|
||||
self.wit.deserialize(f)
|
||||
else:
|
||||
self.wit = CTxWitness()
|
||||
|
@ -500,7 +500,7 @@ class CTransaction:
|
|||
if (len(self.wit.vtxinwit) != len(self.vin)):
|
||||
# vtxinwit must have the same length as vin
|
||||
self.wit.vtxinwit = self.wit.vtxinwit[:len(self.vin)]
|
||||
for i in range(len(self.wit.vtxinwit), len(self.vin)):
|
||||
for _ in range(len(self.wit.vtxinwit), len(self.vin)):
|
||||
self.wit.vtxinwit.append(CTxInWitness())
|
||||
r += self.wit.serialize()
|
||||
r += struct.pack("<I", self.nLockTime)
|
||||
|
@ -735,7 +735,7 @@ class P2PHeaderAndShortIDs:
|
|||
self.header.deserialize(f)
|
||||
self.nonce = struct.unpack("<Q", f.read(8))[0]
|
||||
self.shortids_length = deser_compact_size(f)
|
||||
for i in range(self.shortids_length):
|
||||
for _ in range(self.shortids_length):
|
||||
# shortids are defined to be 6 bytes in the spec, so append
|
||||
# two zero bytes and read it in as an 8-byte number
|
||||
self.shortids.append(struct.unpack("<Q", f.read(6) + b'\x00\x00')[0])
|
||||
|
@ -852,7 +852,7 @@ class BlockTransactionsRequest:
|
|||
def deserialize(self, f):
|
||||
self.blockhash = deser_uint256(f)
|
||||
indexes_length = deser_compact_size(f)
|
||||
for i in range(indexes_length):
|
||||
for _ in range(indexes_length):
|
||||
self.indexes.append(deser_compact_size(f))
|
||||
|
||||
def serialize(self):
|
||||
|
|
|
@ -646,7 +646,7 @@ def LegacySignatureHash(script, txTo, inIdx, hashtype):
|
|||
|
||||
tmp = txtmp.vout[outIdx]
|
||||
txtmp.vout = []
|
||||
for i in range(outIdx):
|
||||
for _ in range(outIdx):
|
||||
txtmp.vout.append(CTxOut(-1))
|
||||
txtmp.vout.append(tmp)
|
||||
|
||||
|
|
|
@ -529,7 +529,7 @@ def create_confirmed_utxos(fee, node, count):
|
|||
addr2 = node.getnewaddress()
|
||||
if iterations <= 0:
|
||||
return utxos
|
||||
for i in range(iterations):
|
||||
for _ in range(iterations):
|
||||
t = utxos.pop()
|
||||
inputs = []
|
||||
inputs.append({"txid": t["txid"], "vout": t["vout"]})
|
||||
|
@ -556,7 +556,7 @@ def gen_return_txouts():
|
|||
# So we have big transactions (and therefore can't fit very many into each block)
|
||||
# create one script_pubkey
|
||||
script_pubkey = "6a4d0200" # OP_RETURN OP_PUSH2 512 bytes
|
||||
for i in range(512):
|
||||
for _ in range(512):
|
||||
script_pubkey = script_pubkey + "01"
|
||||
# concatenate 128 txouts of above script_pubkey which we'll insert before the txout for change
|
||||
txouts = []
|
||||
|
@ -564,7 +564,7 @@ def gen_return_txouts():
|
|||
txout = CTxOut()
|
||||
txout.nValue = 0
|
||||
txout.scriptPubKey = hex_str_to_bytes(script_pubkey)
|
||||
for k in range(128):
|
||||
for _ in range(128):
|
||||
txouts.append(txout)
|
||||
return txouts
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ class WalletBackupTest(BitcoinTestFramework):
|
|||
|
||||
self.log.info("Creating transactions")
|
||||
# Five rounds of sending each other transactions.
|
||||
for i in range(5):
|
||||
for _ in range(5):
|
||||
self.do_one_round()
|
||||
|
||||
self.log.info("Backing up")
|
||||
|
@ -142,7 +142,7 @@ class WalletBackupTest(BitcoinTestFramework):
|
|||
self.nodes[2].dumpwallet(os.path.join(self.nodes[2].datadir, 'wallet.dump'))
|
||||
|
||||
self.log.info("More transactions")
|
||||
for i in range(5):
|
||||
for _ in range(5):
|
||||
self.do_one_round()
|
||||
|
||||
# Generate 101 more blocks, so any fees paid mature
|
||||
|
|
|
@ -569,7 +569,7 @@ class WalletTest(BitcoinTestFramework):
|
|||
# So we should be able to generate exactly chainlimit txs for each original output
|
||||
sending_addr = self.nodes[1].getnewaddress()
|
||||
txid_list = []
|
||||
for i in range(chainlimit * 2):
|
||||
for _ in range(chainlimit * 2):
|
||||
txid_list.append(self.nodes[0].sendtoaddress(sending_addr, Decimal('0.0001')))
|
||||
assert_equal(self.nodes[0].getmempoolinfo()['size'], chainlimit * 2)
|
||||
assert_equal(len(txid_list), chainlimit * 2)
|
||||
|
|
|
@ -62,7 +62,7 @@ class BumpFeeTest(BitcoinTestFramework):
|
|||
self.log.info("Mining blocks...")
|
||||
peer_node.generate(110)
|
||||
self.sync_all()
|
||||
for i in range(25):
|
||||
for _ in range(25):
|
||||
peer_node.sendtoaddress(rbf_node_address, 0.001)
|
||||
self.sync_all()
|
||||
peer_node.generate(1)
|
||||
|
|
|
@ -45,7 +45,7 @@ class CreateTxWalletTest(BitcoinTestFramework):
|
|||
|
||||
def test_tx_size_too_large(self):
|
||||
# More than 10kB of outputs, so that we hit -maxtxfee with a high feerate
|
||||
outputs = {self.nodes[0].getnewaddress(address_type='bech32'): 0.000025 for i in range(400)}
|
||||
outputs = {self.nodes[0].getnewaddress(address_type='bech32'): 0.000025 for _ in range(400)}
|
||||
raw_tx = self.nodes[0].createrawtransaction(inputs=[], outputs=outputs)
|
||||
|
||||
for fee_setting in ['-minrelaytxfee=0.01', '-mintxfee=0.01', '-paytxfee=0.01']:
|
||||
|
|
|
@ -107,7 +107,7 @@ class WalletDescriptorTest(BitcoinTestFramework):
|
|||
assert_equal(info2['desc'], info3['desc'])
|
||||
|
||||
self.log.info("Test that getnewaddress still works after keypool is exhausted in an encrypted wallet")
|
||||
for i in range(0, 500):
|
||||
for _ in range(500):
|
||||
send_wrpc.getnewaddress()
|
||||
|
||||
self.log.info("Test that unlock is needed when deriving only hardened keys in an encrypted wallet")
|
||||
|
@ -120,7 +120,7 @@ class WalletDescriptorTest(BitcoinTestFramework):
|
|||
}])
|
||||
send_wrpc.walletlock()
|
||||
# Exhaust keypool of 100
|
||||
for i in range(0, 100):
|
||||
for _ in range(100):
|
||||
send_wrpc.getnewaddress(address_type='bech32')
|
||||
# This should now error
|
||||
assert_raises_rpc_error(-12, "Keypool ran out, please call keypoolrefill first", send_wrpc.getnewaddress, '', 'bech32')
|
||||
|
|
|
@ -116,7 +116,7 @@ class WalletDumpTest(BitcoinTestFramework):
|
|||
test_addr_count = 10
|
||||
addrs = []
|
||||
for address_type in ['legacy', 'p2sh-segwit', 'bech32']:
|
||||
for i in range(0, test_addr_count):
|
||||
for _ in range(test_addr_count):
|
||||
addr = self.nodes[0].getnewaddress(address_type=address_type)
|
||||
vaddr = self.nodes[0].getaddressinfo(addr) # required to get hd keypath
|
||||
addrs.append(vaddr)
|
||||
|
|
|
@ -27,8 +27,8 @@ class WalletGroupTest(BitcoinTestFramework):
|
|||
self.nodes[0].generate(110)
|
||||
|
||||
# Get some addresses from the two nodes
|
||||
addr1 = [self.nodes[1].getnewaddress() for i in range(3)]
|
||||
addr2 = [self.nodes[2].getnewaddress() for i in range(3)]
|
||||
addr1 = [self.nodes[1].getnewaddress() for _ in range(3)]
|
||||
addr2 = [self.nodes[2].getnewaddress() for _ in range(3)]
|
||||
addrs = addr1 + addr2
|
||||
|
||||
# Send 1 + 0.5 coin to each address
|
||||
|
@ -71,7 +71,7 @@ class WalletGroupTest(BitcoinTestFramework):
|
|||
|
||||
# Fill node2's wallet with 10000 outputs corresponding to the same
|
||||
# scriptPubKey
|
||||
for i in range(5):
|
||||
for _ in range(5):
|
||||
raw_tx = self.nodes[0].createrawtransaction([{"txid":"0"*64, "vout":0}], [{addr2[0]: 0.05}])
|
||||
tx = FromHex(CTransaction(), raw_tx)
|
||||
tx.vin = []
|
||||
|
|
|
@ -118,7 +118,7 @@ class WalletLabelsTest(BitcoinTestFramework):
|
|||
if not self.options.descriptors:
|
||||
for label in labels:
|
||||
addresses = []
|
||||
for x in range(10):
|
||||
for _ in range(10):
|
||||
addresses.append(node.getnewaddress())
|
||||
multisig_address = node.addmultisigaddress(5, addresses, label.name)['address']
|
||||
label.add_address(multisig_address)
|
||||
|
|
|
@ -26,7 +26,7 @@ FEATURE_LATEST = 169900
|
|||
got_loading_error = False
|
||||
def test_load_unload(node, name):
|
||||
global got_loading_error
|
||||
for i in range(10):
|
||||
for _ in range(10):
|
||||
if got_loading_error:
|
||||
return
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue