mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
98949d8075
Co-authored-by: terencechain <terence@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
52 lines
2.0 KiB
Go
52 lines
2.0 KiB
Go
package testutil
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/db"
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/blocks"
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/interfaces"
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
|
ethpbalpha "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
|
)
|
|
|
|
func FillDBWithBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) (*ethpbalpha.SignedBeaconBlock, []*ethpbalpha.BeaconBlockContainer) {
|
|
parentRoot := [32]byte{1, 2, 3}
|
|
genBlk := util.NewBeaconBlock()
|
|
genBlk.Block.ParentRoot = parentRoot[:]
|
|
root, err := genBlk.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
util.SaveBlock(t, ctx, beaconDB, genBlk)
|
|
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, root))
|
|
|
|
count := primitives.Slot(100)
|
|
blks := make([]interfaces.ReadOnlySignedBeaconBlock, count)
|
|
blkContainers := make([]*ethpbalpha.BeaconBlockContainer, count)
|
|
for i := primitives.Slot(0); i < count; i++ {
|
|
b := util.NewBeaconBlock()
|
|
b.Block.Slot = i
|
|
b.Block.ParentRoot = bytesutil.PadTo([]byte{uint8(i)}, 32)
|
|
root, err := b.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
blks[i], err = blocks.NewSignedBeaconBlock(b)
|
|
require.NoError(t, err)
|
|
blkContainers[i] = ðpbalpha.BeaconBlockContainer{
|
|
Block: ðpbalpha.BeaconBlockContainer_Phase0Block{Phase0Block: b},
|
|
BlockRoot: root[:],
|
|
}
|
|
}
|
|
require.NoError(t, beaconDB.SaveBlocks(ctx, blks))
|
|
headRoot := bytesutil.ToBytes32(blkContainers[len(blks)-1].BlockRoot)
|
|
summary := ðpbalpha.StateSummary{
|
|
Root: headRoot[:],
|
|
Slot: blkContainers[len(blks)-1].Block.(*ethpbalpha.BeaconBlockContainer_Phase0Block).Phase0Block.Block.Slot,
|
|
}
|
|
require.NoError(t, beaconDB.SaveStateSummary(ctx, summary))
|
|
require.NoError(t, beaconDB.SaveHeadBlockRoot(ctx, headRoot))
|
|
return genBlk, blkContainers
|
|
}
|