0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

test: Use MiniWallet in mempool_persist

This commit is contained in:
MarcoFalke 2021-09-20 15:25:49 +02:00
parent faca688a85
commit fa32cb2467
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -46,6 +46,7 @@ from test_framework.util import (
assert_greater_than_or_equal, assert_greater_than_or_equal,
assert_raises_rpc_error, assert_raises_rpc_error,
) )
from test_framework.wallet import MiniWallet
class MempoolPersistTest(BitcoinTestFramework): class MempoolPersistTest(BitcoinTestFramework):
@ -53,15 +54,26 @@ class MempoolPersistTest(BitcoinTestFramework):
self.num_nodes = 3 self.num_nodes = 3
self.extra_args = [[], ["-persistmempool=0"], []] self.extra_args = [[], ["-persistmempool=0"], []]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
self.mini_wallet = MiniWallet(self.nodes[2])
self.mini_wallet.rescan_utxos()
if self.is_sqlite_compiled():
self.nodes[2].createwallet(
wallet_name="watch",
descriptors=True,
disable_private_keys=True,
load_on_startup=False,
)
wallet_watch = self.nodes[2].get_wallet_rpc("watch")
assert_equal([{'success': True}], wallet_watch.importdescriptors([{'desc': self.mini_wallet.get_descriptor(), 'timestamp': 0}]))
self.log.debug("Send 5 transactions from node2 (to its own address)") self.log.debug("Send 5 transactions from node2 (to its own address)")
tx_creation_time_lower = int(time.time()) tx_creation_time_lower = int(time.time())
for _ in range(5): for _ in range(5):
last_txid = self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10")) last_txid = self.mini_wallet.send_self_transfer(from_node=self.nodes[2])["txid"]
node2_balance = self.nodes[2].getbalance() if self.is_sqlite_compiled():
self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet
node2_balance = wallet_watch.getbalance()
self.sync_all() self.sync_all()
tx_creation_time_higher = int(time.time()) tx_creation_time_higher = int(time.time())
@ -90,7 +102,7 @@ class MempoolPersistTest(BitcoinTestFramework):
self.disconnect_nodes(0, 1) self.disconnect_nodes(0, 1)
assert(len(self.nodes[0].getpeerinfo()) == 0) assert(len(self.nodes[0].getpeerinfo()) == 0)
assert(len(self.nodes[0].p2ps) == 0) assert(len(self.nodes[0].p2ps) == 0)
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("12")) self.mini_wallet.send_self_transfer(from_node=self.nodes[0])
self.connect_nodes(0, 2) self.connect_nodes(0, 2)
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.") 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 @@ class MempoolPersistTest(BitcoinTestFramework):
assert_equal(tx_creation_time, self.nodes[0].getmempoolentry(txid=last_txid)['time']) assert_equal(tx_creation_time, self.nodes[0].getmempoolentry(txid=last_txid)['time'])
# Verify accounting of mempool transactions after restart is correct # Verify accounting of mempool transactions after restart is correct
self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet if self.is_sqlite_compiled():
assert_equal(node2_balance, self.nodes[2].getbalance()) self.nodes[2].loadwallet("watch")
wallet_watch = self.nodes[2].get_wallet_rpc("watch")
self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet
assert_equal(node2_balance, wallet_watch.getbalance())
# start node0 with wallet disabled so wallet transactions don't get resubmitted
self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.") self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
self.stop_nodes() self.stop_nodes()
self.start_node(0, extra_args=["-persistmempool=0", "-disablewallet"]) self.start_node(0, extra_args=["-persistmempool=0"])
assert self.nodes[0].getmempoolinfo()["loaded"] assert self.nodes[0].getmempoolinfo()["loaded"]
assert_equal(len(self.nodes[0].getrawmempool()), 0) assert_equal(len(self.nodes[0].getrawmempool()), 0)
@ -166,11 +180,10 @@ class MempoolPersistTest(BitcoinTestFramework):
# make a transaction that will remain in the unbroadcast set # make a transaction that will remain in the unbroadcast set
assert(len(node0.getpeerinfo()) == 0) assert(len(node0.getpeerinfo()) == 0)
assert(len(node0.p2ps) == 0) assert(len(node0.p2ps) == 0)
node0.sendtoaddress(self.nodes[1].getnewaddress(), Decimal("12")) self.mini_wallet.send_self_transfer(from_node=node0)
# shutdown, then startup with wallet disabled # shutdown, then startup with wallet disabled
self.stop_nodes() self.restart_node(0, extra_args=["-disablewallet"])
self.start_node(0, extra_args=["-disablewallet"])
# check that txn gets broadcast due to unbroadcast logic # check that txn gets broadcast due to unbroadcast logic
conn = node0.add_p2p_connection(P2PTxInvStore()) conn = node0.add_p2p_connection(P2PTxInvStore())