Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CLI commands for RPC URL and block number #1194

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Data.Set qualified as Set
import Data.Text (Text)
import Data.Time.Clock.System (getSystemTime, systemSeconds)
import Data.Version (showVersion)
import Data.Word (Word8, Word16)
import Data.Word (Word8, Word16, Word64)
import Main.Utf8 (withUtf8)
import Options.Applicative
import Paths_echidna (version)
Expand Down Expand Up @@ -133,6 +133,8 @@ data Options = Options
, cliDeployer :: Maybe Addr
, cliSender :: [Addr]
, cliSeed :: Maybe Int
, cliRpcUrl :: Maybe Text
, cliRpcBlock :: Maybe Word64
, cliCryticArgs :: Maybe String
, cliSolcArgs :: Maybe String
}
Expand Down Expand Up @@ -192,6 +194,12 @@ options = Options
<*> optional (option auto $ long "seed"
<> metavar "SEED"
<> help "Run with a specific seed.")
<*> optional (option str $ long "rpc-url"
<> metavar "URL"
<> help "Fetch contracts over a RPC URL.")
<*> optional (option auto $ long "rpc-block"
<> metavar "BLOCK"
<> help "Block number to use when fetching over RPC.")
<*> optional (option str $ long "crytic-args"
<> metavar "ARGS"
<> help "Additional arguments to use in crytic-compile for the compilation of the contract to test.")
Expand All @@ -206,8 +214,8 @@ versionOption = infoOption

overrideConfig :: EConfig -> Options -> IO EConfig
overrideConfig config Options{..} = do
rpcUrl <- Onchain.rpcUrlEnv
rpcBlock <- Onchain.rpcBlockEnv
rpcUrl <- (pure cliRpcUrl) <|> Onchain.rpcUrlEnv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately won't work since <|> here operates on IO, not on Maybe. Can you rename rpcUrl to envRpcUrl (same for block) and change this instead: rpcUrl = cliRpcUrl <|> envRpcUrl <|> config.rpcUrl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thanks for the quick review!

rpcBlock <- (pure cliRpcBlock) <|> Onchain.rpcBlockEnv
pure $
config { solConf = overrideSolConf config.solConf
, campaignConf = overrideCampaignConf config.campaignConf
Expand Down