mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 07:28:06 -05:00
Update Discv5 to the Latest Version (#3392)
* update workspace * change to new version * gaz * set keys * try more things * finally fixed all tests * fix bootnode * Update beacon-chain/p2p/discovery.go Co-Authored-By: Preston Van Loon <preston@prysmaticlabs.com> * preston's and raul's review * add http server * add tool * add image * change comment * add multiaddr comment * lint * cosmetic changes * fix docker * remove dep * preston's requested changes
This commit is contained in:
@@ -4,9 +4,11 @@ import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/ethereum/go-ethereum/p2p/discv5"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
"github.com/prysmaticlabs/prysm/shared/iputils"
|
||||
_ "go.uber.org/automaxprocs"
|
||||
@@ -17,44 +19,43 @@ func TestBootnode_OK(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
privKey := extractPrivateKey()
|
||||
listener := createListener(ipAddr, 4000, privKey)
|
||||
cfg := discover.Config{
|
||||
PrivateKey: extractPrivateKey(),
|
||||
}
|
||||
listener := createListener(ipAddr, 4000, cfg)
|
||||
defer listener.Close()
|
||||
|
||||
privKey = extractPrivateKey()
|
||||
listener2 := createListener(ipAddr, 4001, privKey)
|
||||
defer listener.Close()
|
||||
|
||||
err = listener.SetFallbackNodes([]*discv5.Node{listener2.Self()})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = listener2.SetFallbackNodes([]*discv5.Node{listener.Self()})
|
||||
cfg.PrivateKey = extractPrivateKey()
|
||||
bootNode, err := enode.Parse(enode.ValidSchemes, listener.Self().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg.Bootnodes = []*enode.Node{bootNode}
|
||||
listener2 := createListener(ipAddr, 4001, cfg)
|
||||
defer listener2.Close()
|
||||
|
||||
// test that both the nodes have the other peer stored in their local table.
|
||||
listenerNode := listener.Self()
|
||||
listenerNode2 := listener2.Self()
|
||||
|
||||
nodes := listener.Lookup(listenerNode2.ID)
|
||||
if len(nodes) != 2 {
|
||||
t.Errorf("Length of nodes stored in table is not expected. Wanted %d but got %d", 2, len(nodes))
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
nodes := listener.Lookup(listenerNode2.ID())
|
||||
if len(nodes) == 0 {
|
||||
t.Fatalf("Length of nodes stored in table is not expected. Wanted to be more than %d but got %d", 0, len(nodes))
|
||||
|
||||
}
|
||||
if nodes[0].ID != listenerNode2.ID {
|
||||
t.Errorf("Wanted node ID of %s but got %s", listenerNode2.ID, nodes[1].ID)
|
||||
if nodes[0].ID() != listenerNode2.ID() {
|
||||
t.Errorf("Wanted node ID of %s but got %s", listenerNode2.ID(), nodes[1].ID())
|
||||
}
|
||||
|
||||
nodes = listener2.Lookup(listenerNode.ID)
|
||||
if len(nodes) != 2 {
|
||||
t.Errorf("Length of nodes stored in table is not expected. Wanted %d but got %d", 2, len(nodes))
|
||||
nodes = listener2.Lookup(listenerNode.ID())
|
||||
if len(nodes) == 0 {
|
||||
t.Errorf("Length of nodes stored in table is not expected. Wanted to be more than %d but got %d", 0, len(nodes))
|
||||
|
||||
}
|
||||
if nodes[0].ID != listenerNode.ID {
|
||||
t.Errorf("Wanted node ID of %s but got %s", listenerNode.ID, nodes[1].ID)
|
||||
if nodes[0].ID() != listenerNode.ID() {
|
||||
t.Errorf("Wanted node ID of %s but got %s", listenerNode.ID(), nodes[1].ID())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user