add prefix config, clean up config types

pull/73/head
JP Smith 6 years ago
parent b483e0879f
commit a5f40a8234
  1. 30
      lib/Echidna/Config.hs
  2. 4
      lib/Echidna/Exec.hs
  3. 4
      lib/Echidna/Solidity.hs
  4. 6
      solidity/config.yaml

@ -8,6 +8,8 @@ import Control.Monad.Reader (ReaderT, runReaderT)
import Control.Lens
import Control.Exception (Exception)
import Data.Aeson
import Data.Text (Text)
import Hedgehog (ShrinkLimit, TestLimit)
import qualified Data.ByteString.Char8 as BS
import qualified Data.Yaml as Y
@ -19,30 +21,34 @@ import EVM.Types (Addr, W256)
data Config = Config
{ _solcArgs :: Maybe String
, _epochs :: Int
, _testLimit :: Int
, _range :: Int
, _contractAddr :: Addr
, _sender :: Addr
, _addrList :: Maybe [Addr]
, _gasLimit :: W256
, _shrinkLimit :: W256
, _testLimit :: TestLimit
, _shrinkLimit :: ShrinkLimit
, _returnType :: PropertyType
, _prefix :: Text
}
deriving Show
makeLenses ''Config
instance FromJSON Config where
parseJSON (Object v) = Config <$> v .:? "solcArgs" .!= Nothing
<*> v .:? "epochs" .!= 2
<*> v .:? "testLimit" .!= 10000
<*> v .:? "range" .!= 10
<*> v .:? "contractAddr" .!= 0x00a329c0648769a73afac7f9381e08fb43dbea72
<*> v .:? "sender" .!= 0x00a329c0648769a73afac7f9381e08fb43dbea70
<*> v .:? "addrList" .!= Nothing
<*> v .:? "gasLimit" .!= 0xffffffffffffffff
<*> v .:? "shrinkLimit" .!= 1000
<*> v .:? "return" .!= ShouldReturnTrue
parseJSON (Object v) =
let fromInt s n = ((v .:? s :: Y.Parser (Maybe Int)) <&> fmap fromIntegral) .!= n in
Config <$> v .:? "solcArgs" .!= Nothing
<*> v .:? "epochs" .!= 2
<*> v .:? "range" .!= 10
<*> v .:? "contractAddr" .!= 0x00a329c0648769a73afac7f9381e08fb43dbea72
<*> v .:? "sender" .!= 0x00a329c0648769a73afac7f9381e08fb43dbea70
<*> v .:? "addrList" .!= Nothing
<*> v .:? "gasLimit" .!= 0xffffffffffffffff
<*> fromInt "testLimit" 10000
<*> fromInt "shrinkLimit" 1000
<*> v .:? "return" .!= ShouldReturnTrue
<*> v .:? "prefix" .!= "echidna_"
parseJSON _ = parseJSON (Object mempty)
newtype ParseException = ParseException FilePath

@ -176,8 +176,8 @@ eCommandCoverage cov p ts conf = let useConf = flip runReaderT conf in case cov
(\(Call c) -> execCallCoverage c) p) xs
configProperty :: Config -> PropertyConfig -> PropertyConfig
configProperty config = \x -> x { propertyTestLimit = fromIntegral $ config ^. testLimit
, propertyShrinkLimit = fromIntegral $ config ^. shrinkLimit
configProperty config = \x -> x { propertyTestLimit = config ^. testLimit
, propertyShrinkLimit = config ^. shrinkLimit
}
ePropertyUsing :: (MonadCatch m, MonadTest m, MonadReader Config n)

@ -22,7 +22,7 @@ import System.IO.Temp (writeSystemTempFile)
import qualified Data.Map as Map (lookup)
import Echidna.ABI (SolSignature)
import Echidna.Config (Config(..), sender, contractAddr, gasLimit, solcArgs)
import Echidna.Config (Config(..), sender, contractAddr, gasLimit, prefix, solcArgs)
import EVM
@ -103,7 +103,7 @@ loadSolidity filePath selectedContract = do
loadContract (vm ^. state . contract)
loaded = execState load $ execState (replaceCodeOfSelf bc) vm
abi = map (liftM2 (,) (view methodName) (map snd . view methodInputs)) . toList $ c ^. abiMap
(tests, funs) = partition (isPrefixOf "echidna_" . fst) abi
(tests, funs) = partition (isPrefixOf (conf ^. prefix) . fst) abi
case find (not . null . snd) tests of
Nothing -> return (loaded, funs, fst <$> tests)
(Just (t,_)) -> throwM $ TestArgsFound t

@ -1,7 +1,7 @@
#Arguments to solc
#solcArgs:
#Choose the number of epochs to use in coverage-guided testing
epochs: 2
epochs: 4
#Set the gas limit for each test
gasLimit: 0xfffff
#Number of tests that will run for each property
@ -17,4 +17,6 @@ sender: 0x00a329c0648769a73afac7f9381e08fb43dbea70
#Gas limit
#gasLimit
#Shrink Limit
shrinkLimit: 1000
shrinkLimit: 1000
#Test Prefix
prefix: echidna_

Loading…
Cancel
Save