mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
62c25eaedb
* Revert "Fix `ListValidatorBalances` for v0.11 (#5458)" This reverts commit3763a8ce5d
. * Revert "Deprecate archival service (#5445)" This reverts commit4fbcedf541
. * Revert "Delete archival DB methods (#5459)" This reverts commit8a3ea1e936
. * Revert "Modify `ListBeaconCommittees ` to use new state service (#5411)" This reverts commit497fa6ed50
. * Revert "Modify `GetValidatorParticipation` to use new state service (#5409)" This reverts commit046a00aa87
. * Revert "Modify `GetValidatorActiveSetChanges` to use new state service (#5408)" This reverts commit5eb6485e14
. * Revert "Modify `ListValidatorAssignments` to use new state service (#5365)" This reverts commit5a1a768135
.
168 lines
4.0 KiB
Go
168 lines
4.0 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
)
|
|
|
|
func TestStore_ArchivedActiveValidatorChanges(t *testing.T) {
|
|
db := setupDB(t)
|
|
defer teardownDB(t, db)
|
|
ctx := context.Background()
|
|
activated := []uint64{3, 4, 5}
|
|
exited := []uint64{6, 7, 8}
|
|
slashed := []uint64{1212}
|
|
someRoot := [32]byte{1, 2, 3}
|
|
changes := &pbp2p.ArchivedActiveSetChanges{
|
|
Activated: activated,
|
|
Exited: exited,
|
|
Slashed: slashed,
|
|
VoluntaryExits: []*ethpb.VoluntaryExit{
|
|
{
|
|
Epoch: 5,
|
|
ValidatorIndex: 6,
|
|
},
|
|
{
|
|
Epoch: 5,
|
|
ValidatorIndex: 7,
|
|
},
|
|
{
|
|
Epoch: 5,
|
|
ValidatorIndex: 8,
|
|
},
|
|
},
|
|
ProposerSlashings: []*ethpb.ProposerSlashing{
|
|
{
|
|
Header_1: ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
ProposerIndex: 1212,
|
|
Slot: 10,
|
|
ParentRoot: someRoot[:],
|
|
StateRoot: someRoot[:],
|
|
BodyRoot: someRoot[:],
|
|
},
|
|
Signature: make([]byte, 96),
|
|
},
|
|
Header_2: ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
ProposerIndex: 1212,
|
|
Slot: 10,
|
|
ParentRoot: someRoot[:],
|
|
StateRoot: someRoot[:],
|
|
BodyRoot: someRoot[:],
|
|
},
|
|
Signature: make([]byte, 96),
|
|
},
|
|
},
|
|
},
|
|
AttesterSlashings: []*ethpb.AttesterSlashing{
|
|
{
|
|
Attestation_1: ðpb.IndexedAttestation{
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: someRoot[:],
|
|
Source: ðpb.Checkpoint{
|
|
Epoch: 5,
|
|
Root: someRoot[:],
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Epoch: 5,
|
|
Root: someRoot[:],
|
|
},
|
|
},
|
|
},
|
|
Attestation_2: ðpb.IndexedAttestation{
|
|
Data: ðpb.AttestationData{
|
|
BeaconBlockRoot: someRoot[:],
|
|
Source: ðpb.Checkpoint{
|
|
Epoch: 5,
|
|
Root: someRoot[:],
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Epoch: 5,
|
|
Root: someRoot[:],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
epoch := uint64(10)
|
|
if err := db.SaveArchivedActiveValidatorChanges(ctx, epoch, changes); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
retrieved, err := db.ArchivedActiveValidatorChanges(ctx, epoch)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !proto.Equal(changes, retrieved) {
|
|
t.Errorf("Wanted %v, received %v", changes, retrieved)
|
|
}
|
|
}
|
|
|
|
func TestStore_ArchivedCommitteeInfo(t *testing.T) {
|
|
db := setupDB(t)
|
|
defer teardownDB(t, db)
|
|
ctx := context.Background()
|
|
someSeed := [32]byte{1, 2, 3}
|
|
info := &pbp2p.ArchivedCommitteeInfo{
|
|
ProposerSeed: someSeed[:],
|
|
AttesterSeed: someSeed[:],
|
|
}
|
|
epoch := uint64(10)
|
|
if err := db.SaveArchivedCommitteeInfo(ctx, epoch, info); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
retrieved, err := db.ArchivedCommitteeInfo(ctx, epoch)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !proto.Equal(info, retrieved) {
|
|
t.Errorf("Wanted %v, received %v", info, retrieved)
|
|
}
|
|
}
|
|
|
|
func TestStore_ArchivedBalances(t *testing.T) {
|
|
db := setupDB(t)
|
|
defer teardownDB(t, db)
|
|
ctx := context.Background()
|
|
balances := []uint64{2, 3, 4, 5, 6, 7}
|
|
epoch := uint64(10)
|
|
if err := db.SaveArchivedBalances(ctx, epoch, balances); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
retrieved, err := db.ArchivedBalances(ctx, epoch)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !reflect.DeepEqual(balances, retrieved) {
|
|
t.Errorf("Wanted %v, received %v", balances, retrieved)
|
|
}
|
|
}
|
|
|
|
func TestStore_ArchivedValidatorParticipation(t *testing.T) {
|
|
db := setupDB(t)
|
|
defer teardownDB(t, db)
|
|
ctx := context.Background()
|
|
epoch := uint64(10)
|
|
part := ðpb.ValidatorParticipation{
|
|
GlobalParticipationRate: 0.99,
|
|
EligibleEther: 12202000,
|
|
VotedEther: 12079998,
|
|
}
|
|
if err := db.SaveArchivedValidatorParticipation(ctx, epoch, part); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
retrieved, err := db.ArchivedValidatorParticipation(ctx, epoch)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !proto.Equal(part, retrieved) {
|
|
t.Errorf("Wanted %v, received %v", part, retrieved)
|
|
}
|
|
}
|