mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 12:27:18 +00:00
a069738c20
* update shared/params * update eth2-types deps * update protobufs * update shared/* * fix testutil/state * update beacon-chain/state * update beacon-chain/db * update tests * fix test * update beacon-chain/core * update beacon-chain/blockchain * update beacon-chain/cache * beacon-chain/forkchoice * update beacon-chain/operations * update beacon-chain/p2p * update beacon-chain/rpc * update sync/initial-sync * update deps * update deps * go fmt * update beacon-chain/sync * update endtoend/ * bazel build //beacon-chain - works w/o issues * update slasher code * udpate tools/ * update validator/ * update fastssz * fix build * fix test building * update tests * update ethereumapis deps * fix tests * update state/stategen * fix build * fix test * add FarFutureSlot * go imports * Radek's suggestions * Ivan's suggestions * type conversions * Nishant's suggestions * add more tests to rpc_send_request * fix test * clean up * fix conflicts Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestService_VerifyWeakSubjectivityRoot(t *testing.T) {
|
|
beaconDB := testDB.SetupDB(t)
|
|
|
|
b := testutil.NewBeaconBlock()
|
|
b.Block.Slot = 32
|
|
require.NoError(t, beaconDB.SaveBlock(context.Background(), b))
|
|
r, err := b.Block.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
tests := []struct {
|
|
wsVerified bool
|
|
wantErr bool
|
|
wsRoot [32]byte
|
|
wsEpoch types.Epoch
|
|
finalizedEpoch types.Epoch
|
|
errString string
|
|
name string
|
|
}{
|
|
{
|
|
name: "nil root and epoch",
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "already verified",
|
|
wsEpoch: 2,
|
|
finalizedEpoch: 2,
|
|
wsVerified: true,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "not yet to verify, ws epoch higher than finalized epoch",
|
|
wsEpoch: 2,
|
|
finalizedEpoch: 1,
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "can't find the block in DB",
|
|
wsEpoch: 1,
|
|
wsRoot: [32]byte{'a'},
|
|
finalizedEpoch: 3,
|
|
wantErr: true,
|
|
errString: "node does not have root in DB",
|
|
},
|
|
{
|
|
name: "can't find the block corresponds to ws epoch in DB",
|
|
wsEpoch: 2,
|
|
wsRoot: r, // Root belongs in epoch 1.
|
|
finalizedEpoch: 3,
|
|
wantErr: true,
|
|
errString: "node does not have root in db corresponding to epoch",
|
|
},
|
|
{
|
|
name: "can verify and pass",
|
|
wsEpoch: 1,
|
|
wsRoot: r,
|
|
finalizedEpoch: 3,
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
s := &Service{
|
|
beaconDB: beaconDB,
|
|
wsRoot: tt.wsRoot[:],
|
|
wsEpoch: tt.wsEpoch,
|
|
wsVerified: tt.wsVerified,
|
|
finalizedCheckpt: ðpb.Checkpoint{Epoch: tt.finalizedEpoch},
|
|
}
|
|
if err := s.VerifyWeakSubjectivityRoot(context.Background()); (err != nil) != tt.wantErr {
|
|
require.ErrorContains(t, tt.errString, err)
|
|
}
|
|
})
|
|
}
|
|
}
|