mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
07c0387be1
* begin reorder * move into beacon server * add proposer server * fix * add proposer server * wrap up rpc reorder * eliminated deprecated RPC endpoints * formatted nicely * RPC protos * fix lint * integrate hash proto * epoch assignments * deprecated committee code * remove deprecated messages * fixed mocks, added tests for validator epoch assignments * gazelle * fix broken bazel * nishant comment
89 lines
2.1 KiB
Go
89 lines
2.1 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/validator/internal"
|
|
)
|
|
|
|
var _ = Validator(&validator{})
|
|
|
|
var fakePubKey = []byte{1}
|
|
|
|
func TestUpdateAssignmentsDoesNothingWhenNotEpochStart(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
client := internal.NewMockValidatorServiceClient(ctrl)
|
|
|
|
slot := uint64(1)
|
|
v := validator{
|
|
pubKey: fakePubKey,
|
|
validatorClient: client,
|
|
}
|
|
client.EXPECT().ValidatorEpochAssignments(
|
|
gomock.Any(),
|
|
gomock.Any(),
|
|
).Times(0)
|
|
|
|
v.UpdateAssignments(context.Background(), slot)
|
|
}
|
|
|
|
func TestUpdateAssignmentsReturnsError(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
client := internal.NewMockValidatorServiceClient(ctrl)
|
|
|
|
v := validator{
|
|
pubKey: fakePubKey,
|
|
validatorClient: client,
|
|
}
|
|
|
|
expected := errors.New("bad")
|
|
|
|
client.EXPECT().ValidatorEpochAssignments(
|
|
gomock.Any(),
|
|
gomock.Any(),
|
|
).Return(nil, expected)
|
|
|
|
err := v.UpdateAssignments(context.Background(), params.BeaconConfig().EpochLength)
|
|
if err != expected {
|
|
t.Errorf("Bad error; want=%v got=%v", expected, err)
|
|
}
|
|
}
|
|
|
|
func TestUpdateAssignmentsDoesUpdateAssignments(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
client := internal.NewMockValidatorServiceClient(ctrl)
|
|
|
|
slot := params.BeaconConfig().EpochLength
|
|
resp := &pb.ValidatorEpochAssignmentsResponse{
|
|
Assignment: &pb.Assignment{
|
|
ProposerSlot: 67,
|
|
AttesterSlot: 78,
|
|
},
|
|
}
|
|
v := validator{
|
|
pubKey: fakePubKey,
|
|
validatorClient: client,
|
|
}
|
|
client.EXPECT().ValidatorEpochAssignments(
|
|
gomock.Any(),
|
|
gomock.Any(),
|
|
).Return(resp, nil)
|
|
|
|
v.UpdateAssignments(context.Background(), slot)
|
|
|
|
if v.assignment.ProposerSlot != 67 {
|
|
t.Errorf("Unexpected validator assignments. want=%v got=%v", 67, v.assignment.ProposerSlot)
|
|
}
|
|
if v.assignment.AttesterSlot != 78 {
|
|
t.Errorf("Unexpected validator assignments. want=%v got=%v", 78, v.assignment.AttesterSlot)
|
|
}
|
|
}
|