Skip to content

Commit fa32cb2

Browse files
author
MarcoFalke
committed
test: Use MiniWallet in mempool_persist
1 parent faca688 commit fa32cb2

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

test/functional/mempool_persist.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,34 @@
4646
assert_greater_than_or_equal,
4747
assert_raises_rpc_error,
4848
)
49+
from test_framework.wallet import MiniWallet
4950

5051

5152
class MempoolPersistTest(BitcoinTestFramework):
5253
def set_test_params(self):
5354
self.num_nodes = 3
5455
self.extra_args = [[], ["-persistmempool=0"], []]
5556

56-
def skip_test_if_missing_module(self):
57-
self.skip_if_no_wallet()
58-
5957
def run_test(self):
58+
self.mini_wallet = MiniWallet(self.nodes[2])
59+
self.mini_wallet.rescan_utxos()
60+
if self.is_sqlite_compiled():
61+
self.nodes[2].createwallet(
62+
wallet_name="watch",
63+
descriptors=True,
64+
disable_private_keys=True,
65+
load_on_startup=False,
66+
)
67+
wallet_watch = self.nodes[2].get_wallet_rpc("watch")
68+
assert_equal([{'success': True}], wallet_watch.importdescriptors([{'desc': self.mini_wallet.get_descriptor(), 'timestamp': 0}]))
69+
6070
self.log.debug("Send 5 transactions from node2 (to its own address)")
6171
tx_creation_time_lower = int(time.time())
6272
for _ in range(5):
63-
last_txid = self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10"))
64-
node2_balance = self.nodes[2].getbalance()
73+
last_txid = self.mini_wallet.send_self_transfer(from_node=self.nodes[2])["txid"]
74+
if self.is_sqlite_compiled():
75+
self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet
76+
node2_balance = wallet_watch.getbalance()
6577
self.sync_all()
6678
tx_creation_time_higher = int(time.time())
6779

@@ -90,7 +102,7 @@ def run_test(self):
90102
self.disconnect_nodes(0, 1)
91103
assert(len(self.nodes[0].getpeerinfo()) == 0)
92104
assert(len(self.nodes[0].p2ps) == 0)
93-
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("12"))
105+
self.mini_wallet.send_self_transfer(from_node=self.nodes[0])
94106
self.connect_nodes(0, 2)
95107

96108
self.log.debug("Stop-start the nodes. Verify that node0 has the transactions in its mempool and node1 does not. Verify that node2 calculates its balance correctly after loading wallet transactions.")
@@ -115,13 +127,15 @@ def run_test(self):
115127
assert_equal(tx_creation_time, self.nodes[0].getmempoolentry(txid=last_txid)['time'])
116128

117129
# Verify accounting of mempool transactions after restart is correct
118-
self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet
119-
assert_equal(node2_balance, self.nodes[2].getbalance())
130+
if self.is_sqlite_compiled():
131+
self.nodes[2].loadwallet("watch")
132+
wallet_watch = self.nodes[2].get_wallet_rpc("watch")
133+
self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet
134+
assert_equal(node2_balance, wallet_watch.getbalance())
120135

121-
# start node0 with wallet disabled so wallet transactions don't get resubmitted
122136
self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
123137
self.stop_nodes()
124-
self.start_node(0, extra_args=["-persistmempool=0", "-disablewallet"])
138+
self.start_node(0, extra_args=["-persistmempool=0"])
125139
assert self.nodes[0].getmempoolinfo()["loaded"]
126140
assert_equal(len(self.nodes[0].getrawmempool()), 0)
127141

@@ -166,11 +180,10 @@ def test_persist_unbroadcast(self):
166180
# make a transaction that will remain in the unbroadcast set
167181
assert(len(node0.getpeerinfo()) == 0)
168182
assert(len(node0.p2ps) == 0)
169-
node0.sendtoaddress(self.nodes[1].getnewaddress(), Decimal("12"))
183+
self.mini_wallet.send_self_transfer(from_node=node0)
170184

171185
# shutdown, then startup with wallet disabled
172-
self.stop_nodes()
173-
self.start_node(0, extra_args=["-disablewallet"])
186+
self.restart_node(0, extra_args=["-disablewallet"])
174187

175188
# check that txn gets broadcast due to unbroadcast logic
176189
conn = node0.add_p2p_connection(P2PTxInvStore())

0 commit comments

Comments
 (0)