From d2d8d4f71d748f0b3f7dcc24a6d8f6a8c6ae63ac Mon Sep 17 00:00:00 2001 From: Ben Perez Date: Thu, 19 Jul 2018 16:05:54 -0400 Subject: [PATCH] Added option to turn on JSON output in Main.hs, removed json logic from Solidity.hs --- lib/Echidna/Solidity.hs | 11 ++++------- src/Main.hs | 7 ++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Echidna/Solidity.hs b/lib/Echidna/Solidity.hs index 0140816f..1e002302 100644 --- a/lib/Echidna/Solidity.hs +++ b/lib/Echidna/Solidity.hs @@ -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, prefix, solcArgs, outputJson) +import Echidna.Config (Config(..), sender, contractAddr, gasLimit, prefix, solcArgs) import EVM @@ -70,14 +70,11 @@ readContracts filePath = do -- | reads either the first contract found or the contract named `selectedContractName` within the solidity file at `filepath` readContract :: (MonadIO m, MonadThrow m, MonadReader Config m) => FilePath -> Maybe Text -> m SolcContract readContract filePath selectedContractName = do - config <- ask cs <- readContracts filePath c <- chooseContract cs selectedContractName - if config ^. outputJson then pure () - else do - warn (isNothing selectedContractName && 1 < length cs) - "Multiple contracts found in file, only analyzing the first" - liftIO $ print $ "Analyzing contract: " <> c ^. contractName + warn (isNothing selectedContractName && 1 < length cs) + "Multiple contracts found in file, only analyzing the first" + liftIO $ print $ "Analyzing contract: " <> c ^. contractName return c where chooseContract :: (MonadThrow m) => [SolcContract] -> Maybe Text -> m SolcContract chooseContract [] _ = throwM NoContracts diff --git a/src/Main.hs b/src/Main.hs index b5e6f889..93bde2c3 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -15,7 +15,6 @@ import Data.Semigroup ((<>)) import Echidna.Config import Echidna.Exec import Echidna.Solidity ---import Echidna.Internal.ZooRunner as Z import Hedgehog hiding (checkParallel) import Hedgehog.Internal.Property (GroupName(..), PropertyName(..)) @@ -56,7 +55,9 @@ main = do -- Read cmd line options and load config (Options file contract usecov configFile) <- execParser opts config <- maybe (pure defaultConfig) parseConfig configFile + let f = checkTest (config ^. returnType) + checkGroup = if config ^. outputJson then checkParallelJson else checkParallel flip runReaderT config $ do -- Load solidity contract and get VM @@ -65,7 +66,7 @@ main = do -- Run without coverage then do let prop t = ePropertySeq (`f` t) a v >>= \x -> return (PropertyName $ show t, x) - _ <- checkParallel . Group (GroupName file) =<< mapM prop ts + _ <- checkGroup . Group (GroupName file) =<< mapM prop ts return () -- Run with coverage @@ -81,7 +82,7 @@ main = do _ <- swapMVar y [] return (lastGen,x,y) - checkParallel . Group (GroupName file) =<< mapM prop xs + checkGroup . Group (GroupName file) =<< mapM prop xs ls <- liftIO $ mapM (readMVar . snd) tests let ci = foldl' (\acc xs -> unions (acc : map snd xs)) mempty ls