1
1
{-# LANGUAGE DuplicateRecordFields #-}
2
+ {-# LANGUAGE OverloadedStrings #-}
2
3
3
4
module Anti.CliSpec
4
5
( spec
@@ -14,6 +15,8 @@ import Anti.Types
14
15
, Directory (.. )
15
16
, Host (.. )
16
17
, Options (.. )
18
+ , OracleCommand (.. )
19
+ , OutputReference (.. )
17
20
, Platform (.. )
18
21
, Port (.. )
19
22
, PublicKeyHash (.. )
@@ -26,7 +29,8 @@ import Anti.Types
26
29
)
27
30
import Control.Concurrent (threadDelay )
28
31
import Control.Concurrent.Async (async )
29
- import Data.Aeson (Value )
32
+ import Data.Aeson (Value , (.=) )
33
+ import Data.Aeson.Types (object )
30
34
import Network.Wai.Handler.Warp (run )
31
35
import System.Environment (withArgs )
32
36
import Test.Hspec
@@ -51,8 +55,6 @@ anti args = do
51
55
, " localhost"
52
56
, " --port"
53
57
, " 8084"
54
- , " --token-id"
55
- , " dummyTokenId"
56
58
]
57
59
++ args
58
60
-- Call the main function with the simulated arguments
@@ -65,13 +67,16 @@ spec :: Spec
65
67
spec = beforeAll_ runDummyServer $ do
66
68
it " can request user registration" $ do
67
69
let args =
68
- [ " register-public-key"
70
+ [ " user"
71
+ , " register-public-key"
69
72
, " --platform"
70
73
, " github"
71
74
, " --username"
72
75
, " bob"
73
76
, " --pubkeyhash"
74
77
, " 607a0d8a64616a407537edf0d9b59cf4cb509c556f6d2de4250ce15df2"
78
+ , " --token-id"
79
+ , " dummyTokenId"
75
80
]
76
81
let opts =
77
82
Options
@@ -92,13 +97,16 @@ spec = beforeAll_ runDummyServer $ do
92
97
`shouldReturn` (opts, dummyTxId)
93
98
it " can request user unregistration" $ do
94
99
let args =
95
- [ " unregister-public-key"
100
+ [ " user"
101
+ , " unregister-public-key"
96
102
, " --platform"
97
103
, " github"
98
104
, " --username"
99
105
, " bob"
100
106
, " --pubkeyhash"
101
107
, " 607a0d8a64616a407537edf0d9b59cf4cb509c556f6d2de4250ce15df2"
108
+ , " --token-id"
109
+ , " dummyTokenId"
102
110
]
103
111
104
112
let opts =
@@ -120,7 +128,8 @@ spec = beforeAll_ runDummyServer $ do
120
128
121
129
it " can request adding user to a project" $ do
122
130
let args =
123
- [ " register-role"
131
+ [ " user"
132
+ , " register-role"
124
133
, " --platform"
125
134
, " github"
126
135
, " --repository"
@@ -129,6 +138,8 @@ spec = beforeAll_ runDummyServer $ do
129
138
, " maintainer"
130
139
, " --username"
131
140
, " bob"
141
+ , " --token-id"
142
+ , " dummyTokenId"
132
143
]
133
144
let opts =
134
145
Options
@@ -149,7 +160,8 @@ spec = beforeAll_ runDummyServer $ do
149
160
150
161
it " can request removing user from a project" $ do
151
162
let args =
152
- [ " unregister-role"
163
+ [ " user"
164
+ , " unregister-role"
153
165
, " --platform"
154
166
, " github"
155
167
, " --repository"
@@ -158,6 +170,8 @@ spec = beforeAll_ runDummyServer $ do
158
170
, " maintainer"
159
171
, " --username"
160
172
, " bob"
173
+ , " --token-id"
174
+ , " dummyTokenId"
161
175
]
162
176
let opts =
163
177
Options
@@ -178,7 +192,8 @@ spec = beforeAll_ runDummyServer $ do
178
192
179
193
it " can request antithesis run" $ do
180
194
let args =
181
- [ " request-test"
195
+ [ " user"
196
+ , " request-test"
182
197
, " --platform"
183
198
, " github"
184
199
, " --repository"
@@ -187,6 +202,8 @@ spec = beforeAll_ runDummyServer $ do
187
202
, " bob"
188
203
, " --commit"
189
204
, " 9114528e2343e6fcf3c92de71364275227e6b16d"
205
+ , " --token-id"
206
+ , " dummyTokenId"
190
207
]
191
208
let opts =
192
209
Options
@@ -204,3 +221,79 @@ spec = beforeAll_ runDummyServer $ do
204
221
}
205
222
}
206
223
anti args `shouldReturn` (opts, dummyTxId)
224
+ it " can retract a request" $ do
225
+ let args =
226
+ [ " user"
227
+ , " retract-request"
228
+ , " --tx-hash"
229
+ , " dummyTxId"
230
+ , " --index"
231
+ , " 0"
232
+ ]
233
+ let opts =
234
+ Options
235
+ { host = Host " localhost"
236
+ , port = Port 8084
237
+ , command =
238
+ UserCommand
239
+ RetractRequest
240
+ { outputReference = OutputReference " dummyTxId" 0
241
+ }
242
+ }
243
+ anti args `shouldReturn` (opts, dummyTxId)
244
+ it " can create a token" $ do
245
+ let args =
246
+ [ " oracle"
247
+ , " create-token"
248
+ ]
249
+ let opts =
250
+ Options
251
+ { host = Host " localhost"
252
+ , port = Port 8084
253
+ , command =
254
+ OracleCommand
255
+ CreateToken
256
+ }
257
+ anti args
258
+ `shouldReturn` ( opts
259
+ , object
260
+ [ " tokenId" .= (" dummyTokenId" :: String )
261
+ ]
262
+ )
263
+ it " can delete a token" $ do
264
+ let args =
265
+ [ " oracle"
266
+ , " delete-token"
267
+ , " --token-id"
268
+ , " dummyTokenId"
269
+ ]
270
+ let opts =
271
+ Options
272
+ { host = Host " localhost"
273
+ , port = Port 8084
274
+ , command =
275
+ OracleCommand
276
+ (DeleteToken $ TokenId " dummyTokenId" )
277
+ }
278
+ anti args `shouldReturn` (opts, dummyTxId)
279
+ it " can get a token" $ do
280
+ let args =
281
+ [ " oracle"
282
+ , " get-token"
283
+ , " --token-id"
284
+ , " dummyTokenId"
285
+ ]
286
+ let opts =
287
+ Options
288
+ { host = Host " localhost"
289
+ , port = Port 8084
290
+ , command =
291
+ OracleCommand
292
+ (GetToken $ TokenId " dummyTokenId" )
293
+ }
294
+ anti args
295
+ `shouldReturn` ( opts
296
+ , object
297
+ [ " tokenId" .= (" dummyTokenId" :: String )
298
+ ]
299
+ )
0 commit comments