diff --git a/lib/Echidna.hs b/lib/Echidna.hs index df156b433..06265a3d9 100644 --- a/lib/Echidna.hs +++ b/lib/Echidna.hs @@ -43,7 +43,9 @@ prepareContract :: (MonadCatch m, MonadReader x m, MonadIO m, MonadFail m, Has S => EConfig -> NE.NonEmpty FilePath -> Maybe ContractName -> Seed -> m (VM, SourceCache, [SolcContract], World, [EchidnaTest], Maybe GenDict, [[Tx]]) prepareContract cfg fs c g = do - ctxs <- liftIO $ loadTxs cd + ctxs1 <- liftIO $ loadTxs (fmap (++ "/reproducers/") cd) + ctxs2 <- liftIO $ loadTxs (fmap (++ "/coverage/") cd) + let ctxs = ctxs1 ++ ctxs2 -- compile and load contracts (cs, scs) <- Echidna.Solidity.contracts fs diff --git a/lib/Echidna/Output/Corpus.hs b/lib/Echidna/Output/Corpus.hs index 8e7b5b1e1..728486be4 100644 --- a/lib/Echidna/Output/Corpus.hs +++ b/lib/Echidna/Output/Corpus.hs @@ -14,19 +14,18 @@ import Echidna.Output.Utils saveTxs :: Maybe FilePath -> [[Tx]] -> IO () saveTxs (Just d) txs = mapM_ saveTx txs where - saveTx v = do let fn = d ++ "/coverage/" ++ (show . hash . show) v ++ ".txt" + saveTx v = do let fn = d ++ (show . hash . show) v ++ ".txt" b <- doesFileExist fn unless b $ encodeFile fn (toJSON v) saveTxs Nothing _ = pure () loadTxs :: Maybe FilePath -> IO [[Tx]] loadTxs (Just d) = do - let d' = d ++ "/coverage" - createDirectoryIfMissing True d' - fs <- listDirectory d' + createDirectoryIfMissing True d + fs <- listDirectory d css <- mapM readCall <$> mapM makeRelativeToCurrentDirectory fs - txs <- catMaybes <$> withCurrentDirectory d' css - putStrLn ("Loaded total of " ++ show (length txs) ++ " transactions from " ++ d') + txs <- catMaybes <$> withCurrentDirectory d css + putStrLn ("Loaded total of " ++ show (length txs) ++ " transactions from " ++ d) return txs where readCall f = decodeStrict <$> BS.readFile f diff --git a/src/Main.hs b/src/Main.hs index a6ec20ef7..aba7c27e4 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -28,7 +28,7 @@ import Echidna.Config import Echidna.Types.Config hiding (cfg) import Echidna.Types.Solidity import Echidna.Types.Campaign -import Echidna.Types.Test (TestMode) +import Echidna.Types.Test (TestMode, testReproducer) import Echidna.Test (validateTestMode) import Echidna.Campaign (isSuccess) import Echidna.UI @@ -133,7 +133,8 @@ main = do return (sc, cs, r) -- save corpus - saveTxs cd (snd <$> DS.toList (cpg ^. corpus)) + saveTxs (fmap (++ "/reproducers/") cd) (filter (not . null) $ map (^. testReproducer) $ cpg ^. tests) + saveTxs (fmap (++ "/coverage/") cd) (snd <$> DS.toList (cpg ^. corpus)) -- get current time to save coverage t <- getSystemTime