Skip to content

Commit 3c8fa6c

Browse files
alfonsoromanzPiRK
authored andcommitted
test, assumeutxo: import descriptors during background sync
bitcoin/bitcoin@595edee
1 parent fb3d47f commit 3c8fa6c

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

test/functional/wallet_assumeutxo.py

Lines changed: 35 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.cashaddr import decode
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, cashaddr_to_scriptpubkey
23+
from test_framework.wallet_util import get_generate_key
2324

2425
START_HEIGHT = 199
2526
SNAPSHOT_BASE_HEIGHT = 299
@@ -45,6 +46,13 @@ def setup_network(self):
4546
self.add_nodes(3)
4647
self.start_nodes(extra_args=self.extra_args)
4748

49+
def import_descriptor(self, node, wallet_name, key, timestamp):
50+
import_request = [{"desc": descsum_create("pkh(" + key.pubkey + ")"),
51+
"timestamp": timestamp,
52+
"label": "Descriptor import test"}]
53+
wrpc = node.get_wallet_rpc(wallet_name)
54+
return wrpc.importdescriptors(import_request)
55+
4856
def run_test(self):
4957
"""
5058
Bring up two (disconnected) nodes, mine some new blocks on the first,
@@ -153,6 +161,26 @@ def run_test(self):
153161
self.log.info("Backup from before the snapshot height can't be loaded during background sync")
154162
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")
155163

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

158186
self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)
@@ -202,6 +230,12 @@ def run_test(self):
202230
self.wait_until(lambda: len(n2.getchainstates()['chainstates']) == 1)
203231
ensure_for(duration=1, f=lambda: (n2.getbalance() == 34_000_000))
204232

233+
if self.options.descriptors:
234+
self.log.info("Ensuring descriptors can be loaded after background sync")
235+
n1.loadwallet(wallet_name)
236+
result = self.import_descriptor(n1, wallet_name, key, timestamp)
237+
assert_equal(result[0]['success'], True)
238+
205239

206240
if __name__ == '__main__':
207241
AssumeutxoTest().main()

0 commit comments

Comments
 (0)