diff --git a/lib/core-integration/src/Test/Integration/Framework/DSL.hs b/lib/core-integration/src/Test/Integration/Framework/DSL.hs index 4a1eb13df2d..cf6dfdeac12 100644 --- a/lib/core-integration/src/Test/Integration/Framework/DSL.hs +++ b/lib/core-integration/src/Test/Integration/Framework/DSL.hs @@ -15,6 +15,7 @@ module Test.Integration.Framework.DSL ( Context(..) + , MnemonicLength(..) , KnownCommand(..) , TxDescription(..) @@ -62,6 +63,8 @@ module Test.Integration.Framework.DSL , emptyWalletWith , emptyByronWalletFromXPrvWith , rewardWallet + , genMnemonics + , genMnemonics' , getFromResponse , getFromResponseList , json @@ -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 @@ -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) @@ -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) diff --git a/lib/core-integration/src/Test/Integration/Framework/TestData.hs b/lib/core-integration/src/Test/Integration/Framework/TestData.hs index 5a6cdba65c7..2a7a88745ae 100644 --- a/lib/core-integration/src/Test/Integration/Framework/TestData.hs +++ b/lib/core-integration/src/Test/Integration/Framework/TestData.hs @@ -11,15 +11,7 @@ module Test.Integration.Framework.TestData , invalidMnemonics15 , japaneseMnemonics12 , japaneseMnemonics15 - , mnemonics3 - , mnemonics6 - , mnemonics9 - , mnemonics12 - , mnemonics15 , notInDictMnemonics15 - , mnemonics18 - , mnemonics21 - , mnemonics24 , specMnemonicByron , specMnemonicSentence , specMnemonicSecondFactor @@ -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"] @@ -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} } |] diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs index d2b40cab4d6..d65f7b0a6a8 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs @@ -76,6 +76,7 @@ import Test.Integration.Framework.DSL , expectWalletUTxO , fixturePassphrase , fixturePassphraseEncrypted + , genMnemonics , getFromResponse , json , request @@ -89,7 +90,6 @@ import Test.Integration.Framework.TestData , errMsg403WrongPass , errMsg404NoWallet , kanjiWalletName - , mnemonics12 , polishWalletName , russianWalletName , updateEmptyPassPayload @@ -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}, diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs index 4b87dde8f7b..7223e85b4cc 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs @@ -17,15 +17,7 @@ module Test.Integration.Scenario.API.Shelley.Wallets import Prelude import Cardano.Mnemonic - ( ConsistentEntropy - , EntropySize - , MnemonicWords - , ValidChecksumSize - , ValidEntropySize - , entropyToMnemonic - , genEntropy - , mnemonicToText - ) + ( entropyToMnemonic, genEntropy, mnemonicToText ) import Cardano.Wallet.Api.Types ( AddressAmount (..) , ApiByronWallet @@ -77,6 +69,7 @@ import Test.Hspec.Extra import Test.Integration.Framework.DSL ( Context (..) , Headers (..) + , MnemonicLength (..) , Payload (..) , emptyByronWalletWith , emptyRandomWallet @@ -91,6 +84,8 @@ import Test.Integration.Framework.DSL , expectWalletUTxO , fixturePassphrase , fixtureWallet + , genMnemonics + , genMnemonics' , getFromResponse , json , listAddresses @@ -110,12 +105,6 @@ import Test.Integration.Framework.TestData , errMsg406 , errMsg415 , kanjiWalletName - , mnemonics12 - , mnemonics15 - , mnemonics18 - , mnemonics21 - , mnemonics24 - , mnemonics9 , payloadWith , payloadWith' , polishWalletName @@ -141,10 +130,12 @@ spec :: forall n t. ) => SpecWith (Context t) spec = describe "SHELLEY_WALLETS" $ do it "WALLETS_CREATE_01 - Create a wallet" $ \ctx -> do + m15 <- genMnemonics @15 + m12 <- genMnemonics @12 let payload = Json [json| { "name": "1st Wallet", - "mnemonic_sentence": #{mnemonics15}, - "mnemonic_second_factor": #{mnemonics12}, + "mnemonic_sentence": #{m15}, + "mnemonic_second_factor": #{m12}, "passphrase": #{fixturePassphrase}, "address_pool_gap": 30 } |] @@ -160,8 +151,6 @@ spec = describe "SHELLEY_WALLETS" $ do , expectField (#balance . #getApiT . #reward) (`shouldBe` Quantity 0) , expectField #delegation (`shouldBe` notDelegating []) - , expectField - walletId (`shouldBe` "2cf060fe53e4e0593f145f22b858dfc60676d4ab") , expectField #passphrase (`shouldNotBe` Nothing) ] let wid = getFromResponse id r @@ -276,9 +265,10 @@ spec = describe "SHELLEY_WALLETS" $ do ] it "WALLETS_CREATE_03,09 - Cannot create wallet that exists" $ \ctx -> do + m21 <- genMnemonics @21 let payload = Json [json| { "name": "Some Wallet", - "mnemonic_sentence": #{mnemonics21}, + "mnemonic_sentence": #{m21}, "passphrase": #{fixturePassphrase} } |] r1 <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload @@ -344,9 +334,10 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, walName, expectations) -> it title $ \ctx -> do + m24 <- genMnemonics @24 let payload = Json [json| { "name": #{walName}, - "mnemonic_sentence": #{mnemonics24}, + "mnemonic_sentence": #{m24}, "passphrase": #{fixturePassphrase} } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload @@ -354,103 +345,63 @@ spec = describe "SHELLEY_WALLETS" $ do describe "WALLETS_CREATE_05 - Mnemonics" $ do let matrix = - [ ( "15 mnemonic words", mnemonics15 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "b062e8ccf3685549b6c489a4e94966bc4695b75b") - ] - ) - , ( "18 mnemonic words", mnemonics18 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "f52ee0daaefd75a0212d70c9fbe15ee8ada9fc11") - ] - ) - , ( "21 mnemonic words" , mnemonics21 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "7e8c1af5ff2218f388a313f9c70f0ff0550277e4") - ] - ) - , ( "24 mnemonic words", mnemonics24 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "a6b6625cd2bfc51a296b0933f77020991cc80374") - ] - ) + [ ( "15 mnemonic words", M15 ) + , ( "18 mnemonic words", M18 ) + , ( "21 mnemonic words", M21 ) + , ( "24 mnemonic words", M24 ) ] - forM_ matrix $ \(title, mnemonics, expectations) -> it title $ \ctx -> do + forM_ matrix $ \(title, mnemonics) -> it title $ \ctx -> do + m <- genMnemonics' mnemonics let payload = Json [json| { "name": "Just a łallet", - "mnemonic_sentence": #{mnemonics}, + "mnemonic_sentence": #{m}, "passphrase": #{fixturePassphrase} } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload - verify r expectations + verify r [ expectResponseCode @IO HTTP.status201 ] describe "WALLETS_CREATE_06 - Mnemonics second factor" $ do let matrix = - [ ( "9 mnemonic words", mnemonics9 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "4b1a865e39d1006efb99f538b05ea2343b567108") - ] - ) - , ( "12 mnemonic words", mnemonics12 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "2cf060fe53e4e0593f145f22b858dfc60676d4ab") - ] - ) + [ ( "9 mnemonic words", M9 ) + , ( "12 mnemonic words", M12 ) ] - forM_ matrix $ \(title, mnemonics, expectations) -> it title $ \ctx -> do + forM_ matrix $ \(title, mnemonics) -> it title $ \ctx -> do + m15 <- genMnemonics' M15 + mSecondFactor <- genMnemonics' mnemonics + let payload = Json [json| { "name": "Just a łallet", - "mnemonic_sentence": #{mnemonics15}, - "mnemonic_second_factor": #{mnemonics}, + "mnemonic_sentence": #{m15}, + "mnemonic_second_factor": #{mSecondFactor}, "passphrase": #{fixturePassphrase} } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload - verify r expectations + verify r [ expectResponseCode @IO HTTP.status201 ] describe "WALLETS_CREATE_07 - Passphrase" $ do let minLength = passphraseMinLength (Proxy @"raw") let maxLength = passphraseMaxLength (Proxy @"raw") let matrix = [ ( show minLength ++ " char long" - , T.pack (replicate minLength 'ź') - , [ expectResponseCode @IO HTTP.status201 - ] - ) + , T.pack (replicate minLength 'ź') ) , ( show maxLength ++ " char long" - , T.pack (replicate maxLength 'ą') - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Russian passphrase", russianWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Polish passphrase", polishWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Kanji passphrase", kanjiWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Arabic passphrase", arabicWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Wildcards passphrase", wildcardsWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) + , T.pack (replicate maxLength 'ą') ) + , ( "Russian passphrase", russianWalletName ) + , ( "Polish passphrase", polishWalletName ) + , ( "Kanji passphrase", kanjiWalletName ) + , ( "Arabic passphrase", arabicWalletName ) + , ( "Wildcards passphrase", wildcardsWalletName ) ] - forM_ matrix $ \(title, passphrase, expectations) -> it title $ \ctx -> do + forM_ matrix $ \(title, passphrase) -> it title $ \ctx -> do + m24 <- genMnemonics @24 let payload = Json [json| { "name": "Secure Wallet", - "mnemonic_sentence": #{mnemonics24}, + "mnemonic_sentence": #{m24}, "passphrase": #{passphrase} } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload - verify r expectations + verify r [ expectResponseCode @IO HTTP.status201 ] describe "WALLETS_CREATE_08 - address_pool_gap" $ do let addrPoolMin = fromIntegral @_ @Int $ getAddressPoolGap minBound @@ -470,7 +421,8 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, addrPoolGap, expectations) -> it title $ \ctx -> do - let payload = payloadWith' "Secure Wallet" mnemonics24 (fromIntegral addrPoolGap) + m24 <- genMnemonics @24 + let payload = payloadWith' "Secure Wallet" m24 (fromIntegral addrPoolGap) rW <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload verify rW expectations -- FIXME: ADP-436 @@ -478,16 +430,15 @@ spec = describe "SHELLEY_WALLETS" $ do -- let w = getFromResponse id rW -- rA <- request @[ApiAddress n] ctx -- (Link.listAddresses @'Shelley w) Default Empty - -- _ <- request @ApiWallet ctx - -- (Link.deleteWallet @'Shelley w) Default Empty -- verify rA -- [ expectListSize addrPoolGap -- ] it "WALLETS_CREATE_08 - default address_pool_gap" $ \ctx -> do + m21 <- genMnemonics @21 let payload = Json [json| { "name": "Secure Wallet", - "mnemonic_sentence": #{mnemonics21}, + "mnemonic_sentence": #{m21}, "passphrase": "Secure passphrase" } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload @@ -526,9 +477,10 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, headers, expectations) -> it title $ \ctx -> do + m21 <- genMnemonics @21 let payload = Json [json| { "name": "Secure Wallet", - "mnemonic_sentence": #{mnemonics21}, + "mnemonic_sentence": #{m21}, "passphrase": "Secure passphrase" } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) headers payload @@ -568,10 +520,12 @@ spec = describe "SHELLEY_WALLETS" $ do expectErrorMessage (errMsg404NoWallet $ w ^. walletId) rg it "WALLETS_LIST_01 - Created a wallet can be listed" $ \ctx -> do + m18 <- genMnemonics @18 + m9 <- genMnemonics @9 let payload = Json [json| { "name": "Wallet to be listed", - "mnemonic_sentence": #{mnemonics18}, - "mnemonic_second_factor": #{mnemonics9}, + "mnemonic_sentence": #{m18}, + "mnemonic_second_factor": #{m9}, "passphrase": #{fixturePassphrase}, "address_pool_gap": 20 } |] @@ -592,13 +546,14 @@ spec = describe "SHELLEY_WALLETS" $ do , expectListField 0 (#balance . #getApiT . #reward) (`shouldBe` Quantity 0) , expectListField 0 #delegation (`shouldBe` notDelegating []) - , expectListField 0 walletId - (`shouldBe` "dfe87fcf0560fb57937a6468ea51e860672fad79") ] it "WALLETS_LIST_01 - Wallets are listed from oldest to newest" $ \ctx -> do - let walletDetails = [("1", mnemonics15), ("2", mnemonics18) - , ("3", mnemonics21)] + m15 <- genMnemonics @15 + m18 <- genMnemonics @18 + m21 <- genMnemonics @21 + let walletDetails = [("1", m15), ("2", m18) + , ("3", m21)] forM_ walletDetails $ \(name, mnemonics) -> do let payload = payloadWith name mnemonics request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload @@ -850,9 +805,10 @@ spec = describe "SHELLEY_WALLETS" $ do , ( "Wildcards passphrase", wildcardsWalletName ) ] forM_ matrix $ \(title, oldPass) -> it title $ \ctx -> do + m24 <- genMnemonics @24 let createPayload = Json [json| { "name": "Name of the wallet", - "mnemonic_sentence": #{mnemonics24}, + "mnemonic_sentence": #{m24}, "passphrase": #{oldPass} } |] (_, w) <- unsafeRequest @ApiWallet ctx @@ -1299,15 +1255,3 @@ spec = describe "SHELLEY_WALLETS" $ do , expectField (#tip . #slotNumber . #getApiT) (`shouldBe` slotNum) , expectField (#tip . #height) (`shouldBe` blockHeight) ] - where - 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 diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs index 8b4b97523e2..d476396b8c0 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs @@ -94,6 +94,7 @@ import Test.Integration.Framework.DSL as DSL , fixtureRandomWallet , fixtureRawTx , fixtureWallet + , genMnemonics , getFromResponse , json , listAddresses @@ -103,7 +104,7 @@ import Test.Integration.Framework.DSL as DSL , walletId ) import Test.Integration.Framework.TestData - ( errMsg400MalformedTxPayload, errMsg404CannotFindTx, mnemonics15 ) + ( errMsg400MalformedTxPayload, errMsg404CannotFindTx ) import Test.Integration.Jcli ( getBlock0H ) import Test.QuickCheck @@ -483,6 +484,7 @@ fixtureExternalTx ctx toSend = do let (Just keysAddrChng) = isOwned st' (rootXPrv, pwd) addrChng -- we create destination empty wallet + mnemonics15 <- genMnemonics @15 let createWallet = Json [json| { "name": "Destination Wallet", "mnemonic_sentence": #{mnemonics15},