mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Decode peer ID properly when fetching peer (#8883)
# Conflicts: # beacon-chain/rpc/nodev1/node_test.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
@@ -78,9 +78,9 @@ func (ns *Server) GetPeer(ctx context.Context, req *ethpb.PeerRequest) (*ethpb.P
|
||||
defer span.End()
|
||||
|
||||
peerStatus := ns.PeersFetcher.Peers()
|
||||
id, err := peer.IDFromString(req.PeerId)
|
||||
id, err := peer.Decode(req.PeerId)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "Invalid peer ID: "+req.PeerId)
|
||||
return nil, status.Errorf(codes.Internal, "Could not decode peer ID: %v", err)
|
||||
}
|
||||
enr, err := peerStatus.ENR(id)
|
||||
if err != nil {
|
||||
|
||||
@@ -172,10 +172,10 @@ func TestSyncStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetPeer(t *testing.T) {
|
||||
const rawId = "16Uiu2HAkvyYtoQXZNTsthjgLHjEnv7kvwzEmjvsJjWXpbhtqpSUN"
|
||||
ctx := context.Background()
|
||||
decodedId, err := peer.Decode("16Uiu2HAkvyYtoQXZNTsthjgLHjEnv7kvwzEmjvsJjWXpbhtqpSUN")
|
||||
decodedId, err := peer.Decode(rawId)
|
||||
require.NoError(t, err)
|
||||
peerId := string(decodedId)
|
||||
enrRecord := &enr.Record{}
|
||||
err = enrRecord.SetSig(dummyIdentity{1}, []byte{42})
|
||||
require.NoError(t, err)
|
||||
@@ -190,9 +190,9 @@ func TestGetPeer(t *testing.T) {
|
||||
peerFetcher.Peers().Add(enrRecord, decodedId, p2pMultiAddr, network.DirInbound)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
resp, err := s.GetPeer(ctx, ðpb.PeerRequest{PeerId: peerId})
|
||||
resp, err := s.GetPeer(ctx, ðpb.PeerRequest{PeerId: rawId})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, peerId, resp.Data.PeerId)
|
||||
assert.Equal(t, rawId, resp.Data.PeerId)
|
||||
assert.Equal(t, p2pAddr, resp.Data.Address)
|
||||
assert.Equal(t, "enr:yoABgmlwhAcHBwc=", resp.Data.Enr)
|
||||
assert.Equal(t, ethpb.ConnectionState_DISCONNECTED, resp.Data.State)
|
||||
@@ -201,11 +201,11 @@ func TestGetPeer(t *testing.T) {
|
||||
|
||||
t.Run("Invalid ID", func(t *testing.T) {
|
||||
_, err = s.GetPeer(ctx, ðpb.PeerRequest{PeerId: "foo"})
|
||||
assert.ErrorContains(t, "Invalid peer ID: foo", err)
|
||||
assert.ErrorContains(t, "Could not decode peer ID", err)
|
||||
})
|
||||
|
||||
t.Run("Peer not found", func(t *testing.T) {
|
||||
generatedId := string(libp2ptest.GeneratePeerIDs(1)[0])
|
||||
generatedId := "16Uiu2HAmQqFdEcHbSmQTQuLoAhnMUrgoWoraKK4cUJT6FuuqHqTU"
|
||||
_, err = s.GetPeer(ctx, ðpb.PeerRequest{PeerId: generatedId})
|
||||
assert.ErrorContains(t, "Peer not found", err)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user