From 2f4a926e95e0379397859c3ba1b5711be5f09925 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 19 Mar 2023 10:30:51 -0700 Subject: test: add test coverage for "warnings" field in createwallet and clarify the "warning" field behavior. --- test/functional/wallet_createwallet.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/functional/wallet_createwallet.py b/test/functional/wallet_createwallet.py index 22c491441b..6e94798174 100755 --- a/test/functional/wallet_createwallet.py +++ b/test/functional/wallet_createwallet.py @@ -15,6 +15,10 @@ 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) @@ -159,7 +163,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 +180,19 @@ 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], + }) + if __name__ == '__main__': CreateWalletTest().main() -- cgit v1.2.3