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
commit 947a599e91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1261 additions and 39 deletions

View File

@ -583,7 +583,7 @@ defaults:
project: uniswap project: uniswap
binary_type: native binary_type: native
nodejs_version: '16' nodejs_version: '16'
- job_native_test_prb_math: &job_native_test_prb_math - job_native_test_ext_prb_math: &job_native_test_ext_prb_math
<<: *workflow_ubuntu2004_static <<: *workflow_ubuntu2004_static
name: t_native_test_ext_prb_math name: t_native_test_ext_prb_math
project: prb-math project: prb-math
@ -1206,8 +1206,34 @@ jobs:
name: External <<parameters.project>> tests (native) name: External <<parameters.project>> tests (native)
command: | command: |
test/externalTests/<<parameters.project>>.sh native /tmp/workspace/solc/solc test/externalTests/<<parameters.project>>.sh native /tmp/workspace/solc/solc
- store_artifacts:
path: reports/externalTests/
# persist_to_workspace fails if the directory does not exist and the test script will create
# it only if it actually has benchmark results.
- run: mkdir -p reports/externalTests/
- persist_to_workspace:
root: .
paths:
- reports/externalTests/
- gitter_notify_failure_unless_pr - gitter_notify_failure_unless_pr
c_ext_benchmarks:
<<: *base_node_small
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Combine benchmark reports
command: cat reports/externalTests/benchmark-*.json | scripts/externalTests/merge_benchmarks.sh > reports/externalTests/all-benchmarks.json
- run:
name: Summarize reports
command: cat reports/externalTests/all-benchmarks.json | scripts/externalTests/summarize_benchmarks.sh > reports/externalTests/summarized-benchmarks.json
- store_artifacts:
path: reports/externalTests/all-benchmarks.json
- store_artifacts:
path: reports/externalTests/summarized-benchmarks.json
b_win: &b_win b_win: &b_win
<<: *base_win_powershell_large <<: *base_win_powershell_large
steps: steps:
@ -1455,9 +1481,27 @@ workflows:
- t_ems_ext: *job_native_test_ext_pool_together - t_ems_ext: *job_native_test_ext_pool_together
- t_ems_ext: *job_native_test_ext_perpetual_pools - t_ems_ext: *job_native_test_ext_perpetual_pools
- t_ems_ext: *job_native_test_ext_uniswap - t_ems_ext: *job_native_test_ext_uniswap
- t_ems_ext: *job_native_test_prb_math - t_ems_ext: *job_native_test_ext_prb_math
- t_ems_ext: *job_native_test_ext_elementfi - t_ems_ext: *job_native_test_ext_elementfi
- c_ext_benchmarks:
<<: *workflow_trigger_on_tags
requires:
- t_ems_compile_ext_colony
- t_native_compile_ext_gnosis
- t_native_test_ext_gnosis_v2
- t_native_test_ext_zeppelin
- t_native_test_ext_ens
- t_native_test_ext_trident
- t_native_test_ext_euler
- t_native_test_ext_yield_liquidator
- t_native_test_ext_bleeps
- t_native_test_ext_pool_together
- t_native_test_ext_perpetual_pools
- t_native_test_ext_uniswap
- t_native_test_ext_prb_math
- t_native_test_ext_elementfi
# Windows build and tests # Windows build and tests
- b_win: *workflow_trigger_on_tags - b_win: *workflow_trigger_on_tags
- b_win_release: *workflow_trigger_on_tags - b_win_release: *workflow_trigger_on_tags

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Reads multiple individual benchmark reports produced by scripts from
# test/externalTests/ from standard input and creates a combined report.
#
# Usage:
# <script name>.sh < <CONCATENATED_REPORTS>
#
# CONCATENATED_REPORTS: JSON report files concatenated into a single stream (e.g. using cat).
#
# Example:
# cat reports/externalTests/benchmark-*.json | <script name>.sh
# ------------------------------------------------------------------------------
# This file is part of solidity.
#
# solidity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# solidity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with solidity. If not, see <http://www.gnu.org/licenses/>
#
# (c) 2021 solidity contributors.
#------------------------------------------------------------------------------
set -euo pipefail
# We expect a series of dicts of the form {"<project>": {"<preset>": {...}}}.
# Unfortunately jq's built-in `add` filter can't handle nested dicts and
# would just overwrite values sharing a project name instead of merging them.
# This is done by first grouping the dicts into an array of the form
# [
# [{"key": "<project1>", "value": {"<preset1>": {...}}}, {"key": "<project1>", "value": {"<preset2>": {...}}, ...],
# [{"key": "<project2>", "value": {"<preset1>": {...}}}, {"key": "<project2>", "value": {"<preset2>": {...}}, ...],
# ...
# ]
# and then using reduce() on each group sharing the same project name to convert it into a
# dict having preset names as keys.
jq --slurp --indent 4 --sort-keys '
map(to_entries[]) |
group_by(.key) |
map({
(.[0].key): (
reduce (.[].value | to_entries[]) as {$key, $value} (
{}; . + {
($key): $value
}
)
)
}) |
add
'

View File

