2021-09-15 00:09:04 +00:00
|
|
|
package slots
|
2020-06-12 18:47:18 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
|
|
prysmTime "github.com/prysmaticlabs/prysm/v3/time"
|
2021-09-02 20:41:01 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-06-12 18:47:18 +00:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCountdownToGenesis(t *testing.T) {
|
2022-05-20 07:16:53 +00:00
|
|
|
params.SetupTestConfigCleanup(t)
|
2021-09-02 20:41:01 +00:00
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
|
2020-06-12 18:47:18 +00:00
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
params.SetupTestConfigCleanup(t)
|
2022-05-20 07:16:53 +00:00
|
|
|
config := params.BeaconConfig().Copy()
|
2020-06-12 18:47:18 +00:00
|
|
|
config.GenesisCountdownInterval = time.Millisecond * 500
|
|
|
|
params.OverrideBeaconConfig(config)
|
|
|
|
|
2020-09-04 18:07:50 +00:00
|
|
|
t.Run("normal countdown", func(t *testing.T) {
|
|
|
|
defer hook.Reset()
|
|
|
|
firstStringResult := "1s until chain genesis"
|
|
|
|
genesisReached := "Chain genesis time reached"
|
|
|
|
CountdownToGenesis(
|
|
|
|
context.Background(),
|
2021-09-15 00:09:04 +00:00
|
|
|
prysmTime.Now().Add(2*time.Second),
|
2020-09-04 18:07:50 +00:00
|
|
|
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
2020-12-01 00:06:16 +00:00
|
|
|
[32]byte{},
|
2020-09-04 18:07:50 +00:00
|
|
|
)
|
|
|
|
require.LogsContain(t, hook, firstStringResult)
|
|
|
|
require.LogsContain(t, hook, genesisReached)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("close context", func(t *testing.T) {
|
|
|
|
defer hook.Reset()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go func() {
|
|
|
|
time.AfterFunc(1500*time.Millisecond, func() {
|
|
|
|
cancel()
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
CountdownToGenesis(
|
|
|
|
ctx,
|
2021-09-15 00:09:04 +00:00
|
|
|
prysmTime.Now().Add(5*time.Second),
|
2020-09-04 18:07:50 +00:00
|
|
|
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
2020-12-01 00:06:16 +00:00
|
|
|
[32]byte{},
|
2020-09-04 18:07:50 +00:00
|
|
|
)
|
|
|
|
require.LogsContain(t, hook, "4s until chain genesis")
|
2021-09-02 20:41:01 +00:00
|
|
|
require.LogsContain(t, hook, "3s until chain genesis")
|
2020-09-04 18:07:50 +00:00
|
|
|
require.LogsContain(t, hook, "Context closed, exiting routine")
|
|
|
|
require.LogsDoNotContain(t, hook, "Chain genesis time reached")
|
|
|
|
})
|
2020-06-12 18:47:18 +00:00
|
|
|
}
|