2019-01-23 02:52:39 +00:00
|
|
|
package client
|
|
|
|
|
2019-01-25 03:26:03 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2019-01-23 02:52:39 +00:00
|
|
|
var _ = Validator(&validator{})
|
2019-01-25 03:26:03 +00:00
|
|
|
|
2019-01-29 12:56:14 +00:00
|
|
|
var fakePubKey = []byte{1}
|
2019-01-25 03:26:03 +00:00
|
|
|
|
|
|
|
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{
|
2019-01-29 12:56:14 +00:00
|
|
|
Assignment: &pb.Assignment{
|
|
|
|
ProposerSlot: 67,
|
|
|
|
AttesterSlot: 78,
|
2019-01-25 03:26:03 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
v := validator{
|
|
|
|
pubKey: fakePubKey,
|
|
|
|
validatorClient: client,
|
|
|
|
}
|
|
|
|
client.EXPECT().ValidatorEpochAssignments(
|
|
|
|
gomock.Any(),
|
|
|
|
gomock.Any(),
|
|
|
|
).Return(resp, nil)
|
|
|
|
|
|
|
|
v.UpdateAssignments(context.Background(), slot)
|
|
|
|
|
2019-01-29 12:56:14 +00:00
|
|
|
if v.assignment.ProposerSlot != 67 {
|
|
|
|
t.Errorf("Unexpected validator assignments. want=%v got=%v", 67, v.assignment.ProposerSlot)
|
2019-01-25 03:26:03 +00:00
|
|
|
}
|
2019-01-29 12:56:14 +00:00
|
|
|
if v.assignment.AttesterSlot != 78 {
|
|
|
|
t.Errorf("Unexpected validator assignments. want=%v got=%v", 78, v.assignment.AttesterSlot)
|
2019-01-25 03:26:03 +00:00
|
|
|
}
|
|
|
|
}
|