Skip to content

Commit 8339f3c

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#26886: test: add rescan utxos inside MiniWallet's initialization
6bd098a test: simplify tests by using the pre-mined chain (kouloumos) 42029a7 test: remove redundant blocks generation logic (kouloumos) 0377d6b test: add `rescan_utxos` in MiniWallet's initialization (kouloumos) Pull request description: When a pre-mined blockchain is used (default behavior), it [contains coinbase outputs in blocks 76-10](https://github.com/bitcoin/bitcoin/blob/07c54de550035c3441f34ef6c34209666267eb38/test/functional/test_framework/test_framework.py#L809-L813) to [the MiniWallet's default address](https://github.com/bitcoin/bitcoin/blob/07c54de550035c3441f34ef6c34209666267eb38/test/functional/test_framework/wallet.py#L99-L101). That's why we always* `rescan_utxos()` after initializing the MiniWallet, in order for the MiniWallet to account for those mature UTXOs. > The tests following this usage pattern can be seen with: > ```git grep -n "MiniWallet(" $(git grep -le "rescan_utxos()" $(git grep -Le "self.setup_clean_chain = True"))``` **This PR adds `rescan_utxos()` inside MiniWallet's initialization to simplify usage when the MiniWallet is used with a pre-mined chain.** ### secondary changes - *There are a few tests that use the pre-mined blockchain but do not `rescan_utxos()`, they instead generate new blocks to create mature UTXOs. > Those were written before the `rescan_utxos()` method was introduced with bitcoin/bitcoin#22955 (fac66d0) and can be seen with: > `git grep -n "MiniWallet(" $(git grep -Le "rescan_utxos()" $(git grep -Le "self.setup_clean_chain = True"))` > After including `rescan_utxos()` inside MiniWallets initilization, this blocks generation logic is not needed as the MiniWallet already accounts for enough mature UTXOs to perform the tests. **Therefore the now redundant blocks generation logic is removed from those tests with the second commit.** - The rest of the MiniWallet tests use a clean chain (`self.setup_clean_chain = True`) and can be seen with `git grep -n "MiniWallet(" $(git grep -le "self.setup_clean_chain = True")` From those, there are a few that start from a clean chain and then create enough mature UTXOs for the MiniWallet with this kind of logic: https://github.com/bitcoin/bitcoin/blob/07c54de550035c3441f34ef6c34209666267eb38/test/functional/mempool_expiry.py#L36-L40 **Those tests are simplified in the third commit to instead utilize the mature UTXOs of the pre-mined chain.** ACKs for top commit: MarcoFalke: ACK 6bd098a 🕷 theStack: re-ACK 6bd098a Tree-SHA512: 7f9361e36910e4000c33a32efdde4449f4a8a763bb42df96de826fcde469f9362f701b8c99e2a2c482d2d5a42a83ae5ae3844fdbed187ed0ff231f386c222493
2 parents 04e54fd + 6bd098a commit 8339f3c

35 files changed

+10
-74
lines changed

test/functional/feature_bip68_sequence.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ def run_test(self):
6363
self.relayfee = self.nodes[0].getnetworkinfo()["relayfee"]
6464
self.wallet = MiniWallet(self.nodes[0])
6565

66-
# Generate some coins
67-
self.generate(self.wallet, 110)
68-
6966
self.log.info("Running test disable flag")
7067
self.test_disable_flag()
7168

test/functional/feature_dbcrash.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ def generate_small_transactions(self, node, count, utxo_list):
202202

203203
def run_test(self):
204204
self.wallet = MiniWallet(self.nodes[3])
205-
self.wallet.rescan_utxos()
206205
initial_height = self.nodes[3].getblockcount()
207206
self.generate(self.nodes[3], COINBASE_MATURITY, sync_fun=self.no_op)
208207

test/functional/feature_fee_estimation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ def run_test(self):
297297
# Split two coinbases into many small utxos
298298
self.start_node(0)
299299
self.wallet = MiniWallet(self.nodes[0])
300-
self.wallet.rescan_utxos()
301300
self.initial_split(self.nodes[0])
302301
self.log.info("Finished splitting")
303302

test/functional/feature_rbf.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ def set_test_params(self):
4242

4343
def run_test(self):
4444
self.wallet = MiniWallet(self.nodes[0])
45-
# the pre-mined test framework chain contains coinbase outputs to the
46-
# MiniWallet's default address in blocks 76-100 (see method
47-
# BitcoinTestFramework._initialize_chain())
48-
self.wallet.rescan_utxos()
4945

5046
self.log.info("Running test simple doublespend...")
5147
self.test_simple_doublespend()
@@ -398,7 +394,6 @@ def test_too_many_replacements_with_default_mempool_params(self):
398394
"""
399395
normal_node = self.nodes[1]
400396
wallet = MiniWallet(normal_node)
401-
wallet.rescan_utxos()
402397
# Clear mempools to avoid cross-node sync failure.
403398
for node in self.nodes:
404399
self.generate(node, 1)

test/functional/feature_txindex_compatibility.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def setup_network(self):
4242

4343
def run_test(self):
4444
mini_wallet = MiniWallet(self.nodes[1])
45-
mini_wallet.rescan_utxos()
4645
spend_utxo = mini_wallet.get_utxo()
4746
mini_wallet.send_self_transfer(from_node=self.nodes[1], utxo_to_spend=spend_utxo)
4847
self.generate(self.nodes[1], 1)

test/functional/interface_rest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def test_rest_request(
9696
def run_test(self):
9797
self.url = urllib.parse.urlparse(self.nodes[0].url)
9898
self.wallet = MiniWallet(self.nodes[0])
99-
self.wallet.rescan_utxos()
10099

101100
self.log.info("Broadcast test transaction and sync nodes")
102101
txid, _ = self.wallet.send_to(from_node=self.nodes[0], scriptPubKey=getnewdestination()[1], amount=int(0.1 * COIN))

test/functional/interface_usdt_utxocache.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def skip_test_if_missing_module(self):
144144

145145
def run_test(self):
146146
self.wallet = MiniWallet(self.nodes[0])
147-
self.generate(self.wallet, 101)
148147

149148
self.test_uncache()
150149
self.test_add_spent()

test/functional/interface_zmq.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ def test_basic(self):
215215
assert_equal([txid.hex()], self.nodes[1].getblock(hash)["tx"])
216216

217217

218-
self.wallet.rescan_utxos()
219218
self.log.info("Wait for tx from second node")
220219
payment_tx = self.wallet.send_self_transfer(from_node=self.nodes[1])
221220
payment_txid = payment_tx['txid']

test/functional/mempool_accept.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def check_mempool_result(self, result_expected, *args, **kwargs):
6969
def run_test(self):
7070
node = self.nodes[0]
7171
self.wallet = MiniWallet(node)
72-
self.wallet.rescan_utxos()
7372

7473
self.log.info('Start with empty mempool, and 200 blocks')
7574
self.mempool_size = 0

test/functional/mempool_datacarrier.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def test_null_data_transaction(self, node: TestNode, data: bytes, success: bool)
4444

4545
def run_test(self):
4646
self.wallet = MiniWallet(self.nodes[0])
47-
self.wallet.rescan_utxos()
4847

4948
# By default, only 80 bytes are used for data (+1 for OP_RETURN, +2 for the pushdata opcodes).
5049
default_size_data = random_bytes(MAX_OP_RETURN_RELAY - 3)

0 commit comments

Comments
 (0)