|
7 | 7 |
|
8 | 8 | ## Possible test improvements
|
9 | 9 |
|
10 |
| -- TODO: test import descriptors while background sync is in progress |
11 | 10 | - TODO: test loading a wallet (backup) on a pruned node
|
12 | 11 |
|
13 | 12 | """
|
14 | 13 | from test_framework.address import address_to_scriptpubkey
|
| 14 | +from test_framework.descriptors import descsum_create |
15 | 15 | from test_framework.test_framework import BitcoinTestFramework
|
16 | 16 | from test_framework.messages import COIN
|
17 | 17 | from test_framework.util import (
|
|
20 | 20 | ensure_for,
|
21 | 21 | )
|
22 | 22 | from test_framework.wallet import MiniWallet
|
| 23 | +from test_framework.wallet_util import get_generate_key |
23 | 24 |
|
24 | 25 | START_HEIGHT = 199
|
25 | 26 | SNAPSHOT_BASE_HEIGHT = 299
|
@@ -49,6 +50,13 @@ def setup_network(self):
|
49 | 50 | self.add_nodes(3)
|
50 | 51 | self.start_nodes(extra_args=self.extra_args)
|
51 | 52 |
|
| 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 | + |
52 | 60 | def run_test(self):
|
53 | 61 | """
|
54 | 62 | Bring up two (disconnected) nodes, mine some new blocks on the first,
|
@@ -157,6 +165,21 @@ def run_test(self):
|
157 | 165 | self.log.info("Backup from before the snapshot height can't be loaded during background sync")
|
158 | 166 | 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")
|
159 | 167 |
|
| 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 | + |
| 179 | + self.log.info("Test that rescanning blocks from before the snapshot fails when blocks are not available from the background sync yet") |
| 180 | + w1 = n1.get_wallet_rpc(wallet_name) |
| 181 | + assert_raises_rpc_error(-1, "Failed to rescan unavailable blocks likely due to an in-progress assumeutxo background sync. Check logs or getchainstates RPC for assumeutxo background sync progress and try again later.", w1.rescanblockchain, 100) |
| 182 | + |
160 | 183 | PAUSE_HEIGHT = FINAL_HEIGHT - 40
|
161 | 184 |
|
162 | 185 | self.log.info("Restarting node to stop at height %d", PAUSE_HEIGHT)
|
@@ -204,6 +227,11 @@ def run_test(self):
|
204 | 227 | self.wait_until(lambda: len(n2.getchainstates()['chainstates']) == 1)
|
205 | 228 | ensure_for(duration=1, f=lambda: (n2.getbalance() == 34))
|
206 | 229 |
|
| 230 | + self.log.info("Ensuring descriptors can be loaded after background sync") |
| 231 | + n1.loadwallet(wallet_name) |
| 232 | + result = self.import_descriptor(n1, wallet_name, key, timestamp) |
| 233 | + assert_equal(result[0]['success'], True) |
| 234 | + |
207 | 235 |
|
208 | 236 | if __name__ == '__main__':
|
209 | 237 | AssumeutxoTest(__file__).main()
|
0 commit comments