Skip to content

Commit

Permalink
feat: add CLI commands for RPC URL and block number (#1194)
Browse files Browse the repository at this point in the history
* feat: add rpc-url and rpc-block to CLI

* chore: simplify with <|>

* chore: keep alphabet order of non-addr options

* chore: linting

* fix: ensure operating on Maybe
  • Loading branch information
penandlim committed Feb 29, 2024
1 parent d9f5016 commit 8339bad
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 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 @@ -127,6 +127,8 @@ data Options = Options
, cliAllContracts :: Bool
, cliTimeout :: Maybe Int
, cliTestLimit :: Maybe Int
, cliRpcBlock :: Maybe Word64
, cliRpcUrl :: Maybe Text
, cliShrinkLimit :: Maybe Int
, cliSeqLen :: Maybe Int
, cliContractAddr :: Maybe Addr
Expand Down Expand Up @@ -174,6 +176,12 @@ options = Options
<*> optional (option auto $ long "test-limit"
<> metavar "INTEGER"
<> help ("Number of sequences of transactions to generate during testing. Default is " ++ show defaultTestLimit))
<*> optional (option auto $ long "rpc-block"
<> metavar "BLOCK"
<> help "Block number to use when fetching over RPC.")
<*> optional (option str $ long "rpc-url"
<> metavar "URL"
<> help "RPC URL to fetch contracts over.")
<*> optional (option auto $ long "shrink-limit"
<> metavar "INTEGER"
<> help ("Number of tries to attempt to shrink a failing sequence of transactions. Default is " ++ show defaultShrinkLimit))
Expand Down Expand Up @@ -206,14 +214,14 @@ versionOption = infoOption

overrideConfig :: EConfig -> Options -> IO EConfig
overrideConfig config Options{..} = do
rpcUrl <- Onchain.rpcUrlEnv
rpcBlock <- Onchain.rpcBlockEnv
envRpcUrl <- Onchain.rpcUrlEnv
envRpcBlock <- Onchain.rpcBlockEnv
pure $
config { solConf = overrideSolConf config.solConf
, campaignConf = overrideCampaignConf config.campaignConf
, uiConf = overrideUiConf config.uiConf
, rpcUrl = rpcUrl <|> config.rpcUrl
, rpcBlock = rpcBlock <|> config.rpcBlock
, rpcUrl = cliRpcUrl <|> envRpcUrl <|> config.rpcUrl
, rpcBlock = cliRpcBlock <|> envRpcBlock <|> config.rpcBlock
}
& overrideFormat
where
Expand Down

0 comments on commit 8339bad

Please sign in to comment.