Update test to verify rewind behavior.

This commit is contained in:
Kris Nuttycombe 2022-04-04 12:50:51 -06:00
parent 344aef435d
commit 5b7370c55e
1 changed files with 47 additions and 3 deletions

View File

@ -6,6 +6,8 @@
import os
import os.path
from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
NU5_BRANCH_ID,
@ -78,6 +80,15 @@ class OrchardWalletInitTest(BitcoinTestFramework):
{'pools': {'orchard': {'valueZat': 1_0000_0000}}, 'minimum_confirmations': 1},
self.nodes[0].z_getbalanceforaccount(acct0))
# Split the network. We'll advance the state of nodes 0/1 so that after
# we re-join the network, we need to roll back more than one block after
# the wallet is restored, into a chain state that the wallet never observed.
self.split_network()
self.sync_all()
self.nodes[0].generate(2)
self.sync_all()
# Shut down the network and delete node 0's wallet
stop_nodes(self.nodes)
wait_bitcoinds()
@ -85,8 +96,8 @@ class OrchardWalletInitTest(BitcoinTestFramework):
tmpdir = self.options.tmpdir
os.remove(os.path.join(tmpdir, "node0", "regtest", "wallet.dat"))
# Restart the network split; the split here is note necessary to reproduce the
# error but it is sufficient, and we will later use the split to check the
# Restart the network, still split; the split here is note necessary to reproduce
# the error but it is sufficient, and we will later use the split to check the
# corresponding rewind.
self.setup_network(True)
@ -103,7 +114,7 @@ class OrchardWalletInitTest(BitcoinTestFramework):
# the state of the global note commitment tree.
recipients = [{"address": ua0new, "amount": 1}]
myopid = self.nodes[1].z_sendmany(ua1, recipients, 1, 0)
wait_and_assert_operationid_status(self.nodes[1], myopid)
rollback_tx = wait_and_assert_operationid_status(self.nodes[1], myopid)
self.sync_all()
self.nodes[0].generate(1)
@ -113,6 +124,39 @@ class OrchardWalletInitTest(BitcoinTestFramework):
{'pools': {'orchard': {'valueZat': 1_0000_0000}}, 'minimum_confirmations': 1},
self.nodes[0].z_getbalanceforaccount(acct0new))
# Node 2 has no progress since the network was first split, so this should roll
# everything back to the original fork point.
self.nodes[2].generate(10)
# Re-join the network
self.join_network()
assert_equal(set([rollback_tx]), set(self.nodes[1].getrawmempool()))
# Resend un-mined transactions and sync the network
self.nodes[1].resendwallettransactions()
self.sync_all()
self.nodes[0].generate(1)
self.sync_all()
assert_equal(
{'pools': {'orchard': {'valueZat': 1_0000_0000}}, 'minimum_confirmations': 1},
self.nodes[0].z_getbalanceforaccount(acct0new))
# Spend from the note that was just received
recipients = [{"address": ua1, "amount": Decimal('0.3')}]
myopid = self.nodes[0].z_sendmany(ua0new, recipients, 1, 0)
wait_and_assert_operationid_status(self.nodes[0], myopid)
self.sync_all()
self.nodes[0].generate(1)
self.sync_all()
assert_equal(
{'pools': {'orchard': {'valueZat': 8_3000_0000}}, 'minimum_confirmations': 1},
self.nodes[1].z_getbalanceforaccount(acct1))
if __name__ == '__main__':
OrchardWalletInitTest().main()