From 97b60d1a608923183966ccffdf7c7ce4487b0b42 Mon Sep 17 00:00:00 2001 From: ggrieco-tob Date: Tue, 26 Jan 2021 15:45:54 -0300 Subject: [PATCH 01/11] semver integration for improve testing with different solc versions --- examples/solidity/basic/now.sol | 2 +- examples/solidity/basic/time.sol | 8 ++-- examples/solidity/research/ilf_crowdsale.yaml | 2 +- .../research/solcfuzz_funwithnumbers.sol | 2 - .../research/solcfuzz_funwithnumbers.yaml | 2 +- package.yaml | 2 + src/test/Common.hs | 40 ++++++++++++++++--- src/test/Tests/Integration.hs | 10 ++--- src/test/Tests/Research.hs | 6 +-- 9 files changed, 51 insertions(+), 23 deletions(-) diff --git a/examples/solidity/basic/now.sol b/examples/solidity/basic/now.sol index ccbd549b0..03c613afd 100644 --- a/examples/solidity/basic/now.sol +++ b/examples/solidity/basic/now.sol @@ -3,7 +3,7 @@ contract C { uint time; function set() public { - time = now; + time = block.timestamp; } function guess(uint x) public { diff --git a/examples/solidity/basic/time.sol b/examples/solidity/basic/time.sol index 9c3b65e87..9e9eca792 100644 --- a/examples/solidity/basic/time.sol +++ b/examples/solidity/basic/time.sol @@ -3,12 +3,12 @@ contract Time { uint marked; constructor() public { - start = now; - marked = now; + start = block.timestamp; + marked = block.timestamp; } function mark() public { - marked = now; + marked = block.timestamp; } function echidna_timepassed() public returns (bool) { @@ -16,7 +16,7 @@ contract Time { } function echidna_moretimepassed() public returns (bool) { - return(now < start + 10 weeks ); + return(block.timestamp < start + 10 weeks ); } } diff --git a/examples/solidity/research/ilf_crowdsale.yaml b/examples/solidity/research/ilf_crowdsale.yaml index cb4bf5ac1..038f65c33 100644 --- a/examples/solidity/research/ilf_crowdsale.yaml +++ b/examples/solidity/research/ilf_crowdsale.yaml @@ -1,4 +1,4 @@ checkAsserts: true maxValue: 10000000000000000000000000 coverage: true -cryticArgs: ["--solc", "solc-0.5.7"] +#cryticArgs: ["--solc", "solc-0.5.7"] diff --git a/examples/solidity/research/solcfuzz_funwithnumbers.sol b/examples/solidity/research/solcfuzz_funwithnumbers.sol index d1227aa9c..43cbdeca3 100644 --- a/examples/solidity/research/solcfuzz_funwithnumbers.sol +++ b/examples/solidity/research/solcfuzz_funwithnumbers.sol @@ -1,7 +1,5 @@ // Original example from https://github.com/b-mueller/sabre#example-2-integer-precision-bug -pragma solidity ^0.5.0; - contract FunWithNumbers { uint constant public tokensPerEth = 10; uint constant public weiPerEth = 1e18; diff --git a/examples/solidity/research/solcfuzz_funwithnumbers.yaml b/examples/solidity/research/solcfuzz_funwithnumbers.yaml index 572be1c52..c0107a282 100644 --- a/examples/solidity/research/solcfuzz_funwithnumbers.yaml +++ b/examples/solidity/research/solcfuzz_funwithnumbers.yaml @@ -1,4 +1,4 @@ testLimit: 1000 coverage: true checkAsserts: true -cryticArgs: ["--solc", "solc-0.5.7"] +#cryticArgs: ["--solc", "solc-0.5.7"] diff --git a/package.yaml b/package.yaml index 55a86aeb4..d088b8c07 100644 --- a/package.yaml +++ b/package.yaml @@ -36,8 +36,10 @@ dependencies: - process - random - rosezipper + - semver - sbv - stm + - split - temporary - text - transformers diff --git a/src/test/Common.hs b/src/test/Common.hs index ccce8368e..7d038e276 100644 --- a/src/test/Common.hs +++ b/src/test/Common.hs @@ -2,6 +2,8 @@ module Common ( testConfig , runContract , testContract + , testContractV + , solcV , testContract' , checkConstructorConditions , solnFor @@ -19,19 +21,24 @@ module Common import Prelude hiding (lookup) -import Test.Tasty (TestTree) +import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (testCase, assertBool) import Control.Lens (view, set, (.~), (^.)) +import Control.Monad (when) import Control.Monad.Reader (runReaderT) import Control.Monad.Random (getRandom) import Control.Monad.State.Strict (evalStateT) import Data.Function ((&)) -import Data.List (find) +import Data.List (find, isInfixOf) import Data.List.NonEmpty (NonEmpty(..)) +import Data.List.Split (splitOn) import Data.Map (lookup, empty) import Data.Maybe (isJust) -import Data.Text (Text) +import Data.Text (Text, pack) +import Data.SemVer (Version, version, fromText) +import System.Process (readProcess) + import Echidna (prepareContract) import Echidna.Campaign (campaign) import Echidna.Config (EConfig, _econfig, parseConfig, defaultConfig, sConf, cConf) @@ -46,6 +53,24 @@ testConfig = defaultConfig & sConf . quiet .~ True & cConf . testLimit .~ 10000 & cConf . shrinkLimit .~ 4000 +type SolcVersion = Version +type SolcVersionComp = Version -> Bool + +solcV :: Int -> Int -> Int -> SolcVersion +solcV x y z = version x y z [] [] + +withSolcVersion :: Maybe SolcVersionComp -> IO () -> IO () +withSolcVersion Nothing t = t +withSolcVersion (Just f) t = do + sv <- readProcess "solc" ["--version"] "" + let (_:sv':_) = splitOn "Version: " sv + let (sv'':_) = splitOn "+" sv' + case (fromText $ pack sv'') of + Right v' -> if (f v') then t else assertBool "skip" True + Left e -> error $ show e + +type Name = String + runContract :: FilePath -> Maybe String -> EConfig -> IO Campaign runContract f c cfg = flip runReaderT cfg $ do @@ -55,10 +80,13 @@ runContract f c cfg = campaign (pure ()) v w ts d txs testContract :: FilePath -> Maybe FilePath -> [(String, Campaign -> Bool)] -> TestTree -testContract fp cfg = testContract' fp Nothing cfg True +testContract fp cfg = testContract' fp Nothing Nothing cfg True + +testContractV :: FilePath -> Maybe SolcVersionComp -> Maybe FilePath -> [(String, Campaign -> Bool)] -> TestTree +testContractV fp v cfg = testContract' fp Nothing v cfg True -testContract' :: FilePath -> Maybe String -> Maybe FilePath -> Bool -> [(String, Campaign -> Bool)] -> TestTree -testContract' fp n cfg s as = testCase fp $ do +testContract' :: FilePath -> Maybe Name -> Maybe SolcVersionComp -> Maybe FilePath -> Bool -> [(String, Campaign -> Bool)] -> TestTree +testContract' fp n v cfg s as = testCase fp $ withSolcVersion v $ do c <- set (sConf . quiet) True <$> maybe (pure testConfig) (fmap _econfig . parseConfig) cfg let c' = c & sConf . quiet .~ True & (if s then cConf . testLimit .~ 10000 else id) diff --git a/src/test/Tests/Integration.hs b/src/test/Tests/Integration.hs index 18bf28a18..61483e39a 100644 --- a/src/test/Tests/Integration.hs +++ b/src/test/Tests/Integration.hs @@ -3,7 +3,7 @@ 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, solvedWithout, coverageEmpty, testsEmpty, gasInRange, countCorpus) +import Common (runContract, testContract, testContractV, solcV, testContract', checkConstructorConditions, testConfig, passed, solved, solvedLen, solvedWith, solvedWithout, coverageEmpty, testsEmpty, gasInRange, countCorpus) import Control.Lens (set) import Control.Monad (when) import Data.Functor ((<&>)) @@ -49,7 +49,7 @@ integrationTests = testGroup "Solidity Integration Testing" ] , testContract "basic/nearbyMining.sol" (Just "coverage/test.yaml") [ ("echidna_findNearby passed", solved "echidna_findNearby") ] - , testContract' "basic/smallValues.sol" Nothing (Just "coverage/test.yaml") False + , testContract' "basic/smallValues.sol" Nothing Nothing (Just "coverage/test.yaml") False [ ("echidna_findSmall passed", solved "echidna_findSmall") ] , testContract "basic/multisender.sol" (Just "basic/multisender.yaml") $ [ ("echidna_all_sender passed", solved "echidna_all_sender") @@ -71,7 +71,7 @@ integrationTests = testGroup "Solidity Integration Testing" [ ("echidna_found_sender failed", solved "echidna_found_sender") ] , testContract "basic/rconstants.sol" Nothing [ ("echidna_found failed", solved "echidna_found") ] - , testContract' "basic/cons-create-2.sol" (Just "C") Nothing True + , testContract' "basic/cons-create-2.sol" (Just "C") Nothing Nothing True [ ("echidna_state failed", solved "echidna_state") ] -- single.sol is really slow and kind of unstable. it also messes up travis. -- , testContract "coverage/single.sol" (Just "coverage/test.yaml") @@ -84,7 +84,7 @@ integrationTests = testGroup "Solidity Integration Testing" [ ("echidna_library_call failed", solved "echidna_library_call") ] , testContract "basic/library.sol" (Just "basic/library.yaml") [ ("echidna_valid_timestamp failed", passed "echidna_valid_timestamp") ] - , testContract "basic/fallback.sol" Nothing + , testContractV "basic/fallback.sol" (Just (<= solcV 0 5 7)) Nothing [ ("echidna_fallback failed", solved "echidna_fallback") ] , testContract "basic/large.sol" Nothing [ ("echidna_large failed", solved "echidna_large") ] @@ -126,7 +126,7 @@ integrationTests = testGroup "Solidity Integration Testing" c <- set (sConf . quiet) True <$> maybe (pure testConfig) (fmap _econfig . parseConfig) cfg res <- runContract fp (Just "Foo") c assertBool "echidna_test passed" $ solved "echidna_test" res - , testContract' "basic/multi-abi.sol" (Just "B") (Just "basic/multi-abi.yaml") True + , testContract' "basic/multi-abi.sol" (Just "B") Nothing (Just "basic/multi-abi.yaml") True [ ("echidna_test passed", solved "echidna_test") ] , testContract "abiv2/Ballot.sol" Nothing [ ("echidna_test passed", solved "echidna_test") ] diff --git a/src/test/Tests/Research.hs b/src/test/Tests/Research.hs index 54f19a5b7..848f31434 100644 --- a/src/test/Tests/Research.hs +++ b/src/test/Tests/Research.hs @@ -2,7 +2,7 @@ module Tests.Research (researchTests) where import Test.Tasty (TestTree, testGroup) -import Common (testContract, testContract', solved) +import Common (testContract, testContractV, testContract', solcV, solved) researchTests :: TestTree researchTests = testGroup "Research-based Integration Testing" @@ -10,9 +10,9 @@ researchTests = testGroup "Research-based Integration Testing" [ ("echidna_assert failed", solved "echidna_assert") ] , testContract "research/harvey_baz.sol" Nothing [ ("echidna_all_states failed", solved "echidna_all_states") ] - , testContract "research/ilf_crowdsale.sol" (Just "research/ilf_crowdsale.yaml") + , testContractV "research/ilf_crowdsale.sol" (Just $ (< solcV 0 6 0)) (Just "research/ilf_crowdsale.yaml") [ ("echidna_assert failed", solved "ASSERTION withdraw") ] - , testContract' "research/solcfuzz_funwithnumbers.sol" (Just "VerifyFunWithNumbers") (Just "research/solcfuzz_funwithnumbers.yaml") True + , testContract' "research/solcfuzz_funwithnumbers.sol" (Just "VerifyFunWithNumbers") (Just $ (< solcV 0 6 0)) (Just "research/solcfuzz_funwithnumbers.yaml") True [ ("echidna_assert failed", solved "ASSERTION sellTokens"), ("echidna_assert failed", solved "ASSERTION buyTokens") ] From 92fe7e411e68f489c02d2498ee96824a16e99101 Mon Sep 17 00:00:00 2001 From: ggrieco-tob Date: Tue, 26 Jan 2021 16:54:20 -0300 Subject: [PATCH 02/11] fixes --- src/test/Common.hs | 9 ++++----- src/test/Tests/Research.hs | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/test/Common.hs b/src/test/Common.hs index 7d038e276..7bf589825 100644 --- a/src/test/Common.hs +++ b/src/test/Common.hs @@ -21,16 +21,15 @@ module Common import Prelude hiding (lookup) -import Test.Tasty (TestTree, testGroup) +import Test.Tasty (TestTree) import Test.Tasty.HUnit (testCase, assertBool) import Control.Lens (view, set, (.~), (^.)) -import Control.Monad (when) import Control.Monad.Reader (runReaderT) import Control.Monad.Random (getRandom) import Control.Monad.State.Strict (evalStateT) import Data.Function ((&)) -import Data.List (find, isInfixOf) +import Data.List (find) import Data.List.NonEmpty (NonEmpty(..)) import Data.List.Split (splitOn) import Data.Map (lookup, empty) @@ -65,8 +64,8 @@ withSolcVersion (Just f) t = do sv <- readProcess "solc" ["--version"] "" let (_:sv':_) = splitOn "Version: " sv let (sv'':_) = splitOn "+" sv' - case (fromText $ pack sv'') of - Right v' -> if (f v') then t else assertBool "skip" True + case fromText $ pack sv'' of + Right v' -> if f v' then t else assertBool "skip" True Left e -> error $ show e type Name = String diff --git a/src/test/Tests/Research.hs b/src/test/Tests/Research.hs index 848f31434..c5fe8a084 100644 --- a/src/test/Tests/Research.hs +++ b/src/test/Tests/Research.hs @@ -10,9 +10,9 @@ researchTests = testGroup "Research-based Integration Testing" [ ("echidna_assert failed", solved "echidna_assert") ] , testContract "research/harvey_baz.sol" Nothing [ ("echidna_all_states failed", solved "echidna_all_states") ] - , testContractV "research/ilf_crowdsale.sol" (Just $ (< solcV 0 6 0)) (Just "research/ilf_crowdsale.yaml") + , testContractV "research/ilf_crowdsale.sol" (Just (< solcV 0 6 0)) (Just "research/ilf_crowdsale.yaml") [ ("echidna_assert failed", solved "ASSERTION withdraw") ] - , testContract' "research/solcfuzz_funwithnumbers.sol" (Just "VerifyFunWithNumbers") (Just $ (< solcV 0 6 0)) (Just "research/solcfuzz_funwithnumbers.yaml") True + , testContract' "research/solcfuzz_funwithnumbers.sol" (Just "VerifyFunWithNumbers") (Just (< solcV 0 6 0)) (Just "research/solcfuzz_funwithnumbers.yaml") True [ ("echidna_assert failed", solved "ASSERTION sellTokens"), ("echidna_assert failed", solved "ASSERTION buyTokens") ] From 9e5c5b638f04367b4e76ca4ae5e3982111182482 Mon Sep 17 00:00:00 2001 From: ggrieco-tob Date: Tue, 26 Jan 2021 17:17:10 -0300 Subject: [PATCH 03/11] more fixes --- examples/solidity/research/ilf_crowdsale.yaml | 1 - examples/solidity/research/solcfuzz_funwithnumbers.yaml | 1 - examples/solidity/research/solcfuzz_registrar.yaml | 1 - src/test/Tests/Integration.hs | 2 +- src/test/Tests/Research.hs | 2 +- 5 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/solidity/research/ilf_crowdsale.yaml b/examples/solidity/research/ilf_crowdsale.yaml index 038f65c33..8bb785ca1 100644 --- a/examples/solidity/research/ilf_crowdsale.yaml +++ b/examples/solidity/research/ilf_crowdsale.yaml @@ -1,4 +1,3 @@ checkAsserts: true maxValue: 10000000000000000000000000 coverage: true -#cryticArgs: ["--solc", "solc-0.5.7"] diff --git a/examples/solidity/research/solcfuzz_funwithnumbers.yaml b/examples/solidity/research/solcfuzz_funwithnumbers.yaml index c0107a282..579e0adb9 100644 --- a/examples/solidity/research/solcfuzz_funwithnumbers.yaml +++ b/examples/solidity/research/solcfuzz_funwithnumbers.yaml @@ -1,4 +1,3 @@ testLimit: 1000 coverage: true checkAsserts: true -#cryticArgs: ["--solc", "solc-0.5.7"] diff --git a/examples/solidity/research/solcfuzz_registrar.yaml b/examples/solidity/research/solcfuzz_registrar.yaml index 9f964ec3d..e76cf4b79 100644 --- a/examples/solidity/research/solcfuzz_registrar.yaml +++ b/examples/solidity/research/solcfuzz_registrar.yaml @@ -1,2 +1 @@ checkAsserts: true -cryticArgs: ["--solc", "solc-0.4.25"] diff --git a/src/test/Tests/Integration.hs b/src/test/Tests/Integration.hs index 61483e39a..11d32c764 100644 --- a/src/test/Tests/Integration.hs +++ b/src/test/Tests/Integration.hs @@ -84,7 +84,7 @@ integrationTests = testGroup "Solidity Integration Testing" [ ("echidna_library_call failed", solved "echidna_library_call") ] , testContract "basic/library.sol" (Just "basic/library.yaml") [ ("echidna_valid_timestamp failed", passed "echidna_valid_timestamp") ] - , testContractV "basic/fallback.sol" (Just (<= solcV 0 5 7)) Nothing + , testContractV "basic/fallback.sol" (Just (< solcV 0 6 0)) Nothing [ ("echidna_fallback failed", solved "echidna_fallback") ] , testContract "basic/large.sol" Nothing [ ("echidna_large failed", solved "echidna_large") ] diff --git a/src/test/Tests/Research.hs b/src/test/Tests/Research.hs index c5fe8a084..bcd497bf6 100644 --- a/src/test/Tests/Research.hs +++ b/src/test/Tests/Research.hs @@ -10,7 +10,7 @@ researchTests = testGroup "Research-based Integration Testing" [ ("echidna_assert failed", solved "echidna_assert") ] , testContract "research/harvey_baz.sol" Nothing [ ("echidna_all_states failed", solved "echidna_all_states") ] - , testContractV "research/ilf_crowdsale.sol" (Just (< solcV 0 6 0)) (Just "research/ilf_crowdsale.yaml") + , testContractV "research/ilf_crowdsale.sol" (Just (\v -> v >= solcV 0 5 0 && v < solcV 0 6 0)) (Just "research/ilf_crowdsale.yaml") [ ("echidna_assert failed", solved "ASSERTION withdraw") ] , testContract' "research/solcfuzz_funwithnumbers.sol" (Just "VerifyFunWithNumbers") (Just (< solcV 0 6 0)) (Just "research/solcfuzz_funwithnumbers.yaml") True [ ("echidna_assert failed", solved "ASSERTION sellTokens"), From 124fda45435a88f3ae2f5aae007b732c5a4975dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Sun, 22 Nov 2020 19:11:18 -0300 Subject: [PATCH 04/11] GitHub Actions: macOS releases: Drop extra libgmp renaming --- .github/scripts/build-macos-release.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/scripts/build-macos-release.sh b/.github/scripts/build-macos-release.sh index 817d8b422..3e1f1b366 100755 --- a/.github/scripts/build-macos-release.sh +++ b/.github/scripts/build-macos-release.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/bin/bash +set -eux add_rpath() { @@ -13,7 +14,7 @@ fix_path() NEW="$3" OLD=$(otool -L "$BINARY" | grep "$MATCH" | awk '{print $1}') install_name_tool -change "$OLD" "$NEW" "$BINARY" - cp -n "$OLD" "$(dirname "$BINARY")/$(basename "$NEW")" + cp -n "$OLD" "$(dirname "$BINARY")/$(basename "$NEW")" || true } @@ -25,7 +26,6 @@ BINARY="$BUILD/echidna-test" add_rpath "$BINARY" fix_path "$BINARY" libsecp256k1 "@rpath/libsecp256k1.dylib" fix_path "$BINARY" libff "@rpath/libff.dylib" -fix_path "$BINARY" libgmp "@rpath/libgmp.dylib" fix_path "$BUILD/libff.dylib" libgmp "@rpath/libgmp.dylib" fix_path "$BUILD/libsecp256k1.dylib" libgmp "@rpath/libgmp.dylib" From a9728a93b7bea8b39412936879c308165a6823b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Sun, 22 Nov 2020 20:15:31 -0300 Subject: [PATCH 05/11] GitHub Actions: drop workaround for actions/virtual-environments#1811 This has been fixed upstream by GitHub. --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66ed73b0c..43c6be092 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,12 +23,6 @@ jobs: # brew: automake steps: - - name: Workaround for actions/virtual-environments#1811 - if: runner.os == 'macOS' - run: | - brew untap local/homebrew-openssl - brew untap local/homebrew-python2 - - name: Workaround for actions/cache#403 if: runner.os == 'macOS' run: | From dd04d4cfb64102c9682837fa1ce94e56008ccc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Sun, 22 Nov 2020 20:25:24 -0300 Subject: [PATCH 06/11] GitHub Actions: upgrade cache and setup-python actions to v2 --- .github/workflows/ci.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43c6be092..86e317fb0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,27 +39,24 @@ jobs: uses: actions/checkout@v2 - name: Setup Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: '3.6' - name: Cache Local - id: cache-local - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ~/.local/ key: ${{ runner.os }}-local-v3 - name: Cache Stack - id: cache-stack - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ~/.stack key: ${{ runner.os }}-stack-v3 - name: Cache Cabal - id: cache-cabal - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ~/.cabal key: ${{ runner.os }}-cabal-v3 From 841e95d418866b6b5c3ce94190e0eb2002e53085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Sun, 22 Nov 2020 20:26:17 -0300 Subject: [PATCH 07/11] GitHub Actions: prettify Linux artifact Currently the tar.gz file has several folders inside from where the binary used to be in the runner, clean those up using -C. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 86e317fb0..433434158 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,7 +100,7 @@ jobs: - name: Compress binary (Linux) if: runner.os == 'Linux' - run: GZIP=-9 tar -czf echidna-test.tar.gz $HOME/.local/bin/echidna-test + run: GZIP=-9 tar -czf echidna-test.tar.gz -C $HOME/.local/bin/ echidna-test - name: Upload artifact uses: actions/upload-artifact@v1 From dc44e74756a8ac5ffeac981ca2834b306a1ac44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Sun, 22 Nov 2020 18:12:41 -0300 Subject: [PATCH 08/11] Make tests static This helps in the case of CI, and allows to run the tests on a separate container without having to set up any library or Haskell dependencies. --- package.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/package.yaml b/package.yaml index d088b8c07..fd4a92618 100644 --- a/package.yaml +++ b/package.yaml @@ -84,3 +84,11 @@ tests: - tasty - tasty-hunit - tasty-quickcheck + when: + - condition: os(linux) + ghc-options: + - -threaded + - -static + - -O2 + cc-options: -static + ld-options: -static -pthread From 6caf20a276d926ba56bc61c5fcbbbe18e8f77312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Sun, 22 Nov 2020 16:40:23 -0300 Subject: [PATCH 09/11] GitHub Actions: implement parallel testing This allows for parallel execution of the echidna tests, which helps improve testing speed, especially once newer solc versions are included in the pipeline. --- .github/scripts/install-solc.sh | 36 +++++++++----- .github/workflows/ci.yml | 87 +++++++++++++++++++++++++-------- 2 files changed, 90 insertions(+), 33 deletions(-) diff --git a/.github/scripts/install-solc.sh b/.github/scripts/install-solc.sh index 1f8b14d21..3df55026e 100755 --- a/.github/scripts/install-solc.sh +++ b/.github/scripts/install-solc.sh @@ -1,13 +1,9 @@ -#! /bin/bash +#!/bin/bash # Adapted from https://github.com/commercialhaskell/stack set -eux -if [ -f $HOME/.local/bin/solc-0.4.25 ] && [ -f $HOME/.local/bin/solc-0.5.7 ]; then - exit 0 -fi - mkdir -p $HOME/.local/bin; travis_retry() { @@ -16,15 +12,29 @@ travis_retry() { } fetch_solc_linux() { - rm -Rf solc-static-linux; - wget https://github.com/ethereum/solidity/releases/download/v0.4.25/solc-static-linux; - chmod +x solc-static-linux; - mv solc-static-linux $HOME/.local/bin/solc-0.4.25; - wget https://github.com/ethereum/solidity/releases/download/v0.5.7/solc-static-linux; - chmod +x solc-static-linux; - mv solc-static-linux $HOME/.local/bin/solc-0.5.7; + VER="$1" + if [ ! -f "$HOME/.local/bin/solc-$VER" ]; then + rm -Rf solc-static-linux + wget "https://github.com/ethereum/solidity/releases/download/v$VER/solc-static-linux" + chmod +x solc-static-linux + mv solc-static-linux "$HOME/.local/bin/solc-$VER" + echo "Downloaded solc $VER" + else + echo "Skipped solc $VER, already present" + fi +} + +fetch_all_solc_linux() { + fetch_solc_linux "0.4.25" + fetch_solc_linux "0.5.7" + fetch_solc_linux "0.6.12" + fetch_solc_linux "0.7.5" } if [ "$HOST_OS" = "Linux" ]; then - travis_retry fetch_solc_linux + if [ "${SOLC_VER:-}" == "" ]; then + travis_retry fetch_all_solc_linux + else + travis_retry fetch_solc_linux "$SOLC_VER" + fi fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 433434158..713faa046 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,8 @@ on: - master jobs: - test: + build: + name: Build Echidna runs-on: ${{ matrix.os }} strategy: matrix: @@ -61,13 +62,6 @@ jobs: path: ~/.cabal key: ${{ runner.os }}-cabal-v3 - - name: Build Binaries - run: | - .github/scripts/install-solc.sh - .github/scripts/install-crytic-compile.sh - env: - HOST_OS: ${{ runner.os }} - - name: Build Libraries run: | .github/scripts/install-libsecp256k1.sh @@ -83,17 +77,6 @@ jobs: run: | stack install --ghc-options="-Werror" --extra-include-dirs=$HOME/.local/include --extra-lib-dirs=$HOME/.local/lib - - name: Test - if: runner.os == 'Linux' - run: | - export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:$HOME/.local/lib" - export PATH="${PATH}:$HOME/.local/bin" - - for VER in "0.4.25" "0.5.7" ; do - cp "$HOME/.local/bin/solc-$VER" "$HOME/.local/bin/solc" - stack test --ghc-options="-Werror" --extra-include-dirs=$HOME/.local/include --extra-lib-dirs=$HOME/.local/lib - done - - name: Amend and compress binaries (macOS) if: runner.os == 'macOS' run: .github/scripts/build-macos-release.sh @@ -103,7 +86,71 @@ jobs: run: GZIP=-9 tar -czf echidna-test.tar.gz -C $HOME/.local/bin/ echidna-test - name: Upload artifact - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v2 with: name: echidna-test-${{ runner.os }} path: echidna-test.tar.gz + + - name: Build and copy test suite + if: runner.os == 'Linux' + run: | + stack build --test --no-run-tests --ghc-options="-Werror" --extra-include-dirs=$HOME/.local/include --extra-lib-dirs=$HOME/.local/lib + cp "$(find "$PWD" -name echidna-testsuite -type f)" . + + - name: Upload testsuite + if: runner.os == 'Linux' + uses: actions/upload-artifact@v2 + with: + name: echidna-testsuite + path: echidna-testsuite + + + test: + name: Test Echidna with solc ${{ matrix.solc }} + runs-on: ubuntu-latest + needs: build + continue-on-error: ${{ matrix.experimental }} + strategy: + fail-fast: false + matrix: + solc: + - "0.4.25" + - "0.5.7" + experimental: [false] + include: + - solc: "0.6.12" + experimental: true + - solc: "0.7.5" + experimental: true + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: '3.6' + + - name: Install dependencies + run: | + .github/scripts/install-solc.sh + .github/scripts/install-crytic-compile.sh + env: + HOST_OS: ${{ runner.os }} + # there are some tests hardcoded for specific solc + # versions, so install everything for the time being + # instead of a precise version + #SOLC_VER: ${{ matrix.solc }} + + - name: Download testsuite + uses: actions/download-artifact@v2 + with: + name: echidna-testsuite + + - name: Test + run: | + export PATH="${PATH}:$HOME/.local/bin" + cp "$HOME/.local/bin/solc-${{ matrix.solc }}" "$HOME/.local/bin/solc" + chmod +x echidna-testsuite + ./echidna-testsuite From 8fb63711041d61b389018084de8ce5531024e25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Tue, 26 Jan 2021 19:12:14 -0300 Subject: [PATCH 10/11] GitHub Actions: install the exact solc needed instead of all versions --- .github/workflows/ci.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 713faa046..f6485e919 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -138,10 +138,7 @@ jobs: .github/scripts/install-crytic-compile.sh env: HOST_OS: ${{ runner.os }} - # there are some tests hardcoded for specific solc - # versions, so install everything for the time being - # instead of a precise version - #SOLC_VER: ${{ matrix.solc }} + SOLC_VER: ${{ matrix.solc }} - name: Download testsuite uses: actions/download-artifact@v2 From 5bd885df3bdc29bf5b86563c6c1c9c57f651a9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Tue, 26 Jan 2021 20:02:42 -0300 Subject: [PATCH 11/11] GitHub Actions: re-enable MacOS CI --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6485e919..b3edd89ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,12 +16,12 @@ jobs: matrix: os: - ubuntu-latest - # - macos-latest + - macos-latest include: - os: ubuntu-latest apt-get: autoconf automake libtool - # - os: macos-latest - # brew: automake + - os: macos-latest + brew: automake steps: - name: Workaround for actions/cache#403