Skip to content

Commit 9039cd1

Browse files
committed
walletunlocker: assert new password can be used to open the store
1 parent c643c47 commit 9039cd1

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

walletunlocker/service_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ func TestChangeWalletPasswordNewRootKey(t *testing.T) {
527527
t.Fatal("file exists but it shouldn't")
528528
}
529529
}
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)
530536
}
531537

532538
// TestChangeWalletPasswordStateless checks that trying to change the password
@@ -630,6 +636,12 @@ func TestChangeWalletPasswordStateless(t *testing.T) {
630636
case <-time.After(defaultTestTimeout):
631637
t.Fatalf("ChangePassword timed out")
632638
}
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)
633645
}
634646

635647
func doChangePassword(service *walletunlocker.UnlockerService,
@@ -653,3 +665,21 @@ func doChangePassword(service *walletunlocker.UnlockerService,
653665

654666
close(errChan)
655667
}
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.
673+
store, err := openOrCreateTestMacStore(
674+
testDir, &newPassword, testNetParams,
675+
)
676+
require.NoError(t, err)
677+
678+
// Assert that we can read the root key.
679+
_, _, err = store.RootKey(defaultRootKeyIDContext)
680+
require.NoError(t, err)
681+
682+
// Close the db once done.
683+
require.NoError(t, store.Close())
684+
require.NoError(t, store.Backend.Close())
685+
}

0 commit comments

Comments
 (0)