@@ -140,7 +140,7 @@ func openOrCreateTestMacStore(tempDir string, pw *[]byte,
140
140
return store , nil
141
141
}
142
142
143
- // TestGenSeedUserEntropy tests that the gen seed method generates a valid
143
+ // TestGenSeed tests that the gen seed method generates a valid
144
144
// cipher seed mnemonic phrase and user provided source of entropy.
145
145
func TestGenSeed (t * testing.T ) {
146
146
t .Parallel ()
@@ -173,8 +173,8 @@ func TestGenSeed(t *testing.T) {
173
173
require .NoError (t , err )
174
174
}
175
175
176
- // TestGenSeedInvalidEntropy tests that the gen seed method generates a valid
177
- // cipher seed mnemonic pass phrase even when the user doesn't provide its own
176
+ // TestGenSeedGenerateEntropy tests that the gen seed method generates a valid
177
+ // cipher seed mnemonic passphrase even when the user doesn't provide its own
178
178
// source of entropy.
179
179
func TestGenSeedGenerateEntropy (t * testing.T ) {
180
180
t .Parallel ()
@@ -318,7 +318,7 @@ func TestInitWallet(t *testing.T) {
318
318
require .Error (t , err )
319
319
}
320
320
321
- // TestInitWalletInvalidCipherSeed tests that if we attempt to create a wallet
321
+ // TestCreateWalletInvalidEntropy tests that if we attempt to create a wallet
322
322
// with an invalid cipher seed, then we'll receive an error.
323
323
func TestCreateWalletInvalidEntropy (t * testing.T ) {
324
324
t .Parallel ()
@@ -344,7 +344,7 @@ func TestCreateWalletInvalidEntropy(t *testing.T) {
344
344
require .Error (t , err )
345
345
}
346
346
347
- // TestUnlockWallet checks that trying to unlock non-existing wallet fail , that
347
+ // TestUnlockWallet checks that trying to unlock non-existing wallet fails , that
348
348
// unlocking existing wallet with wrong passphrase fails, and that unlocking
349
349
// existing wallet with correct passphrase succeeds.
350
350
func TestUnlockWallet (t * testing.T ) {
@@ -491,7 +491,7 @@ func TestChangeWalletPasswordNewRootKey(t *testing.T) {
491
491
// password that meets the length requirement, the password change
492
492
// should succeed.
493
493
errChan := make (chan error , 1 )
494
- go doChangePassword (service , testDir , req , errChan )
494
+ go doChangePassword (service , req , errChan )
495
495
496
496
// The new password should be sent over the channel.
497
497
select {
@@ -510,6 +510,15 @@ func TestChangeWalletPasswordNewRootKey(t *testing.T) {
510
510
t .Fatalf ("password not received" )
511
511
}
512
512
513
+ // Wait for the doChangePassword goroutine to finish.
514
+ select {
515
+ case err := <- errChan :
516
+ require .NoError (t , err , "ChangePassword call failed" )
517
+
518
+ case <- time .After (defaultTestTimeout ):
519
+ t .Fatalf ("ChangePassword timed out" )
520
+ }
521
+
513
522
// The files should no longer exist.
514
523
for _ , tempFile := range tempFiles {
515
524
f , err := os .Open (tempFile )
@@ -518,11 +527,17 @@ func TestChangeWalletPasswordNewRootKey(t *testing.T) {
518
527
t .Fatal ("file exists but it shouldn't" )
519
528
}
520
529
}
530
+
531
+ // Close the old db first.
532
+ require .NoError (t , store .Backend .Close ())
533
+
534
+ // Check that the new password can be used to open the db.
535
+ assertPasswordChanged (t , testDir , req .NewPassword )
521
536
}
522
537
523
538
// TestChangeWalletPasswordStateless checks that trying to change the password
524
- // of an existing wallet that was initialized stateless works when when the
525
- // --stateless_init flat is set. Also checks that if no password is given,
539
+ // of an existing wallet that was initialized stateless works when the
540
+ // --stateless_init flag is set. Also checks that if no password is given,
526
541
// the default password is used.
527
542
func TestChangeWalletPasswordStateless (t * testing.T ) {
528
543
t .Parallel ()
@@ -594,7 +609,7 @@ func TestChangeWalletPasswordStateless(t *testing.T) {
594
609
// async and then wait for the unlock message to arrive so we can send
595
610
// back a fake macaroon.
596
611
errChan := make (chan error , 1 )
597
- go doChangePassword (service , testDir , req , errChan )
612
+ go doChangePassword (service , req , errChan )
598
613
599
614
// Password and recovery window should be sent over the channel.
600
615
select {
@@ -612,9 +627,24 @@ func TestChangeWalletPasswordStateless(t *testing.T) {
612
627
case <- time .After (defaultTestTimeout ):
613
628
t .Fatalf ("password not received" )
614
629
}
630
+
631
+ // Wait for the doChangePassword goroutine to finish.
632
+ select {
633
+ case err := <- errChan :
634
+ require .NoError (t , err , "ChangePassword call failed" )
635
+
636
+ case <- time .After (defaultTestTimeout ):
637
+ t .Fatalf ("ChangePassword timed out" )
638
+ }
639
+
640
+ // Close the old db first.
641
+ require .NoError (t , store .Backend .Close ())
642
+
643
+ // Check that the new password can be used to open the db.
644
+ assertPasswordChanged (t , testDir , req .NewPassword )
615
645
}
616
646
617
- func doChangePassword (service * walletunlocker.UnlockerService , testDir string ,
647
+ func doChangePassword (service * walletunlocker.UnlockerService ,
618
648
req * lnrpc.ChangePasswordRequest , errChan chan error ) {
619
649
620
650
// When providing the correct wallet's current password and a new
@@ -630,37 +660,26 @@ func doChangePassword(service *walletunlocker.UnlockerService, testDir string,
630
660
if ! bytes .Equal (response .AdminMacaroon , testMac ) {
631
661
errChan <- fmt .Errorf ("mismatched macaroon: expected %x, got " +
632
662
"%x" , testMac , response .AdminMacaroon )
663
+ return
633
664
}
634
665
635
- // Close the macaroon DB and try to open it and read the root key with
636
- // the new password.
666
+ close (errChan )
667
+ }
668
+
669
+ // assertPasswordChanged asserts that the new password can be used to open the
670
+ // store.
671
+ func assertPasswordChanged (t * testing.T , testDir string , newPassword []byte ) {
672
+ // Open it and read the root key with the new password.
637
673
store , err := openOrCreateTestMacStore (
638
- testDir , & testPassword , testNetParams ,
674
+ testDir , & newPassword , testNetParams ,
639
675
)
640
- if err != nil {
641
- errChan <- fmt .Errorf ("could not create test store: %w" , err )
642
- return
643
- }
644
- _ , _ , err = store .RootKey (defaultRootKeyIDContext )
645
- if err != nil {
646
- errChan <- fmt .Errorf ("could not get root key: %w" , err )
647
- return
648
- }
676
+ require .NoError (t , err )
649
677
650
- // Do cleanup now. Since we are in a go func, the defer at the top of
651
- // the outer would not work, because it would delete the directory
652
- // before we could check the content in here.
653
- err = store .Close ()
654
- if err != nil {
655
- errChan <- fmt .Errorf ("could not close store: %w" , err )
656
- return
657
- }
678
+ // Assert that we can read the root key.
679
+ _ , _ , err = store .RootKey (defaultRootKeyIDContext )
680
+ require .NoError (t , err )
658
681
659
- // The backend database isn't closed automatically if the store is
660
- // closed, do that now manually.
661
- err = store .Backend .Close ()
662
- if err != nil {
663
- errChan <- fmt .Errorf ("could not close db: %w" , err )
664
- return
665
- }
682
+ // Close the db once done.
683
+ require .NoError (t , store .Close ())
684
+ require .NoError (t , store .Backend .Close ())
666
685
}
0 commit comments