@@ -19,11 +19,14 @@ package main
19
19
import (
20
20
"fmt"
21
21
"net"
22
+ "os"
22
23
"strings"
23
24
"time"
24
25
26
+ "github.com/ethereum/go-ethereum/cmd/devp2p/internal/v4test"
25
27
"github.com/ethereum/go-ethereum/common"
26
28
"github.com/ethereum/go-ethereum/crypto"
29
+ "github.com/ethereum/go-ethereum/internal/utesting"
27
30
"github.com/ethereum/go-ethereum/p2p/discover"
28
31
"github.com/ethereum/go-ethereum/p2p/enode"
29
32
"github.com/ethereum/go-ethereum/params"
40
43
discv4ResolveCommand ,
41
44
discv4ResolveJSONCommand ,
42
45
discv4CrawlCommand ,
46
+ discv4TestCommand ,
43
47
},
44
48
}
45
49
discv4PingCommand = cli.Command {
74
78
Action : discv4Crawl ,
75
79
Flags : []cli.Flag {bootnodesFlag , crawlTimeoutFlag },
76
80
}
81
+ discv4TestCommand = cli.Command {
82
+ Name : "test" ,
83
+ Usage : "Runs tests against a node" ,
84
+ Action : discv4Test ,
85
+ Flags : []cli.Flag {remoteEnodeFlag , testPatternFlag , testListen1Flag , testListen2Flag },
86
+ }
77
87
)
78
88
79
89
var (
@@ -98,6 +108,25 @@ var (
98
108
Usage : "Time limit for the crawl." ,
99
109
Value : 30 * time .Minute ,
100
110
}
111
+ remoteEnodeFlag = cli.StringFlag {
112
+ Name : "remote" ,
113
+ Usage : "Enode of the remote node under test" ,
114
+ EnvVar : "REMOTE_ENODE" ,
115
+ }
116
+ testPatternFlag = cli.StringFlag {
117
+ Name : "run" ,
118
+ Usage : "Pattern of test suite(s) to run" ,
119
+ }
120
+ testListen1Flag = cli.StringFlag {
121
+ Name : "listen1" ,
122
+ Usage : "IP address of the first tester" ,
123
+ Value : v4test .Listen1 ,
124
+ }
125
+ testListen2Flag = cli.StringFlag {
126
+ Name : "listen2" ,
127
+ Usage : "IP address of the second tester" ,
128
+ Value : v4test .Listen2 ,
129
+ }
101
130
)
102
131
103
132
func discv4Ping (ctx * cli.Context ) error {
@@ -184,6 +213,28 @@ func discv4Crawl(ctx *cli.Context) error {
184
213
return nil
185
214
}
186
215
216
+ func discv4Test (ctx * cli.Context ) error {
217
+ // Configure test package globals.
218
+ if ! ctx .IsSet (remoteEnodeFlag .Name ) {
219
+ return fmt .Errorf ("Missing -%v" , remoteEnodeFlag .Name )
220
+ }
221
+ v4test .Remote = ctx .String (remoteEnodeFlag .Name )
222
+ v4test .Listen1 = ctx .String (testListen1Flag .Name )
223
+ v4test .Listen2 = ctx .String (testListen2Flag .Name )
224
+
225
+ // Filter and run test cases.
226
+ tests := v4test .AllTests
227
+ if ctx .IsSet (testPatternFlag .Name ) {
228
+ tests = utesting .MatchTests (tests , ctx .String (testPatternFlag .Name ))
229
+ }
230
+ results := utesting .RunTests (tests , os .Stdout )
231
+ if fails := utesting .CountFailures (results ); fails > 0 {
232
+ return fmt .Errorf ("%v/%v tests passed." , len (tests )- fails , len (tests ))
233
+ }
234
+ fmt .Printf ("%v/%v passed\n " , len (tests ), len (tests ))
235
+ return nil
236
+ }
237
+
187
238
// startV4 starts an ephemeral discovery V4 node.
188
239
func startV4 (ctx * cli.Context ) * discover.UDPv4 {
189
240
ln , config := makeDiscoveryConfig (ctx )
0 commit comments