Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wanwiset25 committed Oct 14, 2024
1 parent 33b18b0 commit 83adfc2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
17 changes: 11 additions & 6 deletions p2p/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestDialStateDynDial(t *testing.T) {
&discoverTask{},
},
new: []task{
&waitExpireTask{Duration: 14 * time.Second},
&discoverTask{},
},
},
},
Expand Down Expand Up @@ -376,9 +376,6 @@ func TestDialStateDynDialFromTable(t *testing.T) {
&dialTask{flags: dynDialedConn, dest: newNode(uintID(11), nil)},
&dialTask{flags: dynDialedConn, dest: newNode(uintID(12), nil)},
},
new: []task{
&discoverTask{},
},
},
// Waiting for expiry. No waitExpireTask is launched because the
// discovery query is still running.
Expand Down Expand Up @@ -497,6 +494,9 @@ func TestDialStateStaticDial(t *testing.T) {
&dialTask{flags: staticDialedConn, dest: newNode(uintID(4), nil)},
&dialTask{flags: staticDialedConn, dest: newNode(uintID(5), nil)},
},
new: []task{
&waitExpireTask{Duration: 14 * time.Second},
},
},
// Wait a round for dial history to expire, no new tasks should spawn.
{
Expand Down Expand Up @@ -551,6 +551,9 @@ func TestDialStaticAfterReset(t *testing.T) {
&dialTask{flags: staticDialedConn, dest: newNode(uintID(1), nil)},
&dialTask{flags: staticDialedConn, dest: newNode(uintID(2), nil)},
},
new: []task{
&waitExpireTask{Duration: 30 * time.Second},
},
},
}
dTest := dialtest{
Expand All @@ -561,9 +564,7 @@ func TestDialStaticAfterReset(t *testing.T) {
for _, n := range wantStatic {
dTest.init.removeStatic(n)
dTest.init.addStatic(n)
delete(dTest.init.dialing, n.ID())
}

// without removing peers they will be considered recently dialed
runDialTest(t, dTest)
}
Expand Down Expand Up @@ -611,6 +612,9 @@ func TestDialStateCache(t *testing.T) {
done: []task{
&dialTask{flags: staticDialedConn, dest: newNode(uintID(3), nil)},
},
new: []task{
&waitExpireTask{Duration: 14 * time.Second},
},
},
// Still waiting for node 3's entry to expire in the cache.
{
Expand Down Expand Up @@ -699,3 +703,4 @@ func (t *resolveMock) Self() *enode.Node { return new(enode.
func (t *resolveMock) Close() {}
func (t *resolveMock) LookupRandom() []*enode.Node { return nil }
func (t *resolveMock) ReadRandomNodes(buf []*enode.Node) int { return 0 }
func (t *resolveMock) Bootstrap([]*enode.Node) {}
6 changes: 3 additions & 3 deletions p2p/discover/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (t *udp) sendPing(toid enode.ID, toaddr *net.UDPAddr, callback func()) <-ch
To: makeEndpoint(toaddr, 0), // TODO: maybe use known TCP port from DB
Expiration: uint64(time.Now().Add(expiration).Unix()),
}
packet, hash, err := encodePacket(t.priv, pingPacket, req)
packet, hash, err := encodePacket(t.priv, pingXDC, req)
if err != nil {
errc := make(chan error, 1)
errc <- err
Expand All @@ -321,7 +321,7 @@ func (t *udp) sendPing(toid enode.ID, toaddr *net.UDPAddr, callback func()) <-ch
}

func (t *udp) waitping(from enode.ID) error {
return <-t.pending(from, pingPacket, func(interface{}) bool { return true })
return <-t.pending(from, pingXDC, func(interface{}) bool { return true })
}

// findnode sends a findnode request to the given node and waits until
Expand Down Expand Up @@ -631,7 +631,7 @@ func (req *ping) handle(t *udp, from *net.UDPAddr, fromKey encPubkey, mac []byte
Expiration: uint64(time.Now().Add(expiration).Unix()),
})
n := wrapNode(enode.NewV4(key, from.IP, int(req.From.TCP), from.Port))
t.handleReply(n.ID(), pingPacket, req)
t.handleReply(n.ID(), pingXDC, req)
if time.Since(t.db.LastPongReceived(n.ID())) > bondExpiration {
t.sendPing(n.ID(), from, func() { t.addThroughPing(n) })
} else {
Expand Down
1 change: 1 addition & 0 deletions p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bytes"
"crypto/ecdsa"
"errors"
"fmt"
"net"
"sync"
"sync/atomic"
Expand Down
17 changes: 2 additions & 15 deletions p2p/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package p2p
import (
"crypto/ecdsa"
"errors"
"fmt"
"math/rand"
"net"
"reflect"
Expand Down Expand Up @@ -196,22 +197,8 @@ func TestServerDial(t *testing.T) {
t.Error("server did not launch peer within one second")
}

select {
case peer := <-connected:
if peer.ID() != enode.PubkeyToIDV4(remid) {
t.Errorf("peer has wrong id")
}
if peer.Name() != "test" {
t.Errorf("peer has wrong name")
}
if peer.RemoteAddr().String() != conn.LocalAddr().String() {
t.Errorf("peer started with wrong conn: got %v, want %v",
peer.RemoteAddr(), conn.LocalAddr())
}
case <-time.After(1 * time.Second):
t.Error("server did not launch peer within one second")
}
case <-time.After(1 * time.Second):
fmt.Println("step 1: didn't work")
t.Error("server did not connect within one second")
}
}
Expand Down
9 changes: 6 additions & 3 deletions p2p/simulations/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ func startTestNetwork(t *testing.T, client *Client) []string {
nodeCount := 2
nodeIDs := make([]string, nodeCount)
for i := 0; i < nodeCount; i++ {
node, err := client.CreateNode(nil)
config := adapters.RandomNodeConfig()
node, err := client.CreateNode(config)
if err != nil {
t.Fatalf("error creating node: %s", err)
}
Expand Down Expand Up @@ -529,7 +530,8 @@ func TestHTTPNodeRPC(t *testing.T) {

// start a node in the network
client := NewClient(s.URL)
node, err := client.CreateNode(nil)
config := adapters.RandomNodeConfig()
node, err := client.CreateNode(config)
if err != nil {
t.Fatalf("error creating node: %s", err)
}
Expand Down Expand Up @@ -591,7 +593,8 @@ func TestHTTPSnapshot(t *testing.T) {
nodeCount := 2
nodes := make([]*p2p.NodeInfo, nodeCount)
for i := 0; i < nodeCount; i++ {
node, err := client.CreateNode(nil)
config := adapters.RandomNodeConfig()
node, err := client.CreateNode(config)
if err != nil {
t.Fatalf("error creating node: %s", err)
}
Expand Down

0 comments on commit 83adfc2

Please sign in to comment.