mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/devp2p: pass test parameters as flags instead of args
CLIs with multiple positional parameters are kind of hard to use.
This commit is contained in:
parent
c6bfefa1b2
commit
9e09c76cbf
2 changed files with 56 additions and 12 deletions
|
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/cmd/devp2p/internal/ethtest"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/ethereum/go-ethereum/p2p/rlpx"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
|
@ -46,22 +47,28 @@ var (
|
|||
}
|
||||
rlpxEthTestCommand = &cli.Command{
|
||||
Name: "eth-test",
|
||||
Usage: "Runs tests against a node",
|
||||
ArgsUsage: "<node> <chain.rlp> <genesis.json>",
|
||||
Usage: "Runs eth protocol tests against a node",
|
||||
ArgsUsage: "<node>",
|
||||
Action: rlpxEthTest,
|
||||
Flags: []cli.Flag{
|
||||
testPatternFlag,
|
||||
testTAPFlag,
|
||||
testChainDirFlag,
|
||||
testNodeJWTFlag,
|
||||
testNodeEngineFlag,
|
||||
},
|
||||
}
|
||||
rlpxSnapTestCommand = &cli.Command{
|
||||
Name: "snap-test",
|
||||
Usage: "Runs tests against a node",
|
||||
ArgsUsage: "<node> <chain.rlp> <genesis.json>",
|
||||
Usage: "Runs snap protocol tests against a node",
|
||||
ArgsUsage: "<node>",
|
||||
Action: rlpxSnapTest,
|
||||
Flags: []cli.Flag{
|
||||
testPatternFlag,
|
||||
testTAPFlag,
|
||||
testChainDirFlag,
|
||||
testNodeJWTFlag,
|
||||
testNodeEngineFlag,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
|
@ -103,10 +110,8 @@ func rlpxPing(ctx *cli.Context) error {
|
|||
|
||||
// rlpxEthTest runs the eth protocol test suite.
|
||||
func rlpxEthTest(ctx *cli.Context) error {
|
||||
if ctx.NArg() < 3 {
|
||||
exit("missing path to chain.rlp as command-line argument")
|
||||
}
|
||||
suite, err := ethtest.NewSuite(getNodeArg(ctx), ctx.Args().Get(1), ctx.Args().Get(2), ctx.Args().Get(3))
|
||||
p := cliTestParams(ctx)
|
||||
suite, err := ethtest.NewSuite(p.node, p.chainDir, p.engineAPI, p.jwt)
|
||||
if err != nil {
|
||||
exit(err)
|
||||
}
|
||||
|
|
@ -115,12 +120,36 @@ func rlpxEthTest(ctx *cli.Context) error {
|
|||
|
||||
// rlpxSnapTest runs the snap protocol test suite.
|
||||
func rlpxSnapTest(ctx *cli.Context) error {
|
||||
if ctx.NArg() < 3 {
|
||||
exit("missing path to chain.rlp as command-line argument")
|
||||
}
|
||||
suite, err := ethtest.NewSuite(getNodeArg(ctx), ctx.Args().Get(1), ctx.Args().Get(2), ctx.Args().Get(3))
|
||||
p := cliTestParams(ctx)
|
||||
suite, err := ethtest.NewSuite(p.node, p.chainDir, p.engineAPI, p.jwt)
|
||||
if err != nil {
|
||||
exit(err)
|
||||
}
|
||||
return runTests(ctx, suite.SnapTests())
|
||||
}
|
||||
|
||||
type testParams struct {
|
||||
node *enode.Node
|
||||
engineAPI string
|
||||
jwt string
|
||||
chainDir string
|
||||
}
|
||||
|
||||
func cliTestParams(ctx *cli.Context) *testParams {
|
||||
p := testParams{
|
||||
node: getNodeArg(ctx),
|
||||
engineAPI: ctx.String(testNodeEngineFlag.Name),
|
||||
jwt: ctx.String(testNodeJWTFlag.Name),
|
||||
chainDir: ctx.String(testChainDirFlag.Name),
|
||||
}
|
||||
if p.engineAPI == "" {
|
||||
exit(fmt.Errorf("missing -%s", testNodeEngineFlag.Name))
|
||||
}
|
||||
if p.jwt == "" {
|
||||
exit(fmt.Errorf("missing -%s", testNodeJWTFlag.Name))
|
||||
}
|
||||
if p.chainDir == "" {
|
||||
exit(fmt.Errorf("missing -%s", testChainDirFlag.Name))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,21 @@ var (
|
|||
Name: "tap",
|
||||
Usage: "Output TAP",
|
||||
}
|
||||
|
||||
// for eth/snap tests
|
||||
testChainDirFlag = &cli.StringFlag{
|
||||
Name: "chain",
|
||||
Usage: "Test chain directory",
|
||||
}
|
||||
testNodeJWTFlag = &cli.StringFlag{
|
||||
Name: "jwt",
|
||||
Usage: "JWT for talking to the engine API of the test node",
|
||||
}
|
||||
testNodeEngineFlag = &cli.StringFlag{
|
||||
Name: "engineapi",
|
||||
Usage: "Engine API endpoint of the test node",
|
||||
}
|
||||
|
||||
// These two are specific to the discovery tests.
|
||||
testListen1Flag = &cli.StringFlag{
|
||||
Name: "listen1",
|
||||
|
|
|
|||
Loading…
Reference in a new issue