Skip to content

Commit dad5e83

Browse files
authored
Merge pull request #16371 from argotorg/fix-gas-report
Fix external tests for hardhat-gas-reporter v2 compatibility
2 parents 089b04b + 1cd9bc2 commit dad5e83

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

scripts/externalTests/common.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# (c) 2019 solidity contributors.
2020
#------------------------------------------------------------------------------
21-
set -e
21+
set -eo pipefail
2222

2323
# Requires $REPO_ROOT to be defined and "${REPO_ROOT}/scripts/common.sh" to be included before.
2424

@@ -434,9 +434,9 @@ function eth_gas_reporter_settings
434434
echo " enabled: true,"
435435
echo " gasPrice: 1," # Gas price does not matter to us at all. Set to whatever to avoid API call.
436436
echo " noColors: true,"
437-
echo " showTimeSpent: false," # We're not interested in test timing
438-
echo " onlyCalledMethods: true," # Exclude entries with no gas for shorter report
437+
echo " showUncalledMethods: false," # Exclude entries with no gas for shorter report
439438
echo " showMethodSig: true," # Should make diffs more stable if there are overloaded functions
439+
echo " reportFormat: 'legacy'," # Use v1.x format for compatibility with parse_eth_gas_report.py
440440
echo " outputFile: \"$(gas_report_path "$preset")\""
441441
echo "}"
442442
}

scripts/externalTests/parse_eth_gas_report.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
REPORT_HEADER_REGEX = re.compile(r'''
1111
^[|\s]+ Solc[ ]version:\s*(?P<solc_version>[\w\d.]+)
1212
[|\s]+ Optimizer[ ]enabled:\s*(?P<optimize>[\w]+)
13-
[|\s]+ Runs:\s*(?P<runs>[\d]+)
14-
[|\s]+ Block[ ]limit:\s*(?P<block_limit>[\d]+)\s*gas
13+
[|\s]+ Runs:\s*(?P<runs>[\d,]+)
14+
[|\s]+ Block[ ]limit:\s*(?P<block_limit>[\d,]+)\s*gas
1515
[|\s]+$
1616
''', re.VERBOSE)
1717
METHOD_HEADER_REGEX = re.compile(r'^[|\s]+Methods[|\s]+$')
@@ -122,10 +122,11 @@ def parse_bool(input_string: str) -> bool:
122122

123123

124124
def parse_optional_int(input_string: str, default: Optional[int] = None) -> Optional[int]:
125-
if input_string.strip() == '-':
125+
stripped = input_string.strip().replace(',', '')
126+
if stripped == '-':
126127
return default
127128

128-
return int(input_string)
129+
return int(stripped)
129130

130131

131132
def parse_report_header(line: str) -> Optional[dict]:
@@ -136,8 +137,8 @@ def parse_report_header(line: str) -> Optional[dict]:
136137
return {
137138
'solc_version': match.group('solc_version'),
138139
'optimize': parse_bool(match.group('optimize')),
139-
'runs': int(match.group('runs')),
140-
'block_limit': int(match.group('block_limit')),
140+
'runs': int(match.group('runs').replace(',', '')),
141+
'block_limit': int(match.group('block_limit').replace(',', '')),
141142
}
142143

143144

@@ -147,7 +148,7 @@ def parse_method_row(line: str, line_number: int) -> Optional[Tuple[str, str, Me
147148
raise ReportParsingError("Expected a table row with method details.", line, line_number)
148149

149150
avg_gas = parse_optional_int(match['avg'])
150-
call_count = int(match['call_count'])
151+
call_count = int(match['call_count'].strip().replace(',', ''))
151152

152153
if avg_gas is None and call_count == 0:
153154
# No calls, no gas values. Uninteresting. Skip the row.
@@ -174,7 +175,7 @@ def parse_deployment_row(line: str, line_number: int) -> Tuple[str, int, int, in
174175
match['contract'].strip(),
175176
parse_optional_int(match['min'].strip()),
176177
parse_optional_int(match['max'].strip()),
177-
int(match['avg'].strip()),
178+
int(match['avg'].strip().replace(',', '')),
178179
)
179180

180181

test/externalTests/gp2.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ function gp2_test
6868
yarn
6969
# Hardhat 3.0+ breaks the test suite
7070
# v2.27.1 is the last v2 Hardhat (introduces Osaka support)
71-
71+
# hardhat-gas-reporter v2 is required for compatibility with our injected gas reporter settings
72+
yarn add [email protected] hardhat-gas-reporter@^2
7273

7374
# Ignore bench directory which fails to compile with current hardhat and ethers versions.
7475
# bench/trace/gas.ts:123:19 - error TS2339: Property 'equals' does not exist on type 'Uint8Array'.

0 commit comments

Comments
 (0)