-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
153 lines (135 loc) · 3.85 KB
/
main.go
File metadata and controls
153 lines (135 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main
import (
"bufio"
"encoding/csv"
"fmt"
"os"
"regexp"
"strings"
"github.com/eth-error-tests/pkg/config"
"github.com/eth-error-tests/pkg/runner"
"github.com/spf13/cobra"
)
func Report(filename string) {
file, err := os.Open(filename)
if err != nil {
panic(err)
}
defer func() {
if err := file.Close(); err != nil {
fmt.Printf("Error closing file: %v\n", err)
}
}()
outputFile, err := os.Create(filename + ".csv")
if err != nil {
panic(err)
}
defer func() {
if err := outputFile.Close(); err != nil {
fmt.Printf("Error closing output file: %v\n", err)
}
}()
scanner := bufio.NewScanner(file)
writer := csv.NewWriter(outputFile)
defer writer.Flush()
scenarioRegexp := regexp.MustCompile(`^Scenario: (.+?)\s+-\s+Request:`)
requestRegexp := regexp.MustCompile(`(?s)Request: (.+)`)
responseRegexp := regexp.MustCompile(`(?s)^Response: (.+)$`)
methodRegex := regexp.MustCompile(`"method":"([^"]+)"`)
err = writer.Write([]string{"Method", "scenario", "Response", "Request"})
if err != nil {
panic(err)
}
var scenario, request, response, method string
for scanner.Scan() {
line := scanner.Text()
if matches := scenarioRegexp.FindStringSubmatch(line); len(matches) > 0 {
scenario = matches[1]
fmt.Println(scenario)
}
if matches := requestRegexp.FindStringSubmatch(line); len(matches) > 0 {
request = matches[1]
if newmatches := methodRegex.FindStringSubmatch(request); len(newmatches) > 0 {
method = newmatches[1]
}
} else if matches := responseRegexp.FindStringSubmatch(line); len(matches) > 0 {
response = matches[1]
err = writer.Write([]string{method, scenario, response, request})
if err != nil {
panic(err)
}
}
}
if err := scanner.Err(); err != nil {
fmt.Println("Error:", err)
}
}
var (
env string
tests string
)
var rootCmd = &cobra.Command{
Use: "eth-err-tests",
Long: `Ethereum RPC Client Tester
Docker Clients: besu-local, geth-local, reth-local, nethermind-local, erigon-local
Remote Networks: sepolia, zkevm`,
Example: ` #Test on local geth via Docker
eth-err-tests --env geth-local
# Run specific tests on zkEVM
eth-err-tests --env zkevm --tests eth_call,eth_estimateGas`,
Run: func(cmd *cobra.Command, args []string) {
cfg, err := config.GetConfig(env)
if err != nil {
fmt.Printf("Error: Invalid environment '%s': %v\n", env, err)
os.Exit(1)
}
fmt.Printf("Testing Network: %s\n", cfg.Network)
fmt.Printf("RPC URL: %s\n", cfg.Url)
fmt.Println("=======================================================")
fmt.Println()
testRunner, err := runner.NewTestRunner(cfg)
if err != nil {
fmt.Printf("Error creating test runner: %v\n", err)
os.Exit(1)
}
defer testRunner.Cleanup()
var testNames []string
if tests != "" {
testNames = strings.Split(tests, ",")
for i := range testNames {
testNames[i] = strings.TrimSpace(testNames[i])
}
}
if err := testRunner.RunWithAutoDeployment(testNames); err != nil {
fmt.Printf("Error running tests: %v\n", err)
os.Exit(1)
}
},
}
var reportCmd = &cobra.Command{
Use: "report [logfile]",
Long: "Generate a CSV report from a test log file",
Example: `eth-err-tests report reports/geth-local.log`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
logFile := args[0]
fmt.Println("Generating report from log file:", logFile)
Report(logFile)
},
}
func init() {
// Root command
rootCmd.Flags().StringVarP(&env, "env", "e", "", "Network/client to test (required)")
rootCmd.Flags().StringVarP(&tests, "tests", "t", "", "Comma-separated list of tests to run (e.g., eth_getBalance,eth_getCode,eth_call,eth_estimateGas,eth_sendRawTransaction)")
if err := rootCmd.MarkFlagRequired("env"); err != nil {
panic(err)
}
// report command
rootCmd.AddCommand(reportCmd)
}
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}