@@ -90,34 +90,13 @@ import Validation (Validation)
9090type ValidateWithContext m a =
9191 Validate UpdateTestRunFailure (WithContext m ) a
9292
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 ))
11695 => TokenId
11796 -> TestRunId
118- -> (TestRun -> ValidateWithContext m a )
97+ -> (Fact TestRun ( TestRunState phase ) -> ValidateWithContext m a )
11998 -> ValidateWithContext m a
120- withResolvedTestRun tk (TestRunId testRunId) cont = do
99+ withPreviousTestRunState tk (TestRunId testRunId) cont = do
121100 facts <- lift
122101 $ fmap parseFacts
123102 $ withMPFS
@@ -126,24 +105,25 @@ withResolvedTestRun tk (TestRunId testRunId) cont = do
126105 match (Fact key _) = case keyHash key of
127106 Nothing -> False
128107 Just keyId -> keyId == testRunId
129- testRun <-
108+ fact <-
130109 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}
133116
134117updateTestRunState
135118 :: (Monad m , FromJSON Maybe (TestRunState phase ))
136119 => TokenId
137120 -> TestRunId
138- -> ( TestRun
139- -> TestRunState phase
121+ -> ( Fact TestRun (TestRunState phase )
140122 -> ValidateWithContext m a
141123 )
142124 -> 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
147127
148128agentCmd
149129 :: MonadIO m
@@ -156,15 +136,15 @@ agentCmd = \case
156136 BlackList tokenId wallet platform repo ->
157137 blackList tokenId wallet platform repo
158138 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
168148
169149data IsReady = NotReady | Ready
170150 deriving (Show , Eq )
@@ -345,11 +325,10 @@ signAndSubmitAnUpdate
345325 )
346326 -> TokenId
347327 -> Wallet
348- -> key
349- -> old
328+ -> Fact key old
350329 -> new
351330 -> ValidateWithContext m (WithTxHash new )
352- signAndSubmitAnUpdate validate tokenId wallet testRun oldState newState = do
331+ signAndSubmitAnUpdate validate tokenId wallet ( Fact testRun oldState) newState = do
353332 let requester = owner wallet
354333 validation <- lift $ askValidation $ Just tokenId
355334 mconfig <- lift $ askConfig tokenId
@@ -374,55 +353,49 @@ reportCommand
374353 :: Monad m
375354 => TokenId
376355 -> Wallet
377- -> TestRun
378- -> TestRunState RunningT
356+ -> Fact TestRun (TestRunState RunningT )
379357 -> Duration
380358 -> URL
381359 -> ValidateWithContext
382360 m
383361 (WithTxHash (TestRunState DoneT ))
384- reportCommand tokenId wallet testRun oldState duration url =
362+ reportCommand tokenId wallet fact duration url =
385363 signAndSubmitAnUpdate
386364 validateToDoneUpdate
387365 tokenId
388366 wallet
389- testRun
390- oldState
391- $ Finished oldState duration url
367+ fact
368+ $ Finished (factValue fact) duration url
392369
393370rejectCommand
394371 :: Monad m
395372 => TokenId
396373 -> Wallet
397- -> TestRun
398- -> TestRunState PendingT
374+ -> Fact TestRun (TestRunState PendingT )
399375 -> [TestRunRejection ]
400376 -> ValidateWithContext
401377 m
402378 (WithTxHash (TestRunState DoneT ))
403- rejectCommand tokenId wallet testRun testRunState reason =
379+ rejectCommand tokenId wallet fact reason =
404380 signAndSubmitAnUpdate
405381 validateToDoneUpdate
406382 tokenId
407383 wallet
408- testRun
409- testRunState
410- $ Rejected testRunState reason
384+ fact
385+ $ Rejected (factValue fact) reason
411386
412387acceptCommand
413388 :: Monad m
414389 => TokenId
415390 -> Wallet
416- -> TestRun
417- -> TestRunState PendingT
391+ -> Fact TestRun (TestRunState PendingT )
418392 -> ValidateWithContext
419393 m
420394 (WithTxHash (TestRunState RunningT ))
421- acceptCommand tokenId wallet testRun testRunState =
395+ acceptCommand tokenId wallet fact =
422396 signAndSubmitAnUpdate
423397 validateToRunningUpdate
424398 tokenId
425399 wallet
426- testRun
427- testRunState
428- $ Accepted testRunState
400+ fact
401+ $ Accepted (factValue fact)
0 commit comments