mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
f8b4d8c57a
* Deprecate store WIP * fix spectests build * mock right interface * sync tests build * more tests builds * blockchain tests - TestFinalizedCheckpt_GenesisRootOk - TestCurrentJustifiedCheckpt_CanRetrieve - TestJustifiedCheckpt_GenesisRootOk - TestHeadRoot_CanRetrieve - TestHeadRoot_UseDB - TestService_ProcessAttestationsAndUpdateHead - TestService_VerifyWeakSubjectivityRoot - TestVerifyFinalizedConsistency_InconsistentRoot_ProtoArray - TestVerifyFinalizedConsistency_InconsistentRoot_DoublyLinkedTree - TestVerifyFinalizedConsistency_Ok - TestStore_OnBlock_ProtoArray - TestStore_OnBlock_DoublyLinkedTree - TestStore_OnBlockBatch_ProtoArray - TestStore_OnBlockBatch_DoublyLinkedTree - TestStore_OnBlockBatch_NotifyNewPayload - TestCachedPreState_CanGetFromStateSummary_ProtoArray - TestCachedPreState_CanGetFromStateSummary_DoublyLinkedTree * more blockchain tests - TestStore_OnBlockBatch_PruneOK_Protoarray - TestFillForkChoiceMissingBlocks_CanSave_ProtoArray - TestFillForkChoiceMissingBlocks_CanSave_DoublyLinkedTree - TestFillForkChoiceMissingBlocks_RootsMatch_Protoarray - TestFillForkChoiceMissingBlocks_RootsMatch_DoublyLinkedTree - TestFillForkChoiceMissingBlocks_FilterFinalized_ProtoArray - TestFillForkChoiceMissingBlocks_FilterFinalized_DoublyLinkedTree - TestVerifyBlkDescendant - Test_verifyBlkFinalizedSlot_invalidBlock - TestChainService_SaveHeadNoDB * update best justified from genesis * deal with nil head on saveHead * initialize prev justified checkpoint * update finalization correctly * update finalization logic * update finalization logic * track the wall clock on forkchoice spectests * export copies of checkpoints from blockchain package * do not use forkchoice's head on HeadRoot * Remove debug remain Co-authored-by: terencechain <terence@prysmaticlabs.com> * terence's review * add forkchoice types deps * wtf * debugging * init-sync: update justified and finalized checkpoints on db * call updateFinalized instead of only DB * remove debug symbols * safe copy headroot Co-authored-by: terencechain <terence@prysmaticlabs.com>
91 lines
2.9 KiB
Go
91 lines
2.9 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/pkg/errors"
|
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
|
|
forkchoicetypes "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/types"
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
|
"github.com/prysmaticlabs/prysm/time/slots"
|
|
)
|
|
|
|
func TestService_VerifyWeakSubjectivityRoot(t *testing.T) {
|
|
beaconDB := testDB.SetupDB(t)
|
|
|
|
b := util.NewBeaconBlock()
|
|
b.Block.Slot = 1792480
|
|
util.SaveBlock(t, context.Background(), beaconDB, b)
|
|
r, err := b.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
|
|
blockEpoch := slots.ToEpoch(b.Block.Slot)
|
|
tests := []struct {
|
|
wsVerified bool
|
|
disabled bool
|
|
wantErr error
|
|
checkpt *ethpb.Checkpoint
|
|
finalizedEpoch types.Epoch
|
|
name string
|
|
}{
|
|
{
|
|
name: "nil root and epoch",
|
|
disabled: true,
|
|
},
|
|
{
|
|
name: "not yet to verify, ws epoch higher than finalized epoch",
|
|
checkpt: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'a'}, 32), Epoch: blockEpoch},
|
|
finalizedEpoch: blockEpoch - 1,
|
|
},
|
|
{
|
|
name: "can't find the block in DB",
|
|
checkpt: ðpb.Checkpoint{Root: bytesutil.PadTo([]byte{'a'}, fieldparams.RootLength), Epoch: 1},
|
|
finalizedEpoch: blockEpoch + 1,
|
|
wantErr: errWSBlockNotFound,
|
|
},
|
|
{
|
|
name: "can't find the block corresponds to ws epoch in DB",
|
|
checkpt: ðpb.Checkpoint{Root: r[:], Epoch: blockEpoch - 2}, // Root belongs in epoch 1.
|
|
finalizedEpoch: blockEpoch - 1,
|
|
wantErr: errWSBlockNotFoundInEpoch,
|
|
},
|
|
{
|
|
name: "can verify and pass",
|
|
checkpt: ðpb.Checkpoint{Root: r[:], Epoch: blockEpoch},
|
|
finalizedEpoch: blockEpoch + 1,
|
|
},
|
|
{
|
|
name: "equal epoch",
|
|
checkpt: ðpb.Checkpoint{Root: r[:], Epoch: blockEpoch},
|
|
finalizedEpoch: blockEpoch,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
wv, err := NewWeakSubjectivityVerifier(tt.checkpt, beaconDB)
|
|
require.Equal(t, !tt.disabled, wv.enabled)
|
|
require.NoError(t, err)
|
|
fcs := protoarray.New()
|
|
s := &Service{
|
|
cfg: &config{BeaconDB: beaconDB, WeakSubjectivityCheckpt: tt.checkpt, ForkChoiceStore: fcs},
|
|
wsVerifier: wv,
|
|
}
|
|
require.NoError(t, fcs.UpdateFinalizedCheckpoint(&forkchoicetypes.Checkpoint{Epoch: tt.finalizedEpoch}))
|
|
cp := s.ForkChoicer().FinalizedCheckpoint()
|
|
err = s.wsVerifier.VerifyWeakSubjectivity(context.Background(), cp.Epoch)
|
|
if tt.wantErr == nil {
|
|
require.NoError(t, err)
|
|
} else {
|
|
require.Equal(t, true, errors.Is(err, tt.wantErr))
|
|
}
|
|
})
|
|
}
|
|
}
|