prysm-pulse/validator/client/validator_aggregate_test.go
terence tsao d26839c1f2 Add aggregator indices to logs (#4385)
* Add validator_log.go

* Use new logging scheme

* Go fmt

* Better name

* Tests

* Tests

* Add wg.done, moved logging before span end

* Add aggregator indices to submit attestation log

* Rename

* Fixed test

* Add proposer index

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-01-02 17:45:48 -06:00

70 lines
2.1 KiB
Go

package client
import (
"context"
"testing"
"time"
"github.com/golang/mock/gomock"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestSubmitAggregateAndProof_AssignmentRequestFailure(t *testing.T) {
hook := logTest.NewGlobal()
validator, _, finish := setup(t)
validator.assignments = &pb.AssignmentResponse{ValidatorAssignment: []*pb.AssignmentResponse_ValidatorAssignment{}}
defer finish()
validator.SubmitAggregateAndProof(context.Background(), 0, validatorPubKey)
testutil.AssertLogsContain(t, hook, "Could not fetch validator assignment")
}
func TestSubmitAggregateAndProof_Ok(t *testing.T) {
validator, m, finish := setup(t)
defer finish()
validator.assignments = &pb.AssignmentResponse{ValidatorAssignment: []*pb.AssignmentResponse_ValidatorAssignment{
{
PublicKey: validatorKey.PublicKey.Marshal(),
},
}}
m.validatorClient.EXPECT().DomainData(
gomock.Any(), // ctx
gomock.Any(), // epoch
).Return(&pb.DomainResponse{}, nil /*err*/)
m.aggregatorClient.EXPECT().SubmitAggregateAndProof(
gomock.Any(), // ctx
gomock.AssignableToTypeOf(&pb.AggregationRequest{}),
).Return(&pb.AggregationResponse{}, nil)
m.validatorClient.EXPECT().ValidatorIndex(
gomock.Any(), // ctx
gomock.AssignableToTypeOf(&pb.ValidatorIndexRequest{}),
).Return(&pb.ValidatorIndexResponse{
Index: 0,
}, nil)
validator.SubmitAggregateAndProof(context.Background(), 0, validatorPubKey)
}
func TestWaitForSlotTwoThird_WaitCorrectly(t *testing.T) {
validator, _, finish := setup(t)
defer finish()
currentTime := uint64(time.Now().Unix())
numOfSlots := uint64(4)
validator.genesisTime = currentTime - (numOfSlots * params.BeaconConfig().SecondsPerSlot)
timeToSleep := params.BeaconConfig().SecondsPerSlot * 2 / 3
twoThirdTime := currentTime + timeToSleep
validator.waitToSlotTwoThirds(context.Background(), numOfSlots)
currentTime = uint64(time.Now().Unix())
if currentTime != twoThirdTime {
t.Errorf("Wanted %d time for slot two third but got %d", twoThirdTime, currentTime)
}
}