diff --git a/lib/core/src/Cardano/Wallet/Primitive/Types.hs b/lib/core/src/Cardano/Wallet/Primitive/Types.hs index babc70b6230..9033e61d671 100644 --- a/lib/core/src/Cardano/Wallet/Primitive/Types.hs +++ b/lib/core/src/Cardano/Wallet/Primitive/Types.hs @@ -225,7 +225,7 @@ instance NFData poolId => NFData (WalletDelegation poolId) newtype WalletPassphraseInfo = WalletPassphraseInfo { lastUpdatedAt :: UTCTime } - deriving (Generic, Eq, Show) + deriving (Generic, Eq, Ord, Show) instance NFData WalletPassphraseInfo diff --git a/lib/core/test/unit/Cardano/WalletSpec.hs b/lib/core/test/unit/Cardano/WalletSpec.hs index 608ae62ae6c..db26ef1d4ce 100644 --- a/lib/core/test/unit/Cardano/WalletSpec.hs +++ b/lib/core/test/unit/Cardano/WalletSpec.hs @@ -49,10 +49,12 @@ import Cardano.Wallet.Primitive.Types , WalletMetadata (..) , WalletName (..) ) +import Control.Concurrent + ( threadDelay ) import Control.DeepSeq ( NFData (..) ) import Control.Monad - ( forM_, replicateM ) + ( forM_, replicateM, void ) import Control.Monad.IO.Class ( liftIO ) import Control.Monad.Trans.Except @@ -66,7 +68,7 @@ import Data.Coerce import Data.Either ( isLeft, isRight ) import Data.Maybe - ( isJust ) + ( isJust, isNothing ) import GHC.Generics ( Generic ) import Test.Hspec @@ -118,6 +120,8 @@ spec = do (property walletUpdatePassphraseWrong) it "Can't change passphrase if wallet doesn't exist" (property walletUpdatePassphraseNoSuchWallet) + it "Passphrase info is up-to-date after wallet passphrase update" + (property walletUpdatePassphraseDate) {------------------------------------------------------------------------------- Properties @@ -241,6 +245,26 @@ walletUpdatePassphraseNoSuchWallet wallet@(wid', _, _) wid (old, new) = let err = ErrUpdatePassphraseWithRootKey (ErrWithRootKeyNoRootKey wid) attempt `shouldBe` Left err +walletUpdatePassphraseDate + :: (WalletId, WalletName, DummyState) + -> (Key 'RootK XPrv, Passphrase "encryption") + -> Property +walletUpdatePassphraseDate wallet (xprv, pwd) = monadicIO $ liftIO $ do + (WalletLayerFixture _ wl [wid]) <- liftIO $ setupFixture wallet + let infoShouldSatisfy predicate = do + info <- (passphraseInfo . snd) <$> unsafeRunExceptT (readWallet wl wid) + info `shouldSatisfy` predicate + return info + + void $ infoShouldSatisfy isNothing + unsafeRunExceptT $ attachPrivateKey wl wid (xprv, pwd) + info <- infoShouldSatisfy isJust + pause + unsafeRunExceptT $ updateWalletPassphrase wl wid (coerce pwd, coerce pwd) + void $ infoShouldSatisfy (\info' -> isJust info' && info' > info) + where + pause = threadDelay 500 + {------------------------------------------------------------------------------- Tests machinery, Arbitrary instances -------------------------------------------------------------------------------}