package gate import ( "net" "testing" "time" ) // TestPeerAcceptsWhatWeDoNot covers the last part of the handshake question // that a client-only test cannot: whether a node this machine runs ever writes // a frame without one being sent first. // // A node presents itself as soon as it accepts a connection. The nodes on this // machine write nothing after accepting, which means they are either not // running the peer listener this connection reached or are answering only // after something the client has not done. Either way, the observation is the // same on a fresh datadir and on the rig's, and it is recorded here so that a // later run can tell whether the behaviour has changed. func TestPeerAcceptsWhatWeDoNot(t *testing.T) { addr := p2pAddr(t) nc, err := net.Dial("tcp", addr) if err != nil { t.Skipf("no listener at %s: %v", addr, err) } defer nc.Close() _ = nc.SetReadDeadline(time.Now().Add(3 * time.Second)) buf := make([]byte, 1024) n, rerr := nc.Read(buf) if n > 0 { t.Logf("the node at %s presented itself with %d bytes before any was sent", addr, n) return } t.Logf("the node at %s wrote nothing after accepting a connection: %v", addr, rerr) }