From f3e6391a5cbe1cfb13c58a623df7b7e1279f978f Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 00:59:31 +0200 Subject: [PATCH 01/19] seth: run-tx: default to fetch etherscan source --- src/dapp-tests/integration/tests.sh | 51 +++++++++++++++++++++++------ src/seth/libexec/seth/seth | 1 + src/seth/libexec/seth/seth-run-tx | 5 +++ 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index 65441d63f..7351e5481 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -6,8 +6,12 @@ set -euo pipefail # CONFIGURATION # ------------------------------------------------ -FUZZ_RUNS=100 -TESTNET_SLEEP=5 +SKIP_SETUP=${SKIP_SETUP:-0} +FUZZ_RUNS=${FUZZ_RUNS:-100} +TESTNET_SLEEP=${TESTNET_SLEEP:-5} +ETHERSCAN_API_KEY=${ETHERSCAN_API_KEY:-15IS6MMRAYB19NZN9VHH6H6P57892Z664M} +RINKEBY_RPC_URL=${RINKEBY_RPC_URL:-https://rinkeby.infura.io/v3/84842078b09946638c03157f83405213} +ARCHIVE_NODE_URL=${ARCHIVE_NODE_URL:-https://eth-mainnet.alchemyapi.io/v2/vpeKFsEF6PHifHzdtcwXSDbhV3ym5Ro4} # ------------------------------------------------ # SHARED SETUP @@ -15,7 +19,7 @@ TESTNET_SLEEP=5 # we spin up a new testnet instance and share it between all tests setup_suite() { - if [[ -z "$SKIP_SETUP" ]]; then + if [[ "$SKIP_SETUP" != 1 ]]; then TMPDIR=$(mktemp -d) dapp testnet --dir "$TMPDIR" & @@ -31,7 +35,7 @@ setup_suite() { # cleanup the testnet teardown_suite() { - if [[ -z "$SKIP_SETUP" ]]; then + if [[ "$SKIP_SETUP" != 1 ]]; then killall geth rm -rf "$TMPDIR" fi @@ -41,10 +45,6 @@ teardown_suite() { # TEST HELPERS # ------------------------------------------------ -# Tests for resolve-name and lookup-address use a Rinkeby name that's been registered for 100 years and will not be changed -# Infura ID source: https://github.com/ethers-io/ethers.js/blob/0d40156fcba5be155aa5def71bcdb95b9c11d889/packages/providers/src.ts/infura-provider.ts#L17 -RINKEBY_RPC_URL=https://rinkeby.infura.io/v3/84842078b09946638c03157f83405213 - # generates a new account and gives it some eth, returns the address fresh_account() { wei_amount=${1:-$(seth --to-wei 42069 ether)} @@ -135,7 +135,7 @@ test_smoke() { TX=$(seth send "$A_ADDR" "off()" --gas 0xffff --password /dev/null --from "$account" --keystore "$TMPDIR"/8545/keystore --async) # since we have one tx per block, seth run-tx and seth debug are equivalent - assert_equals 0x "$(seth run-tx "$TX")" + assert_equals 0x "$(seth run-tx "$TX" --no-src)" # dynamic fee transactions (EIP-1559) seth send "$A_ADDR" "on()" \ @@ -150,7 +150,7 @@ test_smoke() { --create 0x647175696e6550383480393834f3 \ --gas 0xffff \ --password /dev/null \ - --from "$ACC" \ + --from "$account" \ --keystore "$TMPDIR"/8545/keystore \ --prio-fee 2gwei \ --gas-price 10gwei) @@ -573,3 +573,34 @@ test_to_fix3() { test_to_fix4() { assert_equals 1.234567890000000000 "$(seth --to-fix 18 1234567890000000000)" } + +# SETH RUN-TX TESTS +test_run_tx_source_fetching() { + ETH_RPC_URL=$ARCHIVE_NODE_URL + trace=$(mktemp) + + # seth pulls from etherscan by default + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" 2>&1 + assert "grep -q 'UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C' $trace" "did not pull source by default" + assert "grep -q 'PairCreated(UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C, 51691)' $trace" "did not pull source by default" + + # seth does not pull from etherscan if ETHERSCAN_API_KEY is unset + DAPP_JSON=/dev/null seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" 2>&1 + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" + + # seth does not pull from etherscan if DAPP_JSON is set + DAPP_JSON=/dev/null seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" 2>&1 + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" + + # seth does not pull from etherscan if --no-src is passed at the command line + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --no-src > "$trace" 2>&1 + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" + + # seth does not pull from etherscan if SETH_NOSRC is set to "yes" + SETH_NOSRC=yes seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" 2>&1 + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" +} diff --git a/src/seth/libexec/seth/seth b/src/seth/libexec/seth/seth index ee569d842..4607ce68f 100755 --- a/src/seth/libexec/seth/seth +++ b/src/seth/libexec/seth/seth @@ -47,6 +47,7 @@ ### ### --debug run in hevm interactive mode ### --trace dump a trace to stderr +### --no-src don't try to fetch contract source ### --source= path to combined.json source ### --state= directory to store hevm state in ### diff --git a/src/seth/libexec/seth/seth-run-tx b/src/seth/libexec/seth/seth-run-tx index 68aab2d48..780f1abd5 100755 --- a/src/seth/libexec/seth/seth-run-tx +++ b/src/seth/libexec/seth/seth-run-tx @@ -28,6 +28,11 @@ else opts+=(--address "$TO" --calldata "$DATA") fi +if [[ -n "$ETHERSCAN_API_KEY" && -z "$DAPP_JSON" && "$SETH_NOSRC" != yes ]]; then + DAPP_JSON=$(mktemp) + seth bundle-source "$TO" > "$DAPP_JSON" || : +fi + opts+=(--caller "$(<<< "$tx" seth --field from)" ) opts+=(--origin "$(<<< "$tx" seth --field from)") opts+=(--value "$(<<< "$tx" seth --field value)") From 11b251c9f120ce07b7870458d379e22a8eb76530 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 01:00:05 +0200 Subject: [PATCH 02/19] dapp-tests: tweak ci, add more asserts --- .github/workflows/build.yml | 2 +- src/dapp-tests/Makefile | 5 +++++ src/dapp-tests/integration/tests.sh | 8 ++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 55e45e321..0026431ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: name: dapp signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' - name: run dapp tests - run: nix-shell --pure src/dapp-tests/shell.nix --command 'make --directory src/dapp-tests' + run: nix-shell --pure src/dapp-tests/shell.nix --command 'make ci --directory src/dapp-tests' - name: run hevm symbolic tests run: nix-build -j 1 -A hevm-tests - run: nix-collect-garbage diff --git a/src/dapp-tests/Makefile b/src/dapp-tests/Makefile index ad11312dc..69d1e1818 100644 --- a/src/dapp-tests/Makefile +++ b/src/dapp-tests/Makefile @@ -2,4 +2,9 @@ test: pytest --hypothesis-show-statistics integration/diff-fuzz.py bash_unit integration/tests.sh +ci: + export FUZZ_RUNS=10000 + pytest --hypothesis-show-statistics integration/diff-fuzz.py + bash_unit integration/tests.sh + .PHONY: test diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index 7351e5481..d293f46b7 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -192,16 +192,16 @@ test_hevm_symbolic() { solc --bin-runtime -o . --overwrite "$CONTRACTS/factor.sol" # should find counterexample - hevm symbolic --code "$( Date: Wed, 22 Sep 2021 01:00:34 +0200 Subject: [PATCH 03/19] hevm: cli: output trace to stdout --- src/hevm/hevm-cli/hevm-cli.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hevm/hevm-cli/hevm-cli.hs b/src/hevm/hevm-cli/hevm-cli.hs index dde1a2419..e630a27f3 100644 --- a/src/hevm/hevm-cli/hevm-cli.hs +++ b/src/hevm/hevm-cli/hevm-cli.hs @@ -632,7 +632,7 @@ launchExec cmd = do case optsMode cmd of Run -> do vm' <- execStateT (EVM.Stepper.interpret fetcher . void $ EVM.Stepper.execFully) vm - when (trace cmd) $ hPutStr stderr (showTraceTree dapp vm') + when (trace cmd) $ hPutStr stdout $ showTraceTree dapp vm' case view EVM.result vm' of Nothing -> error "internal error; no EVM result" From 3a803aec1d50936446b4eb9c6e84426750d35667 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 01:24:58 +0200 Subject: [PATCH 04/19] seth: run-tx: tests & docs --- src/dapp-tests/integration/tests.sh | 29 ++++++++++++++++++----------- src/seth/libexec/seth/seth-run-tx | 4 ++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index d293f46b7..25a8a7f8d 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -578,29 +578,36 @@ test_to_fix4() { test_run_tx_source_fetching() { ETH_RPC_URL=$ARCHIVE_NODE_URL trace=$(mktemp) + err=$(mktemp) + + # prints a message when source is not available + seth run-tx 0xc1511d7fcc498ae8236a18a67786701e6980dcf641b72bcfd4c2a3cd45fb209c --trace 1> "$trace" 2> "$err" + assert "grep -q 'Contract source code not verified' $err" + assert "grep -q 'delegatecall 0xAa1c1B3BbbB59930a4E88F87345B8C513cc56Fa6::0x526327f2' $trace" # seth pulls from etherscan by default - seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" 2>&1 - assert "grep -q 'UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C' $trace" "did not pull source by default" - assert "grep -q 'PairCreated(UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C, 51691)' $trace" "did not pull source by default" + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" + assert "grep -q 'UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C' $trace" + assert "grep -q 'PairCreated(UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C, 51691)' $trace" - # seth does not pull from etherscan if ETHERSCAN_API_KEY is unset - DAPP_JSON=/dev/null seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" 2>&1 + # seth does not pull from etherscan if --source is passed + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --source /dev/null > "$trace" assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" - # seth does not pull from etherscan if DAPP_JSON is set - DAPP_JSON=/dev/null seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" 2>&1 + # seth does not pull from etherscan if --no-src is passed at the command line + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --no-src > "$trace" assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" - # seth does not pull from etherscan if --no-src is passed at the command line - seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --no-src > "$trace" 2>&1 + # seth does not pull from etherscan if SETH_NOSRC is set to "yes" + SETH_NOSRC=yes seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" - # seth does not pull from etherscan if SETH_NOSRC is set to "yes" - SETH_NOSRC=yes seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" 2>&1 + # seth does not pull from etherscan if ETHERSCAN_API_KEY is unset + unset ETHERSCAN_API_KEY + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" } diff --git a/src/seth/libexec/seth/seth-run-tx b/src/seth/libexec/seth/seth-run-tx index 780f1abd5..087f52c8c 100755 --- a/src/seth/libexec/seth/seth-run-tx +++ b/src/seth/libexec/seth/seth-run-tx @@ -5,9 +5,13 @@ ### ### Run a transaction with hevm in the environment of the given transaction. ### +### Attempts to fetch contract source from etherscan if `ETHERSCAN_API_KEY` is set. +### ### With `--state dir`, load and save state from `dir` ### With `--trace`, print the call trace of the transaction. ### With `--debug`, execute with hevm's interactive debugger +### With `--no-src`, do not attempt to fetch contract source from etherscan +### With `--source`, manually supply a solc compiler output json (implies --no-src) set -e # if the argument begins with 0x, we assume it to be a tx hash From c74f475d57ce74839430a24b997963ad8fde5930 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 01:35:10 +0200 Subject: [PATCH 05/19] changelogs --- src/hevm/CHANGELOG.md | 1 + src/seth/CHANGELOG.md | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hevm/CHANGELOG.md b/src/hevm/CHANGELOG.md index 11e13d3d3..69401c68f 100644 --- a/src/hevm/CHANGELOG.md +++ b/src/hevm/CHANGELOG.md @@ -4,6 +4,7 @@ ## Fixed +- Trace output from `hevm exec --trace` is now output to `stdout` - Test contracts with no code (e.g. `abstract` contracts) are now skipped - Replay data for invariant tests is now displayed in a form that does not cause errors when used with `dapp test --replay` diff --git a/src/seth/CHANGELOG.md b/src/seth/CHANGELOG.md index b2c265be2..037f70bd1 100644 --- a/src/seth/CHANGELOG.md +++ b/src/seth/CHANGELOG.md @@ -6,11 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased -### Fixed - -Contract creations with Dynamic fee transactions. - - ### Changed - `seth 4byte` command returns the response from querying [4byte.directory](https://www.4byte.directory/) for a given function signature @@ -19,10 +14,13 @@ Contract creations with Dynamic fee transactions. - `seth abi-encode` command returns the ABI encoded values without the function signature - `seth index` command returns the slot number for the specified mapping type and input data - `seth --from-fix` command converts fixed point numbers into parsed integers with the specified number of decimals +- `seth run-tx` now fetches contract source from etherscan if `ETHERSCAN_API_KEY` is set ### Fixed - Address lookup no longer fails if `ETH_RPC_ACCOUNTS` is set, and `ETH_FROM` is an unchecksummed address +- Contract creations with Dynamic fee transactions +- Trace output from `seth run-tx --trace` is now output to `stdout` ## [0.11.0] - 2021-09-08 From 63a5d2b84c9fac1a85f9385651a520c77e91b2fc Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 01:39:38 +0200 Subject: [PATCH 06/19] seth: run-tx docs --- src/seth/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/seth/README.md b/src/seth/README.md index 57056cfb3..5e6abe5e3 100644 --- a/src/seth/README.md +++ b/src/seth/README.md @@ -802,16 +802,17 @@ so users must ensure the ENS names they enter are properly formatted. ### `seth run-tx` -Execute a transaction using `hevm`. +Run a transaction with hevm in the environment of the given transaction. seth run-tx [] +Attempts to fetch contract source from etherscan if `ETHERSCAN_API_KEY` is set. + With `--state dir`, load and save state from `dir` -With `--trace`, run in headless mode and print the call trace of the transaction. +With `--trace`, print the call trace of the transaction. With `--debug`, execute with hevm's interactive debugger -Use `--source=` to pass source information for a more illuminating experience. -Source files can be fetched remotely via [`seth bundle-source`], -but you can use the output of [`dapp build`](../dapp/README.md#dapp-build) here. +With `--no-src`, do not attempt to fetch contract source from etherscan +With `--source=`, manually supply a solc compiler output json (implies `--no-src`) ### `seth send` From d8b7535853848d3da78efbe70de7554f95809a6e Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 12:18:41 +0200 Subject: [PATCH 07/19] dapp-tests: integration: fix typos --- src/dapp-tests/integration/tests.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index 25a8a7f8d..7fd6a5899 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -161,13 +161,13 @@ test_smoke() { # checks that seth send works with both checksummed and unchecksummed addresses test_seth_send_address_formats() { local account - account=$(fresh_account) + acc=$(fresh_account) - lower=$(echo "$account" | tr '[:upper:]' '[:lower:]') + lower=$(echo "$acc" | tr '[:upper:]' '[:lower:]') export ETH_GAS=0xffff # with checksummed - tx=$(seth send "$ZERO" --from "$ACC" --password /dev/null --value "$(seth --to-wei 1 ether)" --keystore "$TMPDIR"/8545/keystore --async) + tx=$(seth send "$ZERO" --from "$acc" --password /dev/null --value "$(seth --to-wei 1 ether)" --keystore "$TMPDIR"/8545/keystore --async) assert_equals "$lower" "$(seth tx "$tx" from)" # without checksum @@ -178,7 +178,7 @@ test_seth_send_address_formats() { export ETH_RPC_ACCOUNTS=true # with checksummed - tx=$(seth send "$ZERO" --from "$ACC" --password /dev/null --value "$(seth --to-wei 1 ether)" --keystore "$TMPDIR"/8545/keystore --async) + tx=$(seth send "$ZERO" --from "$acc" --password /dev/null --value "$(seth --to-wei 1 ether)" --keystore "$TMPDIR"/8545/keystore --async) assert_equals "$lower" "$(seth tx "$tx" from)" # without checksum From bf7c4a947da2a0993657f459186b64a79a7b038a Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 12:18:57 +0200 Subject: [PATCH 08/19] dapp-tests: add all required deps to nix-shell --- src/dapp-tests/shell.nix | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/dapp-tests/shell.nix b/src/dapp-tests/shell.nix index dee3268db..3976d1d3d 100644 --- a/src/dapp-tests/shell.nix +++ b/src/dapp-tests/shell.nix @@ -14,5 +14,25 @@ in mkShell { name = "dapp-tests"; - buildInputs = [ killall bash_unit cacert bashInteractive curl dapp gnumake hevm procps seth solc go-ethereum python-with-pkgs ]; + buildInputs = [ + bashInteractive + bash_unit + bc + cacert + coreutils + curl + dapp + gnumake + go-ethereum + hevm + jq + killall + procps + python-with-pkgs + seth + solc + util-linux + which + ]; + LANG="en_US.UTF-8"; } From f02b7737a4464c85d78bb01489d2820cefa3002d Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 13:55:42 +0200 Subject: [PATCH 09/19] dapp-tests: fix TMPDIR usage, quote variables --- src/dapp-tests/integration/tests.sh | 75 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index 7fd6a5899..d83a64657 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -6,12 +6,12 @@ set -euo pipefail # CONFIGURATION # ------------------------------------------------ -SKIP_SETUP=${SKIP_SETUP:-0} -FUZZ_RUNS=${FUZZ_RUNS:-100} -TESTNET_SLEEP=${TESTNET_SLEEP:-5} -ETHERSCAN_API_KEY=${ETHERSCAN_API_KEY:-15IS6MMRAYB19NZN9VHH6H6P57892Z664M} -RINKEBY_RPC_URL=${RINKEBY_RPC_URL:-https://rinkeby.infura.io/v3/84842078b09946638c03157f83405213} -ARCHIVE_NODE_URL=${ARCHIVE_NODE_URL:-https://eth-mainnet.alchemyapi.io/v2/vpeKFsEF6PHifHzdtcwXSDbhV3ym5Ro4} +export SKIP_SETUP=${SKIP_SETUP:-0} +export FUZZ_RUNS=${FUZZ_RUNS:-100} +export TESTNET_SLEEP=${TESTNET_SLEEP:-5} +export RINKEBY_RPC_URL=${RINKEBY_RPC_URL:-https://rinkeby.infura.io/v3/84842078b09946638c03157f83405213} +export ARCHIVE_NODE_URL=${ARCHIVE_NODE_URL:-https://eth-mainnet.alchemyapi.io/v2/vpeKFsEF6PHifHzdtcwXSDbhV3ym5Ro4} +export ETHERSCAN_API_KEY=${ETHERSCAN_API_KEY:-15IS6MMRAYB19NZN9VHH6H6P57892Z664M} # ------------------------------------------------ # SHARED SETUP @@ -20,16 +20,17 @@ ARCHIVE_NODE_URL=${ARCHIVE_NODE_URL:-https://eth-mainnet.alchemyapi.io/v2/vpeKFs # we spin up a new testnet instance and share it between all tests setup_suite() { if [[ "$SKIP_SETUP" != 1 ]]; then - TMPDIR=$(mktemp -d) + export GETHDIR + GETHDIR=$(mktemp -d) - dapp testnet --dir "$TMPDIR" & + dapp testnet --dir "$GETHDIR" & # give it a few secs to start up sleep "$TESTNET_SLEEP" export ETH_RPC_URL="http://127.0.0.1:8545" - export ETH_KEYSTORE="$TMPDIR/8545/keystore" + export ETH_KEYSTORE="$GETHDIR/8545/keystore" export ETH_PASSWORD=/dev/null - read -r ROOT _ <<< "$(seth ls --keystore "$TMPDIR/8545/keystore")" + read -r ROOT _ <<< "$(seth ls --keystore "$GETHDIR/8545/keystore")" fi } @@ -37,7 +38,7 @@ setup_suite() { teardown_suite() { if [[ "$SKIP_SETUP" != 1 ]]; then killall geth - rm -rf "$TMPDIR" + rm -rf "$GETHDIR" fi } @@ -115,24 +116,25 @@ alpha() { # `seth run-tx` # `hevm exec` test_smoke() { - local account + local account bytecode account=$(fresh_account) + bytecode=$(mktemp -d) # Deploy a simple contract: - solc --bin --bin-runtime "$CONTRACTS/stateful.sol" -o "$TMPDIR" + solc --bin --bin-runtime "$CONTRACTS/stateful.sol" -o "$bytecode" - A_ADDR=$(seth send --create "$(<"$TMPDIR"/A.bin)" "constructor(uint y)" 1 --from "$account" --keystore "$TMPDIR"/8545/keystore --password /dev/null --gas 0xffffff) + A_ADDR=$(seth send --create "$(<"$bytecode"/A.bin)" "constructor(uint y)" 1 --from "$account" --gas 0xffffff) # Compare deployed code with what solc gives us - assert_equals 0x"$(cat "$TMPDIR"/A.bin-runtime)" "$(seth code "$A_ADDR")" + assert_equals 0x"$(cat "$bytecode"/A.bin-runtime)" "$(seth code "$A_ADDR")" # And with what hevm gives us EXTRA_CALLDATA=$(seth --to-uint256 1) - HEVM_RET=$(hevm exec --code "$(<"$TMPDIR"/A.bin)""${EXTRA_CALLDATA/0x/}" --gas 0xffffff) + HEVM_RET=$(hevm exec --code "$(<"$bytecode"/A.bin)""${EXTRA_CALLDATA/0x/}" --gas 0xffffff) assert_equals "$HEVM_RET" "$(seth code "$A_ADDR")" - TX=$(seth send "$A_ADDR" "off()" --gas 0xffff --password /dev/null --from "$account" --keystore "$TMPDIR"/8545/keystore --async) + TX=$(seth send "$A_ADDR" "off()" --gas 0xffff --password /dev/null --from "$account" --async) # since we have one tx per block, seth run-tx and seth debug are equivalent assert_equals 0x "$(seth run-tx "$TX" --no-src)" @@ -142,16 +144,13 @@ test_smoke() { --gas 0xffff \ --password /dev/null \ --from "$account" \ - --keystore "$TMPDIR"/8545/keystore \ --prio-fee 2gwei \ --gas-price 10gwei - B_ADDR=$(seth send \ - --create 0x647175696e6550383480393834f3 \ + B_ADDR=$(seth send --create 0x647175696e6550383480393834f3 \ --gas 0xffff \ --password /dev/null \ --from "$account" \ - --keystore "$TMPDIR"/8545/keystore \ --prio-fee 2gwei \ --gas-price 10gwei) @@ -167,22 +166,22 @@ test_seth_send_address_formats() { export ETH_GAS=0xffff # with checksummed - tx=$(seth send "$ZERO" --from "$acc" --password /dev/null --value "$(seth --to-wei 1 ether)" --keystore "$TMPDIR"/8545/keystore --async) + tx=$(seth send "$ZERO" --from "$acc" --password /dev/null --value "$(seth --to-wei 1 ether)" --async) assert_equals "$lower" "$(seth tx "$tx" from)" # without checksum - tx=$(seth send "$ZERO" --from "$lower" --password /dev/null --value "$(seth --to-wei 1 ether)" --keystore "$TMPDIR"/8545/keystore --async) + tx=$(seth send "$ZERO" --from "$lower" --password /dev/null --value "$(seth --to-wei 1 ether)" --async) assert_equals "$lower" "$(seth tx "$tx" from)" # try again with eth_rpc_accounts export ETH_RPC_ACCOUNTS=true # with checksummed - tx=$(seth send "$ZERO" --from "$acc" --password /dev/null --value "$(seth --to-wei 1 ether)" --keystore "$TMPDIR"/8545/keystore --async) + tx=$(seth send "$ZERO" --from "$acc" --password /dev/null --value "$(seth --to-wei 1 ether)" --async) assert_equals "$lower" "$(seth tx "$tx" from)" # without checksum - tx=$(seth send "$ZERO" --from "$lower" --password /dev/null --value "$(seth --to-wei 1 ether)" --keystore "$TMPDIR"/8545/keystore --async) + tx=$(seth send "$ZERO" --from "$lower" --password /dev/null --value "$(seth --to-wei 1 ether)" --async) assert_equals "$lower" "$(seth tx "$tx" from)" } @@ -205,14 +204,14 @@ test_hevm_symbolic() { } test_custom_solc_json() { - TMPDIR=$(mktemp -d) + tmp=$(mktemp -d) # copy source file - mkdir -p "$TMPDIR/src" - cp "$CONTRACTS/factor.sol" "$TMPDIR/src" + mkdir -p "$tmp/src" + cp "$CONTRACTS/factor.sol" "$tmp/src" # init dapp project - cd "$TMPDIR" || exit + cd "$tmp" || exit export GIT_CONFIG_NOSYSTEM=1 export GIT_AUTHOR_NAME=dapp export GIT_AUTHOR_EMAIL=dapp@hub.lol @@ -256,7 +255,7 @@ test_block_1() { } test_decimal_roundtrip() { - for _ in $(seq $FUZZ_RUNS); do + for _ in $(seq "$FUZZ_RUNS"); do local input input=$(uint256) assert_equals "$input" "$(seth --to-dec "$(seth --to-hex "$input")")" @@ -264,7 +263,7 @@ test_decimal_roundtrip() { } test_hex_roundtrip() { - for _ in $(seq $FUZZ_RUNS); do + for _ in $(seq "$FUZZ_RUNS"); do local input input="0x$(bytes32)" lower=$(echo "$input" | tr '[:upper:]' '[:lower:]') @@ -273,7 +272,7 @@ test_hex_roundtrip() { } test_to_fix_roundtrip() { - for _ in $(seq $FUZZ_RUNS); do + for _ in $(seq "$FUZZ_RUNS"); do local input digits input="$(uint256)" digits="$(mod "$(uint8)" 77)" # 78 decimal digits in max uint256 @@ -282,7 +281,7 @@ test_to_fix_roundtrip() { } test_from_fix_roundtrip() { - for _ in $(seq $FUZZ_RUNS); do + for _ in $(seq "$FUZZ_RUNS"); do local input digits input="$(uint256)" length="${#input}" @@ -516,21 +515,21 @@ test_resolve_name1() { test_resolve_name2() { assert_equals \ - "$(seth resolve-name seth-test.eth --rpc-url=$RINKEBY_RPC_URL)" \ - "$(seth resolve-name sEtH-tESt.etH --rpc-url=$RINKEBY_RPC_URL)" + "$(seth resolve-name seth-test.eth --rpc-url="$RINKEBY_RPC_URL")" \ + "$(seth resolve-name sEtH-tESt.etH --rpc-url="$RINKEBY_RPC_URL")" } test_lookup_address1() { # using example from ethers docs: https://docs.ethers.io/v5/single-page/#/v5/api/providers/provider/-%23-Provider-lookupAddress local output - output=$(seth lookup-address 0x49c92F2cE8F876b070b114a6B2F8A60b83c281Ad --rpc-url=$RINKEBY_RPC_URL) + output=$(seth lookup-address 0x49c92F2cE8F876b070b114a6B2F8A60b83c281Ad --rpc-url="$RINKEBY_RPC_URL") assert_equals "seth-test.eth" "$output" } test_lookup_address2() { assert_equals \ - "$(seth lookup-address 0x49c92F2cE8F876b070b114a6B2F8A60b83c281Ad --rpc-url=$RINKEBY_RPC_URL)" \ - "$(seth lookup-address 0x49c92f2ce8f876b070b114a6b2f8a60b83c281ad --rpc-url=$RINKEBY_RPC_URL)" + "$(seth lookup-address 0x49c92F2cE8F876b070b114a6B2F8A60b83c281Ad --rpc-url="$RINKEBY_RPC_URL")" \ + "$(seth lookup-address 0x49c92f2ce8f876b070b114a6b2f8a60b83c281ad --rpc-url="$RINKEBY_RPC_URL")" } # SETH 4BYTE TESTS From bba86742b5655325c6dcbc607d687a42b528c39f Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 13:58:29 +0200 Subject: [PATCH 10/19] seth: run-tx: place source files in a temporary directory --- src/dapp-tests/integration/tests.sh | 42 ++++++++++++++++-------- src/seth/libexec/seth/seth-bundle-source | 14 +++++--- src/seth/libexec/seth/seth-run-tx | 7 ++-- src/seth/libexec/seth/seth-solc | 5 ++- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index d83a64657..6ac1ec3e2 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -576,37 +576,53 @@ test_to_fix4() { # SETH RUN-TX TESTS test_run_tx_source_fetching() { ETH_RPC_URL=$ARCHIVE_NODE_URL + local trace err trace=$(mktemp) err=$(mktemp) # prints a message when source is not available seth run-tx 0xc1511d7fcc498ae8236a18a67786701e6980dcf641b72bcfd4c2a3cd45fb209c --trace 1> "$trace" 2> "$err" - assert "grep -q 'Contract source code not verified' $err" - assert "grep -q 'delegatecall 0xAa1c1B3BbbB59930a4E88F87345B8C513cc56Fa6::0x526327f2' $trace" + assert "grep -q 'Contract source code not verified' $err" "1" + assert "grep -q 'delegatecall 0xAa1c1B3BbbB59930a4E88F87345B8C513cc56Fa6::0x526327f2' $trace" "2" - # seth pulls from etherscan by default + local prefiles + prefiles=$(ls) + + # seth pulls from etherscan by default (flattened) seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" - assert "grep -q 'UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C' $trace" - assert "grep -q 'PairCreated(UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C, 51691)' $trace" + assert "grep -q 'UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C' $trace" "3" + assert "grep -q 'PairCreated(UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C, 51691)' $trace" "4" + + # seth does not write any files to the cwd + assert_equals "$prefiles" "$(ls)" + + # seth pulls from etherscan by default (stdjson) + seth run-tx 0x5da4bf1e5988cf94fd96d2c1dd3f420d2cea1aebe8d1e1c10dd9fe78a2147798 --trace > "$trace" + assert "grep -q 'ownerOf' $trace" "5" + assert "grep -q 'iFeather@0xD1edDfcc4596CC8bD0bd7495beaB9B979fc50336' $trace" "6" + assert "grep -q 'Transfer()' $trace" "7" + + # seth does not write any files to the cwd + assert_equals "$prefiles" "$(ls)" # seth does not pull from etherscan if --source is passed seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --source /dev/null > "$trace" - assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" - assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" "8" + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" "9" # seth does not pull from etherscan if --no-src is passed at the command line seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --no-src > "$trace" - assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" - assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" "10" + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" "11" # seth does not pull from etherscan if SETH_NOSRC is set to "yes" SETH_NOSRC=yes seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" - assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" - assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" "12" + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" "13" # seth does not pull from etherscan if ETHERSCAN_API_KEY is unset unset ETHERSCAN_API_KEY seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" - assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" - assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" "14" + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" "15" } diff --git a/src/seth/libexec/seth/seth-bundle-source b/src/seth/libexec/seth/seth-bundle-source index 9cb0f6a3c..a0b28fde1 100755 --- a/src/seth/libexec/seth/seth-bundle-source +++ b/src/seth/libexec/seth/seth-bundle-source @@ -4,6 +4,8 @@ ### ### Requires an etherscan api key ### +### Use `--dir` to control where the contract source is written (default is cwd) +### set -e [[ -z "$1" ]] && seth --fail-usage @@ -17,24 +19,26 @@ SOLC_VERSION=${SOLC_VERSION/+*} SOURCE="$(jq -r '.SourceCode' <<< "$ETHERSCAN_SRC" | tr -d '\r')" +SETH_DIR=${SETH_DIR:-.} + case "$SOURCE" in \{*\}) # standard-json # for some reason etherscan surrounds the actual json with '{}' SOURCE="${SOURCE/#\{\{/\{}" SOURCE="${SOURCE/%\}\}/\}}" - # write all source files in the local directory + # write all source files to SETH_DIR for x in $(echo "$SOURCE" | jq '.sources | keys | .[]' -r); do - mkdir -p "$(dirname "$x")" - echo "$SOURCE" | jq ".sources.\"$x\".content" -r > $x + mkdir -p "$SETH_DIR/$(dirname "$x")" + echo "$SOURCE" | jq ".sources.\"$x\".content" -r > "$SETH_DIR/$x" done; export DAPP_SOLC_JSON="$SOURCE" - seth --use solc:"${SOLC_VERSION}" solc + seth --use solc:"${SOLC_VERSION}" solc --dir "$SETH_DIR" ;; *) # flattened file NAME="$(jq -r '.ContractName' <<< "$ETHERSCAN_SRC")" - FILE="${SETH_DIR:-.}/${NAME}.sol" + FILE="$SETH_DIR/$NAME.sol" echo "$SOURCE" > "$FILE" OPT=$(jq -r '.OptimizationUsed' <<< "$ETHERSCAN_SRC") if [[ "$OPT" -ne 0 ]]; then diff --git a/src/seth/libexec/seth/seth-run-tx b/src/seth/libexec/seth/seth-run-tx index 087f52c8c..e3a1ade5b 100755 --- a/src/seth/libexec/seth/seth-run-tx +++ b/src/seth/libexec/seth/seth-run-tx @@ -33,8 +33,9 @@ else fi if [[ -n "$ETHERSCAN_API_KEY" && -z "$DAPP_JSON" && "$SETH_NOSRC" != yes ]]; then - DAPP_JSON=$(mktemp) - seth bundle-source "$TO" > "$DAPP_JSON" || : + TMP=$(mktemp -d) + DAPP_JSON="$TMP/solc.out.json" + seth bundle-source --dir "$TMP" "$TO" > "$DAPP_JSON" || : fi opts+=(--caller "$(<<< "$tx" seth --field from)" ) @@ -53,4 +54,4 @@ opts+=(--chainid "${ETH_CHAINID:-$(seth rpc eth_chainId | seth --to-dec)}") [[ "$HEVM_TRACE" ]] && opts+=(--trace) [[ "$DAPP_JSON" ]] && opts+=(--json-file "$DAPP_JSON") -([[ $SETH_VERBOSE ]] && set -x; hevm exec "${opts[@]}") +([[ $SETH_VERBOSE ]] && set -x; [[ $DAPP_JSON ]] && cd "$TMP"; hevm exec "${opts[@]}") diff --git a/src/seth/libexec/seth/seth-solc b/src/seth/libexec/seth/seth-solc index 999826a7d..3a2eb7cca 100755 --- a/src/seth/libexec/seth/seth-solc +++ b/src/seth/libexec/seth/seth-solc @@ -8,11 +8,14 @@ ### - DAPP_SOLC_OPTIMIZE_RUNS (default 200) ### - DAPP_SOLC_JSON (must be provided if not specified) ### +### You can pass --dir to control the directory in which compilation will occur (default cwd) +### set -e OPTIMIZE=${DAPP_SOLC_OPTIMIZE:-false} RUNS=${DAPP_SOLC_OPTIMIZE_RUNS:-200} SOLC=${DAPP_SOLC:-solc} +SETH_DIR=${SETH_DIR:-.} if [[ -z "$DAPP_SOLC_JSON" && -z "$1" ]]; then seth --fail "must provide either .sol input file or DAPP_SOLC_JSON standard json" @@ -49,4 +52,4 @@ JSON="$(<<<"$JSON" jq '. ')" ( [[ $SETH_VERBOSE ]] && set -x; - echo "$JSON" | $SOLC --standard-json --allow-paths "$(realpath $1)" | jq . ) + cd "$SETH_DIR" && echo "$JSON" | $SOLC --standard-json --allow-paths "$(realpath "${1:-.}")" | jq . ) From 5c40aab1bc2f41c2ba3555cdf6d247c5c9e27a84 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 14:05:46 +0200 Subject: [PATCH 11/19] Revert "hevm: cli: output trace to stdout" This reverts commit 1496b72d595e7e6e5722692d1255a6e0c727bae3. --- src/hevm/hevm-cli/hevm-cli.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hevm/hevm-cli/hevm-cli.hs b/src/hevm/hevm-cli/hevm-cli.hs index e630a27f3..dde1a2419 100644 --- a/src/hevm/hevm-cli/hevm-cli.hs +++ b/src/hevm/hevm-cli/hevm-cli.hs @@ -632,7 +632,7 @@ launchExec cmd = do case optsMode cmd of Run -> do vm' <- execStateT (EVM.Stepper.interpret fetcher . void $ EVM.Stepper.execFully) vm - when (trace cmd) $ hPutStr stdout $ showTraceTree dapp vm' + when (trace cmd) $ hPutStr stderr (showTraceTree dapp vm') case view EVM.result vm' of Nothing -> error "internal error; no EVM result" From 8ab0490fdc5c33104d1b04996fef78332a902dc5 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 14:29:01 +0200 Subject: [PATCH 12/19] dapp-tests: update expected results for stdout / stderr --- src/dapp-tests/integration/tests.sh | 56 ++++++++++++++++------------- src/hevm/CHANGELOG.md | 1 - src/seth/CHANGELOG.md | 1 - 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index 6ac1ec3e2..8aa5cd143 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -575,54 +575,60 @@ test_to_fix4() { # SETH RUN-TX TESTS test_run_tx_source_fetching() { - ETH_RPC_URL=$ARCHIVE_NODE_URL - local trace err - trace=$(mktemp) + export ETH_RPC_URL=$ARCHIVE_NODE_URL + local out err + out=$(mktemp) err=$(mktemp) # prints a message when source is not available - seth run-tx 0xc1511d7fcc498ae8236a18a67786701e6980dcf641b72bcfd4c2a3cd45fb209c --trace 1> "$trace" 2> "$err" - assert "grep -q 'Contract source code not verified' $err" "1" - assert "grep -q 'delegatecall 0xAa1c1B3BbbB59930a4E88F87345B8C513cc56Fa6::0x526327f2' $trace" "2" + seth run-tx 0xc1511d7fcc498ae8236a18a67786701e6980dcf641b72bcfd4c2a3cd45fb209c --trace 1> "$out" 2> "$err" + assert "grep -q 'Contract source code not verified' $err" 1 + assert "grep -q 'delegatecall 0xAa1c1B3BbbB59930a4E88F87345B8C513cc56Fa6::0x526327f2' $err" 2 + assert_equals "0x188fffa3a6cd08bdcc3d5bf4add2a2c0ac5e9d94a278ea1630187b3da583a1f0" "$(cat "$out")" local prefiles prefiles=$(ls) # seth pulls from etherscan by default (flattened) - seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" - assert "grep -q 'UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C' $trace" "3" - assert "grep -q 'PairCreated(UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C, 51691)' $trace" "4" + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace 1> "$out" 2> "$err" + assert "grep -q 'UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C' $err" 3 + assert "grep -q 'PairCreated(UniswapV2Pair@0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C, 51691)' $err" 4 + assert_equals "0x00000000000000000000000028d2df1e3481ba90d75e14b9c02cea85b7d6fa2c" "$(cat "$out")" # seth does not write any files to the cwd assert_equals "$prefiles" "$(ls)" # seth pulls from etherscan by default (stdjson) - seth run-tx 0x5da4bf1e5988cf94fd96d2c1dd3f420d2cea1aebe8d1e1c10dd9fe78a2147798 --trace > "$trace" - assert "grep -q 'ownerOf' $trace" "5" - assert "grep -q 'iFeather@0xD1edDfcc4596CC8bD0bd7495beaB9B979fc50336' $trace" "6" - assert "grep -q 'Transfer()' $trace" "7" + seth run-tx 0x5da4bf1e5988cf94fd96d2c1dd3f420d2cea1aebe8d1e1c10dd9fe78a2147798 --trace 1> "$out" 2> "$err" + assert "grep -q 'ownerOf' $err" 5 + assert "grep -q 'iFeather@0xD1edDfcc4596CC8bD0bd7495beaB9B979fc50336' $err" 6 + assert_equals "0x" "$(cat "$out")" # seth does not write any files to the cwd assert_equals "$prefiles" "$(ls)" # seth does not pull from etherscan if --source is passed - seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --source /dev/null > "$trace" - assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" "8" - assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" "9" + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --source /dev/null 1> "$out" 2> "$err" + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $err" 7 + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $err" 8 + assert_equals "0x00000000000000000000000028d2df1e3481ba90d75e14b9c02cea85b7d6fa2c" "$(cat "$out")" # seth does not pull from etherscan if --no-src is passed at the command line - seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --no-src > "$trace" - assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" "10" - assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" "11" + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace --no-src 1> "$out" 2> "$err" + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $err" 9 + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $err" 10 + assert_equals "0x00000000000000000000000028d2df1e3481ba90d75e14b9c02cea85b7d6fa2c" "$(cat "$out")" # seth does not pull from etherscan if SETH_NOSRC is set to "yes" - SETH_NOSRC=yes seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" - assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" "12" - assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" "13" + SETH_NOSRC=yes seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace 1> "$out" 2> "$err" + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $err" 11 + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $err" 12 + assert_equals "0x00000000000000000000000028d2df1e3481ba90d75e14b9c02cea85b7d6fa2c" "$(cat "$out")" # seth does not pull from etherscan if ETHERSCAN_API_KEY is unset unset ETHERSCAN_API_KEY - seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace > "$trace" - assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $trace" "14" - assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $trace" "15" + seth run-tx 0x41ccbab4d7d0cd55f481df7fce449986364bf13e655dddfb30aa9b38a4340db7 --trace 1> "$out" 2> "$err" + assert "grep -q 'call 0x28d2DF1E3481Ba90D75E14b9C02cea85b7d6FA2C::0x485cc9550000000000000000000000007fa7df4' $err" 13 + assert "grep -q 'log3(0xd3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9, 0xffffffffffffffff' $err" 14 + assert_equals "0x00000000000000000000000028d2df1e3481ba90d75e14b9c02cea85b7d6fa2c" "$(cat "$out")" } diff --git a/src/hevm/CHANGELOG.md b/src/hevm/CHANGELOG.md index 69401c68f..11e13d3d3 100644 --- a/src/hevm/CHANGELOG.md +++ b/src/hevm/CHANGELOG.md @@ -4,7 +4,6 @@ ## Fixed -- Trace output from `hevm exec --trace` is now output to `stdout` - Test contracts with no code (e.g. `abstract` contracts) are now skipped - Replay data for invariant tests is now displayed in a form that does not cause errors when used with `dapp test --replay` diff --git a/src/seth/CHANGELOG.md b/src/seth/CHANGELOG.md index 037f70bd1..3a5781078 100644 --- a/src/seth/CHANGELOG.md +++ b/src/seth/CHANGELOG.md @@ -20,7 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Address lookup no longer fails if `ETH_RPC_ACCOUNTS` is set, and `ETH_FROM` is an unchecksummed address - Contract creations with Dynamic fee transactions -- Trace output from `seth run-tx --trace` is now output to `stdout` ## [0.11.0] - 2021-09-08 From 9d11836e86b9dc3e66d54126ff4a465c3b6b3ded Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 14:32:56 +0200 Subject: [PATCH 13/19] seth: docs --- src/seth/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/seth/README.md b/src/seth/README.md index 5e6abe5e3..11b930f9b 100644 --- a/src/seth/README.md +++ b/src/seth/README.md @@ -560,6 +560,8 @@ provide source maps in calls to [`seth run-tx`] or [`hevm exec --debug --rpc`](. Requires the `ETHERSCAN_API_KEY` environment variable to be set. +Use `--dir` to control the directory in which compilation occurs (defaults to current working directory) + ### `seth call` Call a contract without updating the blockchain. From 1d2f806944149c37cf4b7bf561918f3015f2b098 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 14:52:42 +0200 Subject: [PATCH 14/19] dapp-tests: integration: turn off strict mode --- src/dapp-tests/integration/tests.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index 8aa5cd143..503a98f1e 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -1,7 +1,5 @@ #! /usr/bin/env bash -set -euo pipefail - # ------------------------------------------------ # CONFIGURATION # ------------------------------------------------ From 2fbbe89c1d33594c389b28abc78b7f5d4f766200 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 15:00:57 +0200 Subject: [PATCH 15/19] dapp-tests: bump testnet wait time in CI --- src/dapp-tests/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dapp-tests/Makefile b/src/dapp-tests/Makefile index 69d1e1818..902dd862b 100644 --- a/src/dapp-tests/Makefile +++ b/src/dapp-tests/Makefile @@ -4,6 +4,7 @@ test: ci: export FUZZ_RUNS=10000 + export TESTNET_SLEEP=90 pytest --hypothesis-show-statistics integration/diff-fuzz.py bash_unit integration/tests.sh From 281856adeedbfe0e2721f8b8ffe0a793b5f60f77 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 15:13:39 +0200 Subject: [PATCH 16/19] dapp-tests: makefile: fix ci variable export --- src/dapp-tests/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dapp-tests/Makefile b/src/dapp-tests/Makefile index 902dd862b..5dce7df31 100644 --- a/src/dapp-tests/Makefile +++ b/src/dapp-tests/Makefile @@ -3,9 +3,7 @@ test: bash_unit integration/tests.sh ci: - export FUZZ_RUNS=10000 - export TESTNET_SLEEP=90 pytest --hypothesis-show-statistics integration/diff-fuzz.py - bash_unit integration/tests.sh + FUZZ_RUNS=10000 TESTNET_SLEEP=90 bash_unit integration/tests.sh .PHONY: test From c962b4598e32c1181b330250c3f1bb8549503c84 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 15:14:02 +0200 Subject: [PATCH 17/19] dapp-tests: integration: pipe hevm symbolic output to /dev/null --- src/dapp-tests/integration/tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index 503a98f1e..1790c5fc3 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -190,7 +190,7 @@ test_hevm_symbolic() { solc --bin-runtime -o . --overwrite "$CONTRACTS/factor.sol" # should find counterexample hevm symbolic --code "$( /dev/null || fail solc --bin-runtime -o . --overwrite "$CONTRACTS/token.sol" # This one explores all paths (cvc4 is better at this) From 6b8a043f7983e2876e3541bbe99b86aa8a7b0051 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 15:44:32 +0200 Subject: [PATCH 18/19] ci: fix bad substitution error on macos --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0026431ae..c417ec0c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,6 +20,9 @@ jobs: - uses: actions/checkout@v2 # v12 - uses: cachix/install-nix-action@v12 + with: + # https://discourse.nixos.org/t/understanding-binutils-darwin-wrapper-nix-support-bad-substitution/11475/2 + nix_path: nixpkgs=channel:nixos-unstable # v8 - uses: cachix/cachix-action@v8 with: From 75d204f8825b1c9ebd96fbb4d9a58cf63eb1b20f Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 22 Sep 2021 15:46:51 +0200 Subject: [PATCH 19/19] dapp-tests: integration: rework fixpoint roundtrips --- src/dapp-tests/integration/tests.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dapp-tests/integration/tests.sh b/src/dapp-tests/integration/tests.sh index 1790c5fc3..46041c265 100755 --- a/src/dapp-tests/integration/tests.sh +++ b/src/dapp-tests/integration/tests.sh @@ -273,7 +273,10 @@ test_to_fix_roundtrip() { for _ in $(seq "$FUZZ_RUNS"); do local input digits input="$(uint256)" - digits="$(mod "$(uint8)" 77)" # 78 decimal digits in max uint256 + + length="${#input}" + digits="$(mod "$(uint8)" "$length")" + assert_equals "$input" "$(seth --from-fix "$digits" "$(seth --to-fix "$digits" "$input")")" done } @@ -282,10 +285,10 @@ test_from_fix_roundtrip() { for _ in $(seq "$FUZZ_RUNS"); do local input digits input="$(uint256)" + length="${#input}" - digits="$(mod "$(uint8)" 77)" # 78 decimal digits in max uint256 + digits="$(mod "$(uint8)" "$length")" - [[ $digits -ge $length ]] && continue whole_digits=$(bc <<< "$length - $digits" | tr -d '\\\n') input="${input:0:whole_digits}.${input:$whole_digits:$length}"