From 9b26749af5650393d4e3d92aa55577e2310d3236 Mon Sep 17 00:00:00 2001 From: Jongseung Lim Date: Wed, 28 Feb 2024 18:20:29 -0500 Subject: [PATCH 1/5] feat: add rpc-url and rpc-block to CLI --- src/Main.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index d78ec207a..3c8e36ab0 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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) @@ -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 } @@ -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.") @@ -206,8 +214,8 @@ versionOption = infoOption overrideConfig :: EConfig -> Options -> IO EConfig overrideConfig config Options{..} = do - rpcUrl <- Onchain.rpcUrlEnv - rpcBlock <- Onchain.rpcBlockEnv + rpcUrl <- maybe (Onchain.rpcUrlEnv) (pure . Just) cliRpcUrl + rpcBlock <- maybe (Onchain.rpcBlockEnv) (pure . Just) cliRpcBlock pure $ config { solConf = overrideSolConf config.solConf , campaignConf = overrideCampaignConf config.campaignConf From 38ebde2d7a0a42482943bee5b46aab199ea17b25 Mon Sep 17 00:00:00 2001 From: Jongseung Lim Date: Wed, 28 Feb 2024 18:25:45 -0500 Subject: [PATCH 2/5] chore: simplify with <|> --- src/Main.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 3c8e36ab0..7bf9c7ac0 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -214,8 +214,8 @@ versionOption = infoOption overrideConfig :: EConfig -> Options -> IO EConfig overrideConfig config Options{..} = do - rpcUrl <- maybe (Onchain.rpcUrlEnv) (pure . Just) cliRpcUrl - rpcBlock <- maybe (Onchain.rpcBlockEnv) (pure . Just) cliRpcBlock + rpcUrl <- (pure cliRpcUrl) <|> Onchain.rpcUrlEnv + rpcBlock <- (pure cliRpcBlock) <|> Onchain.rpcBlockEnv pure $ config { solConf = overrideSolConf config.solConf , campaignConf = overrideCampaignConf config.campaignConf From 61606d55c88c25783993e61231e3318c736e7e7e Mon Sep 17 00:00:00 2001 From: Jongseung Lim Date: Wed, 28 Feb 2024 18:50:16 -0500 Subject: [PATCH 3/5] chore: keep alphabet order of non-addr options --- src/Main.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 7bf9c7ac0..aeb5deddb 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -127,14 +127,14 @@ 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 , cliDeployer :: Maybe Addr , cliSender :: [Addr] , cliSeed :: Maybe Int - , cliRpcUrl :: Maybe Text - , cliRpcBlock :: Maybe Word64 , cliCryticArgs :: Maybe String , cliSolcArgs :: Maybe String } @@ -176,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 "Fetch contracts over a RPC URL.") <*> 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)) @@ -194,12 +200,6 @@ 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.") From 3381469f0635edd6704121069fa7b9ee15ef06c5 Mon Sep 17 00:00:00 2001 From: Jongseung Lim Date: Wed, 28 Feb 2024 19:37:00 -0500 Subject: [PATCH 4/5] chore: linting --- src/Main.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index aeb5deddb..f204dd60f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -181,7 +181,7 @@ options = Options <> help "Block number to use when fetching over RPC.") <*> optional (option str $ long "rpc-url" <> metavar "URL" - <> help "Fetch contracts over a RPC 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)) @@ -214,8 +214,8 @@ versionOption = infoOption overrideConfig :: EConfig -> Options -> IO EConfig overrideConfig config Options{..} = do - rpcUrl <- (pure cliRpcUrl) <|> Onchain.rpcUrlEnv - rpcBlock <- (pure cliRpcBlock) <|> Onchain.rpcBlockEnv + rpcUrl <- pure cliRpcUrl <|> Onchain.rpcUrlEnv + rpcBlock <- pure cliRpcBlock <|> Onchain.rpcBlockEnv pure $ config { solConf = overrideSolConf config.solConf , campaignConf = overrideCampaignConf config.campaignConf From a562a06cd80fe0900b63ec97a6c969da5eb519bf Mon Sep 17 00:00:00 2001 From: Jongseung Lim Date: Thu, 29 Feb 2024 10:53:35 -0500 Subject: [PATCH 5/5] fix: ensure operating on Maybe --- src/Main.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index f204dd60f..e7ac67342 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -214,14 +214,14 @@ versionOption = infoOption overrideConfig :: EConfig -> Options -> IO EConfig overrideConfig config Options{..} = do - rpcUrl <- pure cliRpcUrl <|> Onchain.rpcUrlEnv - rpcBlock <- pure cliRpcBlock <|> 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