Skip to content

Commit d193177

Browse files
fix(bless): filter commented stdout lines in gas report parsing (#1016)
* fix(bless): filter commented stdout lines in gas report parsing The gas report parser was incorrectly matching commented lines like "# stdout 'GAS USED: 123'" because it only checked if the line contained the pattern, not if it started with it. Changes: - Add isValidStdoutLine function to check line starts with known prefix - Add STORAGE FEE to defaultStdoutPrefixes for consistency - Use isValidStdoutLine in parseGasOutput to filter commented lines * refactor(bless): use map for stdout prefix lookup * test(bless): add unit tests for report.go
1 parent 89bd64d commit d193177

File tree

3 files changed

+567
-7
lines changed

3 files changed

+567
-7
lines changed

tests/integration/bless/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type ScriptProcessor struct {
3636
patterns []MaskPattern
3737
stdoutConv Converter
3838
stderrConv Converter
39-
stdoutPrefixes []string
39+
stdoutPrefixes map[string]bool
4040
}
4141

4242
const (
@@ -48,11 +48,12 @@ const (
4848
okOutput = "OK!"
4949
)
5050

51-
var defaultStdoutPrefixes = []string{
52-
"GAS USED:",
53-
"STORAGE DELTA:",
54-
"TOTAL TX COST:",
55-
"EVENTS:",
51+
var defaultStdoutPrefixes = map[string]bool{
52+
"GAS USED:": true,
53+
"STORAGE DELTA:": true,
54+
"STORAGE FEE:": true,
55+
"TOTAL TX COST:": true,
56+
"EVENTS:": true,
5657
}
5758

5859
func main() {
@@ -366,7 +367,7 @@ func (p *outputParser) shouldKeepStdoutLine(line, cmd string) bool {
366367
}
367368

368369
// Check against known prefixes
369-
for _, prefix := range p.processor.stdoutPrefixes {
370+
for prefix := range p.processor.stdoutPrefixes {
370371
if strings.HasPrefix(line, prefix) {
371372
return true
372373
}

tests/integration/bless/report.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ func (rg *ReportGenerator) parseGasOutput(lines []string) []GasValue {
195195
continue
196196
}
197197

198+
// Only parse lines that START with known stdout prefixes
199+
// This filters out commented lines like "# stdout 'GAS USED:'"
200+
if !isValidStdoutLine(trimmed) {
201+
continue
202+
}
203+
198204
// Parse GAS USED
199205
if matches := gasUsedPattern.FindStringSubmatch(trimmed); len(matches) > 1 {
200206
current.GasUsed, _ = strconv.ParseUint(matches[1], 10, 64)
@@ -219,6 +225,17 @@ func (rg *ReportGenerator) parseGasOutput(lines []string) []GasValue {
219225
return values
220226
}
221227

228+
// isValidStdoutLine checks if a line starts with a known stdout prefix.
229+
// Used to filter out commented lines like "# stdout 'GAS USED:'"
230+
func isValidStdoutLine(line string) bool {
231+
for prefix := range defaultStdoutPrefixes {
232+
if strings.HasPrefix(line, prefix) {
233+
return true
234+
}
235+
}
236+
return false
237+
}
238+
222239
// buildReport creates a GasReport from parsed data
223240
func (rg *ReportGenerator) buildReport(functions []FunctionInfo, gasValues []GasValue) *GasReport {
224241
report := &GasReport{

0 commit comments

Comments
 (0)