It doesn’t seem like we’re actually testing the expected balance at any point, rather the amount received, but I may be missing nuance. Would this diff make sense? I don’t like adding an extra parameter to an already long function for something so specific, if we can avoid it.
0diff --git a/test/functional/wallet_import_rescan.py b/test/functional/wallet_import_rescan.py
1index 1abc9c0c79..fa9f43f66c 100755
2--- a/test/functional/wallet_import_rescan.py
3+++ b/test/functional/wallet_import_rescan.py
4@@ -82,7 +82,7 @@ class Variant(collections.namedtuple("Variant", "call data address_type rescan p
5 )
6 assert_equal(response, [{"success": True}])
7
8- def check(self, txid=None, amount=None, confirmation_height=None, amount_is_balance=True):
9+ def check(self, txid=None, amount=None, confirmation_height=None):
10 """Verify that listtransactions/listreceivedbyaddress return expected values."""
11
12 txs = self.node.listtransactions(label=self.label, count=10000, include_watchonly=True)
13@@ -112,8 +112,7 @@ class Variant(collections.namedtuple("Variant", "call data address_type rescan p
14
15 address, = [ad for ad in addresses if txid in ad["txids"]]
16 assert_equal(address["address"], self.address["address"])
17- if amount_is_balance:
18- assert_equal(address["amount"], self.expected_balance)
19+ assert_equal(address["amount"], self.amount_received)
20 assert_equal(address["confirmations"], confirmations)
21 # Verify the transaction is correctly marked watchonly depending on
22 # whether the transaction pays to an imported public key or
23@@ -227,11 +226,11 @@ class ImportRescanTest(BitcoinTestFramework):
24 variant.node = self.nodes[2 + IMPORT_NODES.index(ImportNode(variant.prune, expect_rescan))]
25 variant.do_import(variant.timestamp)
26 if expect_rescan:
27- variant.expected_balance = variant.initial_amount
28+ variant.amount_received = variant.initial_amount
29 variant.expected_txs = 1
30 variant.check(variant.initial_txid, variant.initial_amount, variant.confirmation_height)
31 else:
32- variant.expected_balance = 0
33+ variant.amount_received = 0
34 variant.expected_txs = 0
35 variant.check()
36
37@@ -251,7 +250,7 @@ class ImportRescanTest(BitcoinTestFramework):
38 # Check the latest results from getbalance and listtransactions.
39 for variant in IMPORT_VARIANTS:
40 self.log.info('Run check for variant {}'.format(variant))
41- variant.expected_balance += variant.sent_amount
42+ variant.amount_received += variant.sent_amount
43 variant.expected_txs += 1
44 variant.check(variant.sent_txid, variant.sent_amount, variant.confirmation_height)
45
46@@ -297,7 +296,6 @@ class ImportRescanTest(BitcoinTestFramework):
47 subtract_fee_from_outputs=[0]
48 )
49 variant.child_txid = child["txid"]
50- variant.expected_balance = 0
51 self.nodes[0].sendrawtransaction(child["hex"])
52
53 # Mempools should contain the child transactions for each variant.
54@@ -321,10 +319,11 @@ class ImportRescanTest(BitcoinTestFramework):
55 # Ensure both transactions were rescanned
56 assert_equal(variant.node.gettransaction(variant.initial_txid)['confirmations'], 0)
57 assert_equal(variant.node.gettransaction(variant.child_txid)['confirmations'], 0)
58+ variant.amount_received = variant.initial_amount
59 variant.expected_txs = 1
60- variant.check(variant.initial_txid, variant.initial_amount, 0, False)
61+ variant.check(variant.initial_txid, variant.initial_amount, 0)
62 else:
63- variant.expected_balance = 0
64+ variant.amount_received = 0
65 variant.expected_txs = 0
66 variant.check()
67