@ -0,0 +1,269 @@
#!/usr/bin/env python3
# coding=utf-8
from dataclasses import asdict, dataclass, field
from typing import Dict, Optional, Tuple
import json
import re
import sys
REPORT_HEADER_REGEX = re.compile(r'''
^[|\s]+ Solc[ ]version:\s*(?P<solc_version>[\w\d.]+)
[|\s]+ Optimizer[ ]enabled:\s*(?P<optimize>[\w]+)
[|\s]+ Runs:\s*(?P<runs>[\d]+)
[|\s]+ Block[ ]limit:\s*(?P<block_limit>[\d]+)\s*gas
[|\s]+$
''', re.VERBOSE)
METHOD_HEADER_REGEX = re.compile(r'^[|\s]+Methods[|\s]+$')
METHOD_COLUMN_HEADERS_REGEX = re.compile(r'''
^[|\s]+ Contract
[|\s]+ Method
[|\s]+ Min
[|\s]+ Max
[|\s]+ Avg
[|\s]+ \#[ ]calls
[|\s]+ \w+[ ]\(avg\)
[|\s]+$
''', re.VERBOSE)
METHOD_ROW_REGEX = re.compile(r'''
^[|\s]+ (?P<contract>[^|]+)
[|\s]+ (?P<method>[^|]+)
[|\s]+ (?P<min>[^|]+)
[|\s]+ (?P<max>[^|]+)
[|\s]+ (?P<avg>[^|]+)
[|\s]+ (?P<call_count>[^|]+)
[|\s]+ (?P<eur_avg>[^|]+)
[|\s]+$
''', re.VERBOSE)
FRAME_REGEX = re.compile(r'^[-|\s]+$')
DEPLOYMENT_HEADER_REGEX = re.compile(r'^[|\s]+Deployments[|\s]+% of limit[|\s]+$')
DEPLOYMENT_ROW_REGEX = re.compile(r'''
^[|\s]+ (?P<contract>[^|]+)
[|\s]+ (?P<min>[^|]+)
[|\s]+ (?P<max>[^|]+)
[|\s]+ (?P<avg>[^|]+)
[|\s]+ (?P<percent_of_limit>[^|]+)\s*%
[|\s]+ (?P<eur_avg>[^|]+)
[|\s]+$
''', re.VERBOSE)
class ReportError(Exception):
pass
class ReportValidationError(ReportError):
pass
class ReportParsingError(Exception):
def __init__(self, message: str, line: str, line_number: int):
# pylint: disable=useless-super-delegation # It's not useless, it adds type annotations.
super().__init__(message, line, line_number)
def __str__(self):
return f"Parsing error on line {self.args[2] + 1}: {self.args[0]}\n{self.args[1]}"
@dataclass(frozen=True)
class MethodGasReport:
min_gas: int
max_gas: int
avg_gas: int
call_count: int
total_gas: int = field(init=False)
def __post_init__(self):
object.__setattr__(self, 'total_gas', self.avg_gas * self.call_count)
@dataclass(frozen=True)
class ContractGasReport:
min_deployment_gas: Optional[int]
max_deployment_gas: Optional[int]
avg_deployment_gas: Optional[int]
methods: Optional[Dict[str, MethodGasReport]]
total_method_gas: int = field(init=False, default=0)
def __post_init__(self):
if self.methods is not None:
object.__setattr__(self, 'total_method_gas', sum(method.total_gas for method in self.methods.values()))
@dataclass(frozen=True)
class GasReport:
solc_version: str
optimize: bool
runs: int
block_limit: int
contracts: Dict[str, ContractGasReport]
total_method_gas: int = field(init=False)
total_deployment_gas: int = field(init=False)
def __post_init__(self):
object.__setattr__(self, 'total_method_gas', sum(
total_method_gas
for total_method_gas in (contract.total_method_gas for contract in self.contracts.values())
if total_method_gas is not None
))
object.__setattr__(self, 'total_deployment_gas', sum(
contract.avg_deployment_gas
for contract in self.contracts.values()
if contract.avg_deployment_gas is not None
))
def to_json(self):
return json.dumps(asdict(self), indent=4, sort_keys=True)
def parse_bool(input_string: str) -> bool:
if input_string == 'true':
return True
elif input_string == 'false':
return True
else:
raise ValueError(f"Invalid boolean value: '{input_string}'")
def parse_optional_int(input_string: str, default: Optional[int] = None) -> Optional[int]:
if input_string.strip() == '-':
return default
return int(input_string)
def parse_report_header(line: str) -> Optional[dict]:
match = REPORT_HEADER_REGEX.match(line)
if match is None:
return None
return {
'solc_version': match.group('solc_version'),
'optimize': parse_bool(match.group('optimize')),
'runs': int(match.group('runs')),
'block_limit': int(match.group('block_limit')),
}
def parse_method_row(line: str, line_number: int) -> Optional[Tuple[str, str, MethodGasReport]]:
match = METHOD_ROW_REGEX.match(line)
if match is None:
raise ReportParsingError("Expected a table row with method details.", line, line_number)
avg_gas = parse_optional_int(match['avg'])
call_count = int(match['call_count'])
if avg_gas is None and call_count == 0:
# No calls, no gas values. Uninteresting. Skip the row.
return None
return (
match['contract'].strip(),
match['method'].strip(),
MethodGasReport(
min_gas=parse_optional_int(match['min'], avg_gas),
max_gas=parse_optional_int(match['max'], avg_gas),
avg_gas=avg_gas,
call_count=call_count,
)
)
def parse_deployment_row(line: str, line_number: int) -> Tuple[str, int, int, int]:
match = DEPLOYMENT_ROW_REGEX.match(line)
if match is None:
raise ReportParsingError("Expected a table row with deployment details.", line, line_number)
return (
match['contract'].strip(),
parse_optional_int(match['min'].strip()),
parse_optional_int(match['max'].strip()),
int(match['avg'].strip()),
)
def preprocess_unicode_frames(input_string: str) -> str:
# The report has a mix of normal pipe chars and its unicode variant.
# Let's just replace all frame chars with normal pipes for easier parsing.
return input_string.replace('\u2502', '|').replace('·', '|')
def parse_report(rst_report: str) -> GasReport:
report_params = None
methods_by_contract = {}
deployment_costs = {}
expected_row_type = None
for line_number, line in enumerate(preprocess_unicode_frames(rst_report).splitlines()):
try:
if (
line.strip() == "" or
FRAME_REGEX.match(line) is not None or
METHOD_COLUMN_HEADERS_REGEX.match(line) is not None
):
continue
if METHOD_HEADER_REGEX.match(line) is not None:
expected_row_type = 'method'
continue
if DEPLOYMENT_HEADER_REGEX.match(line) is not None:
expected_row_type = 'deployment'
continue
new_report_params = parse_report_header(line)
if new_report_params is not None:
if report_params is not None:
raise ReportParsingError("Duplicate report header.", line, line_number)
report_params = new_report_params
continue
if expected_row_type == 'method':
parsed_row = parse_method_row(line, line_number)
if parsed_row is None:
continue
(contract, method, method_report) = parsed_row
if contract not in methods_by_contract:
methods_by_contract[contract] = {}
if method in methods_by_contract[contract]:
# Report must be generated with full signatures for method names to be unambiguous.
raise ReportParsingError(f"Duplicate method row for '{contract}.{method}'.", line, line_number)
methods_by_contract[contract][method] = method_report
elif expected_row_type == 'deployment':
(contract, min_gas, max_gas, avg_gas) = parse_deployment_row(line, line_number)
if contract in deployment_costs:
raise ReportParsingError(f"Duplicate contract deployment row for '{contract}'.", line, line_number)
deployment_costs[contract] = (min_gas, max_gas, avg_gas)
else:
assert expected_row_type is None
raise ReportParsingError("Found data row without a section header.", line, line_number)
except ValueError as error:
raise ReportParsingError(error.args[0], line, line_number) from error
if report_params is None:
raise ReportValidationError("Report header not found.")
report_params['contracts'] = {
contract: ContractGasReport(
min_deployment_gas=deployment_costs.get(contract, (None, None, None))[0],
max_deployment_gas=deployment_costs.get(contract, (None, None, None))[1],
avg_deployment_gas=deployment_costs.get(contract, (None, None, None))[2],
methods=methods_by_contract.get(contract),
)
for contract in methods_by_contract.keys() | deployment_costs.keys()
}
return GasReport(**report_params)
if __name__ == "__main__":
try:
report = parse_report(sys.stdin.read())
print(report.to_json())
except ReportError as exception:
print(f"{exception}", file=sys.stderr)
sys.exit(1)

