Skip to content

Commit

Permalink
Make cbChainId a Text to allow testing invalid chain IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundnoble committed Jan 7, 2025
1 parent f84ae9a commit 36614ae
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Chainweb/Pact/RestAPI/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ validateCommand v cid (fmap encodeUtf8 -> cmdBs) = case parsedCmd of

-- TODO: all of the functions in this module can instead grab the current block height from consensus
-- and pass it here to get a better estimate of what behavior is correct.
validatePact5Command :: ChainwebVersion -> ChainId -> Pact5.Command Text -> Either String Pact5.Transaction
validatePact5Command _v _cid cmdText = case parsedCmd of
validatePact5Command :: ChainwebVersion -> Pact5.Command Text -> Either String Pact5.Transaction
validatePact5Command _v cmdText = case parsedCmd of
Right (commandParsed :: Pact5.Transaction) ->
if isRight (Pact5.assertCommand commandParsed)
then Right commandParsed
Expand Down
8 changes: 4 additions & 4 deletions test/lib/Chainweb/Test/Pact5/CmdBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ data CmdBuilder = CmdBuilder
, _cbVerifiers :: ![Verifier ParsedVerifierProof]
, _cbRPC :: !(PactRPC Text)
, _cbNonce :: !(Maybe Text)
, _cbChainId :: !Chainweb.ChainId
, _cbChainId :: !Text
, _cbSender :: !Text
, _cbGasLimit :: !GasLimit
, _cbGasPrice :: !GasPrice
Expand Down Expand Up @@ -178,7 +178,7 @@ defaultCmd cid = CmdBuilder
, _cbVerifiers = []
, _cbRPC = mkExec' "1"
, _cbNonce = Nothing
, _cbChainId = cid
, _cbChainId = chainIdToText cid
, _cbSender = "sender00"
, _cbGasLimit = GasLimit (Gas 10_000)
, _cbGasPrice = GasPrice 0.000_1
Expand All @@ -190,7 +190,7 @@ defaultCmd cid = CmdBuilder
-- TODO: Use the new `assertPact4Command` function.
buildCwCmd :: (MonadThrow m, MonadIO m) => ChainwebVersion -> CmdBuilder -> m Pact5.Transaction
buildCwCmd v cmd = buildTextCmd v cmd >>= \(c :: Command Text) ->
case validatePact5Command v (_cbChainId cmd) c of
case validatePact5Command v c of
Left err -> throwM $ userError $ "buildCwCmd failed: " ++ err
Right cmd' -> return cmd'

Expand Down Expand Up @@ -241,7 +241,7 @@ buildRawCmd v CmdBuilder{..} = do
pure cmd
where
nid = NetworkId (sshow v)
cid = ChainId $ sshow (chainIdInt _cbChainId :: Int)
cid = ChainId _cbChainId

dieL :: MonadThrow m => [Char] -> Either [Char] a -> m a
dieL msg = either (\s -> throwM $ userError $ msg ++ ": " ++ s) return
Expand Down
2 changes: 1 addition & 1 deletion test/unit/Chainweb/Test/Pact5/PactServiceTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ testNewBlockExcludesInvalid baseRdb = runResourceT $ do
]
}

badChain <- buildCwCmd v $ transferCmd 1.0 & set cbChainId (unsafeChainId 1)
badChain <- buildCwCmd v $ transferCmd 1.0 & set cbChainId (chainIdToText $ unsafeChainId 1)

let pact4Hash = Pact5.Hash . Pact4.unHash . Pact4.toUntypedHash . Pact4._cmdHash
_ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
Expand Down
1 change: 0 additions & 1 deletion test/unit/Chainweb/Test/Pact5/RemotePactTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ instance HasFixture Fixture where
instance HasFixture a => HasFixture (IO a) where
remotePactTestFixture = (>>= remotePactTestFixture)


type Step = String -> IO ()

mkFixture :: ChainwebVersion -> RocksDb -> ResourceT IO Fixture
Expand Down

0 comments on commit 36614ae

Please sign in to comment.