-
Notifications
You must be signed in to change notification settings - Fork 50
/
ByUrl.purs
229 lines (219 loc) · 8.78 KB
/
ByUrl.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
module Ctl.Examples.ByUrl (main) where
import Prelude
import Contract.Config
( ContractParams
, KnownWallet(Nami, Gero, Flint, Eternl, Lode, Lace, NuFi)
, WalletSpec(ConnectToGenericCip30)
, blockfrostPublicPreprodServerConfig
, blockfrostPublicPreviewServerConfig
, mainnetConfig
, mkBlockfrostBackendParams
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract)
import Contract.Test.E2E (E2EConfigName, E2ETestName, addLinks, route)
import Ctl.Examples.AdditionalUtxos as AdditionalUtxos
import Ctl.Examples.AlwaysMints as AlwaysMints
import Ctl.Examples.AlwaysSucceeds as AlwaysSucceeds
import Ctl.Examples.ChangeGeneration as ChangeGeneration
import Ctl.Examples.Cip30 as Cip30
import Ctl.Examples.Datums as Datums
import Ctl.Examples.DropTokens as DropTokens
import Ctl.Examples.ECDSA as ECDSA
import Ctl.Examples.IncludeDatum (contract) as IncludeDatum
import Ctl.Examples.MintsMultipleTokens as MintsMultipleTokens
import Ctl.Examples.NativeScriptMints as NativeScriptMints
import Ctl.Examples.OneShotMinting as OneShotMinting
import Ctl.Examples.PaysWithDatum as PaysWithDatum
import Ctl.Examples.Pkh2Pkh as Pkh2Pkh
import Ctl.Examples.PlutusV2.AlwaysSucceeds as AlwaysSucceedsV2
import Ctl.Examples.PlutusV2.OneShotMinting as OneShotMintingV2
import Ctl.Examples.PlutusV2.ReferenceInputsAndScripts as ReferenceInputsAndScriptsV2
import Ctl.Examples.Schnorr as Schnorr
import Ctl.Examples.SendsToken as SendsToken
import Ctl.Examples.SignData as SignData
import Ctl.Examples.SignMultiple as SignMultiple
import Ctl.Examples.TxChaining as TxChaining
import Ctl.Examples.Utxos as Utxos
import Ctl.Examples.Wallet as Wallet
import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(Just, Nothing), isNothing)
import Data.Time.Duration (Seconds(Seconds))
import Data.Tuple.Nested (type (/\), (/\))
import Effect (Effect)
import Effect.Console as Console
import Test.Ctl.ApplyArgs as ApplyArgs
import Web.HTML (window)
import Web.HTML.Window (localStorage)
import Web.Storage.Storage (getItem)
main :: Effect Unit
main = do
-- Read Blockfrost API key from the browser storage.
-- To set it up, run `npm run e2e-browser` and follow the instructions.
mbApiKey <- getBlockfrostApiKey
let
connectTo wallet =
Just $ ConnectToGenericCip30 (walletName wallet) { cip95: false }
walletsWithBlockfrost =
wallets `Map.union`
if isNothing mbApiKey then Map.empty
else
Map.fromFoldable
[ "blockfrost-nami-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo Nami }
/\ Nothing
, "blockfrost-gero-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo Gero }
/\ Nothing
, "blockfrost-eternl-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo Eternl }
/\ Nothing
, "blockfrost-lode-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo Lode }
/\ Nothing
, "blockfrost-flint-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo Flint }
/\ Nothing
, "blockfrost-nufi-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo NuFi }
/\ Nothing
, "blockfrost-lace-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo Lace }
/\ Nothing
, "blockfrost-nami-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo Nami }
/\ Nothing
, "blockfrost-gero-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo Gero }
/\ Nothing
, "blockfrost-eternl-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo Eternl }
/\ Nothing
, "blockfrost-lode-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo Lode }
/\ Nothing
, "blockfrost-flint-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo Flint }
/\ Nothing
, "blockfrost-nufi-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo NuFi }
/\ Nothing
, "blockfrost-lace-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo Lace }
/\ Nothing
]
addLinks walletsWithBlockfrost examples
route walletsWithBlockfrost examples
getBlockfrostApiKey :: Effect (Maybe String)
getBlockfrostApiKey = do
storage <- localStorage =<< window
res <- getItem "BLOCKFROST_API_KEY" storage
when (isNothing res) do
Console.log
"Set BLOCKFROST_API_KEY LocalStorage key to use Blockfrost services."
Console.log "Run this in the browser console:"
Console.log " localStorage.setItem('BLOCKFROST_API_KEY', 'your-key-here');"
pure res
wallets :: Map E2EConfigName (ContractParams /\ Maybe String)
wallets = map (map walletName) <$> Map.fromFoldable
[ "nami" /\ testnetConfig' Nami /\ Nothing
, "gero" /\ testnetConfig' Gero /\ Nothing
, "flint" /\ testnetConfig' Flint /\ Nothing
, "eternl" /\ testnetConfig' Eternl /\ Nothing
, "lode" /\ testnetConfig' Lode /\ Nothing
, "nufi" /\ testnetConfig' NuFi /\ Nothing
, "lace" /\ testnetConfig' Lace /\ Nothing
, "nami-mainnet" /\ mainnetNamiConfig /\ Nothing
, "nami-mock" /\ testnetConfig' Nami /\ Just Nami
, "gero-mock" /\ testnetConfig' Gero /\ Just Gero
, "flint-mock" /\ testnetConfig' Flint /\ Just Flint
, "lode-mock" /\ testnetConfig' Lode /\ Just Lode
, "plutip-nami-mock" /\ testnetConfig' Nami /\ Just Nami
, "plutip-gero-mock" /\ testnetConfig' Gero /\ Just Gero
, "plutip-flint-mock" /\ testnetConfig' Flint /\ Just Flint
, "plutip-lode-mock" /\ testnetConfig' Lode /\ Just Lode
, "plutip-nufi-mock" /\ testnetConfig' NuFi /\ Just NuFi
]
where
testnetConfig' :: KnownWallet -> ContractParams
testnetConfig' wallet =
testnetConfig
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName wallet) { cip95: false }
}
mainnetNamiConfig :: ContractParams
mainnetNamiConfig =
mainnetConfig
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}
mkBlockfrostPreviewConfig :: Maybe String -> ContractParams
mkBlockfrostPreviewConfig apiKey =
testnetConfig
{ backendParams = mkBlockfrostBackendParams
{ blockfrostConfig: blockfrostPublicPreviewServerConfig
, blockfrostApiKey: apiKey
, confirmTxDelay: Just (Seconds 30.0)
}
}
mkBlockfrostPreprodConfig :: Maybe String -> ContractParams
mkBlockfrostPreprodConfig apiKey =
testnetConfig
{ backendParams = mkBlockfrostBackendParams
{ blockfrostConfig: blockfrostPublicPreprodServerConfig
, blockfrostApiKey: apiKey
, confirmTxDelay: Just (Seconds 30.0)
}
}
examples :: Map E2ETestName (Contract Unit)
examples = addSuccessLog <$> Map.fromFoldable
[ "AdditionalUtxos" /\ AdditionalUtxos.contract false
, "AlwaysMints" /\ AlwaysMints.contract
, "NativeScriptMints" /\ NativeScriptMints.contract
, "AlwaysSucceeds" /\ AlwaysSucceeds.contract
, "AlwaysSucceedsV2" /\ AlwaysSucceedsV2.contract
, "Datums" /\ Datums.contract
, "Wallet" /\ Wallet.contract
, "Pkh2Pkh" /\ Pkh2Pkh.contract
, "TxChaining" /\ TxChaining.contract
, "SendsToken" /\ SendsToken.contract
, "SignData" /\ SignData.contract
, "SignMultiple" /\ SignMultiple.contract
, "MintsMultipleTokens" /\ MintsMultipleTokens.contract
, "OneShotMinting" /\ OneShotMinting.contract
, "OneShotMintingV2" /\ OneShotMintingV2.contract
, "Cip30" /\ Cip30.contract
, "ReferenceInputsAndScripts" /\ ReferenceInputsAndScriptsV2.contract
, "Utxos" /\ Utxos.contract
, "ApplyArgs" /\ ApplyArgs.contract
, "Schnorr" /\ Schnorr.contract
, "ECDSA" /\ ECDSA.contract
, "PaysWithDatum" /\ PaysWithDatum.contract
, "DropTokens" /\ DropTokens.contract
, "ChangeGeneration1-1" /\
ChangeGeneration.checkChangeOutputsDistribution 1 1 3
, "ChangeGeneration3-1" /\
ChangeGeneration.checkChangeOutputsDistribution 3 1 5
, "ChangeGeneration1-3" /\
ChangeGeneration.checkChangeOutputsDistribution 1 3 7
, "IncludeDatum" /\ IncludeDatum.contract
]
addSuccessLog :: Contract Unit -> Contract Unit
addSuccessLog contract = contract *> logInfo' "[CTL TEST SUCCESS]"