-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
126 lines (109 loc) · 3.17 KB
/
main.go
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
package main
import (
"fmt"
"os"
"sort"
"strings"
"github.com/holiman/uint256"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/ethpandaops/goomy-blob/scenarios"
"github.com/ethpandaops/goomy-blob/scenariotypes"
"github.com/ethpandaops/goomy-blob/tester"
"github.com/ethpandaops/goomy-blob/utils"
)
type CliArgs struct {
verbose bool
trace bool
rpchosts []string
rpchostsFile string
privkey string
seed string
}
func mainArgs(flags *pflag.FlagSet, cliArgs *CliArgs) {
}
func main() {
cliArgs := CliArgs{}
flags := pflag.NewFlagSet("main", pflag.ContinueOnError)
flags.BoolVarP(&cliArgs.verbose, "verbose", "v", false, "Run the script with verbose output")
flags.BoolVar(&cliArgs.trace, "trace", false, "Run the script with tracing output")
flags.StringArrayVarP(&cliArgs.rpchosts, "rpchost", "h", []string{}, "The RPC host to send transactions to.")
flags.StringVar(&cliArgs.rpchostsFile, "rpchost-file", "", "File with a list of RPC hosts to send transactions to.")
flags.StringVarP(&cliArgs.privkey, "privkey", "p", "", "The private key of the wallet to send funds from.")
flags.StringVarP(&cliArgs.seed, "seed", "s", "", "The child wallet seed.")
flags.Parse(os.Args)
invalidScenario := false
var scenarioName string
var scenarioBuilder func() scenariotypes.Scenario
if flags.NArg() < 2 {
invalidScenario = true
} else {
scenarioName = flags.Args()[1]
scenarioBuilder = scenarios.Scenarios[scenarioName]
if scenarioBuilder == nil {
invalidScenario = true
}
}
if invalidScenario {
fmt.Printf("invalid or missing scenario\n\n")
fmt.Printf("implemented scenarios:\n")
scenarioNames := []string{}
for sn := range scenarios.Scenarios {
scenarioNames = append(scenarioNames, sn)
}
sort.Slice(scenarioNames, func(a int, b int) bool {
return strings.Compare(scenarioNames[a], scenarioNames[b]) > 0
})
for _, name := range scenarioNames {
fmt.Printf(" %v\n", name)
}
return
}
scenario := scenarioBuilder()
if scenario == nil {
panic("could not create scenario instance")
}
flags.Init(fmt.Sprintf("%v %v", flags.Args()[0], scenarioName), pflag.ExitOnError)
scenario.Flags(flags)
cliArgs = CliArgs{}
flags.Parse(os.Args)
if cliArgs.trace {
logrus.SetLevel(logrus.TraceLevel)
} else if cliArgs.verbose {
logrus.SetLevel(logrus.DebugLevel)
}
rpcHosts := []string{}
for _, rpcHost := range strings.Split(strings.Join(cliArgs.rpchosts, ","), ",") {
if rpcHost != "" {
rpcHosts = append(rpcHosts, rpcHost)
}
}
if cliArgs.rpchostsFile != "" {
fileLines, err := utils.ReadFileLinesTrimmed(cliArgs.rpchostsFile)
if err != nil {
panic(err)
}
rpcHosts = append(rpcHosts, fileLines...)
}
testerConfig := &tester.TesterConfig{
RpcHosts: rpcHosts,
WalletPrivkey: cliArgs.privkey,
WalletCount: 100,
WalletPrefund: utils.EtherToWei(uint256.NewInt(5)),
WalletMinfund: utils.EtherToWei(uint256.NewInt(2)),
}
err := scenario.Init(testerConfig)
if err != nil {
panic(err)
}
tester := tester.NewTester(testerConfig)
err = tester.Start(cliArgs.seed)
if err != nil {
panic(err)
}
defer tester.Stop()
err = scenario.Run(tester)
if err != nil {
panic(err)
}
}