Skip to content

Commit

Permalink
Remove hard-coded mnemonics in case not necessary in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Sep 16, 2020
1 parent 3665332 commit 6e276af
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 163 deletions.
38 changes: 34 additions & 4 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Expand Up @@ -15,6 +15,7 @@

module Test.Integration.Framework.DSL
( Context(..)
, MnemonicLength(..)
, KnownCommand(..)
, TxDescription(..)

Expand Down Expand Up @@ -62,6 +63,8 @@ module Test.Integration.Framework.DSL
, emptyWalletWith
, emptyByronWalletFromXPrvWith
, rewardWallet
, genMnemonics
, genMnemonics'
, getFromResponse
, getFromResponseList
, json
Expand Down Expand Up @@ -142,9 +145,14 @@ module Test.Integration.Framework.DSL
import Cardano.CLI
( Port (..) )
import Cardano.Mnemonic
( MkSomeMnemonic (..)
( ConsistentEntropy
, EntropySize
, MkSomeMnemonic (..)
, Mnemonic
, MnemonicWords
, SomeMnemonic (..)
, ValidChecksumSize
, ValidEntropySize
, entropyToMnemonic
, genEntropy
, mnemonicToText
Expand Down Expand Up @@ -519,6 +527,28 @@ walletId =
minUTxOValue :: Natural
minUTxOValue = 1_000_000

genMnemonics
:: forall mw ent csz.
( ConsistentEntropy ent mw csz
, ValidEntropySize ent
, ValidChecksumSize ent csz
, ent ~ EntropySize mw
, mw ~ MnemonicWords ent
)
=> IO [Text]
genMnemonics =
mnemonicToText . entropyToMnemonic @mw <$> genEntropy

data MnemonicLength = M9 | M12 | M15 | M18 | M21 | M24 deriving (Show)

genMnemonics' :: MnemonicLength -> IO [Text]
genMnemonics' M9 = genMnemonics @9
genMnemonics' M12 = genMnemonics @12
genMnemonics' M15 = genMnemonics @15
genMnemonics' M18 = genMnemonics @18
genMnemonics' M21 = genMnemonics @21
genMnemonics' M24 = genMnemonics @24

getTxId :: (ApiTransaction n) -> String
getTxId tx = T.unpack $ toUrlPiece $ ApiTxId (tx ^. #id)

Expand Down Expand Up @@ -1642,12 +1672,12 @@ postTransactionViaCLI ctx passphrase args = do
hClose stdin
out <- TIO.hGetContents stdout
err <- TIO.hGetContents stderr
-- For some reason, when
-- - waitForProcess is called before hGetContents
-- For some reason, when
-- - waitForProcess is called before hGetContents
-- - os is windows
-- - postTransactionViaCLI was called with >= 5 outputs
-- waitForProcess blocks indefinetely. Hence we call waitForProcess
-- last.
-- last.
c <- waitForProcess h
return (c, T.unpack out, err)

Expand Down
47 changes: 3 additions & 44 deletions lib/core-integration/src/Test/Integration/Framework/TestData.hs
Expand Up @@ -11,15 +11,7 @@ module Test.Integration.Framework.TestData
, invalidMnemonics15
, japaneseMnemonics12
, japaneseMnemonics15
, mnemonics3
, mnemonics6
, mnemonics9
, mnemonics12
, mnemonics15
, notInDictMnemonics15
, mnemonics18
, mnemonics21
, mnemonics24
, specMnemonicByron
, specMnemonicSentence
, specMnemonicSecondFactor
Expand Down Expand Up @@ -106,41 +98,6 @@ falseWalletIds =
, ("41 chars hex", replicate 41 '1')
]

mnemonics3 :: [Text]
mnemonics3 = ["diamond", "flee", "window"]

mnemonics6 :: [Text]
mnemonics6 = ["tornado", "canvas", "peasant", "spike", "enrich", "dilemma"]

mnemonics9 :: [Text]
mnemonics9 = ["subway", "tourist", "abstract", "roast", "border", "curious",
"exercise", "work", "narrow"]

mnemonics12 :: [Text]
mnemonics12 = ["agent", "siren", "roof", "water", "giant", "pepper",
"obtain", "oxygen", "treat", "vessel", "hip", "garlic"]

mnemonics15 :: [Text]
mnemonics15 = ["network", "empty", "cause", "mean", "expire", "private",
"finger", "accident", "session", "problem", "absurd", "banner", "stage",
"void", "what"]

mnemonics18 :: [Text]
mnemonics18 = ["whisper", "control", "diary", "solid", "cattle", "salmon",
"whale", "slender", "spread", "ice", "shock", "solve", "panel",
"caution", "upon", "scatter", "broken", "tonight"]

mnemonics21 :: [Text]
mnemonics21 = ["click", "puzzle", "athlete", "morning", "fold", "retreat",
"across", "timber", "essay", "drill", "finger", "erase", "galaxy",
"spoon", "swift", "eye", "awesome", "shrimp", "depend", "zebra", "token"]

mnemonics24 :: [Text]
mnemonics24 = ["decade", "distance", "denial", "jelly", "wash", "sword",
"olive", "perfect", "jewel", "renew", "wrestle", "cupboard", "record",
"scale", "pattern", "invite", "other", "fruit", "gloom", "west", "oak",
"deal", "seek", "hand"]

invalidMnemonics12 :: [Text]
invalidMnemonics12 = ["word","word","word","word","word","word","word",
"word","word","word","word","hill"]
Expand Down Expand Up @@ -240,7 +197,9 @@ payloadWith' name mnemonics gap = Json [json| {
simplePayload :: Payload
simplePayload = Json [json| {
"name": "Secure Wallet",
"mnemonic_sentence": #{mnemonics21},
"mnemonic_sentence": ["click", "puzzle", "athlete", "morning", "fold", "retreat",
"across", "timber", "essay", "drill", "finger", "erase", "galaxy",
"spoon", "swift", "eye", "awesome", "shrimp", "depend", "zebra", "token"],
"passphrase": #{fixturePassphrase}
} |]

Expand Down
Expand Up @@ -76,6 +76,7 @@ import Test.Integration.Framework.DSL
, expectWalletUTxO
, fixturePassphrase
, fixturePassphraseEncrypted
, genMnemonics
, getFromResponse
, json
, request
Expand All @@ -89,7 +90,6 @@ import Test.Integration.Framework.TestData
, errMsg403WrongPass
, errMsg404NoWallet
, kanjiWalletName
, mnemonics12
, polishWalletName
, russianWalletName
, updateEmptyPassPayload
Expand Down Expand Up @@ -312,6 +312,7 @@ spec = describe "BYRON_WALLETS" $ do
]
forM_ matrix $ \(title, passphrase, expectations) -> it title $
\ctx -> do
mnemonics12 <- genMnemonics @12
let payload = Json [json| {
"name": "Secure Wallet",
"mnemonic_sentence": #{mnemonics12},
Expand Down

0 comments on commit 6e276af

Please sign in to comment.