Skip to content

Commit f20fe33

Browse files
committed
test: Add basic balance coverage to wallet_assumeutxo.py
1 parent 037b101 commit f20fe33

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

test/functional/wallet_assumeutxo.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
- TODO: test loading a wallet (backup) on a pruned node
1212
1313
"""
14+
from test_framework.address import address_to_scriptpubkey
1415
from test_framework.test_framework import BitcoinTestFramework
16+
from test_framework.messages import COIN
1517
from test_framework.util import (
1618
assert_equal,
1719
assert_raises_rpc_error,
@@ -65,10 +67,12 @@ def run_test(self):
6567
# Create a wallet that we will create a backup for later (at snapshot height)
6668
n0.createwallet('w')
6769
w = n0.get_wallet_rpc("w")
70+
w_address = w.getnewaddress()
6871

6972
# Create another wallet and backup now (before snapshot height)
7073
n0.createwallet('w2')
7174
w2 = n0.get_wallet_rpc("w2")
75+
w2_address = w2.getnewaddress()
7276
w2.backupwallet("backup_w2.dat")
7377

7478
# Generate a series of blocks that `n0` will have in the snapshot,
@@ -111,7 +115,13 @@ def run_test(self):
111115

112116
# Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
113117
# will allow us to test n1's sync-to-tip on top of a snapshot.
114-
self.generate(n0, nblocks=100, sync_fun=self.no_op)
118+
w_skp = address_to_scriptpubkey(w_address)
119+
w2_skp = address_to_scriptpubkey(w2_address)
120+
for i in range(100):
121+
if i % 3 == 0:
122+
self.mini_wallet.send_to(from_node=n0, scriptPubKey=w_skp, amount=1 * COIN)
123+
self.mini_wallet.send_to(from_node=n0, scriptPubKey=w2_skp, amount=10 * COIN)
124+
self.generate(n0, nblocks=1, sync_fun=self.no_op)
115125

116126
assert_equal(n0.getblockcount(), FINAL_HEIGHT)
117127
assert_equal(n1.getblockcount(), START_HEIGHT)
@@ -136,6 +146,8 @@ def run_test(self):
136146

137147
self.log.info("Backup from the snapshot height can be loaded during background sync")
138148
n1.restorewallet("w", "backup_w.dat")
149+
# Balance of w wallet is still still 0 because n1 has not synced yet
150+
assert_equal(n1.getbalance(), 0)
139151

140152
self.log.info("Backup from before the snapshot height can't be loaded during background sync")
141153
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 @@ def run_test(self):
172184

173185
self.log.info("Ensuring wallet can be restored from a backup that was created before the snapshot height")
174186
n1.restorewallet("w2", "backup_w2.dat")
187+
# Check balance of w2 wallet
188+
assert_equal(n1.getbalance(), 340)
189+
190+
# Check balance of w wallet after node is synced
191+
n1.loadwallet("w")
192+
w = n1.get_wallet_rpc("w")
193+
assert_equal(w.getbalance(), 34)
175194

176195

177196
if __name__ == '__main__':

0 commit comments

Comments
 (0)