Fix GetValidatorParticipation slot to epoch conversion (#7721)

* Fix current slot conversion

* Update tests

* Use a higher epoch number
This commit is contained in:
terence tsao 2020-11-03 18:54:56 -08:00 committed by GitHub
parent b996824446
commit f1e6aba34e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -469,7 +469,7 @@ func (bs *Server) GetValidatorActiveSetChanges(
func (bs *Server) GetValidatorParticipation(
ctx context.Context, req *ethpb.GetValidatorParticipationRequest,
) (*ethpb.ValidatorParticipationResponse, error) {
currentSlot := helpers.SlotToEpoch(bs.GenesisTimeFetcher.CurrentSlot())
currentSlot := bs.GenesisTimeFetcher.CurrentSlot()
currentEpoch := helpers.SlotToEpoch(currentSlot)
var requestedEpoch uint64

View File

@ -1409,6 +1409,37 @@ func TestServer_GetValidatorParticipation_CannotRequestFutureEpoch(t *testing.T)
assert.ErrorContains(t, wanted, err)
}
func TestServer_GetValidatorParticipation_UnknownState(t *testing.T) {
db, _ := dbTest.SetupDB(t)
ctx := context.Background()
headState := testutil.NewBeaconState()
require.NoError(t, headState.SetSlot(0))
epoch := uint64(50)
slots := epoch * params.BeaconConfig().SlotsPerEpoch
bs := &Server{
BeaconDB: db,
HeadFetcher: &mock.ChainService{
State: headState,
},
GenesisTimeFetcher: &mock.ChainService{
Genesis: time.Now().Add(time.Duration(-1*int64(slots)) * time.Second),
},
StateGen: stategen.New(db, cache.NewStateSummaryCache()),
}
wanted := "Could not get state: unknown state"
_, err := bs.GetValidatorParticipation(
ctx,
&ethpb.GetValidatorParticipationRequest{
QueryFilter: &ethpb.GetValidatorParticipationRequest_Epoch{
Epoch: 1,
},
},
)
assert.ErrorContains(t, wanted, err)
}
func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) {
db, sc := dbTest.SetupDB(t)