Files
prysm/beacon-chain/startup/clock_test.go
terence 774b9a7159 Migrate Prysm repo to Offchain Labs organization ahead of Pectra V6 (#15140)
* Migrate Prysm repo to Offchain Labs organization ahead of Pectra upgrade v6

* Replace prysmaticlabs with OffchainLabs on general markdowns

* Update mock

* Gazelle and add mock.go to excluded generated mock file
2025-04-10 15:40:39 +00:00

50 lines
1.1 KiB
Go

package startup
import (
"testing"
"time"
"github.com/OffchainLabs/prysm/v6/config/params"
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
"github.com/OffchainLabs/prysm/v6/testing/require"
)
func TestClock(t *testing.T) {
vr := [32]byte{}
cases := []struct {
name string
nSlots primitives.Slot
}{
{
name: "3 slots",
nSlots: 3,
},
{
name: "0 slots",
nSlots: 0,
},
{
name: "1 epoch",
nSlots: params.BeaconConfig().SlotsPerEpoch,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
genesis, now := testInterval(c.nSlots)
nower := func() time.Time { return now }
cl := NewClock(genesis, vr, WithNower(nower))
require.Equal(t, genesis, cl.GenesisTime())
require.Equal(t, now, cl.Now())
require.Equal(t, c.nSlots, cl.CurrentSlot())
})
}
}
func testInterval(nSlots primitives.Slot) (time.Time, time.Time) {
oneSlot := time.Second * time.Duration(params.BeaconConfig().SecondsPerSlot)
var start uint64 = 23
endOffset := oneSlot * time.Duration(nSlots)
startTime := time.Unix(int64(start), 0)
return startTime, startTime.Add(endOffset)
}