Skip to content

Commit 595edee

Browse files
alfonsoromanzfjahr
authored andcommitted
test, assumeutxo: import descriptors during background sync
1 parent d73ae60 commit 595edee

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/functional/wallet_assumeutxo.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
88
## Possible test improvements
99
10-
- TODO: test import descriptors while background sync is in progress
1110
- TODO: test loading a wallet (backup) on a pruned node
1211
1312
"""
1413
from test_framework.address import address_to_scriptpubkey
14+
from test_framework.descriptors import descsum_create
1515
from test_framework.test_framework import BitcoinTestFramework
1616
from test_framework.messages import COIN
1717
from test_framework.util import (
@@ -20,6 +20,7 @@
2020
ensure_for,
2121
)
2222
from test_framework.wallet import MiniWallet
23+
from test_framework.wallet_util import get_generate_key
2324

2425
START_HEIGHT = 199
2526
SNAPSHOT_BASE_HEIGHT = 299
@@ -49,6 +50,13 @@ def setup_network(self):
4950
self.add_nodes(3)
5051
self.start_nodes(extra_args=self.extra_args)
5152

53+
def import_descriptor(self, node, wallet_name, key, timestamp):
54+
import_request = [{"desc": descsum_create("pkh(" + key.pubkey + ")"),
55+
"timestamp": timestamp,
56+
"label": "Descriptor import test"}]
57+
wrpc = node.get_wallet_rpc(wallet_name)
58+
return wrpc.importdescriptors(import_request)
59+
5260
def run_test(self):
5361
"""
5462
Bring up two (disconnected) nodes, mine some new blocks on the first,
@@ -157,6 +165,17 @@ def run_test(self):
157165
self.log.info("Backup from before the snapshot height can't be loaded during background sync")
158166
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")
159167

168+
self.log.info("Test loading descriptors during background sync")
169+
wallet_name = "w1"
170+
n1.createwallet(wallet_name, disable_private_keys=True)
171+
key = get_generate_key()
172+
time = n1.getblockchaininfo()['time']
173+
timestamp = 0
174+
expected_error_message = f"Rescan failed for descriptor with timestamp {timestamp}. There was an error reading a block from time {time}, which is after or within 7200 seconds of key creation, and could contain transactions pertaining to the desc. As a result, transactions and coins using this desc may not appear in the wallet. This error is likely caused by an in-progress assumeutxo background sync. Check logs or getchainstates RPC for assumeutxo background sync progress and try again later."
175+
result = self.import_descriptor(n1, wallet_name, key, timestamp)
176+
assert_equal(result[0]['error']['code'], -1)
177+
assert_equal(result[0]['error']['message'], expected_error_message)
178+
160179
PAUSE_HEIGHT = FINAL_HEIGHT - 40
161180

162181
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)
@@ -204,6 +223,11 @@ def run_test(self):
204223
self.wait_until(lambda: len(n2.getchainstates()['chainstates']) == 1)
205224
ensure_for(duration=1, f=lambda: (n2.getbalance() == 34))
206225

226+
self.log.info("Ensuring descriptors can be loaded after background sync")
227+
n1.loadwallet(wallet_name)
228+
result = self.import_descriptor(n1, wallet_name, key, timestamp)
229+
assert_equal(result[0]['success'], True)
230+
207231

208232
if __name__ == '__main__':
209233
AssumeutxoTest(__file__).main()

0 commit comments

Comments
 (0)