Skip to content

Commit 2f4a926

Browse files
committed
test: add test coverage for "warnings" field in createwallet
and clarify the "warning" field behavior.
1 parent 4a1e479 commit 2f4a926

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/functional/wallet_createwallet.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
)
1616
from test_framework.wallet_util import bytes_to_wif, generate_wif_key
1717

18+
EMPTY_PASSPHRASE_MSG = "Empty string given as passphrase, wallet will not be encrypted."
19+
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."
20+
21+
1822
class CreateWalletTest(BitcoinTestFramework):
1923
def add_options(self, parser):
2024
self.add_wallet_options(parser)
@@ -159,7 +163,9 @@ def run_test(self):
159163
assert_equal(walletinfo['keypoolsize_hd_internal'], keys)
160164
# Allow empty passphrase, but there should be a warning
161165
resp = self.nodes[0].createwallet(wallet_name='w7', disable_private_keys=False, blank=False, passphrase='')
162-
assert 'Empty string given as passphrase, wallet will not be encrypted.' in resp['warning']
166+
assert_equal(resp["warning"], EMPTY_PASSPHRASE_MSG if self.options.descriptors else f"{EMPTY_PASSPHRASE_MSG}\n{LEGACY_WALLET_MSG}")
167+
assert_equal(resp["warnings"], [EMPTY_PASSPHRASE_MSG] if self.options.descriptors else [EMPTY_PASSPHRASE_MSG, LEGACY_WALLET_MSG])
168+
163169
w7 = node.get_wallet_rpc('w7')
164170
assert_raises_rpc_error(-15, 'Error: running with an unencrypted wallet, but walletpassphrase was called.', w7.walletpassphrase, '', 60)
165171

@@ -174,8 +180,19 @@ def run_test(self):
174180

175181
if self.is_bdb_compiled():
176182
self.log.info("Test legacy wallet deprecation")
177-
res = self.nodes[0].createwallet(wallet_name="legacy_w0", descriptors=False, passphrase=None)
178-
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.")
183+
result = self.nodes[0].createwallet(wallet_name="legacy_w0", descriptors=False, passphrase=None)
184+
assert_equal(result, {
185+
"name": "legacy_w0",
186+
"warning": LEGACY_WALLET_MSG,
187+
"warnings": [LEGACY_WALLET_MSG],
188+
})
189+
result = self.nodes[0].createwallet(wallet_name="legacy_w1", descriptors=False, passphrase="")
190+
assert_equal(result, {
191+
"name": "legacy_w1",
192+
"warning": f"{EMPTY_PASSPHRASE_MSG}\n{LEGACY_WALLET_MSG}",
193+
"warnings": [EMPTY_PASSPHRASE_MSG, LEGACY_WALLET_MSG],
194+
})
195+
179196

180197
if __name__ == '__main__':
181198
CreateWalletTest().main()

0 commit comments

Comments
 (0)