mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +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>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
|
)
|
|
|
|
func TestService_getBlock(t *testing.T) {
|
|
ctx := context.Background()
|
|
beaconDB := testDB.SetupDB(t)
|
|
s := setupBeaconChain(t, beaconDB)
|
|
b1 := util.NewBeaconBlock()
|
|
r1, err := b1.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
b2 := util.NewBeaconBlock()
|
|
b2.Block.Slot = 100
|
|
r2, err := b2.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
|
|
// block not found
|
|
_, err = s.getBlock(ctx, [32]byte{})
|
|
require.ErrorIs(t, err, errBlockNotFoundInCacheOrDB)
|
|
|
|
// block in cache
|
|
b, err := blocks.NewSignedBeaconBlock(b1)
|
|
require.NoError(t, err)
|
|
require.NoError(t, s.saveInitSyncBlock(ctx, r1, b))
|
|
got, err := s.getBlock(ctx, r1)
|
|
require.NoError(t, err)
|
|
require.DeepEqual(t, b, got)
|
|
|
|
// block in db
|
|
b = util.SaveBlock(t, ctx, s.cfg.BeaconDB, b2)
|
|
got, err = s.getBlock(ctx, r2)
|
|
require.NoError(t, err)
|
|
require.DeepEqual(t, b, got)
|
|
}
|
|
|
|
func TestService_hasBlockInInitSyncOrDB(t *testing.T) {
|
|
ctx := context.Background()
|
|
beaconDB := testDB.SetupDB(t)
|
|
s := setupBeaconChain(t, beaconDB)
|
|
b1 := util.NewBeaconBlock()
|
|
r1, err := b1.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
b2 := util.NewBeaconBlock()
|
|
b2.Block.Slot = 100
|
|
r2, err := b2.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
|
|
// block not found
|
|
require.Equal(t, false, s.hasBlockInInitSyncOrDB(ctx, [32]byte{}))
|
|
|
|
// block in cache
|
|
b, err := blocks.NewSignedBeaconBlock(b1)
|
|
require.NoError(t, err)
|
|
require.NoError(t, s.saveInitSyncBlock(ctx, r1, b))
|
|
require.Equal(t, true, s.hasBlockInInitSyncOrDB(ctx, r1))
|
|
|
|
// block in db
|
|
util.SaveBlock(t, ctx, s.cfg.BeaconDB, b2)
|
|
require.Equal(t, true, s.hasBlockInInitSyncOrDB(ctx, r2))
|
|
}
|