mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
a8e501b3cf
* update deps * update deps * update protos/* * update deps * reset protos * update protos * update shared/params/config * update protos * update /shared * update shared/slotutil and shared/testutil * update beacon-chain/core/helpers * updates beacon-chain/state * update beacon-chain/forkchoice * update beacon-chain/blockchain * update beacon-chain/cache * update beacon-chain/core * update beacon-chain/db * update beacon-chain/node * update beacon-chain/p2p * update beacon-chain/rpc * update beacon-chain/sync * go mod tidy * make sure that beacon-chain build suceeds * go fmt * update e2e tests * update slasher * remove redundant alias * update validator * gazelle * fix build errors in unit tests * go fmt * update deps * update fuzz/BUILD.bazel * fix unit tests * more unit test fixes * fix blockchain UTs * more unit test fixes
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package beaconv1
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
ptypes "github.com/gogo/protobuf/types"
|
|
chainMock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestGetGenesis(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
config := params.BeaconConfig()
|
|
config.GenesisForkVersion = []byte("genesis")
|
|
params.OverrideBeaconConfig(config)
|
|
genesis := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
validatorsRoot := [32]byte{1, 2, 3, 4, 5, 6}
|
|
|
|
t.Run("OK", func(t *testing.T) {
|
|
chainService := &chainMock.ChainService{
|
|
Genesis: genesis,
|
|
ValidatorsRoot: validatorsRoot,
|
|
}
|
|
s := Server{
|
|
GenesisTimeFetcher: chainService,
|
|
ChainInfoFetcher: chainService,
|
|
}
|
|
resp, err := s.GetGenesis(context.Background(), &ptypes.Empty{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, genesis.Unix(), resp.Data.GenesisTime.Seconds)
|
|
assert.Equal(t, int32(0), resp.Data.GenesisTime.Nanos)
|
|
assert.DeepEqual(t, validatorsRoot[:], resp.Data.GenesisValidatorsRoot)
|
|
assert.DeepEqual(t, []byte("genesis"), resp.Data.GenesisForkVersion)
|
|
})
|
|
|
|
t.Run("No genesis time", func(t *testing.T) {
|
|
chainService := &chainMock.ChainService{
|
|
Genesis: time.Time{},
|
|
ValidatorsRoot: validatorsRoot,
|
|
}
|
|
s := Server{
|
|
GenesisTimeFetcher: chainService,
|
|
ChainInfoFetcher: chainService,
|
|
}
|
|
_, err := s.GetGenesis(context.Background(), &ptypes.Empty{})
|
|
assert.ErrorContains(t, "Chain genesis info is not yet known", err)
|
|
})
|
|
|
|
t.Run("No genesis validator root", func(t *testing.T) {
|
|
chainService := &chainMock.ChainService{
|
|
Genesis: genesis,
|
|
ValidatorsRoot: [32]byte{},
|
|
}
|
|
s := Server{
|
|
GenesisTimeFetcher: chainService,
|
|
ChainInfoFetcher: chainService,
|
|
}
|
|
_, err := s.GetGenesis(context.Background(), &ptypes.Empty{})
|
|
assert.ErrorContains(t, "Chain genesis info is not yet known", err)
|
|
})
|
|
}
|