forked from ObolNetwork/charon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgater_test.go
55 lines (44 loc) · 1.63 KB
/
gater_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright © 2022-2024 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1
package core_test
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/obolnetwork/charon/core"
"github.com/obolnetwork/charon/testutil/beaconmock"
)
func TestDutyGater(t *testing.T) {
now := time.Now()
allowedFutureEpochs := 2
// Allow slots 0-3.
slotDuration := time.Second
bmock, err := beaconmock.New(
beaconmock.WithGenesisTime(now),
beaconmock.WithSlotDuration(slotDuration),
beaconmock.WithSlotsPerEpoch(2),
)
require.NoError(t, err)
gater, err := core.NewDutyGater(context.Background(), bmock, core.WithDutyGaterForT(t,
func() time.Time { return now },
allowedFutureEpochs,
))
require.NoError(t, err)
typ := core.DutyAttester
// Allow slots 0-5.
require.True(t, gater(core.Duty{Slot: 0, Type: typ})) // Current epoch
require.True(t, gater(core.Duty{Slot: 1, Type: typ}))
require.True(t, gater(core.Duty{Slot: 2, Type: typ})) // N+1 epoch
require.True(t, gater(core.Duty{Slot: 3, Type: typ}))
require.True(t, gater(core.Duty{Slot: 4, Type: typ})) // N+2 epoch
require.True(t, gater(core.Duty{Slot: 5, Type: typ}))
// Disallow slots 6 and after.
require.False(t, gater(core.Duty{Slot: 6, Type: typ})) // N+3 epoch
require.False(t, gater(core.Duty{Slot: 7, Type: typ}))
require.False(t, gater(core.Duty{Slot: 1000, Type: typ}))
// Disallow invalid type
require.False(t, gater(core.Duty{Slot: 0, Type: -1}))
require.False(t, gater(core.Duty{Slot: 1, Type: 0}))
require.False(t, gater(core.Duty{Slot: 2, Type: 100}))
require.False(t, gater(core.Duty{Slot: 3, Type: 1000}))
}