Skip to content

Commit d842fea

Browse files
committed
test: extra tests for upgradetohd with & without wallet encryption
1 parent 0d41057 commit d842fea

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

test/functional/wallet_mnemonicbits.py

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
assert_equal,
1111
)
1212

13+
custom_mnemonic = "similar behave slot swim scissors throw planet view ghost laugh drift calm"
14+
# this address belongs to custom mnemonic with no passphrase
15+
custom_address_1 = "yLpq97zZUsFQ2rdMqhcPKkYT36MoPK4Hob"
16+
# this address belongs to custom mnemonic with passphrase "custom-passphrase"
17+
custom_address_2 = "yYBPeZQcqgQHu9dxA5pKBWtYbK2hwfFHxf"
18+
19+
1320
class WalletMnemonicbitsTest(BitcoinTestFramework):
1421
def set_test_params(self):
1522
self.setup_clean_chain = True
@@ -97,35 +104,55 @@ def run_test(self):
97104
assert_equal(len(self.get_mnemonic(self.nodes[0].get_wallet_rpc("wallet_224")).split()), 21) # 21 words
98105
assert_equal(len(self.get_mnemonic(self.nodes[0].get_wallet_rpc("wallet_256")).split()), 24) # 24 words
99106

100-
self.test_upgradetohd_custom()
101107

102-
def test_upgradetohd_custom(self):
108+
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
109+
110+
self.nodes[0].get_wallet_rpc(self.default_wallet_name).sendtoaddress(custom_address_1, 11)
111+
self.nodes[0].get_wallet_rpc(self.default_wallet_name).sendtoaddress(custom_address_2, 12)
112+
self.generate(self.nodes[0], 1)
113+
114+
103115
self.log.info("Test upgradetohd with user defined mnemonic")
104-
wname_1a = "w-custom-1a"
105-
wname_1b = "w-custom-1b"
106-
wname_2 = "w-custom-2"
116+
self.test_upgradetohd_custom(False, False)
107117

118+
self.log.info("Test upgradetohd with user defined mnemonic, encrypt wallet after creation")
119+
self.test_upgradetohd_custom(True, False)
120+
121+
self.log.info("Test upgradetohd with user defined mnemonic, encrypt wallet after upgradetohd")
122+
self.test_upgradetohd_custom(False, True)
123+
124+
def test_upgradetohd_custom(self, to_encrypt_1, to_encrypt_2):
125+
wname_1a = f"w-custom-1a-{to_encrypt_1}-{to_encrypt_2}"
126+
wname_1b = f"w-custom-1b-{to_encrypt_1}-{to_encrypt_2}"
127+
wname_2 = f"w-custom-2-{to_encrypt_1}-{to_encrypt_2}"
108128
wnames = [wname_1a, wname_1b, wname_2]
129+
109130
for wname in wnames:
110131
self.nodes[0].createwallet(wname, blank=True)
132+
if to_encrypt_1:
133+
self.nodes[0].get_wallet_rpc(wname).encryptwallet("123")
134+
self.nodes[0].get_wallet_rpc(wname).walletpassphrase("123", 100)
135+
136+
if to_encrypt_1:
137+
self.nodes[0].get_wallet_rpc(wname_1a).upgradetohd(custom_mnemonic, "", "123")
138+
self.nodes[0].get_wallet_rpc(wname_1b).upgradetohd(custom_mnemonic, "", "123")
139+
self.nodes[0].get_wallet_rpc(wname_2).upgradetohd(custom_mnemonic, "custom-passphrase", "123")
140+
else:
141+
self.nodes[0].get_wallet_rpc(wname_1a).upgradetohd(custom_mnemonic)
142+
self.nodes[0].get_wallet_rpc(wname_1b).upgradetohd(custom_mnemonic, "")
143+
self.nodes[0].get_wallet_rpc(wname_2).upgradetohd(custom_mnemonic, "custom-passphrase")
111144

112-
custom_mnemonic = "similar behave slot swim scissors throw planet view ghost laugh drift calm"
113-
# this address belongs to custom mnemonic with no passphrase
114-
custom_address_1 = "yLpq97zZUsFQ2rdMqhcPKkYT36MoPK4Hob"
115-
# this address belongs to custom mnemonic with passphrase "custom-passphrase"
116-
custom_address_2 = "yYBPeZQcqgQHu9dxA5pKBWtYbK2hwfFHxf"
117145

118-
self.nodes[0].get_wallet_rpc(wname_1a).upgradetohd(custom_mnemonic)
119-
self.nodes[0].get_wallet_rpc(wname_1b).upgradetohd(custom_mnemonic, "")
120-
self.nodes[0].get_wallet_rpc(wname_2).upgradetohd(custom_mnemonic, "custom-passphrase")
121-
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
146+
if to_encrypt_2:
147+
for wname in wnames:
148+
self.nodes[0].get_wallet_rpc(wname).encryptwallet("123")
149+
self.nodes[0].get_wallet_rpc(wname).walletpassphrase("123", 100)
122150

123-
self.nodes[0].get_wallet_rpc(self.default_wallet_name).sendtoaddress(custom_address_1, 11)
124-
self.nodes[0].get_wallet_rpc(self.default_wallet_name).sendtoaddress(custom_address_2, 12)
125-
self.generate(self.nodes[0], 1)
126151
self.restart_node(0)
127152
for wname in wnames:
128153
self.nodes[0].loadwallet(wname)
154+
if to_encrypt_1 or to_encrypt_2:
155+
self.nodes[0].get_wallet_rpc(wname).walletpassphrase("123", 100)
129156

130157
assert_equal(11, self.nodes[0].get_wallet_rpc(wname_1a).getbalance())
131158
assert_equal(11, self.nodes[0].get_wallet_rpc(wname_1b).getbalance())

0 commit comments

Comments
 (0)