First step to refactor the Test type (#622)

* refactored test type

* fixed tests
pull/629/head
Gustavo Grieco 4 years ago committed by GitHub
parent 3e828638c1
commit 85f3318da4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      lib/Echidna.hs
  2. 1
      lib/Echidna/Campaign.hs
  3. 17
      lib/Echidna/Output/JSON.hs
  4. 5
      lib/Echidna/Solidity.hs
  5. 1
      lib/Echidna/Test.hs
  6. 29
      lib/Echidna/Types/Campaign.hs
  7. 37
      lib/Echidna/Types/Test.hs
  8. 1
      lib/Echidna/UI.hs
  9. 1
      lib/Echidna/UI/Report.hs
  10. 2
      lib/Echidna/UI/Widgets.hs
  11. 3
      src/test/Common.hs

@ -21,6 +21,7 @@ import Echidna.Solidity
import Echidna.Types.Campaign
import Echidna.Types.Random
import Echidna.Types.Signature
import Echidna.Types.Test
import Echidna.Types.Tx
import Echidna.Types.World
import Echidna.Processor

@ -43,6 +43,7 @@ import Echidna.Solidity
import Echidna.Test
import Echidna.Transaction
import Echidna.Types.Campaign
import Echidna.Types.Test (TestState(..), SolTest)
import Echidna.Types.Tx (TxCall(..), Tx(..), TxConf, getResult, src, call, _SolCall)
import Echidna.Types.World (World, eventMap)
import Echidna.Mutator.Corpus

@ -4,9 +4,10 @@
module Echidna.Output.JSON where
import Echidna.ABI (ppAbiValue, GenDict(..))
import qualified Echidna.Types.Campaign as C
import Echidna.Solidity (SolTest)
import Echidna.Exec (PC, OpIx)
import qualified Echidna.Types.Campaign as C
import qualified Echidna.Types.Test as T
import Echidna.Types.Test (SolTest)
import Echidna.Types.Tx (Tx(..), TxCall(..), TxResult)
import Data.Aeson hiding (Error)
import qualified Data.ByteString.Base16 as BS16
@ -99,7 +100,7 @@ encodeCampaign C.Campaign{..} = encode
, gasInfo = toList _gasInfo
}
mapTest :: (SolTest, C.TestState) -> Test
mapTest :: (SolTest, T.TestState) -> Test
mapTest (solTest, testState) =
let (status, transactions, err) = mapTestState testState in
Test { contract = "" -- TODO add when mapping is available https://github.com/crytic/echidna/issues/415
@ -110,11 +111,11 @@ mapTest (solTest, testState) =
, transactions = transactions
}
where
mapTestState (C.Open _) = (Fuzzing, Nothing, Nothing)
mapTestState C.Passed = (Passed, Nothing, Nothing)
mapTestState (C.Solved txs) = (Solved, Just $ mapTx <$> txs, Nothing)
mapTestState (C.Large _ txs) = (Shrinking, Just $ mapTx <$> txs, Nothing)
mapTestState (C.Failed e) = (Error, Nothing, Just $ show e) -- TODO add (show e)
mapTestState (T.Open _) = (Fuzzing, Nothing, Nothing)
mapTestState T.Passed = (Passed, Nothing, Nothing)
mapTestState (T.Solved txs) = (Solved, Just $ mapTx <$> txs, Nothing)
mapTestState (T.Large _ txs) = (Shrinking, Just $ mapTx <$> txs, Nothing)
mapTestState (T.Failed e) = (Error, Nothing, Just $ show e) -- TODO add (show e)
mapTx Tx{..} =
let (function, args) = mapCall _call in

@ -33,6 +33,7 @@ import Echidna.Events (EventMap)
import Echidna.RPC (loadEthenoBatch)
import Echidna.Types.Signature (ContractName, FunctionHash, SolSignature, SignatureMap, getBytecodeMetadata)
import Echidna.Types.Tx (TxConf, createTx, createTxWithValue, unlimitedGasPerBlock, initialTimestamp, initialBlockNumber)
import Echidna.Types.Test (SolTest)
import Echidna.Types.World (World(..))
import Echidna.Processor
@ -107,10 +108,6 @@ data SolConf = SolConf { _contractAddr :: Addr -- ^ Contract addr
}
makeLenses ''SolConf
-- | An Echidna test is either the name of the function to call and the address where its contract is,
-- or a function that could experience an exception
type SolTest = Either (Text, Addr) SolSignature
-- | Given a list of files, use its extenstion to check if it is a precompiled
-- contract or try to compile it and get a list of its contracts, throwing
-- exceptions if necessary.

@ -28,6 +28,7 @@ import Echidna.Exec
import Echidna.Solidity
import Echidna.Transaction
import Echidna.Types.Buffer (viewBuffer)
import Echidna.Types.Test (SolTest)
import Echidna.Types.Tx (Tx, TxConf, basicTx, propGas, src)
-- | Configuration for evaluating Echidna tests.

