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/cmd/devp2p/internal/ethtest"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"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/p2p/rlpx"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
@ -46,22 +47,28 @@ var (
|
||||||
}
|
}
|
||||||
rlpxEthTestCommand = &cli.Command{
|
rlpxEthTestCommand = &cli.Command{
|
||||||
Name: "eth-test",
|
Name: "eth-test",
|
||||||
Usage: "Runs tests against a node",
|
Usage: "Runs eth protocol tests against a node",
|
||||||
ArgsUsage: "<node> <chain.rlp> <genesis.json>",
|
ArgsUsage: "<node>",
|
||||||
Action: rlpxEthTest,
|
Action: rlpxEthTest,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
testPatternFlag,
|
testPatternFlag,
|
||||||
testTAPFlag,
|
testTAPFlag,
|
||||||
|
testChainDirFlag,
|
||||||
|
testNodeJWTFlag,
|
||||||
|
testNodeEngineFlag,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
rlpxSnapTestCommand = &cli.Command{
|
rlpxSnapTestCommand = &cli.Command{
|
||||||
Name: "snap-test",
|
Name: "snap-test",
|
||||||
Usage: "Runs tests against a node",
|
Usage: "Runs snap protocol tests against a node",
|
||||||
ArgsUsage: "<node> <chain.rlp> <genesis.json>",
|
ArgsUsage: "<node>",
|
||||||
Action: rlpxSnapTest,
|
Action: rlpxSnapTest,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
testPatternFlag,
|
testPatternFlag,
|
||||||
testTAPFlag,
|
testTAPFlag,
|
||||||
|
testChainDirFlag,
|
||||||
|
testNodeJWTFlag,
|
||||||
|
testNodeEngineFlag,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -103,10 +110,8 @@ func rlpxPing(ctx *cli.Context) error {
|
||||||
|
|
||||||
// rlpxEthTest runs the eth protocol test suite.
|
// rlpxEthTest runs the eth protocol test suite.
|
||||||
func rlpxEthTest(ctx *cli.Context) error {
|
func rlpxEthTest(ctx *cli.Context) error {
|
||||||
if ctx.NArg() < 3 {
|
p := cliTestParams(ctx)
|
||||||
exit("missing path to chain.rlp as command-line argument")
|
suite, err := ethtest.NewSuite(p.node, p.chainDir, p.engineAPI, p.jwt)
|
||||||
}
|
|
||||||
suite, err := ethtest.NewSuite(getNodeArg(ctx), ctx.Args().Get(1), ctx.Args().Get(2), ctx.Args().Get(3))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit(err)
|
exit(err)
|
||||||
}
|
}
|
||||||
|
|
@ -115,12 +120,36 @@ func rlpxEthTest(ctx *cli.Context) error {
|
||||||
|
|
||||||
// rlpxSnapTest runs the snap protocol test suite.
|
// rlpxSnapTest runs the snap protocol test suite.
|
||||||
func rlpxSnapTest(ctx *cli.Context) error {
|
func rlpxSnapTest(ctx *cli.Context) error {
|
||||||
if ctx.NArg() < 3 {
|
p := cliTestParams(ctx)
|
||||||
exit("missing path to chain.rlp as command-line argument")
|
suite, err := ethtest.NewSuite(p.node, p.chainDir, p.engineAPI, p.jwt)
|
||||||
}
|
|
||||||
suite, err := ethtest.NewSuite(getNodeArg(ctx), ctx.Args().Get(1), ctx.Args().Get(2), ctx.Args().Get(3))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit(err)
|
exit(err)
|
||||||
}
|
}
|
||||||
return runTests(ctx, suite.SnapTests())
|
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",
|
Name: "tap",
|
||||||
Usage: "Output 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.
|
// These two are specific to the discovery tests.
|
||||||
testListen1Flag = &cli.StringFlag{
|
testListen1Flag = &cli.StringFlag{
|
||||||
Name: "listen1",
|
Name: "listen1",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue