Skip to content

Commit

Permalink
add extra property test to verify passphrase gets updated correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed May 10, 2019
1 parent fc8dd28 commit b6c72b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/Primitive/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 26 additions & 2 deletions lib/core/test/unit/Cardano/WalletSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit b6c72b4

Please sign in to comment.