Skip to content

Commit

Permalink
Use assertCommand in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imalsogreg committed Nov 17, 2023
1 parent c173b8d commit 59733d0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/Chainweb/Test/Pact/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import Data.ByteString (ByteString)
import qualified Data.ByteString.Short as BS
import Data.Decimal
import Data.Default (def)
import Data.Either (isRight)
import Data.Foldable
import qualified Data.HashMap.Strict as HM
import Data.IORef
Expand Down Expand Up @@ -185,6 +186,7 @@ import Chainweb.Pact.Backend.SQLite.DirectV2
import Chainweb.Pact.Backend.Types
import Chainweb.Pact.Backend.Utils
import Chainweb.Pact.PactService
import Chainweb.Pact.RestAPI.Server (validateCommand)
import Chainweb.Pact.Service.PactQueue
import Chainweb.Pact.Service.Types
import Chainweb.Pact.Types
Expand Down Expand Up @@ -560,8 +562,18 @@ mkCmd nonce rpc = defaultCmd
--
-- TODO: Use the new `assertCommand` function.
buildCwCmd :: (MonadThrow m, MonadIO m) => CmdBuilder -> m ChainwebTransaction
buildCwCmd cmd = buildRawCmd cmd >>= \c -> case verifyCommand c of
ProcSucc r -> return $ fmap (mkPayloadWithText c) r
buildCwCmd cmd = buildRawCmd cmd >>= \(c :: Command ByteString) ->
let
commandText :: Command Text = T.decodeUtf8 <$> c
cmdValid = isRight $
validateCommand (fromJust $ _cbNetworkId cmd) (_cbChainId cmd) commandText

in
case verifyCommand c of
ProcSucc r ->
if cmdValid
then return $ fmap (mkPayloadWithText c) r
else throwM $ userError $ "buildCmd failed: "
ProcFail e -> throwM $ userError $ "buildCmd failed: " ++ e


Expand Down

0 comments on commit 59733d0

Please sign in to comment.