View File

@ -0,0 +1,53 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Reads a combined benchmark report from standard input and outputs an abbreviated
# report containing only totals. Can handle individual reports coming directly
# from scripts in test/externalTests/ as well as combined report from merge_benchmarks.sh.
#
# Usage:
# <script name>.sh < <CONCATENATED_REPORTS>
#
# CONCATENATED_REPORTS: JSON report files concatenated into a single stream (e.g. using cat).
#
# Example:
# cat reports/externalTests/benchmark-*.json | <script name>.sh
# ------------------------------------------------------------------------------
# This file is part of solidity.
#
# solidity is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# solidity is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with solidity. If not, see <http://www.gnu.org/licenses/>
#
# (c) 2021 solidity contributors.
#------------------------------------------------------------------------------
set -euo pipefail
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
# Iterates over presets in a dict of the form {"<project>": {"<preset>": {...}}} and for each
# one preserves only the few keys with totals that we want to see in the summary.
exec "${REPO_ROOT}/scripts/externalTests/merge_benchmarks.sh" | jq --indent 4 --sort-keys '
with_entries({
key: .key,
value: .value | with_entries({
key: .key,
value: {
bytecode_size: .value.total_bytecode_size,
method_gas: .value.gas.total_method_gas,
deployment_gas: .value.gas.total_deployment_gas,
version: .value.project.version
}
})
})
'

View File

