test: Add basic balance coverage to wallet_assumeutxo.py

pull/30678/head
Fabian Jahr 2 months ago
parent 037b101e80
commit f20fe33e94
No known key found for this signature in database
GPG Key ID: F13D1E9D890798CD

@ -11,7 +11,9 @@ See feature_assumeutxo.py for background.
- TODO: test loading a wallet (backup) on a pruned node - TODO: test loading a wallet (backup) on a pruned node
""" """
from test_framework.address import address_to_scriptpubkey
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.messages import COIN
from test_framework.util import ( from test_framework.util import (
assert_equal, assert_equal,
assert_raises_rpc_error, assert_raises_rpc_error,
@ -65,10 +67,12 @@ class AssumeutxoTest(BitcoinTestFramework):
# Create a wallet that we will create a backup for later (at snapshot height) # Create a wallet that we will create a backup for later (at snapshot height)
n0.createwallet('w') n0.createwallet('w')
w = n0.get_wallet_rpc("w") w = n0.get_wallet_rpc("w")
w_address = w.getnewaddress()
# Create another wallet and backup now (before snapshot height) # Create another wallet and backup now (before snapshot height)
n0.createwallet('w2') n0.createwallet('w2')
w2 = n0.get_wallet_rpc("w2") w2 = n0.get_wallet_rpc("w2")
w2_address = w2.getnewaddress()
w2.backupwallet("backup_w2.dat") w2.backupwallet("backup_w2.dat")
# Generate a series of blocks that `n0` will have in the snapshot, # Generate a series of blocks that `n0` will have in the snapshot,
@ -111,7 +115,13 @@ class AssumeutxoTest(BitcoinTestFramework):
# Mine more blocks on top of the snapshot that n1 hasn't yet seen. This # Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
# will allow us to test n1's sync-to-tip on top of a snapshot. # will allow us to test n1's sync-to-tip on top of a snapshot.
self.generate(n0, nblocks=100, sync_fun=self.no_op) w_skp = address_to_scriptpubkey(w_address)
w2_skp = address_to_scriptpubkey(w2_address)
for i in range(100):
if i % 3 == 0:
self.mini_wallet.send_to(from_node=n0, scriptPubKey=w_skp, amount=1 * COIN)
self.mini_wallet.send_to(from_node=n0, scriptPubKey=w2_skp, amount=10 * COIN)
self.generate(n0, nblocks=1, sync_fun=self.no_op)
assert_equal(n0.getblockcount(), FINAL_HEIGHT) assert_equal(n0.getblockcount(), FINAL_HEIGHT)
assert_equal(n1.getblockcount(), START_HEIGHT) assert_equal(n1.getblockcount(), START_HEIGHT)
@ -136,6 +146,8 @@ class AssumeutxoTest(BitcoinTestFramework):
self.log.info("Backup from the snapshot height can be loaded during background sync") self.log.info("Backup from the snapshot height can be loaded during background sync")
n1.restorewallet("w", "backup_w.dat") n1.restorewallet("w", "backup_w.dat")
# Balance of w wallet is still still 0 because n1 has not synced yet
assert_equal(n1.getbalance(), 0)
self.log.info("Backup from before the snapshot height can't be loaded during background sync") self.log.info("Backup from before the snapshot height can't be loaded during background sync")
assert_raises_rpc_error(-4, "Wallet loading failed. Error loading wallet. Wallet requires blocks to be downloaded, and software does not currently support loading wallets while blocks are being downloaded out of order when using assumeutxo snapshots. Wallet should be able to load successfully after node sync reaches height 299", n1.restorewallet, "w2", "backup_w2.dat") assert_raises_rpc_error(-4, "Wallet loading failed. Error loading wallet. Wallet requires blocks to be downloaded, and software does not currently support loading wallets while blocks are being downloaded out of order when using assumeutxo snapshots. Wallet should be able to load successfully after node sync reaches height 299", n1.restorewallet, "w2", "backup_w2.dat")
@ -172,6 +184,13 @@ class AssumeutxoTest(BitcoinTestFramework):
self.log.info("Ensuring wallet can be restored from a backup that was created before the snapshot height") self.log.info("Ensuring wallet can be restored from a backup that was created before the snapshot height")
n1.restorewallet("w2", "backup_w2.dat") n1.restorewallet("w2", "backup_w2.dat")
# Check balance of w2 wallet
assert_equal(n1.getbalance(), 340)
# Check balance of w wallet after node is synced
n1.loadwallet("w")
w = n1.get_wallet_rpc("w")
assert_equal(w.getbalance(), 34)
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save