@@ -90,34 +90,13 @@ import Validation (Validation)
90
90
type ValidateWithContext m a =
91
91
Validate UpdateTestRunFailure (WithContext m ) a
92
92
93
- withExpectedState
94
- :: (FromJSON Maybe (TestRunState phase ), Monad m )
95
- => TokenId
96
- -> TestRun
97
- -> (TestRunState phase -> ValidateWithContext m result )
98
- -> ValidateWithContext m result
99
- withExpectedState tokenId testRun cont = do
100
- facts <- lift
101
- $ fmap parseFacts
102
- $ withMPFS
103
- $ \ mpfs -> mpfsGetTokenFacts mpfs tokenId
104
- jsonKey <- toJSON testRun
105
- jPreviousState <-
106
- liftMaybe UpdateTestRunPreviousStateNotFound
107
- $ find ((== jsonKey) . factKey) facts
108
- value <-
109
- liftMaybe UpdateTestRunWrongPreviousState
110
- $ fromJSON
111
- $ factValue jPreviousState
112
- cont value
113
-
114
- withResolvedTestRun
115
- :: Monad m
93
+ withPreviousTestRunState
94
+ :: (Monad m , FromJSON Maybe (TestRunState phase ))
116
95
=> TokenId
117
96
-> TestRunId
118
- -> (TestRun -> ValidateWithContext m a )
97
+ -> (Fact TestRun ( TestRunState phase ) -> ValidateWithContext m a )
119
98
-> ValidateWithContext m a
120
- withResolvedTestRun tk (TestRunId testRunId) cont = do
99
+ withPreviousTestRunState tk (TestRunId testRunId) cont = do
121
100
facts <- lift
122
101
$ fmap parseFacts
123
102
$ withMPFS
@@ -126,24 +105,25 @@ withResolvedTestRun tk (TestRunId testRunId) cont = do
126
105
match (Fact key _) = case keyHash key of
127
106
Nothing -> False
128
107
Just keyId -> keyId == testRunId
129
- testRun <-
108
+ fact <-
130
109
liftMaybe UpdateTestRunTestRunIdNotResolved
131
- $ factKey <$> find match facts
132
- cont testRun
110
+ $ find match facts
111
+ value <-
112
+ liftMaybe UpdateTestRunWrongPreviousState
113
+ $ fromJSON
114
+ $ factValue fact
115
+ cont fact{factValue = value}
133
116
134
117
updateTestRunState
135
118
:: (Monad m , FromJSON Maybe (TestRunState phase ))
136
119
=> TokenId
137
120
-> TestRunId
138
- -> ( TestRun
139
- -> TestRunState phase
121
+ -> ( Fact TestRun (TestRunState phase )
140
122
-> ValidateWithContext m a
141
123
)
142
124
-> WithContext m (AValidationResult UpdateTestRunFailure a )
143
- updateTestRunState tokenId key f = do
144
- runValidate
145
- $ withResolvedTestRun tokenId key
146
- $ \ testRun -> withExpectedState tokenId testRun $ f testRun
125
+ updateTestRunState tokenId key =
126
+ runValidate . withPreviousTestRunState tokenId key
147
127
148
128
agentCmd
149
129
:: MonadIO m
@@ -156,15 +136,15 @@ agentCmd = \case
156
136
BlackList tokenId wallet platform repo ->
157
137
blackList tokenId wallet platform repo
158
138
DownloadAssets tokenId key dir -> downloadAssets tokenId key dir
159
- Accept tokenId wallet key () -> do
160
- updateTestRunState tokenId key $ \ testRun testRunState ->
161
- acceptCommand tokenId wallet testRun testRunState
162
- Reject tokenId wallet key () reason -> do
163
- updateTestRunState tokenId key $ \ testRun testRunState ->
164
- rejectCommand tokenId wallet testRun testRunState reason
165
- Report tokenId wallet key () duration url -> do
166
- updateTestRunState tokenId key $ \ testRun testRunState ->
167
- reportCommand tokenId wallet testRun testRunState duration url
139
+ Accept tokenId wallet key () ->
140
+ updateTestRunState tokenId key $ \ fact ->
141
+ acceptCommand tokenId wallet fact
142
+ Reject tokenId wallet key () reason ->
143
+ updateTestRunState tokenId key $ \ fact ->
144
+ rejectCommand tokenId wallet fact reason
145
+ Report tokenId wallet key () duration url ->
146
+ updateTestRunState tokenId key $ \ fact ->
147
+ reportCommand tokenId wallet fact duration url
168
148
169
149
data IsReady = NotReady | Ready
170
150
deriving (Show , Eq )
@@ -345,11 +325,10 @@ signAndSubmitAnUpdate
345
325
)
346
326
-> TokenId
347
327
-> Wallet
348
- -> key
349
- -> old
328
+ -> Fact key old
350
329
-> new
351
330
-> ValidateWithContext m (WithTxHash new )
352
- signAndSubmitAnUpdate validate tokenId wallet testRun oldState newState = do
331
+ signAndSubmitAnUpdate validate tokenId wallet ( Fact testRun oldState) newState = do
353
332
let requester = owner wallet
354
333
validation <- lift $ askValidation $ Just tokenId
355
334
mconfig <- lift $ askConfig tokenId
@@ -374,55 +353,49 @@ reportCommand
374
353
:: Monad m
375
354
=> TokenId
376
355
-> Wallet
377
- -> TestRun
378
- -> TestRunState RunningT
356
+ -> Fact TestRun (TestRunState RunningT )
379
357
-> Duration
380
358
-> URL
381
359
-> ValidateWithContext
382
360
m
383
361
(WithTxHash (TestRunState DoneT ))
384
- reportCommand tokenId wallet testRun oldState duration url =
362
+ reportCommand tokenId wallet fact duration url =
385
363
signAndSubmitAnUpdate
386
364
validateToDoneUpdate
387
365
tokenId
388
366
wallet
389
- testRun
390
- oldState
391
- $ Finished oldState duration url
367
+ fact
368
+ $ Finished (factValue fact) duration url
392
369
393
370
rejectCommand
394
371
:: Monad m
395
372
=> TokenId
396
373
-> Wallet
397
- -> TestRun
398
- -> TestRunState PendingT
374
+ -> Fact TestRun (TestRunState PendingT )
399
375
-> [TestRunRejection ]
400
376
-> ValidateWithContext
401
377
m
402
378
(WithTxHash (TestRunState DoneT ))
403
- rejectCommand tokenId wallet testRun testRunState reason =
379
+ rejectCommand tokenId wallet fact reason =
404
380
signAndSubmitAnUpdate
405
381
validateToDoneUpdate
406
382
tokenId
407
383
wallet
408
- testRun
409
- testRunState
410
- $ Rejected testRunState reason
384
+ fact
385
+ $ Rejected (factValue fact) reason
411
386
412
387
acceptCommand
413
388
:: Monad m
414
389
=> TokenId
415
390
-> Wallet
416
- -> TestRun
417
- -> TestRunState PendingT
391
+ -> Fact TestRun (TestRunState PendingT )
418
392
-> ValidateWithContext
419
393
m
420
394
(WithTxHash (TestRunState RunningT ))
421
- acceptCommand tokenId wallet testRun testRunState =
395
+ acceptCommand tokenId wallet fact =
422
396
signAndSubmitAnUpdate
423
397
validateToRunningUpdate
424
398
tokenId
425
399
wallet
426
- testRun
427
- testRunState
428
- $ Accepted testRunState
400
+ fact
401
+ $ Accepted (factValue fact)
0 commit comments