@ -28,26 +28,26 @@
set -e set -e
REPO_ROOT="$(dirname "$0")"
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/..")
verify_input "$@" verify_input "$@"
printTask "Running external tests..." printTask "Running external tests..."
"$REPO_ROOT/externalTests/zeppelin.sh" "$@" "{$REPO_ROOT}/test/externalTests/zeppelin.sh" "$@"
"$REPO_ROOT/externalTests/gnosis.sh" "$@" "{$REPO_ROOT}/test/externalTests/gnosis.sh" "$@"
"$REPO_ROOT/externalTests/gnosis-v2.sh" "$@" "{$REPO_ROOT}/test/externalTests/gnosis-v2.sh" "$@"
"$REPO_ROOT/externalTests/colony.sh" "$@" "{$REPO_ROOT}/test/externalTests/colony.sh" "$@"
"$REPO_ROOT/externalTests/ens.sh" "$@" "{$REPO_ROOT}/test/externalTests/ens.sh" "$@"
"$REPO_ROOT/externalTests/trident.sh" "$@" "{$REPO_ROOT}/test/externalTests/trident.sh" "$@"
"$REPO_ROOT/externalTests/euler.sh" "$@" "{$REPO_ROOT}/test/externalTests/euler.sh" "$@"
"$REPO_ROOT/externalTests/yield-liquidator.sh" "$@" "{$REPO_ROOT}/test/externalTests/yield-liquidator.sh" "$@"
"$REPO_ROOT/externalTests/bleeps.sh" "$@" "{$REPO_ROOT}/test/externalTests/bleeps.sh" "$@"
"$REPO_ROOT/externalTests/pool-together.sh" "$@" "{$REPO_ROOT}/test/externalTests/pool-together.sh" "$@"
"$REPO_ROOT/externalTests/perpetual-pools.sh" "$@" "{$REPO_ROOT}/test/externalTests/perpetual-pools.sh" "$@"
"$REPO_ROOT/externalTests/uniswap.sh" "$@" "{$REPO_ROOT}/test/externalTests/uniswap.sh" "$@"
"$REPO_ROOT/externalTests/prb-math.sh" "$@" "{$REPO_ROOT}/test/externalTests/prb-math.sh" "$@"
"$REPO_ROOT/externalTests/elementfi.sh" "$@" "{$REPO_ROOT}/test/externalTests/elementfi.sh" "$@"

View File

@ -24,13 +24,16 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
SELECTED_PRESETS="$3" SELECTED_PRESETS="$3"
function compile_fn { npm run compile; } 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 function bleeps_test
{ {
@ -87,6 +90,7 @@ function bleeps_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat bleeps "$repo" "$preset"
done done
popd popd

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -73,6 +75,7 @@ function colony_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
truffle_run_test "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$preset" "${compile_only_presets[*]}" compile_fn test_fn 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 done
} }

View File

