fixed config parsing

pull/70/head
JP Smith 6 years ago
parent 42225b20c6
commit cb0238b533
  1. BIN
      lib/Echidna/.Exec.hs.swp
  2. 43
      lib/Echidna/Config.hs
  3. 9
      lib/Echidna/Solidity.hs
  4. 6
      solidity/config.yaml

Binary file not shown.

@ -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)

@ -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

@ -1,4 +1,2 @@
_epochs: 2
_gasLimit: 0xfffff
_testLimit: 10000
_range: 10
epochs: 3
range: 20

Loading…
Cancel
Save