Skip to content

Commit dd8fa86

Browse files
committed
test: use tagged ephemeral MiniWallet instance in fill_mempool
1 parent b2037ad commit dd8fa86

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

test/functional/mempool_limit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_mid_package_eviction(self):
9595
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
9696
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
9797

98-
fill_mempool(self, node, self.wallet)
98+
fill_mempool(self, node)
9999
current_info = node.getmempoolinfo()
100100
mempoolmin_feerate = current_info["mempoolminfee"]
101101

@@ -185,7 +185,7 @@ def test_mid_package_replacement(self):
185185
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
186186
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
187187

188-
fill_mempool(self, node, self.wallet)
188+
fill_mempool(self, node)
189189
current_info = node.getmempoolinfo()
190190
mempoolmin_feerate = current_info["mempoolminfee"]
191191

@@ -259,7 +259,7 @@ def run_test(self):
259259
assert_equal(node.getmempoolinfo()['minrelaytxfee'], Decimal('0.00001000'))
260260
assert_equal(node.getmempoolinfo()['mempoolminfee'], Decimal('0.00001000'))
261261

262-
fill_mempool(self, node, self.wallet)
262+
fill_mempool(self, node)
263263

264264
# Deliberately try to create a tx with a fee less than the minimum mempool fee to assert that it does not get added to the mempool
265265
self.log.info('Create a mempool tx that will not pass mempoolminfee')

test/functional/p2p_1p1c_network.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def set_test_params(self):
4747
self.supports_cli = False
4848

4949
def raise_network_minfee(self):
50-
filler_wallet = MiniWallet(self.nodes[0])
51-
fill_mempool(self, self.nodes[0], filler_wallet)
50+
fill_mempool(self, self.nodes[0])
5251

5352
self.log.debug("Wait for the network to sync mempools")
5453
self.sync_mempools()

test/functional/p2p_opportunistic_1p1c.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ def run_test(self):
388388
self.generate(self.wallet_nonsegwit, 10)
389389
self.generate(self.wallet, 20)
390390

391-
filler_wallet = MiniWallet(node)
392-
fill_mempool(self, node, filler_wallet)
391+
fill_mempool(self, node)
393392

394393
self.log.info("Check opportunistic 1p1c logic when parent (txid != wtxid) is received before child")
395394
self.test_basic_parent_then_child(self.wallet)

test/functional/p2p_tx_download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_spurious_notfound(self):
250250
def test_rejects_filter_reset(self):
251251
self.log.info('Check that rejected tx is not requested again')
252252
node = self.nodes[0]
253-
fill_mempool(self, node, self.wallet)
253+
fill_mempool(self, node)
254254
self.wallet.rescan_utxos()
255255
mempoolminfee = node.getmempoolinfo()['mempoolminfee']
256256
peer = node.add_p2p_connection(TestP2PConn())

test/functional/rpc_packages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def test_maxfeerate_submitpackage(self):
390390
])
391391
self.wallet.rescan_utxos()
392392

393-
fill_mempool(self, node, self.wallet)
393+
fill_mempool(self, node)
394394

395395
minrelay = node.getmempoolinfo()["minrelaytxfee"]
396396
parent = self.wallet.create_self_transfer(

test/functional/test_framework/mempool_util.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
create_lots_of_big_transactions,
1515
gen_return_txouts,
1616
)
17+
from .wallet import (
18+
MiniWallet,
19+
)
1720

1821

19-
def fill_mempool(test_framework, node, miniwallet):
22+
def fill_mempool(test_framework, node):
2023
"""Fill mempool until eviction.
2124
2225
Allows for simpler testing of scenarios with floating mempoolminfee > minrelay
@@ -25,8 +28,8 @@ def fill_mempool(test_framework, node, miniwallet):
2528
It will not ensure mempools become synced as it
2629
is based on a single node and assumes -minrelaytxfee
2730
is 1 sat/vbyte.
28-
To avoid unintentional tx dependencies, it is recommended to use separate miniwallets for
29-
mempool filling vs transactions in tests.
31+
To avoid unintentional tx dependencies, the mempool filling txs are created with a
32+
tagged ephemeral miniwallet instance.
3033
"""
3134
test_framework.log.info("Fill the mempool until eviction is triggered and the mempoolminfee rises")
3235
txouts = gen_return_txouts()
@@ -39,19 +42,20 @@ def fill_mempool(test_framework, node, miniwallet):
3942
# Generate UTXOs to flood the mempool
4043
# 1 to create a tx initially that will be evicted from the mempool later
4144
# 75 transactions each with a fee rate higher than the previous one
42-
test_framework.generate(miniwallet, 1 + (num_of_batches * tx_batch_size))
45+
ephemeral_miniwallet = MiniWallet(node, tag_name="fill_mempool_ephemeral_wallet")
46+
test_framework.generate(ephemeral_miniwallet, 1 + num_of_batches * tx_batch_size)
4347

4448
# Mine enough blocks so that the UTXOs are allowed to be spent
4549
test_framework.generate(node, COINBASE_MATURITY - 1)
4650

4751
# Get all UTXOs up front to ensure none of the transactions spend from each other, as that may
4852
# change their effective feerate and thus the order in which they are selected for eviction.
49-
confirmed_utxos = [miniwallet.get_utxo(confirmed_only=True) for _ in range(num_of_batches * tx_batch_size + 1)]
53+
confirmed_utxos = [ephemeral_miniwallet.get_utxo(confirmed_only=True) for _ in range(num_of_batches * tx_batch_size + 1)]
5054
assert_equal(len(confirmed_utxos), num_of_batches * tx_batch_size + 1)
5155

5256
test_framework.log.debug("Create a mempool tx that will be evicted")
53-
tx_to_be_evicted_id = miniwallet.send_self_transfer(from_node=node, utxo_to_spend=confirmed_utxos[0], fee_rate=relayfee)["txid"]
54-
del confirmed_utxos[0]
57+
tx_to_be_evicted_id = ephemeral_miniwallet.send_self_transfer(
58+
from_node=node, utxo_to_spend=confirmed_utxos.pop(0), fee_rate=relayfee)["txid"]
5559

5660
# Increase the tx fee rate to give the subsequent transactions a higher priority in the mempool
5761
# The tx has an approx. vsize of 65k, i.e. multiplying the previous fee rate (in sats/kvB)
@@ -63,7 +67,7 @@ def fill_mempool(test_framework, node, miniwallet):
6367
for batch_of_txid in range(num_of_batches):
6468
fee = (batch_of_txid + 1) * base_fee
6569
utxos = confirmed_utxos[:tx_batch_size]
66-
create_lots_of_big_transactions(miniwallet, node, fee, tx_batch_size, txouts, utxos)
70+
create_lots_of_big_transactions(ephemeral_miniwallet, node, fee, tx_batch_size, txouts, utxos)
6771
del confirmed_utxos[:tx_batch_size]
6872

6973
test_framework.log.debug("The tx should be evicted by now")

0 commit comments

Comments
 (0)