@ -20,7 +20,7 @@
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
set -e 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 CURRENT_EVM_VERSION=london
@ -215,9 +215,19 @@ function force_truffle_compiler_settings
echo "Compiler version (full): ${SOLCVERSION}" echo "Compiler version (full): ${SOLCVERSION}"
echo "-------------------------------------" echo "-------------------------------------"
# Forcing the settings should always work by just overwriting the solc object. Forcing them by using a local compiler_settings gas_reporter_settings
# dedicated settings objects should only be the fallback. compiler_settings=$(truffle_compiler_settings "$solc_path" "$preset" "$evm_version")
echo "module.exports['compilers'] = $(truffle_compiler_settings "$solc_path" "$preset" "$evm_version");" >> "$config_file" 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 function name_hardhat_default_export
@ -286,16 +296,21 @@ function force_hardhat_compiler_settings
echo "Compiler version (full): ${SOLCVERSION}" echo "Compiler version (full): ${SOLCVERSION}"
echo "-------------------------------------" echo "-------------------------------------"
local settings local compiler_settings gas_reporter_settings
settings=$(hardhat_compiler_settings "$SOLCVERSION_SHORT" "$preset" "$evm_version") compiler_settings=$(hardhat_compiler_settings "$SOLCVERSION_SHORT" "$preset" "$evm_version")
gas_reporter_settings=$(eth_gas_reporter_settings "$preset")
if [[ $config_file == *\.js ]]; then if [[ $config_file == *\.js ]]; then
[[ $config_var_name == "" ]] || assertFail [[ $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 else
[[ $config_file == *\.ts ]] || assertFail [[ $config_file == *\.ts ]] || assertFail
[[ $config_var_name != "" ]] || assertFail [[ $config_var_name != "" ]] || assertFail
echo "${config_var_name}.solidity = {compilers: [${settings}]}" >> "$config_file" echo 'import "hardhat-gas-reporter";'
fi echo "${config_var_name}.gasReporter = ${gas_reporter_settings};"
echo "${config_var_name}.solidity = {compilers: [${compiler_settings}]};"
fi >> "$config_file"
} }
function truffle_verify_compiler_version function truffle_verify_compiler_version
@ -328,7 +343,7 @@ function truffle_clean
function hardhat_clean function hardhat_clean
{ {
rm -rf artifacts/ cache/ rm -rf build/ artifacts/ cache/
} }
function settings_from_preset function settings_from_preset
@ -362,6 +377,21 @@ function replace_global_solc
export PATH="$PWD:$PATH" 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 function truffle_compiler_settings
{ {
local solc_path="$1" local solc_path="$1"
@ -489,3 +519,121 @@ function external_test
rm -rf "$DIR" rm -rf "$DIR"
echo "Done." 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"
}

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -96,6 +98,7 @@ function elementfi_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat elementfi "$repo" "$preset"
done done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -68,6 +70,7 @@ function ens_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report hardhat ens "$repo" "$preset"
done done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -68,6 +70,7 @@ function euler_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report hardhat euler "$repo" "$preset"
done done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -40,12 +42,12 @@ function gnosis_safe_test
local config_file="truffle-config.js" local config_file="truffle-config.js"
local compile_only_presets=( 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=( local settings_presets=(
"${compile_only_presets[@]}" "${compile_only_presets[@]}"
#ir-no-optimize # "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 # "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 ir-optimize-evm+yul
legacy-optimize-evm-only legacy-optimize-evm-only
legacy-optimize-evm+yul legacy-optimize-evm+yul
@ -65,12 +67,14 @@ function gnosis_safe_test
neutralize_package_json_hooks neutralize_package_json_hooks
force_truffle_compiler_settings "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$(first_word "$SELECTED_PRESETS")" force_truffle_compiler_settings "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$(first_word "$SELECTED_PRESETS")"
npm install --package-lock npm install --package-lock
npm install eth-gas-reporter
replace_version_pragmas replace_version_pragmas
[[ $BINARY_TYPE == solcjs ]] && force_solc_modules "${DIR}/solc/dist" [[ $BINARY_TYPE == solcjs ]] && force_solc_modules "${DIR}/solc/dist"
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
truffle_run_test "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$preset" "${compile_only_presets[*]}" compile_fn test_fn 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 done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -42,11 +44,11 @@ function gnosis_safe_test
local compile_only_presets=() local compile_only_presets=()
local settings_presets=( local settings_presets=(
"${compile_only_presets[@]}" "${compile_only_presets[@]}"
#ir-no-optimize # "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 # "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 ir-optimize-evm+yul
#legacy-no-optimize # "Stack too deep" error #legacy-no-optimize # Compilation fails with "Stack too deep" error
#legacy-optimize-evm-only # "Stack too deep" error #legacy-optimize-evm-only # Compilation fails with "Stack too deep" error
legacy-optimize-evm+yul legacy-optimize-evm+yul
) )
@ -63,12 +65,14 @@ function gnosis_safe_test
neutralize_package_json_hooks neutralize_package_json_hooks
force_truffle_compiler_settings "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$(first_word "$SELECTED_PRESETS")" force_truffle_compiler_settings "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$(first_word "$SELECTED_PRESETS")"
npm install --package-lock npm install --package-lock
npm install eth-gas-reporter
replace_version_pragmas replace_version_pragmas
[[ $BINARY_TYPE == solcjs ]] && force_solc_modules "${DIR}/solc/dist" [[ $BINARY_TYPE == solcjs ]] && force_solc_modules "${DIR}/solc/dist"
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
truffle_run_test "$config_file" "$BINARY_TYPE" "${DIR}/solc/dist" "$preset" "${compile_only_presets[*]}" compile_fn test_fn 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 done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -68,6 +70,7 @@ function perpetual_pools_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat perpetual-pools "$repo" "$preset"
done done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -72,6 +74,7 @@ function pool_together_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat pool-together "$repo" "$preset"
done done
} }

View File

@ -24,13 +24,16 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
SELECTED_PRESETS="$3" SELECTED_PRESETS="$3"
function compile_fn { yarn compile; } 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 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_binary "$config_file" "$BINARY_TYPE" "$BINARY_PATH"
force_hardhat_compiler_settings "$config_file" "$(first_word "$SELECTED_PRESETS")" "$config_var" force_hardhat_compiler_settings "$config_file" "$(first_word "$SELECTED_PRESETS")" "$config_var"
yarn install --no-lock-file yarn install --no-lock-file
yarn add hardhat-gas-reporter
replace_version_pragmas replace_version_pragmas
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat prb-math "$repo" "$preset"
done done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -92,6 +94,7 @@ function trident_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat trident "$repo" "$preset"
done done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -73,11 +75,13 @@ function uniswap_test
yarn add @ethereumjs/tx@3.1.3 yarn add @ethereumjs/tx@3.1.3
yarn install yarn install
yarn add hardhat-gas-reporter
replace_version_pragmas replace_version_pragmas
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat uniswap "$repo" "$preset"
done done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -68,6 +70,7 @@ function yield_liquidator_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var" hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn "$config_var"
store_benchmark_report hardhat yield_liquidator "$repo" "$preset"
done done
} }

View File

@ -24,6 +24,8 @@ set -e
source scripts/common.sh source scripts/common.sh
source test/externalTests/common.sh source test/externalTests/common.sh
REPO_ROOT=$(realpath "$(dirname "$0")/../..")
verify_input "$@" verify_input "$@"
BINARY_TYPE="$1" BINARY_TYPE="$1"
BINARY_PATH="$2" BINARY_PATH="$2"
@ -44,8 +46,8 @@ function zeppelin_test
) )
local settings_presets=( local settings_presets=(
"${compile_only_presets[@]}" "${compile_only_presets[@]}"
#ir-no-optimize # "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 # "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-no-optimize
legacy-optimize-evm-only legacy-optimize-evm-only
legacy-optimize-evm+yul legacy-optimize-evm+yul
@ -66,6 +68,7 @@ function zeppelin_test
for preset in $SELECTED_PRESETS; do for preset in $SELECTED_PRESETS; do
hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn hardhat_run_test "$config_file" "$preset" "${compile_only_presets[*]}" compile_fn test_fn
store_benchmark_report hardhat zeppelin "$repo" "$preset"
done done
} }

View File

