cmd/devp2p: add -node flag for testing

This commit is contained in:
Felix Lange 2023-11-07 13:27:07 +01:00
parent 9e09c76cbf
commit 10ea0443b7
3 changed files with 42 additions and 18 deletions

View file

@ -54,6 +54,7 @@ var (
testPatternFlag, testPatternFlag,
testTAPFlag, testTAPFlag,
testChainDirFlag, testChainDirFlag,
testNodeFlag,
testNodeJWTFlag, testNodeJWTFlag,
testNodeEngineFlag, testNodeEngineFlag,
}, },
@ -61,12 +62,13 @@ var (
rlpxSnapTestCommand = &cli.Command{ rlpxSnapTestCommand = &cli.Command{
Name: "snap-test", Name: "snap-test",
Usage: "Runs snap protocol tests against a node", Usage: "Runs snap protocol tests against a node",
ArgsUsage: "<node>", ArgsUsage: "",
Action: rlpxSnapTest, Action: rlpxSnapTest,
Flags: []cli.Flag{ Flags: []cli.Flag{
testPatternFlag, testPatternFlag,
testTAPFlag, testTAPFlag,
testChainDirFlag, testChainDirFlag,
testNodeFlag,
testNodeJWTFlag, testNodeJWTFlag,
testNodeEngineFlag, testNodeEngineFlag,
}, },
@ -136,8 +138,16 @@ type testParams struct {
} }
func cliTestParams(ctx *cli.Context) *testParams { func cliTestParams(ctx *cli.Context) *testParams {
nodeStr := ctx.String(testNodeFlag.Name)
if nodeStr == "" {
exit(fmt.Errorf("missing -%s", testNodeFlag.Name))
}
node, err := parseNode(nodeStr)
if err != nil {
exit(err)
}
p := testParams{ p := testParams{
node: getNodeArg(ctx), node: node,
engineAPI: ctx.String(testNodeEngineFlag.Name), engineAPI: ctx.String(testNodeEngineFlag.Name),
jwt: ctx.String(testNodeJWTFlag.Name), jwt: ctx.String(testNodeJWTFlag.Name),
chainDir: ctx.String(testChainDirFlag.Name), chainDir: ctx.String(testChainDirFlag.Name),

View file

@ -20,6 +20,7 @@ import (
"os" "os"
"github.com/ethereum/go-ethereum/cmd/devp2p/internal/v4test" "github.com/ethereum/go-ethereum/cmd/devp2p/internal/v4test"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/internal/utesting" "github.com/ethereum/go-ethereum/internal/utesting"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -29,24 +30,34 @@ var (
testPatternFlag = &cli.StringFlag{ testPatternFlag = &cli.StringFlag{
Name: "run", Name: "run",
Usage: "Pattern of test suite(s) to run", Usage: "Pattern of test suite(s) to run",
Category: flags.TestingCategory,
} }
testTAPFlag = &cli.BoolFlag{ testTAPFlag = &cli.BoolFlag{
Name: "tap", Name: "tap",
Usage: "Output TAP", Usage: "Output test results in TAP format",
Category: flags.TestingCategory,
} }
// for eth/snap tests // for eth/snap tests
testChainDirFlag = &cli.StringFlag{ testChainDirFlag = &cli.StringFlag{
Name: "chain", Name: "chain",
Usage: "Test chain directory", Usage: "Test chain directory (required)",
Category: flags.TestingCategory,
}
testNodeFlag = &cli.StringFlag{
Name: "node",
Usage: "Peer-to-Peer endpoint (ENR) of the test node (required)",
Category: flags.TestingCategory,
} }
testNodeJWTFlag = &cli.StringFlag{ testNodeJWTFlag = &cli.StringFlag{
Name: "jwt", Name: "jwt",
Usage: "JWT for talking to the engine API of the test node", Usage: "JWT for talking to the engine API of the test node (required)",
Category: flags.TestingCategory,
} }
testNodeEngineFlag = &cli.StringFlag{ testNodeEngineFlag = &cli.StringFlag{
Name: "engineapi", Name: "engineapi",
Usage: "Engine API endpoint of the test node", Usage: "Engine API endpoint of the test node (required)",
Category: flags.TestingCategory,
} }
// These two are specific to the discovery tests. // These two are specific to the discovery tests.
@ -54,11 +65,13 @@ var (
Name: "listen1", Name: "listen1",
Usage: "IP address of the first tester", Usage: "IP address of the first tester",
Value: v4test.Listen1, Value: v4test.Listen1,
Category: flags.TestingCategory,
} }
testListen2Flag = &cli.StringFlag{ testListen2Flag = &cli.StringFlag{
Name: "listen2", Name: "listen2",
Usage: "IP address of the second tester", Usage: "IP address of the second tester",
Value: v4test.Listen2, Value: v4test.Listen2,
Category: flags.TestingCategory,
} }
) )

View file

@ -35,6 +35,7 @@ const (
LoggingCategory = "LOGGING AND DEBUGGING" LoggingCategory = "LOGGING AND DEBUGGING"
MetricsCategory = "METRICS AND STATS" MetricsCategory = "METRICS AND STATS"
MiscCategory = "MISC" MiscCategory = "MISC"
TestingCategory = "TESTING"
DeprecatedCategory = "ALIASED (deprecated)" DeprecatedCategory = "ALIASED (deprecated)"
) )