prysm-pulse/time/slots/countdown_test.go
kasey 588dea83b7
Config registry (#10683)
* test coverage and updates to config twiddlers

* LoadChainConfigFile error if SetActive conflicts

* lint

* wip working around test issues

* more fixes, mass test updates

* lint

* linting

* thanks deepsource!

* fix undeclared vars

* fixing more undefined

* fix a bug, make a bug, repeat

* gaz

* use stock mainnet in case fork schedule matters

* remove unused KnownConfigs

* post-merge cleanup

* eliminating OverrideBeaconConfig outside tests

* more cleanup of OverrideBeaconConfig outside tests

* config for interop w/ genesis gen support

* improve var name

* API on package instead of exported value

* cleanup remainders of "registry" naming

* Nishant feedback

* add ropstein to configset

* lint

* lint #2

* ✂️

* revert accidental commented line

* check if active is nil (replace called on empty)

* Nishant feedback

* replace OverrideBeaconConfig call

* update interop instructions w/ new flag

* don't let interop replace config set via cli flags

Co-authored-by: kasey <kasey@users.noreply.github.com>
2022-05-20 07:16:53 +00:00

59 lines
1.6 KiB
Go

package slots
import (
"context"
"testing"
"time"
"github.com/prysmaticlabs/prysm/config/params"
"github.com/prysmaticlabs/prysm/testing/require"
prysmTime "github.com/prysmaticlabs/prysm/time"
"github.com/sirupsen/logrus"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestCountdownToGenesis(t *testing.T) {
params.SetupTestConfigCleanup(t)
logrus.SetLevel(logrus.DebugLevel)
hook := logTest.NewGlobal()
params.SetupTestConfigCleanup(t)
config := params.BeaconConfig().Copy()
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")
})
}