-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4db36a
commit 905b495
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright © 2021, 2023 Attestant Limited. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package multi | ||
|
||
import ( | ||
"context" | ||
|
||
consensusclient "github.com/attestantio/go-eth2-client" | ||
"github.com/attestantio/go-eth2-client/api" | ||
apiv1 "github.com/attestantio/go-eth2-client/api/v1" | ||
) | ||
|
||
// NodePeers provides the peers of the node | ||
func (s *Service) NodePeers(ctx context.Context, opts *api.PeerOpts) (*api.Response[*apiv1.Peers], error) { | ||
res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { | ||
nodePeers, err := client.(consensusclient.NodePeersProvider).NodePeers(ctx, opts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nodePeers, nil | ||
}, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res.(*api.Response[*apiv1.Peers]), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright © 2021 Attestant Limited. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package multi_test | ||
|
||
import ( | ||
"context" | ||
"github.com/attestantio/go-eth2-client/api" | ||
"testing" | ||
|
||
consensusclient "github.com/attestantio/go-eth2-client" | ||
"github.com/attestantio/go-eth2-client/mock" | ||
"github.com/attestantio/go-eth2-client/multi" | ||
"github.com/attestantio/go-eth2-client/testclients" | ||
"github.com/rs/zerolog" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNodePeers(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
client1, err := mock.New(ctx, mock.WithName("mock 1")) | ||
require.NoError(t, err) | ||
erroringClient1, err := testclients.NewErroring(ctx, 0.1, client1) | ||
require.NoError(t, err) | ||
client2, err := mock.New(ctx, mock.WithName("mock 2")) | ||
require.NoError(t, err) | ||
erroringClient2, err := testclients.NewErroring(ctx, 0.1, client2) | ||
require.NoError(t, err) | ||
client3, err := mock.New(ctx, mock.WithName("mock 3")) | ||
require.NoError(t, err) | ||
|
||
multiClient, err := multi.New(ctx, | ||
multi.WithLogLevel(zerolog.Disabled), | ||
multi.WithClients([]consensusclient.Service{ | ||
erroringClient1, | ||
erroringClient2, | ||
client3, | ||
}), | ||
) | ||
require.NoError(t, err) | ||
|
||
for i := 0; i < 128; i++ { | ||
res, err := multiClient.(consensusclient.NodePeersProvider).NodePeers(ctx, &api.PeerOpts{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, res) | ||
} | ||
// At this point we expect mock 3 to be in active (unless probability hates us). | ||
require.Equal(t, "mock 3", multiClient.Address()) | ||
} |