@ -0,0 +1,381 @@
·----------------------------------------------------------------------------------------------------------------------------------------|---------------------------|-------------|------------------------------·
| Solc version: 0.8.10 · Optimizer enabled: true · Runs: 200 · Block limit: 100000000 gas │
·········································································································································|···························|·············|·······························
| Methods │
·································|·······································································································|·············|·············|·············|···············|···············
| Contract · Method · Min · Max · Avg · # calls · eur (avg) │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · getMessageHash(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · getMessageHashForSafe(address,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · getModules() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · isValidSignature(bytes,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · isValidSignature(bytes32,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · NAME() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · onERC1155BatchReceived(address,address,uint256[],uint256[],bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · onERC1155Received(address,address,uint256,uint256,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · onERC721Received(address,address,uint256,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · simulate(address,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · supportsInterface(bytes4) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · tokensReceived(address,address,address,uint256,bytes,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CompatibilityFallbackHandler · VERSION() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CreateCall · performCreate(uint256,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| CreateCall · performCreate2(uint256,bytes,bytes32) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DebugTransactionGuard · checkAfterExecution(bytes32,bool) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DebugTransactionGuard · checkTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DebugTransactionGuard · supportsInterface(bytes4) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DebugTransactionGuard · txNonces(bytes32) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DefaultCallbackHandler · NAME() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DefaultCallbackHandler · onERC1155BatchReceived(address,address,uint256[],uint256[],bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DefaultCallbackHandler · onERC1155Received(address,address,uint256,uint256,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DefaultCallbackHandler · onERC721Received(address,address,uint256,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DefaultCallbackHandler · supportsInterface(bytes4) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DefaultCallbackHandler · tokensReceived(address,address,address,uint256,bytes,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DefaultCallbackHandler · VERSION() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DelegateCallTransactionGuard · allowedTarget() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DelegateCallTransactionGuard · checkAfterExecution(bytes32,bool) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DelegateCallTransactionGuard · checkTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| DelegateCallTransactionGuard · supportsInterface(bytes4) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC1155Token · balanceOf(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC1155Token · mint(address,uint256,uint256,bytes) · 47934 · 59804 · 57826 · 6 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC1155Token · safeTransferFrom(address,address,uint256,uint256,bytes) · - · - · 53900 · 2 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · allowance(address,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · approve(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · balanceOf(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · decimals() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · decreaseAllowance(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · increaseAllowance(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · name() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · symbol() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · totalSupply() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · transfer(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20 · transferFrom(address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · allowance(address,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · approve(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · balanceOf(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · decimals() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · decreaseAllowance(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · increaseAllowance(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · name() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · symbol() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · totalSupply() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · transfer(address,uint256) · - · - · 51567 · 8 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ERC20Token · transferFrom(address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| FallbackManager · setFallbackHandler(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · addOwnerWithThreshold(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · approvedHashes(address,bytes32) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · approveHash(bytes32) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · changeThreshold(uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · checkNSignatures(bytes32,bytes,bytes,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · checkSignatures(bytes32,bytes,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · disableModule(address,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · domainSeparator() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · enableModule(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · encodeTransactionData(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes) · 59563 · 151736 · 94816 · 85 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · execTransactionFromModule(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · execTransactionFromModuleReturnData(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · getChainId() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · getModulesPaginated(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · getOwners() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · getStorageAt(uint256,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · getThreshold() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · getTransactionHash(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · isModuleEnabled(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · isOwner(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · nonce() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · removeOwner(address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · requiredTxGas(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · setFallbackHandler(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · setGuard(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · setup(address[],uint256,address,bytes,address,address,uint256,address) · 167642 · 263690 · 201944 · 49 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · signedMessages(bytes32) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · simulateAndRevert(address,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · swapOwner(address,address,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafe · VERSION() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · addOwnerWithThreshold(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · approvedHashes(address,bytes32) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · approveHash(bytes32) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · changeThreshold(uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · checkNSignatures(bytes32,bytes,bytes,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · checkSignatures(bytes32,bytes,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · disableModule(address,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · domainSeparator() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · enableModule(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · encodeTransactionData(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · execTransactionFromModule(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · execTransactionFromModuleReturnData(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · getChainId() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · getModulesPaginated(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · getOwners() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · getStorageAt(uint256,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · getThreshold() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · getTransactionHash(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · isModuleEnabled(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · isOwner(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · nonce() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · removeOwner(address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · requiredTxGas(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · setFallbackHandler(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · setGuard(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · setup(address[],uint256,address,bytes,address,address,uint256,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · signedMessages(bytes32) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · simulateAndRevert(address,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · swapOwner(address,address,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeL2 · VERSION() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeProxyFactory · calculateCreateProxyWithNonceAddress(address,bytes,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeProxyFactory · createProxy(address,bytes) · 105568 · 105580 · 105568 · 52 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeProxyFactory · createProxyWithCallback(address,bytes,uint256,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeProxyFactory · createProxyWithNonce(address,bytes,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeProxyFactory · proxyCreationCode() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GnosisSafeProxyFactory · proxyRuntimeCode() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| GuardManager · setGuard(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| Migration · migrate() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| Migration · migrationSingleton() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| Migration · safe120Singleton() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · DEFAULT_FALLBACK_VALUE() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenAnyReturn(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenAnyReturnAddress(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenAnyReturnBool(bool) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenAnyReturnUint(uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenAnyRevert() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenAnyRevertWithMessage(string) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenAnyRunOutOfGas() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenCalldataReturn(bytes,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenCalldataReturnAddress(bytes,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenCalldataReturnBool(bytes,bool) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenCalldataReturnUint(bytes,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenCalldataRevert(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenCalldataRevertWithMessage(bytes,string) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenCalldataRunOutOfGas(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenMethodReturn(bytes,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenMethodReturnAddress(bytes,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenMethodReturnBool(bytes,bool) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenMethodReturnUint(bytes,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenMethodRevert(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenMethodRevertWithMessage(bytes,string) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · givenMethodRunOutOfGas(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · invocationCount() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · invocationCountForCalldata(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · invocationCountForMethod(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · MOCKS_LIST_END_HASH() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · MOCKS_LIST_END() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · MOCKS_LIST_START() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · reset() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · SENTINEL_ANY_MOCKS() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MockContract · updateInvocationCount(bytes4,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ModuleManager · disableModule(address,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ModuleManager · enableModule(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ModuleManager · execTransactionFromModule(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ModuleManager · execTransactionFromModuleReturnData(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ModuleManager · getModulesPaginated(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ModuleManager · isModuleEnabled(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MultiSend · multiSend(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| MultiSendCallOnly · multiSend(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| OwnerManager · addOwnerWithThreshold(address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| OwnerManager · changeThreshold(uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| OwnerManager · getOwners() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| OwnerManager · getThreshold() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| OwnerManager · isOwner(address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| OwnerManager · removeOwner(address,address,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| OwnerManager · swapOwner(address,address,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ReentrancyTransactionGuard · checkAfterExecution(bytes32,bool) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ReentrancyTransactionGuard · checkTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,address) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| ReentrancyTransactionGuard · supportsInterface(bytes4) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| SignMessageLib · getMessageHash(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| SignMessageLib · signMessage(bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| SimulateTxAccessor · simulate(address,uint256,bytes,uint8) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| StorageAccessible · getStorageAt(uint256,uint256) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| StorageAccessible · simulateAndRevert(address,bytes) · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| TestHandler · dudududu() · - · - · - · 0 · - │
·································|·······································································································|·············|·············|·············|···············|···············
| Deployments · · % of limit · │
·········································································································································|·············|·············|·············|···············|···············
| DelegateCallTransactionGuard · 283510 · 283522 · 283516 · 0.3 % · - │
·········································································································································|·············|·············|·············|···············|···············
| ERC1155Token · - · - · 525869 · 0.5 % · - │
·········································································································································|·············|·············|·············|···············|···············
| ERC20Token · - · - · 733462 · 0.7 % · - │
·----------------------------------------------------------------------------------------------------------------------------------------|-------------|-------------|-------------|---------------|--------------·

