2020-03-11 09:11:07 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2020-05-04 10:15:33 +00:00
|
|
|
"runtime/debug"
|
2020-03-11 09:11:07 +00:00
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
|
2020-07-18 07:56:48 +00:00
|
|
|
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2020-03-11 09:11:07 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2020-07-18 07:56:48 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-03-11 09:11:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBeaconState_SlotDataRace(t *testing.T) {
|
2020-04-14 16:41:09 +00:00
|
|
|
headState, err := InitializeFromProto(&pb.BeaconState{Slot: 1})
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-03-11 09:11:07 +00:00
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(2)
|
|
|
|
go func() {
|
2020-07-18 07:56:48 +00:00
|
|
|
require.NoError(t, headState.SetSlot(uint64(0)))
|
2020-03-11 09:11:07 +00:00
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
headState.Slot()
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
}
|
2020-04-22 04:44:33 +00:00
|
|
|
|
|
|
|
func TestNilState_NoPanic(t *testing.T) {
|
|
|
|
var st *BeaconState
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
2020-05-04 10:15:33 +00:00
|
|
|
t.Errorf("Method panicked when it was not supposed to: %v\n%v\n", r, string(debug.Stack()))
|
2020-04-22 04:44:33 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
// retrieve elements from nil state
|
2020-05-04 10:15:33 +00:00
|
|
|
_ = st.GenesisTime()
|
2020-04-22 04:44:33 +00:00
|
|
|
_ = st.GenesisValidatorRoot()
|
2020-05-04 10:15:33 +00:00
|
|
|
_ = st.GenesisUnixTime()
|
|
|
|
_ = st.GenesisValidatorRoot()
|
|
|
|
_ = st.Slot()
|
|
|
|
_ = st.Fork()
|
|
|
|
_ = st.LatestBlockHeader()
|
|
|
|
_ = st.ParentRoot()
|
|
|
|
_ = st.BlockRoots()
|
|
|
|
_, err := st.BlockRootAtIndex(0)
|
|
|
|
_ = st.StateRoots()
|
|
|
|
_ = st.HistoricalRoots()
|
2020-04-22 04:44:33 +00:00
|
|
|
_ = st.Eth1Data()
|
2020-05-04 10:15:33 +00:00
|
|
|
_ = st.Eth1DataVotes()
|
|
|
|
_ = st.Eth1DepositIndex()
|
|
|
|
_ = st.ValidatorsReadOnly()
|
|
|
|
_, err = st.ValidatorAtIndex(0)
|
|
|
|
_, err = st.ValidatorAtIndexReadOnly(0)
|
|
|
|
_, _ = st.ValidatorIndexByPubkey([48]byte{})
|
|
|
|
_ = st.validatorIndexMap()
|
|
|
|
_ = st.PubkeyAtIndex(0)
|
|
|
|
_ = st.NumValidators()
|
|
|
|
_ = st.Balances()
|
|
|
|
_, err = st.BalanceAtIndex(0)
|
|
|
|
_ = st.BalancesLength()
|
|
|
|
_ = st.RandaoMixes()
|
|
|
|
_, err = st.RandaoMixAtIndex(0)
|
|
|
|
_ = st.RandaoMixesLength()
|
|
|
|
_ = st.Slashings()
|
|
|
|
_ = st.PreviousEpochAttestations()
|
|
|
|
_ = st.CurrentEpochAttestations()
|
|
|
|
_ = st.JustificationBits()
|
|
|
|
_ = st.PreviousJustifiedCheckpoint()
|
|
|
|
_ = st.CurrentJustifiedCheckpoint()
|
|
|
|
_ = st.FinalizedCheckpoint()
|
|
|
|
_ = err
|
2020-04-22 04:44:33 +00:00
|
|
|
}
|
2020-06-11 17:38:03 +00:00
|
|
|
|
|
|
|
func TestReadOnlyValidator_NoPanic(t *testing.T) {
|
|
|
|
v := &ReadOnlyValidator{}
|
2020-07-18 07:56:48 +00:00
|
|
|
assert.Equal(t, false, v.Slashed(), "Expected not slashed")
|
|
|
|
assert.Equal(t, (*eth.Validator)(nil), v.CopyValidator(), "Expected nil result")
|
2020-06-11 17:38:03 +00:00
|
|
|
}
|
2020-06-22 19:41:21 +00:00
|
|
|
|
|
|
|
func TestReadOnlyValidator_ActivationEligibilityEpochNoPanic(t *testing.T) {
|
|
|
|
v := &ReadOnlyValidator{}
|
2020-07-18 07:56:48 +00:00
|
|
|
assert.Equal(t, uint64(0), v.ActivationEligibilityEpoch(), "Expected 0 and not panic")
|
2020-06-22 19:41:21 +00:00
|
|
|
}
|