Skip to content

Commit fd385c3

Browse files
committed
scripted-diff: tests replaced < to use assert_less_than
-BEGIN VERIFY SCRIPT- git grep -l -E -e "assert .*<{1} [\=\<]{0}" --and --not -e "assert .*!=" --and --not -e "assert .*<=" --and --not -e "assert (.*<" -- ./test/functional | xargs sed -i.bak -E -e "/assert .*< / s/assert /assert_less_than(/g" -e "/assert_less_than\(/ s/ </,/g" -e "/assert_less_than\(/ s/ (#)/) #/g" -e "/assert_less_than\(.*/ s/$/)/g" -e "/assert_less_than\(.*#.*\)/ s/\)$//g" -END VERIFY SCRIPT-
1 parent 67a2aa0 commit fd385c3

14 files changed

+18
-18
lines changed

test/functional/feature_block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ def run_test(self):
799799
self.move_tip(57)
800800
self.next_block(58, spend=out[17])
801801
tx = CTransaction()
802-
assert len(out[17].vout) < 42
802+
assert_less_than(len(out[17].vout), 42)
803803
tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), SEQUENCE_FINAL))
804804
tx.vout.append(CTxOut(0, b""))
805805
tx.calc_sha256()

test/functional/feature_coinstatsindex.py

Lines changed: 1 addition & 1 deletion
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_less_than(res8['txouts'], res10['txouts'])
231231

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

test/functional/feature_rbf.py

Lines changed: 1 addition & 1 deletion
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_less_than(new_size, mempool_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

Lines changed: 2 additions & 2 deletions
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_less_than(spends_ids, confirmed_txns)
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_less_than(spends_ids, confirmed_txns)
5858

5959

6060
if __name__ == '__main__':

test/functional/p2p_addr_relay.py

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

test/functional/p2p_segwit.py

Lines changed: 2 additions & 2 deletions
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_less_than(block.get_weight(), MAX_BLOCK_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_less_than(extra_sigops_available, 100) # 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

Lines changed: 1 addition & 1 deletion
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_less_than(sendtxrcncl_index, verack_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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def _test_gettxoutsetinfo(self):
340340
assert_equal(res['bestblock'], node.getblockhash(HEIGHT))
341341
size = res['disk_size']
342342
assert size > 6400
343-
assert size < 64000
343+
assert_less_than(size, 64000)
344344
assert_equal(len(res['bestblock']), 64)
345345
assert_equal(len(res['hash_serialized_3']), 64)
346346

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

439439
def _test_getnetworkhashps(self):
440440
self.log.info("Test getnetworkhashps")
@@ -476,7 +476,7 @@ def _test_getnetworkhashps(self):
476476

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

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

test/functional/rpc_createmultisig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def checkbalances(self):
144144
balw = self.wallet.get_balance()
145145

146146
height = node0.getblockchaininfo()["blocks"]
147-
assert 150 < height < 350
147+
assert_less_than(150, height, 350)
148148
total = 149 * 50 + (height - 149 - 100) * 25
149149
assert bal1 == 0
150150
assert bal2 == self.moved

test/functional/test_framework/blocktools.py

Lines changed: 1 addition & 1 deletion
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_less_than(n, len(prevtx.vout))
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

Lines changed: 1 addition & 1 deletion
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_less_than(x, 2)
139139
else: # two bytes per component
140140
val = int(comp, 16)
141141
sub[x].append(val >> 8)

test/functional/wallet_abandonconflict.py

Lines changed: 1 addition & 1 deletion
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_less_than(balance - newbalance, Decimal("0.001")) #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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ def test_unconfirmed_not_spendable(self, rbf_node, rbf_node_address):
741741

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

test/functional/wallet_conflicts.py

Lines changed: 1 addition & 1 deletion
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_less_than(conflicted_AB_tx["confirmations"], 0)
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)