2019-09-23 19:24:42 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2020-02-15 18:57:49 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2019-09-23 19:24:42 +00:00
|
|
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
2020-04-14 20:27:03 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
|
2020-07-16 12:11:39 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2019-09-23 19:24:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeadSlot_DataRace(t *testing.T) {
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB := testDB.SetupDB(t)
|
2019-09-23 19:24:42 +00:00
|
|
|
s := &Service{
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB: beaconDB,
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
go func() {
|
2020-07-16 12:11:39 +00:00
|
|
|
require.NoError(t, s.saveHead(context.Background(), [32]byte{}))
|
2019-09-23 19:24:42 +00:00
|
|
|
}()
|
|
|
|
s.HeadSlot()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeadRoot_DataRace(t *testing.T) {
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB := testDB.SetupDB(t)
|
2019-09-23 19:24:42 +00:00
|
|
|
s := &Service{
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB: beaconDB,
|
2020-02-15 18:57:49 +00:00
|
|
|
head: &head{root: [32]byte{'A'}},
|
2020-12-18 19:12:30 +00:00
|
|
|
stateGen: stategen.New(beaconDB),
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
go func() {
|
2020-07-16 12:11:39 +00:00
|
|
|
require.NoError(t, s.saveHead(context.Background(), [32]byte{}))
|
2019-09-23 19:24:42 +00:00
|
|
|
}()
|
2020-07-16 12:11:39 +00:00
|
|
|
_, err := s.HeadRoot(context.Background())
|
|
|
|
require.NoError(t, err)
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeadBlock_DataRace(t *testing.T) {
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB := testDB.SetupDB(t)
|
2019-09-23 19:24:42 +00:00
|
|
|
s := &Service{
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB: beaconDB,
|
2020-02-15 18:57:49 +00:00
|
|
|
head: &head{block: ðpb.SignedBeaconBlock{}},
|
2020-12-18 19:12:30 +00:00
|
|
|
stateGen: stategen.New(beaconDB),
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
go func() {
|
2020-07-16 12:11:39 +00:00
|
|
|
require.NoError(t, s.saveHead(context.Background(), [32]byte{}))
|
2019-09-23 19:24:42 +00:00
|
|
|
}()
|
2020-07-16 12:11:39 +00:00
|
|
|
_, err := s.HeadBlock(context.Background())
|
|
|
|
require.NoError(t, err)
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeadState_DataRace(t *testing.T) {
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB := testDB.SetupDB(t)
|
2019-09-23 19:24:42 +00:00
|
|
|
s := &Service{
|
2020-12-18 19:12:30 +00:00
|
|
|
beaconDB: beaconDB,
|
|
|
|
stateGen: stategen.New(beaconDB),
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
go func() {
|
2020-07-16 12:11:39 +00:00
|
|
|
require.NoError(t, s.saveHead(context.Background(), [32]byte{}))
|
2019-09-23 19:24:42 +00:00
|
|
|
}()
|
2020-07-16 12:11:39 +00:00
|
|
|
_, err := s.HeadState(context.Background())
|
|
|
|
require.NoError(t, err)
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|