Skip to content

Commit 25191bb

Browse files
authored
cmd/devp2p/internal/v4test: fix false-positive hive test (ethereum#23962)
This PR fixes two problems in devp2p tests (and through them, hive). - Make the output more detailed about what is returned (always print packet kind). - Allow Ping response to unsolicited findnode. Without this PR, nethermind fails a hive protocol tests, and I misinterpreted the result (NethermindEth/nethermind#3617). Ergo, the output was not fool-proof.
1 parent 0a7672f commit 25191bb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

cmd/devp2p/internal/v4test/discv4tests.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func PingPastExpiration(t *utesting.T) {
229229

230230
reply, _, _ := te.read(te.l1)
231231
if reply != nil {
232-
t.Fatal("Expected no reply, got", reply)
232+
t.Fatalf("Expected no reply, got %v %v", reply.Name(), reply)
233233
}
234234
}
235235

@@ -247,7 +247,7 @@ func WrongPacketType(t *utesting.T) {
247247

248248
reply, _, _ := te.read(te.l1)
249249
if reply != nil {
250-
t.Fatal("Expected no reply, got", reply)
250+
t.Fatalf("Expected no reply, got %v %v", reply.Name(), reply)
251251
}
252252
}
253253

@@ -282,9 +282,16 @@ func FindnodeWithoutEndpointProof(t *utesting.T) {
282282
rand.Read(req.Target[:])
283283
te.send(te.l1, &req)
284284

285-
reply, _, _ := te.read(te.l1)
286-
if reply != nil {
287-
t.Fatal("Expected no response, got", reply)
285+
for {
286+
reply, _, _ := te.read(te.l1)
287+
if reply == nil {
288+
// No response, all good
289+
break
290+
}
291+
if reply.Kind() == v4wire.PingPacket {
292+
continue // A ping is ok, just ignore it
293+
}
294+
t.Fatalf("Expected no reply, got %v %v", reply.Name(), reply)
288295
}
289296
}
290297

@@ -304,7 +311,7 @@ func BasicFindnode(t *utesting.T) {
304311
t.Fatal("read find nodes", err)
305312
}
306313
if reply.Kind() != v4wire.NeighborsPacket {
307-
t.Fatal("Expected neighbors, got", reply.Name())
314+
t.Fatalf("Expected neighbors, got %v %v", reply.Name(), reply)
308315
}
309316
}
310317

@@ -341,7 +348,7 @@ func UnsolicitedNeighbors(t *utesting.T) {
341348
t.Fatal("read find nodes", err)
342349
}
343350
if reply.Kind() != v4wire.NeighborsPacket {
344-
t.Fatal("Expected neighbors, got", reply.Name())
351+
t.Fatalf("Expected neighbors, got %v %v", reply.Name(), reply)
345352
}
346353
nodes := reply.(*v4wire.Neighbors).Nodes
347354
if contains(nodes, encFakeKey) {

0 commit comments

Comments
 (0)