View File

@ -0,0 +1,219 @@
#!/usr/bin/env python3
from dataclasses import asdict
import unittest
from textwrap import dedent
from unittest_helpers import FIXTURE_DIR, load_fixture
# NOTE: This test file file only works with scripts/ added to PYTHONPATH so pylint can't find the imports
# pragma pylint: disable=import-error
from externalTests.parse_eth_gas_report import parse_report, ReportParsingError, ReportValidationError
# pragma pylint: enable=import-error
ETH_GAS_REPORT_GNOSIS_RST_PATH = FIXTURE_DIR / 'eth_gas_report_gnosis.rst'
ETH_GAS_REPORT_GNOSIS_RST_CONTENT = load_fixture(ETH_GAS_REPORT_GNOSIS_RST_PATH)
class TestEthGasReport(unittest.TestCase):
def setUp(self):
self.maxDiff = 10000
def test_parse_report(self):
parsed_report = parse_report(ETH_GAS_REPORT_GNOSIS_RST_CONTENT)
expected_report = {
'solc_version': '0.8.10',
'optimize': True,
'runs': 200,
'block_limit': 100000000,
'total_method_gas': 57826 * 6 + 53900 * 2 + 51567 * 8 + 94816 * 85 + 201944 * 49 + 105568 * 52,
'total_deployment_gas': 283516 + 525869 + 733462,
'contracts': {
'DelegateCallTransactionGuard': {
'total_method_gas': 0,
'min_deployment_gas': 283510,
'max_deployment_gas': 283522,
'avg_deployment_gas': 283516,
'methods': None,
},
'ERC1155Token': {
'total_method_gas': 57826 * 6 + 53900 * 2,
'min_deployment_gas': None,
'max_deployment_gas': None,
'avg_deployment_gas': 525869,
'methods': {
'mint(address,uint256,uint256,bytes)': {
'total_gas': 57826 * 6,
'min_gas': 47934,
'max_gas': 59804,
'avg_gas': 57826,
'call_count': 6
},
'safeTransferFrom(address,address,uint256,uint256,bytes)': {
'total_gas': 53900 * 2,
'min_gas': 53900,
'max_gas': 53900,
'avg_gas': 53900,
'call_count': 2,
},
},
},
'ERC20Token': {
'total_method_gas': 51567 * 8,
'min_deployment_gas': None,
'max_deployment_gas': None,
'avg_deployment_gas': 733462,
'methods': {
'transfer(address,uint256)': {
'total_gas': 51567 * 8,
'min_gas': 51567,
'max_gas': 51567,
'avg_gas': 51567,
'call_count': 8,
},
},
},
'GnosisSafe': {
'total_method_gas': 94816 * 85 + 201944 * 49,
'min_deployment_gas': None,
'max_deployment_gas': None,
'avg_deployment_gas': None,
'methods': {
'execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes)': {
'total_gas': 94816 * 85,
'min_gas': 59563,
'max_gas': 151736,
'avg_gas': 94816,
'call_count': 85,
},
'setup(address[],uint256,address,bytes,address,address,uint256,address)': {
'total_gas': 201944 * 49,
'min_gas': 167642,
'max_gas': 263690,
'avg_gas': 201944,
'call_count': 49,
},
},
},
'GnosisSafeProxyFactory': {
'total_method_gas': 105568 * 52,
'min_deployment_gas': None,
'max_deployment_gas': None,
'avg_deployment_gas': None,
'methods': {
'createProxy(address,bytes)': {
'total_gas': 105568 * 52,
'min_gas': 105568,
'max_gas': 105580,
'avg_gas': 105568,
'call_count': 52,
},
},
},
}
}
self.assertEqual(asdict(parsed_report), expected_report)
def test_parse_report_should_fail_if_report_is_empty(self):
text_report = ""
with self.assertRaises(ReportValidationError) as manager:
parse_report(text_report)
self.assertEqual(str(manager.exception), "Report header not found.")
def test_parse_report_should_fail_if_report_has_no_header(self):
text_report = dedent("""
| Methods |
| ERC1155Token · mint() · 1 · 3 · 2 · 6 · - |
| Deployments · · % of limit ·
| ERC1155Token · - · - · 5 · 1 % · - |
""").strip('\n')
with self.assertRaises(ReportValidationError) as manager:
parse_report(text_report)
self.assertEqual(str(manager.exception), "Report header not found.")
def test_parse_report_should_fail_if_data_rows_have_no_headers(self):
text_report = dedent("""
| ERC1155Token · mint() · 1 · 3 · 2 · 6 · - |
""").strip('\n')
expected_message = dedent("""
Parsing error on line 1: Found data row without a section header.
| ERC1155Token | mint() | 1 | 3 | 2 | 6 | - |
""").strip('\n')
with self.assertRaises(ReportParsingError) as manager:
parse_report(text_report)
self.assertEqual(str(manager.exception), expected_message)
def test_parse_report_should_fail_if_report_has_more_than_one_header(self):
text_report = dedent("""
| Solc version: 0.8.10 · Optimizer enabled: true · Runs: 200 · Block limit: 100000000 gas |
| Solc version: 0.8.9 · Optimizer enabled: false · Runs: 111 · Block limit: 999999999 gas |
""").strip('\n')
expected_message = dedent("""
Parsing error on line 2: Duplicate report header.
| Solc version: 0.8.9 | Optimizer enabled: false | Runs: 111 | Block limit: 999999999 gas |
""").strip('\n')
with self.assertRaises(ReportParsingError) as manager:
parse_report(text_report)
self.assertEqual(str(manager.exception), expected_message)
def test_parse_report_should_fail_if_row_matching_same_method_call_appears_twice(self):
text_report = dedent("""
| Methods |
| ERC1155Token · mint() · 47934 · 59804 · 57826 · 6 · - |
| ERC1155Token · mint() · 11111 · 22222 · 33333 · 4 · - |
""").strip('\n')
expected_message = dedent("""
Parsing error on line 3: Duplicate method row for 'ERC1155Token.mint()'.
| ERC1155Token | mint() | 11111 | 22222 | 33333 | 4 | - |
""").strip('\n')
with self.assertRaises(ReportParsingError) as manager:
parse_report(text_report)
self.assertEqual(str(manager.exception), expected_message)
def test_parse_report_should_fail_if_row_matching_same_contract_deployment_appears_twice(self):
text_report = dedent("""
| Deployments · · % of limit ·
| ERC1155Token · - · - · 525869 · 0.5 % · - |
| ERC1155Token · - · - · 111111 · 0.6 % · - |
""").strip('\n')
expected_message = dedent("""
Parsing error on line 3: Duplicate contract deployment row for 'ERC1155Token'.
| ERC1155Token | - | - | 111111 | 0.6 % | - |
""").strip('\n')
with self.assertRaises(ReportParsingError) as manager:
parse_report(text_report)
self.assertEqual(str(manager.exception), expected_message)
def test_parse_report_should_fail_if_method_row_appears_under_deployments_header(self):
text_report = dedent("""
| Deployments · · % of limit ·
| ERC1155Token · mint() · 47934 · 59804 · 57826 · 6 · - |
""").strip('\n')
expected_message = dedent("""
Parsing error on line 2: Expected a table row with deployment details.
| ERC1155Token | mint() | 47934 | 59804 | 57826 | 6 | - |
""").strip('\n')
with self.assertRaises(ReportParsingError) as manager:
parse_report(text_report)
self.assertEqual(str(manager.exception), expected_message)
def test_parse_report_should_fail_if_deployment_row_appears_under_methods_header(self):
text_report = dedent("""
| Methods |
| ERC1155Token · - · - · 525869 · 5 · - |
""").strip('\n')
expected_message = dedent("""
Parsing error on line 2: Expected a table row with method details.
| ERC1155Token | - | - | 525869 | 5 | - |
""").strip('\n')
with self.assertRaises(ReportParsingError) as manager:
parse_report(text_report)
self.assertEqual(str(manager.exception), expected_message)