mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +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>
87 lines
2.8 KiB
Go
87 lines
2.8 KiB
Go
package debug
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
mock "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
|
|
dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
|
|
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
|
"github.com/prysmaticlabs/prysm/v3/config/params"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
|
)
|
|
|
|
func TestServer_GetBlock(t *testing.T) {
|
|
db := dbTest.SetupDB(t)
|
|
ctx := context.Background()
|
|
|
|
b := util.NewBeaconBlock()
|
|
b.Block.Slot = 100
|
|
util.SaveBlock(t, ctx, db, b)
|
|
blockRoot, err := b.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
bs := &Server{
|
|
BeaconDB: db,
|
|
}
|
|
res, err := bs.GetBlock(ctx, ðpb.BlockRequestByRoot{
|
|
BlockRoot: blockRoot[:],
|
|
})
|
|
require.NoError(t, err)
|
|
wanted, err := b.MarshalSSZ()
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, wanted, res.Encoded)
|
|
|
|
// Checking for nil block.
|
|
blockRoot = [32]byte{}
|
|
res, err = bs.GetBlock(ctx, ðpb.BlockRequestByRoot{
|
|
BlockRoot: blockRoot[:],
|
|
})
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, []byte{}, res.Encoded)
|
|
}
|
|
|
|
func TestServer_GetAttestationInclusionSlot(t *testing.T) {
|
|
db := dbTest.SetupDB(t)
|
|
ctx := context.Background()
|
|
offset := int64(2 * params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
|
|
bs := &Server{
|
|
BeaconDB: db,
|
|
StateGen: stategen.New(db),
|
|
GenesisTimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*offset) * time.Second)},
|
|
}
|
|
|
|
s, _ := util.DeterministicGenesisState(t, 2048)
|
|
tr := [32]byte{'a'}
|
|
require.NoError(t, bs.StateGen.SaveState(ctx, tr, s))
|
|
c, err := helpers.BeaconCommitteeFromState(context.Background(), s, 1, 0)
|
|
require.NoError(t, err)
|
|
|
|
a := ðpb.Attestation{
|
|
Data: ðpb.AttestationData{
|
|
Target: ðpb.Checkpoint{Root: tr[:]},
|
|
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
|
BeaconBlockRoot: make([]byte, 32),
|
|
Slot: 1,
|
|
},
|
|
AggregationBits: bitfield.Bitlist{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01},
|
|
Signature: make([]byte, fieldparams.BLSSignatureLength),
|
|
}
|
|
b := util.NewBeaconBlock()
|
|
b.Block.Slot = 2
|
|
b.Block.Body.Attestations = []*ethpb.Attestation{a}
|
|
util.SaveBlock(t, ctx, bs.BeaconDB, b)
|
|
res, err := bs.GetInclusionSlot(ctx, ðpb.InclusionSlotRequest{Slot: 1, Id: uint64(c[0])})
|
|
require.NoError(t, err)
|
|
require.Equal(t, b.Block.Slot, res.Slot)
|
|
res, err = bs.GetInclusionSlot(ctx, ðpb.InclusionSlotRequest{Slot: 1, Id: 9999999})
|
|
require.NoError(t, err)
|
|
require.Equal(t, params.BeaconConfig().FarFutureSlot, res.Slot)
|
|
}
|