Skip to content

Commit 7d5b25a

Browse files
Show all events from all the transactions when a property or assertion fails (#1475)
* show all events from all the transaction when a property or assertion fails * fixed tests and removed ECHIDNA_SAVE_TRACES
1 parent 00f14cc commit 7d5b25a

File tree

5 files changed

+9
-19
lines changed

5 files changed

+9
-19
lines changed

lib/Echidna/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ instance FromJSON EConfigWithUsage where
5555
<*> testConfParser
5656
<*> txConfParser
5757
<*> (UIConf <$> v ..:? "timeout" <*> formatParser)
58+
<*> v ..:? "allEvents" ..!= False
5859
<*> v ..:? "rpcUrl"
5960
<*> v ..:? "rpcBlock"
6061
<*> v ..:? "etherscanApiKey"

lib/Echidna/Exec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ execTxWith executeTx tx = do
9090
if hasSelfdestructed vm tx.dst then
9191
pure $ VMFailure (Revert (ConcreteBuf ""))
9292
else do
93-
#traces .= emptyEvents
93+
config <- asks (.cfg)
94+
when (not config.allEvents) $ #traces .= emptyEvents
9495
vmBeforeTx <- get
9596
setupTx tx
9697
case tx.call of

lib/Echidna/Types/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ data EConfig = EConfig
4444
, txConf :: TxConf
4545
, uiConf :: UIConf
4646

47+
, allEvents :: Bool
4748
, rpcUrl :: Maybe Text
4849
, rpcBlock :: Maybe Word64
4950
, etherscanApiKey :: Maybe Text

src/Main.hs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Main where
44

5-
import Control.Monad (unless, forM_, when)
5+
import Control.Monad (unless, forM_)
66
import Control.Monad.Reader (runReaderT, liftIO)
77
import Control.Monad.Random (getRandomR)
88
import Data.Aeson.Key qualified as Aeson.Key
@@ -12,7 +12,7 @@ import Data.Hashable (hash)
1212
import Data.IORef (readIORef)
1313
import Data.List.NonEmpty qualified as NE
1414
import Data.Map qualified as Map
15-
import Data.Maybe (fromMaybe, isJust)
15+
import Data.Maybe (fromMaybe)
1616
import Data.Set qualified as Set
1717
import Data.Text (Text)
1818
import Data.Text qualified as T
@@ -24,7 +24,6 @@ import Main.Utf8 (withUtf8)
2424
import Options.Applicative
2525
import Paths_echidna (version)
2626
import System.Directory (createDirectoryIfMissing)
27-
import System.Environment (lookupEnv)
2827
import System.Exit (exitWith, exitSuccess, ExitCode(..))
2928
import System.FilePath ((</>), (<.>))
3029
import System.IO (hPutStrLn, stderr)
@@ -42,13 +41,12 @@ import Echidna.Output.Corpus
4241
import Echidna.Output.Foundry
4342
import Echidna.Output.Source
4443
import Echidna.Solidity (compileContracts)
45-
import Echidna.Test (reproduceTest, validateTestMode)
44+
import Echidna.Test (validateTestMode)
4645
import Echidna.Types.Campaign
4746
import Echidna.Types.Config
4847
import Echidna.Types.Solidity
4948
import Echidna.Types.Test (TestMode, EchidnaTest(..), TestType(..), TestState(..))
5049
import Echidna.UI
51-
import Echidna.UI.Report (ppFailWithTraces, ppTestName)
5250
import Echidna.Utility (measureIO)
5351

5452
main :: IO ()
@@ -86,19 +84,6 @@ main = withUtf8 $ withCP65001 $ do
8684
measureIO cfg.solConf.quiet "Saving test reproducers" $
8785
saveTxs env (dir </> "reproducers") (filter (not . null) $ (.reproducer) <$> tests)
8886

89-
saveTracesEnabled <- lookupEnv "ECHIDNA_SAVE_TRACES"
90-
when (isJust saveTracesEnabled) $ do
91-
measureIO cfg.solConf.quiet "Saving test reproducers-traces" $ do
92-
flip runReaderT env $ do
93-
forM_ tests $ \test ->
94-
unless (null test.reproducer) $ do
95-
(results, finalVM) <- reproduceTest vm test
96-
let subdir = dir </> "reproducers-traces"
97-
liftIO $ createDirectoryIfMissing True subdir
98-
let file = subdir </> (show . abs . hash) test.reproducer <.> "txt"
99-
txsPrinted <- ppFailWithTraces Nothing finalVM results
100-
liftIO $ writeFile file (ppTestName test <> ": " <> txsPrinted)
101-
10287
measureIO cfg.solConf.quiet "Saving corpus" $ do
10388
corpus <- readIORef env.corpusRef
10489
saveTxs env (dir </> "coverage") (snd <$> Set.toList corpus)

tests/solidity/basic/default.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ rpcBlock: null
9898
etherscanApiKey: null
9999
# number of workers. By default (unset) its value is the clamp of the number cores between 1 and 4
100100
workers: null
101+
# show all events from all the transactions, not just the last one
102+
allEvents: false
101103
# events server port
102104
server: null
103105
# whether to add an additional symbolic execution worker

0 commit comments

Comments
 (0)