Skip to content

Commit 233e8e3

Browse files
committed
scripted-diff: swapped where < was used and used assert_greater_than
-BEGIN VERIFY SCRIPT- git grep -l -E "assert .*<{1} [\=\<]{0}" -- ':(exclude)*script.py' ':(exclude)*rpc_createmultisig.py' ':(exclude)*feature_taproot.py' ':(exclude)*wallet_create_tx.py' ':(exclude)*p2p.py' ./test/functional | xargs sed -i.bak -e "/assert .*< / s/assert \(.*\) <\([^#]*\)/assert\2 < \1/" git grep -l -E "assert .*<{1} [\=\<]{0}" -- ':(exclude)*script.py' ':(exclude)*rpc_createmultisig.py' ':(exclude)*feature_taproot.py' ':(exclude)*wallet_create_tx.py' ':(exclude)*p2p.py' ./test/functional | xargs sed -i.bak -e "/assert .*< / s/assert \(.*\) <\([^#]*\)/assert_greater_than(\1,\2)/g" -e "s/assert_greater_than(\(.*\)\(#.*\)/assert_greater_than(\1 \2/g" -e "/assert_greater_than(/ s/\ \ ,/,/g" -END VERIFY SCRIPT-
1 parent accb42f commit 233e8e3

13 files changed

+17
-17
lines changed

test/functional/feature_block.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ def run_test(self):
798798
self.move_tip(57)
799799
self.next_block(58, spend=out[17])
800800
tx = CTransaction()
801-
assert len(out[17].vout) < 42
801+
assert_greater_than(42, len(out[17].vout))
802802
tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), SEQUENCE_FINAL))
803803
tx.vout.append(CTxOut(0, b""))
804804
tx.calc_sha256()

test/functional/feature_coinstatsindex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def _test_coin_stats_index(self):
227227

228228
self.generate(index_node, 1, sync_fun=self.no_op)
229229
res10 = index_node.gettxoutsetinfo('muhash')
230-
assert res8['txouts'] < res10['txouts']
230+
assert_greater_than(res10['txouts'], res8['txouts'])
231231

232232
self.log.info("Test that the index works with -reindex")
233233

test/functional/feature_rbf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def make_utxo(self, node, amount, *, confirmed=True, scriptPubKey=None):
103103
new_size = len(node.getrawmempool())
104104
# Error out if we have something stuck in the mempool, as this
105105
# would likely be a bug.
106-
assert new_size < mempool_size
106+
assert_greater_than(mempool_size, new_size)
107107
mempool_size = new_size
108108

109109
return self.wallet.get_utxo(txid=tx["txid"], vout=tx["sent_vout"])

test/functional/mempool_resurrect.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def run_test(self):
4141
assert_equal(set(node.getrawmempool()), set())
4242
confirmed_txns = set(node.getblock(blocks[0])['tx'] + node.getblock(blocks[1])['tx'])
4343
# Checks that all spend txns are contained in the mined blocks
44-
assert spends_ids < confirmed_txns
44+
assert_greater_than(confirmed_txns, spends_ids)
4545

4646
# Use invalidateblock to re-org back
4747
node.invalidateblock(blocks[0])
@@ -54,7 +54,7 @@ def run_test(self):
5454
# mempool should be empty, all txns confirmed
5555
assert_equal(set(node.getrawmempool()), set())
5656
confirmed_txns = set(node.getblock(blocks[0])['tx'])
57-
assert spends_ids < confirmed_txns
57+
assert_greater_than(confirmed_txns, spends_ids)
5858

5959

6060
if __name__ == '__main__':

test/functional/p2p_addr_relay.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def setup_addr_msg(self, num, sequential_ips=True):
113113
addr.time = self.mocktime + random.randrange(-100, 100)
114114
addr.nServices = P2P_SERVICES
115115
if sequential_ips:
116-
assert self.counter < 256 ** 2 # Don't allow the returned ip addresses to wrap.
116+
assert_greater_than(256 ** 2, self.counter) # Don't allow the returned ip addresses to wrap.
117117
addr.ip = f"123.123.{self.counter // 256}.{self.counter % 256}"
118118
self.counter += 1
119119
else:

test/functional/p2p_segwit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def test_block_malleability(self):
847847
assert self.nodes[0].getbestblockhash() != block.hash
848848

849849
block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.pop()
850-
assert block.get_weight() < MAX_BLOCK_WEIGHT
850+
assert_greater_than(MAX_BLOCK_WEIGHT, block.get_weight())
851851
assert_equal(None, self.nodes[0].submitblock(block.serialize().hex()))
852852

853853
assert self.nodes[0].getbestblockhash() == block.hash
@@ -1885,7 +1885,7 @@ def test_witness_sigops(self):
18851885
extra_sigops_available = MAX_SIGOP_COST % sigops_per_script
18861886

