44from electrum .interface import ServerAddr
55from electrum .network import NetworkParameters , ProxySettings
66from electrum .plugin import Plugins
7- from electrum .wizard import ServerConnectWizard , NewWalletWizard
7+ from electrum .wizard import ServerConnectWizard , NewWalletWizard , WizardViewState
88from electrum .daemon import Daemon
99
1010from . import ElectrumTestCase
@@ -136,6 +136,27 @@ def wizard_for(self, *, name, wallet_type):
136136
137137 return w
138138
139+ def _set_password_and_check_address (
140+ self ,
141+ * ,
142+ v : WizardViewState ,
143+ w : NewWalletWizard ,
144+ recv_addr : str ,
145+ ):
146+ d = v .wizard_data
147+ self .assertEqual ('wallet_password' , v .view )
148+
149+ d .update ({'password' : None , 'encrypt' : False })
150+ self .assertTrue (w .is_last_view (v .view , d ))
151+ v = w .resolve_next (v .view , d )
152+
153+ wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
154+ w .create_storage (wallet_path , d )
155+
156+ self .assertTrue (os .path .exists (wallet_path ))
157+ wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
158+ self .assertEqual (recv_addr , wallet .get_receiving_addresses ()[0 ])
159+
139160 async def test_create_standard_wallet_createseed (self ):
140161 w = self .wizard_for (name = 'test_standard_wallet' , wallet_type = 'standard' )
141162 v = w ._current
@@ -153,18 +174,7 @@ async def test_create_standard_wallet_createseed(self):
153174 self .assertEqual ('confirm_seed' , v .view )
154175
155176 v = w .resolve_next (v .view , d )
156- self .assertEqual ('wallet_password' , v .view )
157-
158- d .update ({'password' : None , 'encrypt' : False })
159- self .assertTrue (w .is_last_view (v .view , d ))
160- v = w .resolve_next (v .view , d )
161-
162- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
163- w .create_storage (wallet_path , d )
164-
165- self .assertTrue (os .path .exists (wallet_path ))
166- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
167- self .assertEqual ("bc1qq2tmmcngng78nllq2pvrkchcdukemtj56uyue0" , wallet .get_receiving_addresses ()[0 ])
177+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qq2tmmcngng78nllq2pvrkchcdukemtj56uyue0" )
168178
169179 async def test_create_standard_wallet_createseed_passphrase (self ):
170180 w = self .wizard_for (name = 'test_standard_wallet' , wallet_type = 'standard' )
@@ -190,18 +200,7 @@ async def test_create_standard_wallet_createseed_passphrase(self):
190200 self .assertEqual ('confirm_ext' , v .view )
191201
192202 v = w .resolve_next (v .view , d )
193- self .assertEqual ('wallet_password' , v .view )
194-
195- d .update ({'password' : None , 'encrypt' : False })
196- self .assertTrue (w .is_last_view (v .view , d ))
197- v = w .resolve_next (v .view , d )
198-
199- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
200- w .create_storage (wallet_path , d )
201-
202- self .assertTrue (os .path .exists (wallet_path ))
203- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
204- self .assertEqual ("bc1qgvx24uzdv4mapfmtlu8azty5fxdcw9ghxu4pr4" , wallet .get_receiving_addresses ()[0 ])
203+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qgvx24uzdv4mapfmtlu8azty5fxdcw9ghxu4pr4" )
205204
206205 async def test_create_standard_wallet_haveseed_electrum_oldseed (self ):
207206 w = self .wizard_for (name = 'test_standard_wallet' , wallet_type = 'standard' )
@@ -217,18 +216,7 @@ async def test_create_standard_wallet_haveseed_electrum_oldseed(self):
217216 'seed' : 'powerful random nobody notice nothing important anyway look away hidden message over' ,
218217 'seed_type' : 'old' , 'seed_extend' : False , 'seed_variant' : 'electrum' })
219218 v = w .resolve_next (v .view , d )
220- self .assertEqual ('wallet_password' , v .view )
221-
222- d .update ({'password' : None , 'encrypt' : False })
223- self .assertTrue (w .is_last_view (v .view , d ))
224- v = w .resolve_next (v .view , d )
225-
226- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
227- w .create_storage (wallet_path , d )
228-
229- self .assertTrue (os .path .exists (wallet_path ))
230- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
231- self .assertEqual ("1FJEEB8ihPMbzs2SkLmr37dHyRFzakqUmo" , wallet .get_receiving_addresses ()[0 ])
219+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "1FJEEB8ihPMbzs2SkLmr37dHyRFzakqUmo" )
232220
233221 async def test_create_standard_wallet_haveseed_electrum_oldseed_passphrase (self ):
234222 w = self .wizard_for (name = 'test_standard_wallet' , wallet_type = 'standard' )
@@ -266,18 +254,7 @@ async def test_create_standard_wallet_haveseed_electrum(self):
266254
267255 d .update ({'seed' : '9dk' , 'seed_type' : 'segwit' , 'seed_extend' : False , 'seed_variant' : 'electrum' })
268256 v = w .resolve_next (v .view , d )
269- self .assertEqual ('wallet_password' , v .view )
270-
271- d .update ({'password' : None , 'encrypt' : False })
272- self .assertTrue (w .is_last_view (v .view , d ))
273- v = w .resolve_next (v .view , d )
274-
275- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
276- w .create_storage (wallet_path , d )
277-
278- self .assertTrue (os .path .exists (wallet_path ))
279- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
280- self .assertEqual ("bc1qq2tmmcngng78nllq2pvrkchcdukemtj56uyue0" , wallet .get_receiving_addresses ()[0 ])
257+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qq2tmmcngng78nllq2pvrkchcdukemtj56uyue0" )
281258
282259 async def test_create_standard_wallet_haveseed_electrum_passphrase (self ):
283260 w = self .wizard_for (name = 'test_standard_wallet' , wallet_type = 'standard' )
@@ -295,18 +272,7 @@ async def test_create_standard_wallet_haveseed_electrum_passphrase(self):
295272
296273 d .update ({'seed_extra_words' : UNICODE_HORROR })
297274 v = w .resolve_next (v .view , d )
298- self .assertEqual ('wallet_password' , v .view )
299-
300- d .update ({'password' : None , 'encrypt' : False })
301- self .assertTrue (w .is_last_view (v .view , d ))
302- v = w .resolve_next (v .view , d )
303-
304- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
305- w .create_storage (wallet_path , d )
306-
307- self .assertTrue (os .path .exists (wallet_path ))
308- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
309- self .assertEqual ("bc1qgvx24uzdv4mapfmtlu8azty5fxdcw9ghxu4pr4" , wallet .get_receiving_addresses ()[0 ])
275+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qgvx24uzdv4mapfmtlu8azty5fxdcw9ghxu4pr4" )
310276
311277 async def test_create_standard_wallet_haveseed_bip39 (self ):
312278 w = self .wizard_for (name = 'test_standard_wallet' , wallet_type = 'standard' )
@@ -324,18 +290,7 @@ async def test_create_standard_wallet_haveseed_bip39(self):
324290
325291 d .update ({'script_type' : 'p2wpkh' , 'derivation_path' : 'm' })
326292 v = w .resolve_next (v .view , d )
327- self .assertEqual ('wallet_password' , v .view )
328-
329- d .update ({'password' : None , 'encrypt' : False })
330- self .assertTrue (w .is_last_view (v .view , d ))
331- v = w .resolve_next (v .view , d )
332-
333- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
334- w .create_storage (wallet_path , d )
335-
336- self .assertTrue (os .path .exists (wallet_path ))
337- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
338- self .assertEqual ("bc1qrjr8qn4669jgr3s34f2pyj9awhz02eyvk5eh8g" , wallet .get_receiving_addresses ()[0 ])
293+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qrjr8qn4669jgr3s34f2pyj9awhz02eyvk5eh8g" )
339294
340295 async def test_create_standard_wallet_haveseed_bip39_passphrase (self ):
341296 w = self .wizard_for (name = 'test_standard_wallet' , wallet_type = 'standard' )
@@ -357,18 +312,7 @@ async def test_create_standard_wallet_haveseed_bip39_passphrase(self):
357312
358313 d .update ({'script_type' : 'p2wpkh' , 'derivation_path' : 'm' })
359314 v = w .resolve_next (v .view , d )
360- self .assertEqual ('wallet_password' , v .view )
361-
362- d .update ({'password' : None , 'encrypt' : False })
363- self .assertTrue (w .is_last_view (v .view , d ))
364- v = w .resolve_next (v .view , d )
365-
366- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
367- w .create_storage (wallet_path , d )
368-
369- self .assertTrue (os .path .exists (wallet_path ))
370- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
371- self .assertEqual ("bc1qjexrunguxz8rlfuul8h4apafyh3sq5yp9kg98j" , wallet .get_receiving_addresses ()[0 ])
315+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qjexrunguxz8rlfuul8h4apafyh3sq5yp9kg98j" )
372316
373317 async def test_2fa_createseed (self ):
374318 self .assertTrue (self .config .get ('enable_plugin_trustedcoin' ))
@@ -392,19 +336,7 @@ async def test_2fa_createseed(self):
392336 v = w .resolve_next (v .view , d )
393337 self .assertEqual ('trustedcoin_show_confirm_otp' , v .view )
394338 v = w .resolve_next (v .view , d )
395- self .assertEqual ('wallet_password' , v .view )
396-
397- d .update ({'password' : None , 'encrypt' : False })
398- self .assertTrue (w .is_last_view (v .view , d ))
399- v = w .resolve_next (v .view , d )
400-
401- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
402- w .create_storage (wallet_path , d )
403-
404- self .assertTrue (os .path .exists (wallet_path ))
405- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
406- self .assertEqual ("bc1qnf5qafvpx0afk47433j3tt30pqkxp5wa263m77wt0pvyqq67rmfs522m94" , wallet .get_receiving_addresses ()[0 ])
407-
339+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qnf5qafvpx0afk47433j3tt30pqkxp5wa263m77wt0pvyqq67rmfs522m94" )
408340
409341 async def test_2fa_haveseed (self ):
410342 self .assertTrue (self .config .get ('enable_plugin_trustedcoin' ))
@@ -430,18 +362,7 @@ async def test_2fa_haveseed(self):
430362 v = w .resolve_next (v .view , d )
431363 self .assertEqual ('trustedcoin_show_confirm_otp' , v .view )
432364 v = w .resolve_next (v .view , d )
433- self .assertEqual ('wallet_password' , v .view )
434-
435- d .update ({'password' : None , 'encrypt' : False })
436- self .assertTrue (w .is_last_view (v .view , d ))
437- v = w .resolve_next (v .view , d )
438-
439- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
440- w .create_storage (wallet_path , d )
441-
442- self .assertTrue (os .path .exists (wallet_path ))
443- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
444- self .assertEqual ("bc1qnf5qafvpx0afk47433j3tt30pqkxp5wa263m77wt0pvyqq67rmfs522m94" , wallet .get_receiving_addresses ()[0 ])
365+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qnf5qafvpx0afk47433j3tt30pqkxp5wa263m77wt0pvyqq67rmfs522m94" )
445366
446367 async def test_2fa_haveseed_passphrase (self ):
447368 self .assertTrue (self .config .get ('enable_plugin_trustedcoin' ))
@@ -470,16 +391,5 @@ async def test_2fa_haveseed_passphrase(self):
470391 v = w .resolve_next (v .view , d )
471392 self .assertEqual ('trustedcoin_show_confirm_otp' , v .view )
472393 v = w .resolve_next (v .view , d )
473- self .assertEqual ('wallet_password' , v .view )
474-
475- d .update ({'password' : None , 'encrypt' : False })
476- self .assertTrue (w .is_last_view (v .view , d ))
477- v = w .resolve_next (v .view , d )
478-
479- wallet_path = os .path .join (w ._daemon .config .get_datadir_wallet_path (), d ['wallet_name' ])
480- w .create_storage (wallet_path , d )
481-
482- self .assertTrue (os .path .exists (wallet_path ))
483- wallet = Daemon ._load_wallet (wallet_path , password = None , config = self .config )
484- self .assertEqual ("bc1qcnu9ay4v3w0tawuxe6wlh6mh33rrpauqnufdgkxx7we8vpx3e6wqa25qud" , wallet .get_receiving_addresses ()[0 ])
394+ self ._set_password_and_check_address (v = v , w = w , recv_addr = "bc1qcnu9ay4v3w0tawuxe6wlh6mh33rrpauqnufdgkxx7we8vpx3e6wqa25qud" )
485395
0 commit comments