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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeadSlot_DataRace(t *testing.T) {
|
|
|
|
db := testDB.SetupDB(t)
|
|
|
|
defer testDB.TeardownDB(t, db)
|
|
|
|
s := &Service{
|
2020-02-15 18:57:49 +00:00
|
|
|
beaconDB: db,
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
s.saveHead(
|
|
|
|
context.Background(),
|
|
|
|
[32]byte{},
|
|
|
|
)
|
|
|
|
}()
|
|
|
|
s.HeadSlot()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeadRoot_DataRace(t *testing.T) {
|
|
|
|
db := testDB.SetupDB(t)
|
|
|
|
defer testDB.TeardownDB(t, db)
|
|
|
|
s := &Service{
|
2020-02-15 18:57:49 +00:00
|
|
|
beaconDB: db,
|
|
|
|
head: &head{root: [32]byte{'A'}},
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
s.saveHead(
|
|
|
|
context.Background(),
|
|
|
|
[32]byte{},
|
|
|
|
)
|
|
|
|
}()
|
2020-01-15 05:02:02 +00:00
|
|
|
if _, err := s.HeadRoot(context.Background()); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeadBlock_DataRace(t *testing.T) {
|
|
|
|
db := testDB.SetupDB(t)
|
|
|
|
defer testDB.TeardownDB(t, db)
|
|
|
|
s := &Service{
|
2020-02-15 18:57:49 +00:00
|
|
|
beaconDB: db,
|
|
|
|
head: &head{block: ðpb.SignedBeaconBlock{}},
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
s.saveHead(
|
|
|
|
context.Background(),
|
|
|
|
[32]byte{},
|
|
|
|
)
|
|
|
|
}()
|
2020-02-17 18:21:42 +00:00
|
|
|
s.HeadBlock(context.Background())
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeadState_DataRace(t *testing.T) {
|
|
|
|
db := testDB.SetupDB(t)
|
|
|
|
defer testDB.TeardownDB(t, db)
|
|
|
|
s := &Service{
|
2020-02-15 18:57:49 +00:00
|
|
|
beaconDB: db,
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
s.saveHead(
|
|
|
|
context.Background(),
|
|
|
|
[32]byte{},
|
|
|
|
)
|
|
|
|
}()
|
2019-11-19 16:12:50 +00:00
|
|
|
s.HeadState(context.Background())
|
2019-09-23 19:24:42 +00:00
|
|
|
}
|