18871887
# We chose the number of checkmultisigs/checksigs to make this work:
1888-
assert extra_sigops_available < 100 # steer clear of MAX_OPS_PER_SCRIPT
1888+
assert_greater_than(100, extra_sigops_available) # steer clear of MAX_OPS_PER_SCRIPT
18891889

18901890
# This script, when spent with the first
18911891
# N(=MAX_SIGOP_COST//sigops_per_script) outputs of our transaction,

test/functional/p2p_sendtxrcncl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def run_test(self):
8585
peer.wait_for_verack()
8686
verack_index = [i for i, msg in enumerate(peer.messages) if msg.msgtype == b'verack'][0]
8787
sendtxrcncl_index = [i for i, msg in enumerate(peer.messages) if msg.msgtype == b'sendtxrcncl'][0]
88-
assert sendtxrcncl_index < verack_index
88+
assert_greater_than(verack_index, sendtxrcncl_index)
8989
self.nodes[0].disconnect_p2ps()
9090

9191
self.log.info('SENDTXRCNCL on pre-WTXID version should not be sent')

test/functional/rpc_blockchain.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def _test_gettxoutsetinfo(self):
339339
assert_equal(res['bestblock'], node.getblockhash(HEIGHT))
340340
size = res['disk_size']
341341
assert size > 6400
342-
assert size < 64000
342+
assert_greater_than(64000, size)
343343
assert_equal(len(res['bestblock']), 64)
344344
assert_equal(len(res['hash_serialized_3']), 64)
345345

@@ -433,7 +433,7 @@ def _test_getdifficulty(self):
433433
difficulty = self.nodes[0].getdifficulty()
434434
# 1 hash in 2 should be valid, so difficulty should be 1/2**31
435435
# binary => decimal => binary math is why we do this check
436-
assert abs(difficulty * 2**31 - 1) < 0.0001
436+
assert_greater_than(0.0001, abs(difficulty * 2**31 - 1))
437437

438438
def _test_getnetworkhashps(self):
439439
self.log.info("Test getnetworkhashps")
@@ -475,7 +475,7 @@ def _test_getnetworkhashps(self):
475475

476476
# This should be 2 hashes every 10 minutes or 1/300
477477
hashes_per_second = self.nodes[0].getnetworkhashps()
478-
assert abs(hashes_per_second * 300 - 1) < 0.0001
478+
assert_greater_than(0.0001, abs(hashes_per_second * 300 - 1))
479479

480480
# Test setting the first param of getnetworkhashps to -1 returns the average network
481481
# hashes per second from the last difficulty change.

test/functional/test_framework/blocktools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, script_pub_key=C
163163
Can optionally pass scriptPubKey and scriptSig, default is anyone-can-spend output.
164164
"""
165165
tx = CTransaction()
166-
assert n < len(prevtx.vout)
166+
assert_greater_than(len(prevtx.vout), n)
167167
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), script_sig, SEQUENCE_FINAL))
168168
tx.vout.append(CTxOut(amount, script_pub_key))
169169
tx.calc_sha256()

test/functional/test_framework/netutil.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def addr_to_hex(addr):
135135
if i == 0 or i == (len(addr)-1): # skip empty component at beginning or end
136136
continue
137137
x += 1 # :: skips to suffix
138-
assert x < 2
138+
assert_greater_than(2, x)
139139
else: # two bytes per component
140140
val = int(comp, 16)
141141
sub[x].append(val >> 8)

test/functional/wallet_abandonconflict.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_test(self):
5454
assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: alice.abandontransaction(txid=txA))
5555

5656
newbalance = alice.getbalance()
57-
assert balance - newbalance < Decimal("0.001") #no more than fees lost
57+
assert_greater_than(Decimal("0.001"), balance - newbalance) #no more than fees lost
5858
balance = newbalance
5959

6060
# Disconnect nodes so node0's transactions don't get into node1's mempool

test/functional/wallet_bumpfee.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address):
740740

741741
def test_bumpfee_metadata(self, rbf_node, dest_address):
742742
self.log.info('Test that bumped txn metadata persists to new txn record')
743-
assert rbf_node.getbalance() < 49
743+
assert_greater_than(49, rbf_node.getbalance())
744744
self.generatetoaddress(rbf_node, 101, rbf_node.getnewaddress())
745745
rbfid = rbf_node.sendtoaddress(dest_address, 49, "comment value", "to value")
746746
bumped_tx = rbf_node.bumpfee(rbfid)

test/functional/wallet_conflicts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_block_conflicts(self):
105105

106106
self.log.info("Verify, after the reorg, that Tx_A was accepted, and tx_AB and its Child_Tx are conflicting now")
107107
# Tx A was accepted, Tx AB was not.
108-
assert conflicted_AB_tx["confirmations"] < 0
108+
assert_greater_than(0, conflicted_AB_tx["confirmations"])
109109
assert conflicted_A_tx["confirmations"] > 0
110110

111111
# Conflicted tx should have confirmations set to the confirmations of the most conflicting tx

0 commit comments

Comments
 (0)