Skip to content

Commit 1a6fc04

Browse files
committed
Merge bitcoin/bitcoin#29500: test: create assert_not_equal util
7bb83f6 test: create assert_not_equal util and add to where imports are needed (kevkevin) Pull request description: In the functional tests there are lots of cases where we assert != which we now swap with assert_not_equal to be more readable This is motivated/uses logic from this PR which was closed bitcoin/bitcoin#28528 This partially helps bitcoin/bitcoin#23119 I've broken it up to just `assert_not_equal` to keep the PR smaller as suggested in bitcoin/bitcoin#28528 (comment) I can create follow up PR's if this is wanted ACKs for top commit: hodlinator: re-ACK 7bb83f6 ryanofsky: Code review ACK 7bb83f6. Only change since last review is fixing error message formatting and passing it as a keyword argument janb84: Re-ACK [7bb83f6](bitcoin/bitcoin@7bb83f6) Tree-SHA512: de09f41a690033a5b61e6f861d3bd69a32b889d6655a28fbc0d5cfac9f7ec9c642432967d33913970882b4cfdd47bdd377d0ddc44e25976cbaa49f7f9d8f7b10
2 parents 6af68bb + 7bb83f6 commit 1a6fc04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+137
-83
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from test_framework.util import (
3737
assert_approx,
3838
assert_equal,
39+
assert_not_equal,
3940
assert_raises_rpc_error,
4041
ensure_for,
4142
sha256sum_file,
@@ -476,7 +477,7 @@ def check_dump_output(output):
476477
assert_equal(
477478
dump_output4['txoutset_hash'],
478479
"8a1db0d6e958ce0d7c963bc6fc91ead596c027129bacec68acc40351037b09d7")
479-
assert sha256sum_file(dump_output['path']) != sha256sum_file(dump_output4['path'])
480+
assert_not_equal(sha256sum_file(dump_output['path']), sha256sum_file(dump_output4['path']))
480481

481482
# Use a hash instead of a height
482483
prev_snap_hash = n0.getblockhash(prev_snap_height)

test/functional/feature_bind_port_discover.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"""
88

99
from test_framework.test_framework import BitcoinTestFramework, SkipTest
10-
from test_framework.util import assert_equal
10+
from test_framework.util import (
11+
assert_equal,
12+
assert_not_equal,
13+
)
1114

1215
# We need to bind to a routable address for this test to exercise the relevant code
1316
# and also must have another routable address on another interface which must not
@@ -71,7 +74,7 @@ def run_test(self):
7174
if local['address'] == ADDR1:
7275
found_addr1 = True
7376
assert_equal(local['port'], BIND_PORT)
74-
assert local['address'] != ADDR2
77+
assert_not_equal(local['address'], ADDR2)
7578
assert found_addr1
7679

7780
if __name__ == '__main__':

test/functional/feature_coinstatsindex.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
)
2828
from test_framework.test_framework import BitcoinTestFramework
2929
from test_framework.util import (
30+
assert_not_equal,
3031
assert_equal,
3132
assert_raises_rpc_error,
3233
)
@@ -275,12 +276,12 @@ def _test_reorg_index(self):
275276
res2 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=112)
276277
assert_equal(res["bestblock"], block)
277278
assert_equal(res["muhash"], res2["muhash"])
278-
assert res["muhash"] != res_invalid["muhash"]
279+
assert_not_equal(res["muhash"], res_invalid["muhash"])
279280

280281
# Test that requesting reorged out block by hash is still returning correct results
281282
res_invalid2 = index_node.gettxoutsetinfo(hash_type='muhash', hash_or_height=reorg_block)
282283
assert_equal(res_invalid2["muhash"], res_invalid["muhash"])
283-
assert res["muhash"] != res_invalid2["muhash"]
284+
assert_not_equal(res["muhash"], res_invalid2["muhash"])
284285

285286
# Add another block, so we don't depend on reconsiderblock remembering which
286287
# blocks were touched by invalidateblock

test/functional/feature_dbcrash.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
)
3737
from test_framework.test_framework import BitcoinTestFramework
3838
from test_framework.util import (
39+
assert_not_equal,
3940
assert_equal,
4041
)
4142
from test_framework.wallet import (
@@ -274,7 +275,7 @@ def run_test(self):
274275
self.log.info(f"Restarted nodes: {self.restart_counts}; crashes on restart: {self.crashed_on_restart}")
275276

276277
# If no nodes were restarted, we didn't test anything.
277-
assert self.restart_counts != [0, 0, 0]
278+
assert_not_equal(self.restart_counts, [0, 0, 0])
278279

279280
# Make sure we tested the case of crash-during-recovery.
280281
assert self.crashed_on_restart > 0

test/functional/feature_fee_estimation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515
from test_framework.test_framework import BitcoinTestFramework
1616
from test_framework.util import (
17+
assert_not_equal,
1718
assert_equal,
1819
assert_greater_than,
1920
assert_greater_than_or_equal,
@@ -363,15 +364,15 @@ def test_estimate_dat_is_flushed_periodically(self):
363364
self.nodes[0].mockscheduler(SECONDS_PER_HOUR)
364365

365366
fee_dat_current_content = open(fee_dat, "rb").read()
366-
assert fee_dat_current_content != fee_dat_initial_content
367+
assert_not_equal(fee_dat_current_content, fee_dat_initial_content)
367368

368369
fee_dat_initial_content = fee_dat_current_content
369370

370371
# Generate blocks before shutdown and verify that the fee estimates are not the same
371372
self.generate(self.nodes[0], 5, sync_fun=self.no_op)
372373
self.restart_node(0)
373374
fee_dat_current_content = open(fee_dat, "rb").read()
374-
assert fee_dat_current_content != fee_dat_initial_content
375+
assert_not_equal(fee_dat_current_content, fee_dat_initial_content)
375376

376377

377378
def test_acceptstalefeeestimates_option(self):

test/functional/feature_minchainwork.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from test_framework.util import (
2323
assert_equal,
2424
ensure_for,
25+
assert_not_equal,
2526
)
2627

2728
# 2 hashes required per regtest block (with no difficulty adjustment)
@@ -71,7 +72,7 @@ def run_test(self):
7172
ensure_for(duration=3, f=lambda: len(self.nodes[2].getchaintips()) == 1)
7273
assert_equal(self.nodes[2].getchaintips()[0]['height'], 0)
7374

74-
assert self.nodes[1].getbestblockhash() != self.nodes[0].getbestblockhash()
75+
assert_not_equal(self.nodes[1].getbestblockhash(), self.nodes[0].getbestblockhash())
7576
assert_equal(self.nodes[2].getblockcount(), starting_blockcount)
7677

7778
self.log.info("Check that getheaders requests to node2 are ignored")

test/functional/feature_taproot.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
)
9494
from test_framework.test_framework import BitcoinTestFramework
9595
from test_framework.util import (
96+
assert_not_equal,
9697
assert_raises_rpc_error,
9798
assert_equal,
9899
)
@@ -1570,20 +1571,20 @@ def gen_test_vectors(self):
15701571
# Require negated taps[0]
15711572
assert taps[0].negflag
15721573
# Require one negated and one non-negated in taps 1 and 2.
1573-
assert taps[1].negflag != taps[2].negflag
1574+
assert_not_equal(taps[1].negflag, taps[2].negflag)
15741575
# Require one negated and one non-negated in taps 3 and 4.
1575-
assert taps[3].negflag != taps[4].negflag
1576+
assert_not_equal(taps[3].negflag, taps[4].negflag)
15761577
# Require one negated and one non-negated in taps 5 and 6.
1577-
assert taps[5].negflag != taps[6].negflag
1578+
assert_not_equal(taps[5].negflag, taps[6].negflag)
15781579

15791580
cblks = [{leaf: get({**DEFAULT_CONTEXT, 'tap': taps[i], 'leaf': leaf}, 'controlblock') for leaf in taps[i].leaves} for i in range(7)]
15801581
# Require one swapped and one unswapped in taps 3 and 4.
1581-
assert (cblks[3]['0'][33:65] < cblks[3]['1'][33:65]) != (cblks[4]['0'][33:65] < cblks[4]['1'][33:65])
1582+
assert_not_equal((cblks[3]['0'][33:65] < cblks[3]['1'][33:65]), (cblks[4]['0'][33:65] < cblks[4]['1'][33:65]))
15821583
# Require one swapped and one unswapped in taps 5 and 6, both at the top and child level.
1583-
assert (cblks[5]['0'][33:65] < cblks[5]['1'][65:]) != (cblks[6]['0'][33:65] < cblks[6]['1'][65:])
1584-
assert (cblks[5]['1'][33:65] < cblks[5]['2'][33:65]) != (cblks[6]['1'][33:65] < cblks[6]['2'][33:65])
1584+
assert_not_equal((cblks[5]['0'][33:65] < cblks[5]['1'][65:]), (cblks[6]['0'][33:65] < cblks[6]['1'][65:]))
1585+
assert_not_equal((cblks[5]['1'][33:65] < cblks[5]['2'][33:65]), (cblks[6]['1'][33:65] < cblks[6]['2'][33:65]))
15851586
# Require within taps 5 (and thus also 6) that one level is swapped and the other is not.
1586-
assert (cblks[5]['0'][33:65] < cblks[5]['1'][65:]) != (cblks[5]['1'][33:65] < cblks[5]['2'][33:65])
1587+
assert_not_equal((cblks[5]['0'][33:65] < cblks[5]['1'][65:]), (cblks[5]['1'][33:65] < cblks[5]['2'][33:65]))
15871588

15881589
# Compute a deterministic set of scriptPubKeys
15891590
tap_spks = []

test/functional/mempool_accept_wtxid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)
3232
from test_framework.test_framework import BitcoinTestFramework
3333
from test_framework.util import (
34+
assert_not_equal,
3435
assert_equal,
3536
)
3637

@@ -86,7 +87,7 @@ def run_test(self):
8687
child_two_txid = child_two.rehash()
8788

8889
assert_equal(child_one_txid, child_two_txid)
89-
assert child_one_wtxid != child_two_wtxid
90+
assert_not_equal(child_one_wtxid, child_two_wtxid)
9091

9192
self.log.info("Submit child_one to the mempool")
9293
txid_submitted = node.sendrawtransaction(child_one.serialize().hex())

test/functional/mempool_ephemeral_dust.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
assert_equal,
1616
assert_greater_than,
1717
assert_raises_rpc_error,
18+
assert_not_equal,
1819
)
1920
from test_framework.wallet import (
2021
MiniWallet,
@@ -239,7 +240,7 @@ def test_unspent_ephemeral(self):
239240

240241
# Spend works with dust spent
241242
sweep_tx_2 = self.wallet.create_self_transfer_multi(fee_per_output=2000, utxos_to_spend=dusty_tx["new_utxos"], version=3)
242-
assert sweep_tx["hex"] != sweep_tx_2["hex"]
243+
assert_not_equal(sweep_tx["hex"], sweep_tx_2["hex"])
243244
res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx_2["hex"]])
244245
assert_equal(res["package_msg"], "success")
245246

test/functional/mempool_truc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import (
9+
assert_not_equal,
910
assert_equal,
1011
assert_greater_than,
1112
assert_greater_than_or_equal,
@@ -479,7 +480,7 @@ def test_reorg_2child_rbf(self):
479480
child_1_conflict = self.wallet.send_self_transfer(from_node=node, version=3, utxo_to_spend=ancestor_tx["new_utxos"][0], fee_rate=Decimal("0.01"))
480481

481482
# Ensure child_1 and child_1_conflict are different transactions
482-
assert (child_1_conflict["txid"] != child_1["txid"])
483+
assert_not_equal(child_1_conflict["txid"], child_1["txid"])
483484
self.check_mempool([ancestor_tx["txid"], child_1_conflict["txid"], child_2["txid"]])
484485
assert_equal(node.getmempoolentry(ancestor_tx["txid"])["descendantcount"], 3)
485486

0 commit comments

Comments
 (0)