Merge pull request #12441 from ethereum/benchmarking-ext-tests

Benchmarking external tests
This commit is contained in:
Leo
2022-02-14 20:14:27 +01:00
committed by GitHub
22 changed files with 1261 additions and 39 deletions
+5 -1
View File
@@ -24,13 +24,16 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
SELECTED_PRESETS="$3"
function compile_fn { npm run compile; }
function test_fn { npm run test; }
# NOTE: `npm run test` runs `mocha` which seems to disable the gas reporter.
function test_fn { HARDHAT_DEPLOY_FIXTURE=true npx --no hardhat --no-compile test; }
function bleeps_test
{
@@ -87,6 +90,7 @@ function bleeps_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat bleeps "$repo" "$preset"
done
popd
+3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -73,6 +75,7 @@ function colony_test
for preset in $SELECTED_PRESETS; do
truffle_run_test "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report truffle colony "$repo" "$preset"
done
}
+158 -10
View File
@@ -20,7 +20,7 @@
#------------------------------------------------------------------------------
set -e
# Requires "${REPO_ROOT}/scripts/common.sh" to be included before.
# Requires $REPO_ROOT to be defined and "${REPO_ROOT}/scripts/common.sh" to be included before.
CURRENT_EVM_VERSION=london
@@ -215,9 +215,19 @@ function force_truffle_compiler_settings
echo "Compiler version (full): ${SOLCVERSION}"
echo "-------------------------------------"
# Forcing the settings should always work by just overwriting the solc object. Forcing them by using a
# dedicated settings objects should only be the fallback.
echo "module.exports['compilers'] = $(truffle_compiler_settings "$solc_path" "$preset" "$evm_version");" >> "$config_file"
local compiler_settings gas_reporter_settings
compiler_settings=$(truffle_compiler_settings "$solc_path" "$preset" "$evm_version")
gas_reporter_settings=$(eth_gas_reporter_settings "$preset")
{
echo "require('eth-gas-reporter');"
echo "module.exports['mocha'] = {"
echo " reporter: 'eth-gas-reporter',"
echo " reporterOptions: ${gas_reporter_settings}"
echo "};"
echo "module.exports['compilers'] = ${compiler_settings};"
} >> "$config_file"
}
function name_hardhat_default_export
@@ -286,16 +296,21 @@ function force_hardhat_compiler_settings
echo "Compiler version (full): ${SOLCVERSION}"
echo "-------------------------------------"
local settings
settings=$(hardhat_compiler_settings "$SOLCVERSION_SHORT" "$preset" "$evm_version")
local compiler_settings gas_reporter_settings
compiler_settings=$(hardhat_compiler_settings "$SOLCVERSION_SHORT" "$preset" "$evm_version")
gas_reporter_settings=$(eth_gas_reporter_settings "$preset")
if [[ $config_file == *\.js ]]; then
[[ $config_var_name == "" ]] || assertFail
echo "module.exports['solidity'] = ${settings}" >> "$config_file"
echo "require('hardhat-gas-reporter');"
echo "module.exports.gasReporter = ${gas_reporter_settings};"
echo "module.exports.solidity = ${compiler_settings};"
else
[[ $config_file == *\.ts ]] || assertFail
[[ $config_var_name != "" ]] || assertFail
echo "${config_var_name}.solidity = {compilers: [${settings}]}" >> "$config_file"
fi
echo 'import "hardhat-gas-reporter";'
echo "${config_var_name}.gasReporter = ${gas_reporter_settings};"
echo "${config_var_name}.solidity = {compilers: [${compiler_settings}]};"
fi >> "$config_file"
}
function truffle_verify_compiler_version
@@ -328,7 +343,7 @@ function truffle_clean
function hardhat_clean
{
rm -rf artifacts/ cache/
rm -rf build/ artifacts/ cache/
}
function settings_from_preset
@@ -362,6 +377,21 @@ function replace_global_solc
export PATH="$PWD:$PATH"
}
function eth_gas_reporter_settings
{
local preset="$1"
echo "{"
echo " enabled: true,"
echo " gasPrice: 1," # Gas price does not matter to us at all. Set to whatever to avoid API call.
echo " noColors: true,"
echo " showTimeSpent: false," # We're not interested in test timing
echo " onlyCalledMethods: true," # Exclude entries with no gas for shorter report
echo " showMethodSig: true," # Should make diffs more stable if there are overloaded functions
echo " outputFile: \"$(gas_report_path "$preset")\""
echo "}"
}
function truffle_compiler_settings
{
local solc_path="$1"
@@ -489,3 +519,121 @@ function external_test
rm -rf "$DIR"
echo "Done."
}
function gas_report_path
{
local preset="$1"
echo "${DIR}/gas-report-${preset}.rst"
}
function gas_report_to_json
{
cat - | "${REPO_ROOT}/scripts/externalTests/parse_eth_gas_report.py" | jq '{gas: .}'
}
function detect_hardhat_artifact_dir
{
if [[ -e build/ && -e artifacts/ ]]; then
fail "Cannot determine Hardhat artifact location. Both build/ and artifacts/ exist"
elif [[ -e build/ ]]; then
echo -n build/artifacts
elif [[ -e artifacts/ ]]; then
echo -n artifacts
else
fail "Hardhat build artifacts not found."
fi
}
function bytecode_size_json_from_truffle_artifacts
{
# NOTE: The output of this function is a series of concatenated JSON dicts rather than a list.
for artifact in build/contracts/*.json; do
if [[ $(jq '. | has("unlinked_binary")' "$artifact") == false ]]; then
# Each artifact represents compilation output for a single contract. Some top-level keys contain
# bits of Standard JSON output while others are generated by Truffle. Process it into a dict
# of the form `{"<file>": {"<contract>": <size>}}`.
# NOTE: The `bytecode` field starts with 0x, which is why we subtract 1 from size.
jq '{
(.ast.absolutePath): {
(.contractName): (.bytecode | length / 2 - 1)
}
}' "$artifact"
fi
done
}
function bytecode_size_json_from_hardhat_artifacts
{
# NOTE: The output of this function is a series of concatenated JSON dicts rather than a list.
for artifact in "$(detect_hardhat_artifact_dir)"/build-info/*.json; do
# Each artifact contains Standard JSON output under the `output` key.
# Process it into a dict of the form `{"<file>": {"<contract>": <size>}}`,
# Note that one Hardhat artifact often represents multiple input files.
jq '.output.contracts | to_entries[] | {
"\(.key)": .value | to_entries[] | {
"\(.key)": (.value.evm.bytecode.object | length / 2)
}
}' "$artifact"
done
}
function combine_artifact_json
{
# Combine all dicts into a list with `jq --slurp` and then use `reduce` to merge them into one
# big dict with keys of the form `"<file>:<contract>"`. Then run jq again to filter out items
# with zero size and put the rest under under a top-level `bytecode_size` key. Also add another
# key with total bytecode size.
# NOTE: The extra inner `bytecode_size` key is there only to make diffs more readable.
cat - |
jq --slurp 'reduce (.[] | to_entries[]) as {$key, $value} ({}; . + {
($key + ":" + ($value | to_entries[].key)): {
bytecode_size: $value | to_entries[].value
}
})' |
jq --indent 4 --sort-keys '{
bytecode_size: [. | to_entries[] | select(.value.bytecode_size > 0)] | from_entries,
total_bytecode_size: (reduce (. | to_entries[]) as {$key, $value} (0; . + $value.bytecode_size))
}'
}
function project_info_json
{
local project_url="$1"
echo "{"
echo " \"project\": {"
# NOTE: Given that we clone with `--depth 1`, we'll only get useful output out of `git describe`
# if we directly check out a tag. Still better than nothing.
echo " \"version\": \"$(git describe --always)\","
echo " \"commit\": \"$(git rev-parse HEAD)\","
echo " \"url\": \"${project_url}\""
echo " }"
echo "}"
}
function store_benchmark_report
{
local framework="$1"
local project_name="$2"
local project_url="$3"
local preset="$4"
[[ $framework == truffle || $framework == hardhat ]] || assertFail
[[ " ${AVAILABLE_PRESETS[*]} " == *" $preset "* ]] || assertFail
local report_dir="${REPO_ROOT}/reports/externalTests"
local output_file="${report_dir}/benchmark-${project_name}-${preset}.json"
mkdir -p "$report_dir"
{
if [[ -e $(gas_report_path "$preset") ]]; then
gas_report_to_json < "$(gas_report_path "$preset")"
fi
"bytecode_size_json_from_${framework}_artifacts" | combine_artifact_json
project_info_json "$project_url"
} | jq --slurp "{\"${project_name}\": {\"${preset}\": add}}" --indent 4 --sort-keys > "$output_file"
}
+3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -96,6 +98,7 @@ function elementfi_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat elementfi "$repo" "$preset"
done
}
+3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -68,6 +70,7 @@ function ens_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report hardhat ens "$repo" "$preset"
done
}
+3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -68,6 +70,7 @@ function euler_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report hardhat euler "$repo" "$preset"
done
}
+7 -3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -40,12 +42,12 @@ function gnosis_safe_test
local config_file="truffle-config.js"
local compile_only_presets=(
legacy-no-optimize # "Error: while migrating GnosisSafe: Returned error: base fee exceeds gas limit"
legacy-no-optimize # Compiles but migrations run out of gas: "Error: while migrating GnosisSafe: Returned error: base fee exceeds gas limit"
)
local settings_presets=(
"${compile_only_presets[@]}"
#ir-no-optimize # "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack."
#ir-optimize-evm-only # "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack."
#ir-no-optimize # Compilation fails with "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack."
#ir-optimize-evm-only # Compilation fails with "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack."
ir-optimize-evm+yul
legacy-optimize-evm-only
legacy-optimize-evm+yul
@@ -65,12 +67,14 @@ function gnosis_safe_test
neutralize_package_json_hooks
force_truffle_compiler_settings "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$(first_word "$SELECTED_PRESETS")"
npm install --package-lock
npm install eth-gas-reporter
replace_version_pragmas
[[ $BINARY_TYPE == solcjs ]] && force_solc_modules "${DIR}/solc/dist"
for preset in $SELECTED_PRESETS; do
truffle_run_test "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report truffle gnosis2 "$repo" "$preset"
done
}
+8 -4
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -42,11 +44,11 @@ function gnosis_safe_test
local compile_only_presets=()
local settings_presets=(
"${compile_only_presets[@]}"
#ir-no-optimize # "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack."
#ir-optimize-evm-only # "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack."
#ir-no-optimize # Compilation fails with "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack."
#ir-optimize-evm-only # Compilation fails with "YulException: Variable var_call_430_mpos is 1 slot(s) too deep inside the stack."
ir-optimize-evm+yul
#legacy-no-optimize # "Stack too deep" error
#legacy-optimize-evm-only # "Stack too deep" error
#legacy-no-optimize # Compilation fails with "Stack too deep" error
#legacy-optimize-evm-only # Compilation fails with "Stack too deep" error
legacy-optimize-evm+yul
)
@@ -63,12 +65,14 @@ function gnosis_safe_test
neutralize_package_json_hooks
force_truffle_compiler_settings "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$(first_word "$SELECTED_PRESETS")"
npm install --package-lock
npm install eth-gas-reporter
replace_version_pragmas
[[ $BINARY_TYPE == solcjs ]] && force_solc_modules "${DIR}/solc/dist"
for preset in $SELECTED_PRESETS; do
truffle_run_test "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report truffle gnosis "$repo" "$preset"
done
}
+3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -68,6 +70,7 @@ function perpetual_pools_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat perpetual-pools "$repo" "$preset"
done
}
+3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -72,6 +74,7 @@ function pool_together_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat pool-together "$repo" "$preset"
done
}
+6 -1
View File
@@ -24,13 +24,16 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
SELECTED_PRESETS="$3"
function compile_fn { yarn compile; }
function test_fn { yarn test; }
# NOTE: `yarn test` runs `mocha` which seems to disable the gas reporter.
function test_fn { npx --no hardhat --no-compile test; }
function prb_math_test
{
@@ -70,11 +73,13 @@ function prb_math_test
force_hardhat_compiler_binary "$config_file" "$BINARY_TYPE" "$BINARY_PATH"
force_hardhat_compiler_settings "$config_file" "$(first_word "$SELECTED_PRESETS")" "$config_var"
yarn install --no-lock-file
yarn add hardhat-gas-reporter
replace_version_pragmas
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat prb-math "$repo" "$preset"
done
}
+3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -92,6 +94,7 @@ function trident_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat trident "$repo" "$preset"
done
}
+4
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -73,11 +75,13 @@ function uniswap_test
yarn add @ethereumjs/tx@3.1.3
yarn install
yarn add hardhat-gas-reporter
replace_version_pragmas
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat uniswap "$repo" "$preset"
done
}
+3
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -68,6 +70,7 @@ function yield_liquidator_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat yield_liquidator "$repo" "$preset"
done
}
+5 -2
View File
@@ -24,6 +24,8 @@ set -e
source scripts/common.sh
source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@"
BINARY_TYPE="$1"
BINARY_PATH="$2"
@@ -44,8 +46,8 @@ function zeppelin_test
)
local settings_presets=(
"${compile_only_presets[@]}"
#ir-no-optimize # "YulException: Variable var_account_852 is 4 slot(s) too deep inside the stack."
#ir-optimize-evm-only # "YulException: Variable var_account_852 is 4 slot(s) too deep inside the stack."
#ir-no-optimize # Compilation fails with "YulException: Variable var_account_852 is 4 slot(s) too deep inside the stack."
#ir-optimize-evm-only # Compilation fails with "YulException: Variable var_account_852 is 4 slot(s) too deep inside the stack."
legacy-no-optimize
legacy-optimize-evm-only
legacy-optimize-evm+yul
@@ -66,6 +68,7 @@ function zeppelin_test
for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report hardhat zeppelin "$repo" "$preset"
done
}