diff --git a/lib/Echidna/.Exec.hs.swp b/lib/Echidna/.Exec.hs.swp new file mode 100644 index 00000000..1f928520 Binary files /dev/null and b/lib/Echidna/.Exec.hs.swp differ diff --git a/lib/Echidna/Config.hs b/lib/Echidna/Config.hs index b0d0d351..6f390612 100644 --- a/lib/Echidna/Config.hs +++ b/lib/Echidna/Config.hs @@ -1,46 +1,42 @@ -{-# LANGUAGE DeriveGeneric, FlexibleContexts, TemplateHaskell #-} +{-# LANGUAGE FlexibleContexts, TemplateHaskell #-} module Echidna.Config where import Control.Monad.Catch (MonadThrow(..)) import Control.Monad.IO.Class (MonadIO(..)) +import Control.Monad.Reader (ReaderT, runReaderT) import Control.Lens import Control.Exception (Exception) -import Control.Monad.Reader (ReaderT, runReaderT) import Data.Aeson -import GHC.Generics import qualified Data.ByteString.Char8 as BS import qualified Data.Yaml as Y import EVM.Types (W256) - data Config = Config { _solcArgs :: Maybe String , _epochs :: Int , _testLimit :: Int , _range :: Int , _gasLimit :: W256 } - deriving (Show, Generic) + deriving Show makeLenses ''Config -instance FromJSON Config - -defaultConfig :: Config -defaultConfig = Config - { _solcArgs = Nothing - , _epochs = 2 - , _testLimit = 10000 - , _range = 10 - , _gasLimit = 0xffffffffffffffff } - -withDefaultConfig :: ReaderT Config m a -> m a -withDefaultConfig = (flip runReaderT) defaultConfig +instance FromJSON Config where + parseJSON (Object v) = Config <$> v .:? "solcArgs" .!= Nothing + <*> v .:? "epochs" .!= 2 + <*> v .:? "testLimit" .!= 10000 + <*> v .:? "range" .!= 10 + <*> v .:? "gasLimit" .!= 0xffffffffffffffff + parseJSON _ = parseJSON (Object mempty) data ParseException = ParseException FilePath +defaultConfig :: Config +defaultConfig = either (error "Config parser got messed up :(") id $ Y.decodeEither "" + instance Show ParseException where show (ParseException f) = "Could not parse config file " ++ (show f) @@ -48,8 +44,11 @@ instance Exception ParseException parseConfig :: (MonadThrow m, MonadIO m) => FilePath -> m Config parseConfig file = do - content <- liftIO $ BS.readFile file - let parsedContent = Y.decode content :: Maybe Config - case parsedContent of - Nothing -> throwM (ParseException file) - (Just c) -> return c + content <- liftIO $ BS.readFile file + let parsedContent = Y.decode content :: Maybe Config + case parsedContent of + Nothing -> throwM (ParseException file) + (Just c) -> return c + +withDefaultConfig :: ReaderT Config m a -> m a +withDefaultConfig = (`runReaderT` defaultConfig) diff --git a/lib/Echidna/Solidity.hs b/lib/Echidna/Solidity.hs index bec11413..92bce2b3 100644 --- a/lib/Echidna/Solidity.hs +++ b/lib/Echidna/Solidity.hs @@ -8,7 +8,7 @@ import Control.Exception (Exception) import Control.Monad (liftM2) import Control.Monad.Catch (MonadThrow(..)) import Control.Monad.IO.Class (MonadIO(..)) -import Control.Monad.Reader (MonadReader, ask, runReaderT) +import Control.Monad.Reader (MonadReader, ask) import Control.Monad.State.Strict (MonadState, execState, modify, runState) import Data.Foldable (toList) import Data.List (find, partition) @@ -22,7 +22,7 @@ import System.IO.Temp (writeSystemTempFile) import qualified Data.Map as Map (lookup) import Echidna.ABI (SolSignature) -import Echidna.Config (Config(..), gasLimit, solcArgs, defaultConfig) +import Echidna.Config (Config(..), gasLimit, solcArgs) import EVM (Contract, VM, VMResult(..), contract, contracts, env, gas, loadContract, replaceCodeOfSelf, resetState, state) @@ -114,6 +114,5 @@ currentContract :: MonadThrow m => VM -> m Contract currentContract v = let a = v ^. state . contract in maybe (throwM $ BadAddr a) pure . Map.lookup a $ v ^. env . contracts - -addSolidity :: (MonadIO m, MonadThrow m, MonadState VM m) => FilePath -> Maybe Text -> m () -addSolidity f mc = insertContract =<< currentContract =<< view _1 <$> runReaderT (loadSolidity f mc) defaultConfig +addSolidity :: (MonadIO m, MonadReader Config m, MonadState VM m, MonadThrow m) => FilePath -> Maybe Text -> m () +addSolidity f mc = insertContract =<< currentContract =<< view _1 <$> loadSolidity f mc diff --git a/solidity/config.yaml b/solidity/config.yaml index 15c7f7c4..a1a7a4ae 100644 --- a/solidity/config.yaml +++ b/solidity/config.yaml @@ -1,4 +1,2 @@ -_epochs: 2 -_gasLimit: 0xfffff -_testLimit: 10000 -_range: 10 \ No newline at end of file +epochs: 3 +range: 20