mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
REST VC: Use POST to fetch validators (#13239)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package beacon_api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -61,15 +62,6 @@ func TestActivation_Nominal(t *testing.T) {
|
||||
}
|
||||
|
||||
pubKeys := make([][]byte, len(stringPubKeys))
|
||||
|
||||
url := strings.Join([]string{
|
||||
"/eth/v1/beacon/states/head/validators?",
|
||||
"id=0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13&",
|
||||
"id=0x80000e851c0f53c3246ff726d7ff7766661ca5e12a07c45c114d208d54f0f8233d4380b2e9aff759d69795d1df905526&",
|
||||
"id=0x424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242&",
|
||||
"id=0x800015473bdc3a7f45ef8eb8abc598bc20021e55ad6e6ad1d745aaef9730dd2c28ec08bf42df18451de94dd4a6d24ec5",
|
||||
}, "")
|
||||
|
||||
for i, stringPubKey := range stringPubKeys {
|
||||
pubKey, err := hexutil.Decode(stringPubKey)
|
||||
require.NoError(t, err)
|
||||
@@ -115,16 +107,25 @@ func TestActivation_Nominal(t *testing.T) {
|
||||
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
|
||||
req := &beacon.GetValidatorsRequest{
|
||||
Ids: stringPubKeys,
|
||||
Statuses: []string{},
|
||||
}
|
||||
reqBytes, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Get does not return any result for non existing key
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
url,
|
||||
"/eth/v1/beacon/states/head/validators",
|
||||
nil,
|
||||
bytes.NewBuffer(reqBytes),
|
||||
&stateValidatorsResponseJson,
|
||||
).Return(
|
||||
nil,
|
||||
nil,
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: []*beacon.ValidatorContainer{
|
||||
{
|
||||
@@ -239,15 +240,17 @@ func TestActivation_InvalidData(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
nil,
|
||||
nil,
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: testCase.data,
|
||||
},
|
||||
@@ -279,10 +282,12 @@ func TestActivation_JsonResponseError(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
gomock.Any(),
|
||||
).Return(
|
||||
nil,
|
||||
errors.New("some specific json error"),
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
type beaconApiBeaconChainClient struct {
|
||||
fallbackClient iface.BeaconChainClient
|
||||
jsonRestHandler JsonRestHandler
|
||||
stateValidatorsProvider stateValidatorsProvider
|
||||
stateValidatorsProvider StateValidatorsProvider
|
||||
}
|
||||
|
||||
const getValidatorPerformanceEndpoint = "/prysm/validators/performance"
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestListValidators(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
|
||||
nil,
|
||||
errors.New("foo error"),
|
||||
@@ -79,7 +79,7 @@ func TestListValidators(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
|
||||
nil,
|
||||
errors.New("bar error"),
|
||||
@@ -97,7 +97,7 @@ func TestListValidators(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
|
||||
nil,
|
||||
errors.New("foo error"),
|
||||
@@ -115,7 +115,7 @@ func TestListValidators(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
|
||||
nil,
|
||||
nil,
|
||||
@@ -191,7 +191,7 @@ func TestListValidators(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidatorsForHead(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return(
|
||||
nil,
|
||||
nil,
|
||||
@@ -333,7 +333,7 @@ func TestListValidators(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidatorsForSlot(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(
|
||||
testCase.generateStateValidatorsResponse(),
|
||||
nil,
|
||||
@@ -561,7 +561,7 @@ func TestListValidators(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidatorsForSlot(ctx, primitives.Slot(0), make([]string, 0), []primitives.ValidatorIndex{}, nil).Return(
|
||||
testCase.generateJsonStateValidatorsResponse(),
|
||||
nil,
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
type beaconApiValidatorClient struct {
|
||||
genesisProvider GenesisProvider
|
||||
dutiesProvider dutiesProvider
|
||||
stateValidatorsProvider stateValidatorsProvider
|
||||
stateValidatorsProvider StateValidatorsProvider
|
||||
jsonRestHandler JsonRestHandler
|
||||
beaconBlockConverter beaconBlockConverter
|
||||
prysmBeaconChainCLient iface.PrysmBeaconChainClient
|
||||
|
||||
@@ -367,7 +367,7 @@ func TestCheckDoppelGanger_Nominal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
|
||||
if testCase.getStateValidatorsInterface != nil {
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
@@ -784,7 +784,7 @@ func TestCheckDoppelGanger_Errors(t *testing.T) {
|
||||
).Times(1)
|
||||
}
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
|
||||
if testCase.getStateValidatorsInterface != nil {
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
|
||||
@@ -1148,7 +1148,7 @@ func TestGetDuties_Valid(t *testing.T) {
|
||||
).Times(2)
|
||||
}
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
gomock.Any(),
|
||||
@@ -1314,7 +1314,7 @@ func TestGetDuties_GetValidatorStatusFailed(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
gomock.Any(),
|
||||
@@ -1343,7 +1343,7 @@ func TestGetDuties_GetDutiesForEpochFailed(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
gomock.Any(),
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package beacon_api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
@@ -18,35 +19,39 @@ import (
|
||||
|
||||
const stringPubKey = "0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13"
|
||||
|
||||
func getPubKeyAndURL(t *testing.T) ([]byte, string) {
|
||||
baseUrl := "/eth/v1/beacon/states/head/validators"
|
||||
url := fmt.Sprintf("%s?id=%s", baseUrl, stringPubKey)
|
||||
|
||||
func getPubKeyAndReqBuffer(t *testing.T) ([]byte, *bytes.Buffer) {
|
||||
pubKey, err := hexutil.Decode(stringPubKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
return pubKey, url
|
||||
req := beacon.GetValidatorsRequest{
|
||||
Ids: []string{stringPubKey},
|
||||
Statuses: []string{},
|
||||
}
|
||||
reqBytes, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
return pubKey, bytes.NewBuffer(reqBytes)
|
||||
}
|
||||
|
||||
func TestIndex_Nominal(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
pubKey, url := getPubKeyAndURL(t)
|
||||
pubKey, reqBuffer := getPubKeyAndReqBuffer(t)
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsResponseJson := beacon.GetValidatorsResponse{}
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
url,
|
||||
"/eth/v1/beacon/states/head/validators",
|
||||
nil,
|
||||
reqBuffer,
|
||||
&stateValidatorsResponseJson,
|
||||
).Return(
|
||||
nil,
|
||||
nil,
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: []*beacon.ValidatorContainer{
|
||||
{
|
||||
@@ -81,21 +86,23 @@ func TestIndex_UnexistingValidator(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
pubKey, url := getPubKeyAndURL(t)
|
||||
pubKey, reqBuffer := getPubKeyAndReqBuffer(t)
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsResponseJson := beacon.GetValidatorsResponse{}
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
url,
|
||||
"/eth/v1/beacon/states/head/validators",
|
||||
nil,
|
||||
reqBuffer,
|
||||
&stateValidatorsResponseJson,
|
||||
).Return(
|
||||
nil,
|
||||
nil,
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: []*beacon.ValidatorContainer{},
|
||||
},
|
||||
@@ -122,21 +129,23 @@ func TestIndex_BadIndexError(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
pubKey, url := getPubKeyAndURL(t)
|
||||
pubKey, reqBuffer := getPubKeyAndReqBuffer(t)
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsResponseJson := beacon.GetValidatorsResponse{}
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
url,
|
||||
"/eth/v1/beacon/states/head/validators",
|
||||
nil,
|
||||
reqBuffer,
|
||||
&stateValidatorsResponseJson,
|
||||
).Return(
|
||||
nil,
|
||||
nil,
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: []*beacon.ValidatorContainer{
|
||||
{
|
||||
@@ -170,15 +179,17 @@ func TestIndex_JsonResponseError(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
pubKey, url := getPubKeyAndURL(t)
|
||||
pubKey, reqBuffer := getPubKeyAndReqBuffer(t)
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsResponseJson := beacon.GetValidatorsResponse{}
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
url,
|
||||
"/eth/v1/beacon/states/head/validators",
|
||||
nil,
|
||||
reqBuffer,
|
||||
&stateValidatorsResponseJson,
|
||||
).Return(
|
||||
nil,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: validator/client/beacon-api/state_validators.go
|
||||
// Source: github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api (interfaces: StateValidatorsProvider)
|
||||
|
||||
// Package mock is a generated GoMock package.
|
||||
package mock
|
||||
@@ -9,35 +9,35 @@ import (
|
||||
reflect "reflect"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon"
|
||||
beacon "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon"
|
||||
primitives "github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
||||
)
|
||||
|
||||
// MockstateValidatorsProvider is a mock of stateValidatorsProvider interface.
|
||||
type MockstateValidatorsProvider struct {
|
||||
// MockStateValidatorsProvider is a mock of StateValidatorsProvider interface.
|
||||
type MockStateValidatorsProvider struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockstateValidatorsProviderMockRecorder
|
||||
recorder *MockStateValidatorsProviderMockRecorder
|
||||
}
|
||||
|
||||
// MockstateValidatorsProviderMockRecorder is the mock recorder for MockstateValidatorsProvider.
|
||||
type MockstateValidatorsProviderMockRecorder struct {
|
||||
mock *MockstateValidatorsProvider
|
||||
// MockStateValidatorsProviderMockRecorder is the mock recorder for MockStateValidatorsProvider.
|
||||
type MockStateValidatorsProviderMockRecorder struct {
|
||||
mock *MockStateValidatorsProvider
|
||||
}
|
||||
|
||||
// NewMockstateValidatorsProvider creates a new mock instance.
|
||||
func NewMockstateValidatorsProvider(ctrl *gomock.Controller) *MockstateValidatorsProvider {
|
||||
mock := &MockstateValidatorsProvider{ctrl: ctrl}
|
||||
mock.recorder = &MockstateValidatorsProviderMockRecorder{mock}
|
||||
// NewMockStateValidatorsProvider creates a new mock instance.
|
||||
func NewMockStateValidatorsProvider(ctrl *gomock.Controller) *MockStateValidatorsProvider {
|
||||
mock := &MockStateValidatorsProvider{ctrl: ctrl}
|
||||
mock.recorder = &MockStateValidatorsProviderMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockstateValidatorsProvider) EXPECT() *MockstateValidatorsProviderMockRecorder {
|
||||
func (m *MockStateValidatorsProvider) EXPECT() *MockStateValidatorsProviderMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetStateValidators mocks base method.
|
||||
func (m *MockstateValidatorsProvider) GetStateValidators(arg0 context.Context, arg1 []string, arg2 []int64, arg3 []string) (*beacon.GetValidatorsResponse, error) {
|
||||
func (m *MockStateValidatorsProvider) GetStateValidators(arg0 context.Context, arg1 []string, arg2 []primitives.ValidatorIndex, arg3 []string) (*beacon.GetValidatorsResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetStateValidators", arg0, arg1, arg2, arg3)
|
||||
ret0, _ := ret[0].(*beacon.GetValidatorsResponse)
|
||||
@@ -46,13 +46,13 @@ func (m *MockstateValidatorsProvider) GetStateValidators(arg0 context.Context, a
|
||||
}
|
||||
|
||||
// GetStateValidators indicates an expected call of GetStateValidators.
|
||||
func (mr *MockstateValidatorsProviderMockRecorder) GetStateValidators(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
|
||||
func (mr *MockStateValidatorsProviderMockRecorder) GetStateValidators(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateValidators", reflect.TypeOf((*MockstateValidatorsProvider)(nil).GetStateValidators), arg0, arg1, arg2, arg3)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateValidators", reflect.TypeOf((*MockStateValidatorsProvider)(nil).GetStateValidators), arg0, arg1, arg2, arg3)
|
||||
}
|
||||
|
||||
// GetStateValidatorsForHead mocks base method.
|
||||
func (m *MockstateValidatorsProvider) GetStateValidatorsForHead(arg0 context.Context, arg1 []string, arg2 []primitives.ValidatorIndex, arg3 []string) (*beacon.GetValidatorsResponse, error) {
|
||||
func (m *MockStateValidatorsProvider) GetStateValidatorsForHead(arg0 context.Context, arg1 []string, arg2 []primitives.ValidatorIndex, arg3 []string) (*beacon.GetValidatorsResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetStateValidatorsForHead", arg0, arg1, arg2, arg3)
|
||||
ret0, _ := ret[0].(*beacon.GetValidatorsResponse)
|
||||
@@ -61,13 +61,13 @@ func (m *MockstateValidatorsProvider) GetStateValidatorsForHead(arg0 context.Con
|
||||
}
|
||||
|
||||
// GetStateValidatorsForHead indicates an expected call of GetStateValidatorsForHead.
|
||||
func (mr *MockstateValidatorsProviderMockRecorder) GetStateValidatorsForHead(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
|
||||
func (mr *MockStateValidatorsProviderMockRecorder) GetStateValidatorsForHead(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateValidatorsForHead", reflect.TypeOf((*MockstateValidatorsProvider)(nil).GetStateValidatorsForHead), arg0, arg1, arg2, arg3)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateValidatorsForHead", reflect.TypeOf((*MockStateValidatorsProvider)(nil).GetStateValidatorsForHead), arg0, arg1, arg2, arg3)
|
||||
}
|
||||
|
||||
// GetStateValidatorsForSlot mocks base method.
|
||||
func (m *MockstateValidatorsProvider) GetStateValidatorsForSlot(arg0 context.Context, arg1 primitives.Slot, arg2 []string, arg3 []primitives.ValidatorIndex, arg4 []string) (*beacon.GetValidatorsResponse, error) {
|
||||
func (m *MockStateValidatorsProvider) GetStateValidatorsForSlot(arg0 context.Context, arg1 primitives.Slot, arg2 []string, arg3 []primitives.ValidatorIndex, arg4 []string) (*beacon.GetValidatorsResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetStateValidatorsForSlot", arg0, arg1, arg2, arg3, arg4)
|
||||
ret0, _ := ret[0].(*beacon.GetValidatorsResponse)
|
||||
@@ -76,7 +76,7 @@ func (m *MockstateValidatorsProvider) GetStateValidatorsForSlot(arg0 context.Con
|
||||
}
|
||||
|
||||
// GetStateValidatorsForSlot indicates an expected call of GetStateValidatorsForSlot.
|
||||
func (mr *MockstateValidatorsProviderMockRecorder) GetStateValidatorsForSlot(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
|
||||
func (mr *MockStateValidatorsProviderMockRecorder) GetStateValidatorsForSlot(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateValidatorsForSlot", reflect.TypeOf((*MockstateValidatorsProvider)(nil).GetStateValidatorsForSlot), arg0, arg1, arg2, arg3, arg4)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateValidatorsForSlot", reflect.TypeOf((*MockStateValidatorsProvider)(nil).GetStateValidatorsForSlot), arg0, arg1, arg2, arg3, arg4)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package beacon_api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
neturl "net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -11,8 +12,8 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
||||
)
|
||||
|
||||
type stateValidatorsProvider interface {
|
||||
GetStateValidators(context.Context, []string, []int64, []string) (*beacon.GetValidatorsResponse, error)
|
||||
type StateValidatorsProvider interface {
|
||||
GetStateValidators(context.Context, []string, []primitives.ValidatorIndex, []string) (*beacon.GetValidatorsResponse, error)
|
||||
GetStateValidatorsForSlot(context.Context, primitives.Slot, []string, []primitives.ValidatorIndex, []string) (*beacon.GetValidatorsResponse, error)
|
||||
GetStateValidatorsForHead(context.Context, []string, []primitives.ValidatorIndex, []string) (*beacon.GetValidatorsResponse, error)
|
||||
}
|
||||
@@ -24,19 +25,11 @@ type beaconApiStateValidatorsProvider struct {
|
||||
func (c beaconApiStateValidatorsProvider) GetStateValidators(
|
||||
ctx context.Context,
|
||||
stringPubkeys []string,
|
||||
indexes []int64,
|
||||
indexes []primitives.ValidatorIndex,
|
||||
statuses []string,
|
||||
) (*beacon.GetValidatorsResponse, error) {
|
||||
params := neturl.Values{}
|
||||
indexesSet := make(map[int64]struct{}, len(indexes))
|
||||
for _, index := range indexes {
|
||||
if _, ok := indexesSet[index]; !ok {
|
||||
indexesSet[index] = struct{}{}
|
||||
params.Add("id", strconv.FormatInt(index, 10))
|
||||
}
|
||||
}
|
||||
|
||||
return c.getStateValidatorsHelper(ctx, "/eth/v1/beacon/states/head/validators", params, stringPubkeys, statuses)
|
||||
stringIndices := convertValidatorIndicesToStrings(indexes)
|
||||
return c.getStateValidatorsHelper(ctx, "/eth/v1/beacon/states/head/validators", append(stringIndices, stringPubkeys...), statuses)
|
||||
}
|
||||
|
||||
func (c beaconApiStateValidatorsProvider) GetStateValidatorsForSlot(
|
||||
@@ -46,9 +39,9 @@ func (c beaconApiStateValidatorsProvider) GetStateValidatorsForSlot(
|
||||
indices []primitives.ValidatorIndex,
|
||||
statuses []string,
|
||||
) (*beacon.GetValidatorsResponse, error) {
|
||||
params := convertValidatorIndicesToParams(indices)
|
||||
stringIndices := convertValidatorIndicesToStrings(indices)
|
||||
url := fmt.Sprintf("/eth/v1/beacon/states/%d/validators", slot)
|
||||
return c.getStateValidatorsHelper(ctx, url, params, stringPubkeys, statuses)
|
||||
return c.getStateValidatorsHelper(ctx, url, append(stringIndices, stringPubkeys...), statuses)
|
||||
}
|
||||
|
||||
func (c beaconApiStateValidatorsProvider) GetStateValidatorsForHead(
|
||||
@@ -57,46 +50,48 @@ func (c beaconApiStateValidatorsProvider) GetStateValidatorsForHead(
|
||||
indices []primitives.ValidatorIndex,
|
||||
statuses []string,
|
||||
) (*beacon.GetValidatorsResponse, error) {
|
||||
params := convertValidatorIndicesToParams(indices)
|
||||
return c.getStateValidatorsHelper(ctx, "/eth/v1/beacon/states/head/validators", params, stringPubkeys, statuses)
|
||||
stringIndices := convertValidatorIndicesToStrings(indices)
|
||||
return c.getStateValidatorsHelper(ctx, "/eth/v1/beacon/states/head/validators", append(stringIndices, stringPubkeys...), statuses)
|
||||
}
|
||||
|
||||
func convertValidatorIndicesToParams(indices []primitives.ValidatorIndex) neturl.Values {
|
||||
params := neturl.Values{}
|
||||
func convertValidatorIndicesToStrings(indices []primitives.ValidatorIndex) []string {
|
||||
var result []string
|
||||
indicesSet := make(map[primitives.ValidatorIndex]struct{}, len(indices))
|
||||
for _, index := range indices {
|
||||
if _, ok := indicesSet[index]; !ok {
|
||||
indicesSet[index] = struct{}{}
|
||||
params.Add("id", strconv.FormatUint(uint64(index), 10))
|
||||
result = append(result, strconv.FormatUint(uint64(index), 10))
|
||||
}
|
||||
}
|
||||
return params
|
||||
return result
|
||||
}
|
||||
|
||||
func (c beaconApiStateValidatorsProvider) getStateValidatorsHelper(
|
||||
ctx context.Context,
|
||||
endpoint string,
|
||||
params neturl.Values,
|
||||
stringPubkeys []string,
|
||||
vals []string,
|
||||
statuses []string,
|
||||
) (*beacon.GetValidatorsResponse, error) {
|
||||
stringPubKeysSet := make(map[string]struct{}, len(stringPubkeys))
|
||||
req := beacon.GetValidatorsRequest{
|
||||
Ids: []string{},
|
||||
Statuses: []string{},
|
||||
}
|
||||
req.Statuses = append(req.Statuses, statuses...)
|
||||
|
||||
for _, stringPubkey := range stringPubkeys {
|
||||
if _, ok := stringPubKeysSet[stringPubkey]; !ok {
|
||||
stringPubKeysSet[stringPubkey] = struct{}{}
|
||||
params.Add("id", stringPubkey)
|
||||
valSet := make(map[string]struct{}, len(vals))
|
||||
for _, v := range vals {
|
||||
if _, ok := valSet[v]; !ok {
|
||||
valSet[v] = struct{}{}
|
||||
req.Ids = append(req.Ids, v)
|
||||
}
|
||||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
params.Add("status", status)
|
||||
reqBytes, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to marshal request into JSON")
|
||||
}
|
||||
|
||||
url := buildURL(endpoint, params)
|
||||
stateValidatorsJson := &beacon.GetValidatorsResponse{}
|
||||
|
||||
errJson, err := c.jsonRestHandler.Get(ctx, url, stateValidatorsJson)
|
||||
errJson, err := c.jsonRestHandler.Post(ctx, endpoint, nil, bytes.NewBuffer(reqBytes), stateValidatorsJson)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, msgUnexpectedError)
|
||||
}
|
||||
@@ -105,7 +100,7 @@ func (c beaconApiStateValidatorsProvider) getStateValidatorsHelper(
|
||||
}
|
||||
|
||||
if stateValidatorsJson.Data == nil {
|
||||
return &beacon.GetValidatorsResponse{}, errors.New("stateValidatorsJson.Data is nil")
|
||||
return nil, errors.New("stateValidatorsJson.Data is nil")
|
||||
}
|
||||
|
||||
return stateValidatorsJson, nil
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package beacon_api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/beacon"
|
||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api/mock"
|
||||
@@ -17,15 +19,18 @@ func TestGetStateValidators_Nominal(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
url := strings.Join([]string{
|
||||
"/eth/v1/beacon/states/head/validators?",
|
||||
"id=12345&",
|
||||
"id=0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13&", // active_ongoing
|
||||
"id=0x80000e851c0f53c3246ff726d7ff7766661ca5e12a07c45c114d208d54f0f8233d4380b2e9aff759d69795d1df905526&", // active_exiting
|
||||
"id=0x424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242&", // does not exist
|
||||
"id=0x800015473bdc3a7f45ef8eb8abc598bc20021e55ad6e6ad1d745aaef9730dd2c28ec08bf42df18451de94dd4a6d24ec5&", // exited_slashed
|
||||
"status=active_ongoing&status=active_exiting&status=exited_slashed&status=exited_unslashed",
|
||||
}, "")
|
||||
req := &beacon.GetValidatorsRequest{
|
||||
Ids: []string{
|
||||
"12345",
|
||||
"0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13",
|
||||
"0x80000e851c0f53c3246ff726d7ff7766661ca5e12a07c45c114d208d54f0f8233d4380b2e9aff759d69795d1df905526",
|
||||
"0x424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242424242",
|
||||
"0x800015473bdc3a7f45ef8eb8abc598bc20021e55ad6e6ad1d745aaef9730dd2c28ec08bf42df18451de94dd4a6d24ec5",
|
||||
},
|
||||
Statuses: []string{"active_ongoing", "active_exiting", "exited_slashed", "exited_unslashed"},
|
||||
}
|
||||
reqBytes, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
stateValidatorsResponseJson := beacon.GetValidatorsResponse{}
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
@@ -63,15 +68,17 @@ func TestGetStateValidators_Nominal(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
url,
|
||||
"/eth/v1/beacon/states/head/validators",
|
||||
nil,
|
||||
bytes.NewBuffer(reqBytes),
|
||||
&stateValidatorsResponseJson,
|
||||
).Return(
|
||||
nil,
|
||||
nil,
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: wanted,
|
||||
},
|
||||
@@ -85,7 +92,7 @@ func TestGetStateValidators_Nominal(t *testing.T) {
|
||||
"0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13", // active_ongoing - duplicate
|
||||
"0x800015473bdc3a7f45ef8eb8abc598bc20021e55ad6e6ad1d745aaef9730dd2c28ec08bf42df18451de94dd4a6d24ec5", // exited_slashed
|
||||
},
|
||||
[]int64{
|
||||
[]primitives.ValidatorIndex{
|
||||
12345, // active_ongoing
|
||||
12345, // active_ongoing - duplicate
|
||||
},
|
||||
@@ -99,16 +106,23 @@ func TestGetStateValidators_GetRestJsonResponseOnError(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
url := "/eth/v1/beacon/states/head/validators?id=0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13"
|
||||
req := &beacon.GetValidatorsRequest{
|
||||
Ids: []string{"0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13"},
|
||||
Statuses: []string{},
|
||||
}
|
||||
reqBytes, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
stateValidatorsResponseJson := beacon.GetValidatorsResponse{}
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
url,
|
||||
"/eth/v1/beacon/states/head/validators",
|
||||
nil,
|
||||
bytes.NewBuffer(reqBytes),
|
||||
&stateValidatorsResponseJson,
|
||||
).Return(
|
||||
nil,
|
||||
@@ -116,7 +130,7 @@ func TestGetStateValidators_GetRestJsonResponseOnError(t *testing.T) {
|
||||
).Times(1)
|
||||
|
||||
stateValidatorsProvider := beaconApiStateValidatorsProvider{jsonRestHandler: jsonRestHandler}
|
||||
_, err := stateValidatorsProvider.GetStateValidators(ctx, []string{
|
||||
_, err = stateValidatorsProvider.GetStateValidators(ctx, []string{
|
||||
"0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13", // active_ongoing
|
||||
},
|
||||
nil,
|
||||
@@ -129,28 +143,34 @@ func TestGetStateValidators_DataIsNil(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
url := "/eth/v1/beacon/states/head/validators?id=0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13"
|
||||
req := &beacon.GetValidatorsRequest{
|
||||
Ids: []string{"0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13"},
|
||||
Statuses: []string{},
|
||||
}
|
||||
reqBytes, err := json.Marshal(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
stateValidatorsResponseJson := beacon.GetValidatorsResponse{}
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
url,
|
||||
"/eth/v1/beacon/states/head/validators",
|
||||
nil, bytes.NewBuffer(reqBytes),
|
||||
&stateValidatorsResponseJson,
|
||||
).Return(
|
||||
nil,
|
||||
nil,
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: nil,
|
||||
},
|
||||
).Times(1)
|
||||
|
||||
stateValidatorsProvider := beaconApiStateValidatorsProvider{jsonRestHandler: jsonRestHandler}
|
||||
_, err := stateValidatorsProvider.GetStateValidators(ctx, []string{
|
||||
_, err = stateValidatorsProvider.GetStateValidators(ctx, []string{
|
||||
"0x8000091c2ae64ee414a54c1cc1fc67dec663408bc636cb86756e0200e41a75c8f86603f104f02c856983d2783116be13", // active_ongoing
|
||||
},
|
||||
nil,
|
||||
|
||||
@@ -29,7 +29,11 @@ func (c *beaconApiValidatorClient) validatorStatus(ctx context.Context, in *ethp
|
||||
}
|
||||
|
||||
func (c *beaconApiValidatorClient) multipleValidatorStatus(ctx context.Context, in *ethpb.MultipleValidatorStatusRequest) (*ethpb.MultipleValidatorStatusResponse, error) {
|
||||
publicKeys, indices, statuses, err := c.getValidatorsStatusResponse(ctx, in.PublicKeys, in.Indices)
|
||||
indices := make([]primitives.ValidatorIndex, len(in.Indices))
|
||||
for i, ix := range in.Indices {
|
||||
indices[i] = primitives.ValidatorIndex(ix)
|
||||
}
|
||||
publicKeys, indices, statuses, err := c.getValidatorsStatusResponse(ctx, in.PublicKeys, indices)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get validators status response")
|
||||
}
|
||||
@@ -41,7 +45,7 @@ func (c *beaconApiValidatorClient) multipleValidatorStatus(ctx context.Context,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *beaconApiValidatorClient) getValidatorsStatusResponse(ctx context.Context, inPubKeys [][]byte, inIndexes []int64) (
|
||||
func (c *beaconApiValidatorClient) getValidatorsStatusResponse(ctx context.Context, inPubKeys [][]byte, inIndexes []primitives.ValidatorIndex) (
|
||||
[][]byte,
|
||||
[]primitives.ValidatorIndex,
|
||||
[]*ethpb.ValidatorStatusResponse,
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestValidatorStatus_Nominal(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
@@ -97,7 +97,7 @@ func TestValidatorStatus_Error(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
@@ -139,12 +139,12 @@ func TestMultipleValidatorStatus_Nominal(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
stringValidatorsPubKey,
|
||||
nil,
|
||||
[]primitives.ValidatorIndex{},
|
||||
nil,
|
||||
).Return(
|
||||
&beacon.GetValidatorsResponse{
|
||||
@@ -225,12 +225,12 @@ func TestMultipleValidatorStatus_Error(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
|
||||
ctx := context.Background()
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
gomock.Any(),
|
||||
nil,
|
||||
[]primitives.ValidatorIndex{},
|
||||
nil,
|
||||
).Return(
|
||||
&beacon.GetValidatorsResponse{},
|
||||
@@ -270,14 +270,14 @@ func TestGetValidatorsStatusResponse_Nominal_SomeActiveValidators(t *testing.T)
|
||||
validatorsPubKey[i] = validatorPubKey
|
||||
}
|
||||
|
||||
validatorsIndex := []int64{
|
||||
validatorsIndex := []primitives.ValidatorIndex{
|
||||
12345, // NOT existing
|
||||
33333, // existing
|
||||
}
|
||||
|
||||
extraStringValidatorKey := "0x80003eb1e78ffdea6c878026b7074f84aaa16536c8e1960a652e817c848e7ccb051087f837b7d2bb6773cd9705601ede"
|
||||
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
@@ -459,7 +459,7 @@ func TestGetValidatorsStatusResponse_Nominal_NoActiveValidators(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.Background()
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
@@ -525,7 +525,7 @@ func TestGetValidatorsStatusResponse_Nominal_NoActiveValidators(t *testing.T) {
|
||||
type getStateValidatorsInterface struct {
|
||||
// Inputs
|
||||
inputStringPubKeys []string
|
||||
inputIndexes []int64
|
||||
inputIndexes []primitives.ValidatorIndex
|
||||
inputStatuses []string
|
||||
|
||||
// Outputs
|
||||
@@ -543,7 +543,7 @@ func TestValidatorStatusResponse_InvalidData(t *testing.T) {
|
||||
|
||||
// Inputs
|
||||
inputPubKeys [][]byte
|
||||
inputIndexes []int64
|
||||
inputIndexes []primitives.ValidatorIndex
|
||||
inputGetStateValidatorsInterface getStateValidatorsInterface
|
||||
validatorCountCalled int
|
||||
|
||||
@@ -711,7 +711,7 @@ func TestValidatorStatusResponse_InvalidData(t *testing.T) {
|
||||
defer ctrl.Finish()
|
||||
|
||||
ctx := context.Background()
|
||||
stateValidatorsProvider := mock.NewMockstateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider := mock.NewMockStateValidatorsProvider(ctrl)
|
||||
stateValidatorsProvider.EXPECT().GetStateValidators(
|
||||
ctx,
|
||||
testCase.inputGetStateValidatorsInterface.inputStringPubKeys,
|
||||
|
||||
@@ -174,13 +174,22 @@ func TestSubmitAggregateSelectionProof(t *testing.T) {
|
||||
test.syncingErr,
|
||||
).Times(1)
|
||||
|
||||
valsReq := &beacon.GetValidatorsRequest{
|
||||
Ids: []string{stringPubKey},
|
||||
Statuses: []string{},
|
||||
}
|
||||
valReqBytes, err := json.Marshal(valsReq)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Call validators endpoint to get validator index.
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
fmt.Sprintf("%s?id=%s", validatorsEndpoint, pubkeyStr),
|
||||
validatorsEndpoint,
|
||||
nil,
|
||||
bytes.NewBuffer(valReqBytes),
|
||||
&beacon.GetValidatorsResponse{},
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: []*beacon.ValidatorContainer{
|
||||
{
|
||||
|
||||
@@ -315,13 +315,21 @@ func TestGetSyncSubCommitteeIndex(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
valsReq := &beacon.GetValidatorsRequest{
|
||||
Ids: []string{pubkeyStr},
|
||||
Statuses: []string{},
|
||||
}
|
||||
valsReqBytes, err := json.Marshal(valsReq)
|
||||
require.NoError(t, err)
|
||||
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
|
||||
jsonRestHandler.EXPECT().Get(
|
||||
jsonRestHandler.EXPECT().Post(
|
||||
ctx,
|
||||
fmt.Sprintf("%s?id=%s", validatorsEndpoint, pubkeyStr),
|
||||
validatorsEndpoint,
|
||||
nil,
|
||||
bytes.NewBuffer(valsReqBytes),
|
||||
&beacon.GetValidatorsResponse{},
|
||||
).SetArg(
|
||||
2,
|
||||
4,
|
||||
beacon.GetValidatorsResponse{
|
||||
Data: []*beacon.ValidatorContainer{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user