mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-13 13:43:30 +00:00
d077483577
* 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>
92 lines
2.6 KiB
Go
92 lines
2.6 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
|
|
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
|
)
|
|
|
|
func TestHeadSlot_DataRace(t *testing.T) {
|
|
beaconDB := testDB.SetupDB(t)
|
|
s := &Service{
|
|
cfg: &config{BeaconDB: beaconDB},
|
|
}
|
|
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
|
|
require.NoError(t, err)
|
|
st, _ := util.DeterministicGenesisState(t, 1)
|
|
wait := make(chan struct{})
|
|
go func() {
|
|
defer close(wait)
|
|
require.NoError(t, s.saveHead(context.Background(), [32]byte{}, b, st))
|
|
}()
|
|
s.HeadSlot()
|
|
<-wait
|
|
}
|
|
|
|
func TestHeadRoot_DataRace(t *testing.T) {
|
|
beaconDB := testDB.SetupDB(t)
|
|
s := &Service{
|
|
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
|
|
head: &head{root: [32]byte{'A'}},
|
|
}
|
|
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
|
|
require.NoError(t, err)
|
|
wait := make(chan struct{})
|
|
st, _ := util.DeterministicGenesisState(t, 1)
|
|
go func() {
|
|
defer close(wait)
|
|
require.NoError(t, s.saveHead(context.Background(), [32]byte{}, b, st))
|
|
|
|
}()
|
|
_, err = s.HeadRoot(context.Background())
|
|
require.NoError(t, err)
|
|
<-wait
|
|
}
|
|
|
|
func TestHeadBlock_DataRace(t *testing.T) {
|
|
beaconDB := testDB.SetupDB(t)
|
|
wsb, err := blocks.NewSignedBeaconBlock(ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}})
|
|
require.NoError(t, err)
|
|
s := &Service{
|
|
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
|
|
head: &head{block: wsb},
|
|
}
|
|
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
|
|
require.NoError(t, err)
|
|
wait := make(chan struct{})
|
|
st, _ := util.DeterministicGenesisState(t, 1)
|
|
go func() {
|
|
defer close(wait)
|
|
require.NoError(t, s.saveHead(context.Background(), [32]byte{}, b, st))
|
|
|
|
}()
|
|
_, err = s.HeadBlock(context.Background())
|
|
require.NoError(t, err)
|
|
<-wait
|
|
}
|
|
|
|
func TestHeadState_DataRace(t *testing.T) {
|
|
beaconDB := testDB.SetupDB(t)
|
|
s := &Service{
|
|
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
|
|
}
|
|
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
|
|
require.NoError(t, err)
|
|
wait := make(chan struct{})
|
|
st, _ := util.DeterministicGenesisState(t, 1)
|
|
go func() {
|
|
defer close(wait)
|
|
require.NoError(t, s.saveHead(context.Background(), [32]byte{}, b, st))
|
|
|
|
}()
|
|
_, err = s.HeadState(context.Background())
|
|
require.NoError(t, err)
|
|
<-wait
|
|
}
|