mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 13:18:57 +00:00
482a054ee1
* handle panic * Merge branch 'master' into handlePanic * Merge refs/heads/master into handlePanic * Merge refs/heads/master into handlePanic
43 lines
734 B
Go
43 lines
734 B
Go
package state
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
)
|
|
|
|
func TestBeaconState_SlotDataRace(t *testing.T) {
|
|
headState, err := InitializeFromProto(&pb.BeaconState{Slot: 1})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(2)
|
|
go func() {
|
|
if err := headState.SetSlot(uint64(0)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wg.Done()
|
|
}()
|
|
go func() {
|
|
headState.Slot()
|
|
wg.Done()
|
|
}()
|
|
|
|
wg.Wait()
|
|
}
|
|
|
|
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()
|
|
}
|