From 9039cd13963e11a6427ef41a93e8cf5526931cde Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 16 Jul 2025 02:21:13 +0800 Subject: [PATCH] walletunlocker: assert new password can be used to open the store --- walletunlocker/service_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/walletunlocker/service_test.go b/walletunlocker/service_test.go index 0d9984174..7de2961cc 100644 --- a/walletunlocker/service_test.go +++ b/walletunlocker/service_test.go @@ -527,6 +527,12 @@ func TestChangeWalletPasswordNewRootKey(t *testing.T) { t.Fatal("file exists but it shouldn't") } } + + // Close the old db first. + require.NoError(t, store.Backend.Close()) + + // Check that the new password can be used to open the db. + assertPasswordChanged(t, testDir, req.NewPassword) } // TestChangeWalletPasswordStateless checks that trying to change the password @@ -630,6 +636,12 @@ func TestChangeWalletPasswordStateless(t *testing.T) { case <-time.After(defaultTestTimeout): t.Fatalf("ChangePassword timed out") } + + // Close the old db first. + require.NoError(t, store.Backend.Close()) + + // Check that the new password can be used to open the db. + assertPasswordChanged(t, testDir, req.NewPassword) } func doChangePassword(service *walletunlocker.UnlockerService, @@ -653,3 +665,21 @@ func doChangePassword(service *walletunlocker.UnlockerService, close(errChan) } + +// assertPasswordChanged asserts that the new password can be used to open the +// store. +func assertPasswordChanged(t *testing.T, testDir string, newPassword []byte) { + // Open it and read the root key with the new password. + store, err := openOrCreateTestMacStore( + testDir, &newPassword, testNetParams, + ) + require.NoError(t, err) + + // Assert that we can read the root key. + _, _, err = store.RootKey(defaultRootKeyIDContext) + require.NoError(t, err) + + // Close the db once done. + require.NoError(t, store.Close()) + require.NoError(t, store.Backend.Close()) +}