mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package debug
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
|
mockP2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestDebugServer_GetPeer(t *testing.T) {
|
|
peersProvider := &mockP2p.MockPeersProvider{}
|
|
mP2P := mockP2p.NewTestP2P(t)
|
|
ds := &Server{
|
|
PeersFetcher: peersProvider,
|
|
PeerManager: &mockP2p.MockPeerManager{BHost: mP2P.BHost},
|
|
}
|
|
firstPeer := peersProvider.Peers().All()[0]
|
|
|
|
res, err := ds.GetPeer(context.Background(), ðpb.PeerRequest{PeerId: firstPeer.String()})
|
|
require.NoError(t, err)
|
|
require.Equal(t, firstPeer.String(), res.PeerId, "Unexpected peer ID")
|
|
|
|
assert.Equal(t, int(ethpb.PeerDirection_INBOUND), int(res.Direction), "Expected 1st peer to be an inbound connection")
|
|
assert.Equal(t, ethpb.ConnectionState_CONNECTED, res.ConnectionState, "Expected peer to be connected")
|
|
}
|
|
|
|
func TestDebugServer_ListPeers(t *testing.T) {
|
|
peersProvider := &mockP2p.MockPeersProvider{}
|
|
mP2P := mockP2p.NewTestP2P(t)
|
|
ds := &Server{
|
|
PeersFetcher: peersProvider,
|
|
PeerManager: &mockP2p.MockPeerManager{BHost: mP2P.BHost},
|
|
}
|
|
|
|
res, err := ds.ListPeers(context.Background(), &empty.Empty{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 2, len(res.Responses))
|
|
|
|
direction1 := res.Responses[0].Direction
|
|
direction2 := res.Responses[1].Direction
|
|
assert.Equal(t,
|
|
true,
|
|
direction1 == ethpb.PeerDirection_INBOUND || direction2 == ethpb.PeerDirection_INBOUND,
|
|
"Expected an inbound peer")
|
|
assert.Equal(t,
|
|
true,
|
|
direction1 == ethpb.PeerDirection_OUTBOUND || direction2 == ethpb.PeerDirection_OUTBOUND,
|
|
"Expected an outbound peer")
|
|
if len(res.Responses[0].ListeningAddresses) == 0 {
|
|
t.Errorf("Expected 1st peer to have a multiaddress, instead they have no addresses")
|
|
}
|
|
if len(res.Responses[1].ListeningAddresses) == 0 {
|
|
t.Errorf("Expected 2nd peer to have a multiaddress, instead they have no addresses")
|
|
}
|
|
}
|