2020-03-11 09:11:07 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBeaconState_SlotDataRace(t *testing.T) {
|
2020-04-14 16:41:09 +00:00
|
|
|
headState, err := InitializeFromProto(&pb.BeaconState{Slot: 1})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-03-11 09:11:07 +00:00
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(2)
|
|
|
|
go func() {
|
2020-04-14 16:41:09 +00:00
|
|
|
if err := headState.SetSlot(uint64(0)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
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 {
|
|
|
|
t.Errorf("Method panicked when it was not supposed to: %v", r)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
// retrieve elements from nil state
|
|
|
|
_ = st.GenesisValidatorRoot()
|
|
|
|
_ = st.Eth1Data()
|
|
|
|
}
|