@ -10,14 +10,14 @@ import Data.Aeson (ToJSON(..), object)
import Data.Foldable (toList)
import Data.Has (Has(..))
import Data.Map (Map, mapKeys)
import Data.Maybe (mapMaybe, maybeToList)
import Data.Maybe (mapMaybe)
import Data.Text (Text)
import EVM.Keccak (keccak)
import Numeric (showHex)
import Echidna.ABI (GenDict, defaultDict)
import Echidna.Exec (CoverageMap, ExecException)
import Echidna.Solidity (SolTest)
import Echidna.Exec (CoverageMap)
import Echidna.Types.Test (SolTest, TestState(..))
import Echidna.Types.Tx (Tx)
import Echidna.Types.Corpus
import Echidna.Mutator.Corpus
@ -47,29 +47,6 @@ data CampaignConf = CampaignConf { _testLimit :: Int
}
makeLenses ''CampaignConf
-- | State of a particular Echidna test. N.B.: \"Solved\" means a falsifying call sequence was found.
data TestState = Open Int -- ^ Maybe solvable, tracking attempts already made
| Large Int [Tx] -- ^ Solved, maybe shrinable, tracking shrinks tried + best solve
| Passed -- ^ Presumed unsolvable
| Solved [Tx] -- ^ Solved with no need for shrinking
| Failed ExecException -- ^ Broke the execution environment
deriving Show
instance Eq TestState where
(Open i) == (Open j) = i == j
(Large i l) == (Large j m) = i == j && l == m
Passed == Passed = True
(Solved l) == (Solved m) = l == m
_ == _ = False
instance ToJSON TestState where
toJSON s = object $ ("passed", toJSON passed) : maybeToList desc where
(passed, desc) = case s of Open _ -> (True, Nothing)
Passed -> (True, Nothing)
Large _ l -> (False, Just ("callseq", toJSON l))
Solved l -> (False, Just ("callseq", toJSON l))
Failed e -> (False, Just ("exception", toJSON $ show e))
-- | The state of a fuzzing campaign.
data Campaign = Campaign { _tests :: [(SolTest, TestState)]
-- ^ Tests being evaluated

@ -0,0 +1,37 @@
module Echidna.Types.Test where
import Data.Aeson (ToJSON(..), object)
import Data.Maybe (maybeToList)
import Data.Text (Text)
import EVM.Types (Addr)
import Echidna.Exec (ExecException)
import Echidna.Types.Tx (Tx)
import Echidna.Types.Signature (SolSignature)
-- | An Echidna test is either the name of the function to call and the address where its contract is,
-- or a function that could experience an exception
type SolTest = Either (Text, Addr) SolSignature
-- | State of a particular Echidna test. N.B.: \"Solved\" means a falsifying call sequence was found.
data TestState = Open Int -- ^ Maybe solvable, tracking attempts already made
| Large Int [Tx] -- ^ Solved, maybe shrinable, tracking shrinks tried + best solve
| Passed -- ^ Presumed unsolvable
| Solved [Tx] -- ^ Solved with no need for shrinking
| Failed ExecException -- ^ Broke the execution environment
deriving Show
instance Eq TestState where
(Open i) == (Open j) = i == j
(Large i l) == (Large j m) = i == j && l == m
Passed == Passed = True
(Solved l) == (Solved m) = l == m
_ == _ = False
instance ToJSON TestState where
toJSON s = object $ ("passed", toJSON passed) : maybeToList desc where
(passed, desc) = case s of Open _ -> (True, Nothing)
Passed -> (True, Nothing)
Large _ l -> (False, Just ("callseq", toJSON l))
Solved l -> (False, Just ("callseq", toJSON l))
Failed e -> (False, Just ("exception", toJSON $ show e))

@ -34,6 +34,7 @@ import qualified Echidna.Output.JSON
import Echidna.Solidity
import Echidna.Test
import Echidna.Types.Campaign
import Echidna.Types.Test (SolTest)
import Echidna.Types.Tx (Tx, TxConf)
import Echidna.Types.World (World)
import Echidna.UI.Report

@ -18,6 +18,7 @@ import Echidna.ABI (defSeed)
import Echidna.Exec
import Echidna.Pretty (ppTxCall)
import Echidna.Types.Campaign
import Echidna.Types.Test (TestState(..))
import Echidna.Types.Tx (Tx(Tx), TxCall(..), TxConf, txGas, src)
-- | An address involved with a 'Transaction' is either the sender, the recipient, or neither of those things.

@ -21,8 +21,8 @@ import qualified Paths_echidna (version)
import Echidna.ABI
import Echidna.Campaign (isDone)
import Echidna.Solidity
import Echidna.Types.Campaign
import Echidna.Types.Test (TestState(..), SolTest)
import Echidna.Types.Tx (Tx, TxConf, src)
import Echidna.UI.Report

@ -43,8 +43,9 @@ import Echidna.Campaign (campaign)
import Echidna.Config (EConfig, _econfig, parseConfig, defaultConfig, sConf, cConf)
import Echidna.Solidity (loadSolTests, quiet)
import Echidna.Test (checkETest)
import Echidna.Types.Campaign (Campaign, TestState(..), testLimit, shrinkLimit, tests, gasInfo, corpus, coverage)
import Echidna.Types.Campaign (Campaign, testLimit, shrinkLimit, tests, gasInfo, corpus, coverage)
import Echidna.Types.Signature (ContractName)
import Echidna.Types.Test (TestState(..))
import Echidna.Types.Tx (Tx(..), TxCall(..), call)
import Echidna.Types.World (eventMap)

Loading…
Cancel
Save