mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
3e71997290
* add time pkg * Go fmt
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package slots
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
prysmTime "github.com/prysmaticlabs/prysm/time"
|
|
"github.com/sirupsen/logrus"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestCountdownToGenesis(t *testing.T) {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
hook := logTest.NewGlobal()
|
|
params.SetupTestConfigCleanup(t)
|
|
config := params.BeaconConfig()
|
|
config.GenesisCountdownInterval = time.Millisecond * 500
|
|
params.OverrideBeaconConfig(config)
|
|
|
|
t.Run("normal countdown", func(t *testing.T) {
|
|
defer hook.Reset()
|
|
firstStringResult := "1s until chain genesis"
|
|
genesisReached := "Chain genesis time reached"
|
|
CountdownToGenesis(
|
|
context.Background(),
|
|
prysmTime.Now().Add(2*time.Second),
|
|
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
|
[32]byte{},
|
|
)
|
|
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,
|
|
prysmTime.Now().Add(5*time.Second),
|
|
params.BeaconConfig().MinGenesisActiveValidatorCount,
|
|
[32]byte{},
|
|
)
|
|
require.LogsContain(t, hook, "4s until chain genesis")
|
|
require.LogsContain(t, hook, "3s until chain genesis")
|
|
require.LogsContain(t, hook, "Context closed, exiting routine")
|
|
require.LogsDoNotContain(t, hook, "Chain genesis time reached")
|
|
})
|
|
}
|