mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 09:15:04 +02:00
Merge bitcoin/bitcoin#27279: Add "warnings", deprecate "warning" in {create,load,unload,restore}wallet
7ccdd741fetest: fix importmulti/importdescriptors assertion (Jon Atack)19d888ce40rpc: move WALLET_FLAG_CAVEATS to the compilation unit of its caller (Jon Atack)01df011ca2doc: release note for wallet RPCs "warning" field deprecation (Jon Atack)9ea8b3739atest: createwallet "warning" field deprecation test (Jon Atack)645d7f75acrpc: deprecate "warning" field in {create,load,unload,restore}wallet (Jon Atack)2f4a926e95test: add test coverage for "warnings" field in createwallet (Jon Atack)4a1e479ca6rpc: add "warnings" field to RPCs {create,load,unload,restore}wallet (Jon Atack)079d8cdda8rpc: extract wallet "warnings" fields to a util helper (Jon Atack)f73782a903doc: fix/improve warning helps in {create,load,unload,restore}wallet (Jon Atack) Pull request description: Based on discussion and concept ACKed in #27138, add a `warnings` field to RPCs createwallet, loadwallet, unloadwallet, and restorewallet as a JSON array of strings to replace the `warning` string field in these 4 RPCs. The idea is to more gracefully handle multiple warning messages and for consistency with other wallet RPCs. Then, deprecate the latter fields, which represent all the remaining RPC `warning` fields. The first commitf73782a903implements https://github.com/bitcoin/bitcoin/pull/27138#issuecomment-1474789198 as an alternative to #27138. One of those two could potentially be backported to our currently supported releases. ACKs for top commit: achow101: ACK7ccdd741fe1440000bytes: utACK7ccdd741fevasild: ACK7ccdd741fepinheadmz: re-ACK7ccdd741feTree-SHA512: 314e0a4c41fa383d95e2817bfacf359d449e460529d235c3eb902851e2f4eacbabe646d9a5a4beabc4964cdfabf6397ed8301366a58d344a2f787f83b75e9d64
This commit is contained in:
@@ -265,7 +265,12 @@ class BackwardsCompatibilityTest(BitcoinTestFramework):
|
||||
)
|
||||
load_res = node_master.loadwallet("u1_v16")
|
||||
# Make sure this wallet opens without warnings. See https://github.com/bitcoin/bitcoin/pull/19054
|
||||
assert_equal(load_res['warning'], '')
|
||||
if int(node_master.getnetworkinfo()["version"]) >= 249900:
|
||||
# loadwallet#warnings (added in v25) -- only present if there is a warning
|
||||
assert "warnings" not in load_res
|
||||
else:
|
||||
# loadwallet#warning (deprecated in v25) -- always present, but empty string if no warning
|
||||
assert_equal(load_res["warning"], '')
|
||||
wallet = node_master.get_wallet_rpc("u1_v16")
|
||||
info = wallet.getaddressinfo(v16_addr)
|
||||
descriptor = f"wpkh([{info['hdmasterfingerprint']}{hdkeypath[1:]}]{v16_pubkey})"
|
||||
|
||||
@@ -15,12 +15,17 @@ from test_framework.util import (
|
||||
)
|
||||
from test_framework.wallet_util import bytes_to_wif, generate_wif_key
|
||||
|
||||
EMPTY_PASSPHRASE_MSG = "Empty string given as passphrase, wallet will not be encrypted."
|
||||
LEGACY_WALLET_MSG = "Wallet created successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future."
|
||||
|
||||
|
||||
class CreateWalletTest(BitcoinTestFramework):
|
||||
def add_options(self, parser):
|
||||
self.add_wallet_options(parser)
|
||||
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [["-deprecatedrpc=walletwarningfield"]]
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
@@ -55,7 +60,7 @@ class CreateWalletTest(BitcoinTestFramework):
|
||||
else:
|
||||
result = w1.importmulti([{'scriptPubKey': {'address': key_to_p2wpkh(eckey.get_pubkey().get_bytes())}, 'timestamp': 'now', 'keys': [privkey]}])
|
||||
assert not result[0]['success']
|
||||
assert 'warning' not in result[0]
|
||||
assert 'warnings' not in result[0]
|
||||
assert_equal(result[0]['error']['code'], -4)
|
||||
assert_equal(result[0]['error']['message'], 'Cannot import private keys to a wallet with private keys disabled')
|
||||
|
||||
@@ -159,7 +164,9 @@ class CreateWalletTest(BitcoinTestFramework):
|
||||
assert_equal(walletinfo['keypoolsize_hd_internal'], keys)
|
||||
# Allow empty passphrase, but there should be a warning
|
||||
resp = self.nodes[0].createwallet(wallet_name='w7', disable_private_keys=False, blank=False, passphrase='')
|
||||
assert 'Empty string given as passphrase, wallet will not be encrypted.' in resp['warning']
|
||||
assert_equal(resp["warning"], EMPTY_PASSPHRASE_MSG if self.options.descriptors else f"{EMPTY_PASSPHRASE_MSG}\n{LEGACY_WALLET_MSG}")
|
||||
assert_equal(resp["warnings"], [EMPTY_PASSPHRASE_MSG] if self.options.descriptors else [EMPTY_PASSPHRASE_MSG, LEGACY_WALLET_MSG])
|
||||
|
||||
w7 = node.get_wallet_rpc('w7')
|
||||
assert_raises_rpc_error(-15, 'Error: running with an unencrypted wallet, but walletpassphrase was called.', w7.walletpassphrase, '', 60)
|
||||
|
||||
@@ -174,8 +181,24 @@ class CreateWalletTest(BitcoinTestFramework):
|
||||
|
||||
if self.is_bdb_compiled():
|
||||
self.log.info("Test legacy wallet deprecation")
|
||||
res = self.nodes[0].createwallet(wallet_name="legacy_w0", descriptors=False, passphrase=None)
|
||||
assert_equal(res["warning"], "Wallet created successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future.")
|
||||
result = self.nodes[0].createwallet(wallet_name="legacy_w0", descriptors=False, passphrase=None)
|
||||
assert_equal(result, {
|
||||
"name": "legacy_w0",
|
||||
"warning": LEGACY_WALLET_MSG,
|
||||
"warnings": [LEGACY_WALLET_MSG],
|
||||
})
|
||||
result = self.nodes[0].createwallet(wallet_name="legacy_w1", descriptors=False, passphrase="")
|
||||
assert_equal(result, {
|
||||
"name": "legacy_w1",
|
||||
"warning": f"{EMPTY_PASSPHRASE_MSG}\n{LEGACY_WALLET_MSG}",
|
||||
"warnings": [EMPTY_PASSPHRASE_MSG, LEGACY_WALLET_MSG],
|
||||
})
|
||||
|
||||
self.log.info('Test "warning" field deprecation, i.e. not returned without -deprecatedrpc=walletwarningfield')
|
||||
self.restart_node(0, extra_args=[])
|
||||
result = self.nodes[0].createwallet(wallet_name="w7_again", disable_private_keys=False, blank=False, passphrase="")
|
||||
assert "warning" not in result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
CreateWalletTest().main()
|
||||
|
||||
Reference in New Issue
Block a user