11module Ctl.Internal.Test.E2E.Route
22 ( E2ETestName
33 , E2EConfigName
4- , route
5- , parseRoute
64 , Route
75 , addLinks
6+ , e2eConfigs
7+ , parseRoute
8+ , route
89 ) where
910
1011import Prelude
@@ -13,12 +14,14 @@ import Cardano.Types (NetworkId(TestnetId))
1314import Cardano.Types.PrivateKey (PrivateKey )
1415import Cardano.Types.PrivateKey as PrivateKey
1516import Cardano.Types.RawBytes (RawBytes (RawBytes))
16- import Contract.Config (ContractParams )
17+ import Contract.Config (ContractParams , testnetConfig )
1718import Contract.Monad (Contract , runContract )
1819import Contract.Test.Cip30Mock (withCip30Mock )
1920import Contract.Wallet
20- ( PrivatePaymentKey (PrivatePaymentKey)
21+ ( KnownWallet (Gero, Eternl, Lode, Lace)
22+ , PrivatePaymentKey (PrivatePaymentKey)
2123 , PrivateStakeKey (PrivateStakeKey)
24+ , walletName
2225 )
2326import Contract.Wallet.Key (privateKeysToKeyWallet )
2427import Control.Alt ((<|>))
@@ -33,15 +36,17 @@ import Data.Array (last)
3336import Data.Array as Array
3437import Data.Bifunctor (lmap )
3538import Data.ByteArray (hexToByteArray )
36- import Data.Either (Either (Left), note )
39+ import Data.Either (Either (Left, Right ), note )
3740import Data.Foldable (fold )
3841import Data.Map (Map )
3942import Data.Map as Map
40- import Data.Maybe (Maybe (Just, Nothing), maybe )
43+ import Data.Maybe (Maybe (Just, Nothing), fromMaybe , maybe )
4144import Data.Newtype (wrap )
42- import Data.String (stripPrefix )
45+ import Data.String (stripPrefix , stripSuffix )
4346import Data.String.Common (split )
4447import Data.String.Pattern (Pattern (Pattern))
48+ import Data.Traversable (traverse )
49+ import Data.Tuple (Tuple (Tuple))
4550import Data.Tuple.Nested (type (/\), (/\))
4651import Effect (Effect )
4752import Effect.Aff (Aff , delay , launchAff_ )
@@ -55,6 +60,47 @@ type E2ETestName = String
5560-- | CIP-30 mock). Used in the URL for routing
5661type E2EConfigName = String
5762
63+ e2eConfigs
64+ :: Array E2EConfigName
65+ -> Either String (Map E2EConfigName (ContractParams /\ Maybe String ))
66+ e2eConfigs =
67+ map Map .fromFoldable
68+ <<< traverse (\env -> Tuple env <$> resolveConfigName env)
69+ where
70+ resolveConfigName
71+ :: E2EConfigName
72+ -> Either String (ContractParams /\ Maybe String )
73+ resolveConfigName configName = do
74+ let
75+ walletSpec =
76+ fromMaybe configName $ stripPrefix (Pattern " localnet-" )
77+ configName
78+ wallet' /\ isMock =
79+ maybe (walletSpec /\ false ) (flip Tuple true ) $ stripSuffix
80+ (Pattern " -mock" )
81+ walletSpec
82+ wallet <- resolveWallet wallet'
83+ pure $
84+ Tuple
85+ (mkContractParams wallet)
86+ (if isMock then Just wallet else Nothing )
87+
88+ resolveWallet :: String -> Either String String
89+ resolveWallet =
90+ case _ of
91+ " gero" -> Right $ walletName Gero
92+ " eternl" -> Right $ walletName Eternl
93+ " lode" -> Right $ walletName Lode
94+ " lace" -> Right $ walletName Lace
95+ wallet -> Left $ " e2eConfigs: unsupported wallet: " <> wallet
96+
97+ mkContractParams :: String -> ContractParams
98+ mkContractParams wallet =
99+ testnetConfig
100+ { walletSpec =
101+ Just $ ConnectToGenericCip30 wallet { cip95: false }
102+ }
103+
58104-- | Router state - parsed from URL by `parseRoute`
59105type Route =
60106 { configName :: E2EConfigName
0 commit comments