diff --git a/beacon-chain/sync/backfill/service_test.go b/beacon-chain/sync/backfill/service_test.go index 977f16cc2dfa..bb9d1a28e5f4 100644 --- a/beacon-chain/sync/backfill/service_test.go +++ b/beacon-chain/sync/backfill/service_test.go @@ -107,3 +107,28 @@ func testReadN(t *testing.T, ctx context.Context, c chan batch, n int, into []ba } return into } + +func TestBackfillMinSlotDefault(t *testing.T) { + oe := helpers.MinEpochsForBlockRequests() + current := primitives.Slot((oe + 100).Mul(uint64(params.BeaconConfig().SlotsPerEpoch))) + s := &Service{} + specMin := minimumBackfillSlot(current) + + t.Run("equal to specMin", func(t *testing.T) { + opt := WithMinimumSlot(specMin) + require.NoError(t, opt(s)) + require.Equal(t, specMin, s.ms(current)) + }) + t.Run("older than specMin", func(t *testing.T) { + opt := WithMinimumSlot(specMin - 1) + require.NoError(t, opt(s)) + // if WithMinimumSlot is older than the spec minimum, we should use it. + require.Equal(t, specMin-1, s.ms(current)) + }) + t.Run("newer than specMin", func(t *testing.T) { + opt := WithMinimumSlot(specMin + 1) + require.NoError(t, opt(s)) + // if WithMinimumSlot is newer than the spec minimum, we should use the spec minimum + require.Equal(t, specMin, s.ms(current)) + }) +}