prysm-pulse/time/slots/countdown_test.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

59 lines
1.6 KiB
Go

package slots
import (
"context"
"testing"
"time"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/testing/require"
prysmTime "github.com/prysmaticlabs/prysm/v3/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")
})
}