Skip to content

Commit 4d38fff

Browse files
committed
rpcfuzz cmd refactoring to avoid memory leak and better compatibility with unix standards
1 parent 96a861c commit 4d38fff

File tree

11 files changed

+827
-287
lines changed

11 files changed

+827
-287
lines changed

cmd/rpcfuzz/cmd.go

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ var (
2020
usage string
2121

2222
// flags
23-
rpcUrl *string
24-
testPrivateHexKey *string
25-
testContractAddress *string
26-
testNamespaces *string
27-
testFuzz *bool
28-
testFuzzNum *int
29-
seed *int64
30-
testOutputExportPath *string
31-
testExportJson *bool
32-
testExportCSV *bool
33-
testExportMarkdown *bool
34-
testExportHTML *bool
23+
rpcUrl *string
24+
testPrivateHexKey *string
25+
testContractAddress *string
26+
testNamespaces *string
27+
testFuzz *bool
28+
testFuzzNum *int
29+
seed *int64
30+
streamJSON *bool
31+
streamCSV *bool
32+
streamCompact *bool
33+
streamHTML *bool
34+
streamMarkdown *bool
35+
outputFilter *string
36+
summaryInterval *int
37+
quietMode *bool
3538
)
3639

3740
var RPCFuzzCmd = &cobra.Command{
@@ -61,11 +64,18 @@ func init() {
6164
testFuzz = flagSet.Bool("fuzz", false, "Flag to indicate whether to fuzz input or not.")
6265
testFuzzNum = flagSet.Int("fuzzn", 100, "Number of times to run the fuzzer per test.")
6366
seed = flagSet.Int64("seed", 123456, "A seed for generating random values within the fuzzer")
64-
testOutputExportPath = flagSet.String("export-path", "", "The directory export path of the output of the tests. Must pair this with either --json, --csv, --md, or --html")
65-
testExportJson = flagSet.Bool("json", false, "Flag to indicate that output will be exported as a JSON.")
66-
testExportCSV = flagSet.Bool("csv", false, "Flag to indicate that output will be exported as a CSV.")
67-
testExportMarkdown = flagSet.Bool("md", false, "Flag to indicate that output will be exported as a Markdown.")
68-
testExportHTML = flagSet.Bool("html", false, "Flag to indicate that output will be exported as a HTML.")
67+
68+
// Streamer type flags (mutually exclusive)
69+
streamJSON = flagSet.Bool("json", false, "Stream output in JSON format")
70+
streamCSV = flagSet.Bool("csv", false, "Stream output in CSV format")
71+
streamCompact = flagSet.Bool("compact", false, "Stream output in compact format (default)")
72+
streamHTML = flagSet.Bool("html", false, "Stream output in HTML format")
73+
streamMarkdown = flagSet.Bool("md", false, "Stream output in Markdown format")
74+
75+
// Output control flags
76+
outputFilter = flagSet.String("output", "all", "What to output: all, failures, summary")
77+
summaryInterval = flagSet.Int("summary-interval", 0, "Print summary every N tests (0=disabled)")
78+
quietMode = flagSet.Bool("quiet", false, "Only show final summary")
6979

7080
argfuzz.SetSeed(seed)
7181

@@ -82,6 +92,28 @@ func checkFlags() (err error) {
8292
return
8393
}
8494

95+
// Ensure only one streamer type is selected
96+
streamerCount := 0
97+
if *streamJSON {
98+
streamerCount++
99+
}
100+
if *streamCSV {
101+
streamerCount++
102+
}
103+
if *streamCompact {
104+
streamerCount++
105+
}
106+
if *streamHTML {
107+
streamerCount++
108+
}
109+
if *streamMarkdown {
110+
streamerCount++
111+
}
112+
113+
if streamerCount > 1 {
114+
return fmt.Errorf("only one output format can be specified: --json, --csv, --compact, --html, or --md")
115+
}
116+
85117
// Check private key flag.
86118
trimmedHexPrivateKey := strings.TrimPrefix(*testPrivateHexKey, "0x")
87119
privateKey, err := crypto.HexToECDSA(trimmedHexPrivateKey)

0 commit comments

Comments
 (0)