@@ -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 )
@@ -594,7 +603,7 @@ func TestChangeWalletPasswordStateless(t *testing.T) {
594
603
// async and then wait for the unlock message to arrive so we can send
595
604
// back a fake macaroon.
596
605
errChan := make (chan error , 1 )
597
- go doChangePassword (service , testDir , req , errChan )
606
+ go doChangePassword (service , req , errChan )
598
607
599
608
// Password and recovery window should be sent over the channel.
600
609
select {
@@ -612,9 +621,18 @@ func TestChangeWalletPasswordStateless(t *testing.T) {
612
621
case <- time .After (defaultTestTimeout ):
613
622
t .Fatalf ("password not received" )
614
623
}
624
+
625
+ // Wait for the doChangePassword goroutine to finish.
626
+ select {
627
+ case err := <- errChan :
628
+ require .NoError (t , err , "ChangePassword call failed" )
629
+
630
+ case <- time .After (defaultTestTimeout ):
631
+ t .Fatalf ("ChangePassword timed out" )
632
+ }
615
633
}
616
634
617
- func doChangePassword (service * walletunlocker.UnlockerService , testDir string ,
635
+ func doChangePassword (service * walletunlocker.UnlockerService ,
618
636
req * lnrpc.ChangePasswordRequest , errChan chan error ) {
619
637
620
638
// When providing the correct wallet's current password and a new
@@ -633,35 +651,5 @@ func doChangePassword(service *walletunlocker.UnlockerService, testDir string,
633
651
return
634
652
}
635
653
636
- // Close the macaroon DB and try to open it and read the root key with
637
- // the new password.
638
- store , err := openOrCreateTestMacStore (
639
- testDir , & req .NewPassword , testNetParams ,
640
- )
641
- if err != nil {
642
- errChan <- fmt .Errorf ("could not create test store: %w" , err )
643
- return
644
- }
645
- _ , _ , err = store .RootKey (defaultRootKeyIDContext )
646
- if err != nil {
647
- errChan <- fmt .Errorf ("could not get root key: %w" , err )
648
- return
649
- }
650
-
651
- // Do cleanup now. Since we are in a go func, the defer at the top of
652
- // the outer would not work, because it would delete the directory
653
- // before we could check the content in here.
654
- err = store .Close ()
655
- if err != nil {
656
- errChan <- fmt .Errorf ("could not close store: %w" , err )
657
- return
658
- }
659
-
660
- // The backend database isn't closed automatically if the store is
661
- // closed, do that now manually.
662
- err = store .Backend .Close ()
663
- if err != nil {
664
- errChan <- fmt .Errorf ("could not close db: %w" , err )
665
- return
666
- }
654
+ close (errChan )
667
655
}
0 commit comments