Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed wait bug when shrinking #584

Merged
merged 4 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
matrix:
os:
- ubuntu-latest
- macos-latest
#- macos-latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intended in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, macos building was failing. I think we should disabled it until we can make it work again (or remove it)

include:
- os: ubuntu-latest
apt-get: autoconf automake libtool
- os: macos-latest
brew: automake
#- os: macos-latest
#brew: automake

steps:
- name: Workaround for actions/virtual-environments#1811
Expand Down
25 changes: 25 additions & 0 deletions examples/solidity/basic/push_long.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
contract TEST {

address [] a;
bool lengthChecking = false;

function push_1() public {
a.push(address(1));
}

function turn_on_length_checking() public {
lengthChecking = true;
}

function turn_off_length_checking() public {
lengthChecking = false;
}

function test_long_5() public {
if (a.length >= 5) {
if (lengthChecking) {
assert(false);
}
}
}
}
1 change: 1 addition & 0 deletions examples/solidity/basic/push_long.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checkAsserts: true
2 changes: 1 addition & 1 deletion lib/Echidna/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ liftSH = stateST . runState . zoom hasLens
-- 'Transaction's \"on-chain\".
setupTx :: (MonadState x m, Has VM x) => Tx -> m ()
setupTx (Tx NoCall _ r _ _ _ (t, b)) = liftSH . sequence_ $
[ result .= Nothing, state . pc .= 0, state . stack .= mempty, state . memory .= mempty
[ state . pc .= 0, state . stack .= mempty, state . memory .= mempty
, block . timestamp += litWord t, block . number += b, loadContract r]

setupTx (Tx c s r g gp v (t, b)) = liftSH . sequence_ $
Expand Down
9 changes: 6 additions & 3 deletions src/test/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Common
, passed
, solvedLen
, solvedWith
, solvedWithout
, getGas
, gasInRange
, countCorpus
Expand Down Expand Up @@ -37,7 +38,6 @@ import Echidna.Config (EConfig, _econfig, parseConfig, defaultConfig, sConf, cCo
import Echidna.Solidity (loadSolTests, quiet)
import Echidna.Test (checkETest)
import Echidna.Types.Campaign (Campaign, TestState(..), testLimit, shrinkLimit, tests, gasInfo, corpus, coverage)
import Echidna.Types.Signature (SolCall)
import Echidna.Types.Tx (Tx(..), TxCall(..), call)
import Echidna.Types.World (eventMap)

Expand Down Expand Up @@ -96,8 +96,11 @@ solvedLen :: Int -> Text -> Campaign -> Bool
solvedLen i t = (== Just i) . fmap length . solnFor t

-- NOTE: this just verifies a call was found in the solution. Doesn't care about ordering/seq length
solvedWith :: SolCall -> Text -> Campaign -> Bool
solvedWith c t = maybe False (any $ (== SolCall c) . view call) . solnFor t
solvedWith :: TxCall -> Text -> Campaign -> Bool
solvedWith tx t = maybe False (any $ (== tx) . view call) . solnFor t

solvedWithout :: TxCall -> Text -> Campaign -> Bool
solvedWithout tx t = maybe False (all $ (/= tx) . view call) . solnFor t

getGas :: Text -> Campaign -> Maybe (Int, [Tx])
getGas t = lookup t . view gasInfo
Expand Down
9 changes: 6 additions & 3 deletions src/test/Tests/Integration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ module Tests.Integration (integrationTests) where
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCase, assertBool)

import Common (runContract, testContract, testContract', checkConstructorConditions, testConfig, passed, solved, solvedLen, solvedWith, coverageEmpty, testsEmpty, gasInRange, countCorpus)
import Common (runContract, testContract, testContract', checkConstructorConditions, testConfig, passed, solved, solvedLen, solvedWith, solvedWithout, coverageEmpty, testsEmpty, gasInRange, countCorpus)
import Control.Lens (set)
import Control.Monad (when)
import Data.Functor ((<&>))
import Data.List (isInfixOf)
import Data.Text (unpack)
import Echidna.Config (_econfig, parseConfig, sConf)
import Echidna.Solidity (quiet)
import Echidna.Types.Tx (TxCall(..))
import EVM.ABI (AbiValue(..))
import System.Process (readProcess)

Expand Down Expand Up @@ -44,7 +45,7 @@ integrationTests = testGroup "Solidity Integration Testing"
, ("echidna_fails_on_revert didn't shrink to one transaction",
solvedLen 1 "echidna_fails_on_revert")
, ("echidna_revert_is_false didn't shrink to f(-1, 0x0, 0xdeadbeef)",
solvedWith ("f", [AbiInt 256 (-1), AbiAddress 0, AbiAddress 0xdeadbeef]) "echidna_fails_on_revert")
solvedWith (SolCall ("f", [AbiInt 256 (-1), AbiAddress 0, AbiAddress 0xdeadbeef])) "echidna_fails_on_revert")
]
, testContract "basic/nearbyMining.sol" (Just "coverage/test.yaml")
[ ("echidna_findNearby passed", solved "echidna_findNearby") ]
Expand All @@ -54,7 +55,7 @@ integrationTests = testGroup "Solidity Integration Testing"
[ ("echidna_all_sender passed", solved "echidna_all_sender")
, ("echidna_all_sender didn't shrink optimally", solvedLen 3 "echidna_all_sender")
] ++ (["s1", "s2", "s3"] <&> \n ->
("echidna_all_sender solved without " ++ unpack n, solvedWith (n, []) "echidna_all_sender"))
("echidna_all_sender solved without " ++ unpack n, solvedWith (SolCall (n, [])) "echidna_all_sender"))
, testContract "basic/memory-reset.sol" Nothing
[ ("echidna_memory failed", passed "echidna_memory") ]
, testContract "basic/contractAddr.sol" Nothing
Expand Down Expand Up @@ -90,6 +91,8 @@ integrationTests = testGroup "Solidity Integration Testing"
, testContract "basic/darray.sol" Nothing
[ ("echidna_darray passed", solved "echidna_darray")
, ("echidna_darray didn't shrink optimally", solvedLen 1 "echidna_darray") ]
, testContract "basic/push_long.sol" (Just "basic/push_long.yaml")
[ ("test_long_5 passed", solvedWithout NoCall "ASSERTION test_long_5")]
, testContract "basic/propGasLimit.sol" (Just "basic/propGasLimit.yaml")
[ ("echidna_runForever passed", solved "echidna_runForever") ]
, testContract "basic/assert.sol" (Just "basic/assert.yaml")
Expand Down