mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 20:20:05 +00:00
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
|
package kv
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/gogo/protobuf/proto"
|
||
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||
|
)
|
||
|
|
||
|
func TestStore_ValidatorIndexCRUD(t *testing.T) {
|
||
|
db := setupDB(t)
|
||
|
defer teardownDB(t, db)
|
||
|
validatorIdx := uint64(100)
|
||
|
pubKey := [48]byte{1, 2, 3, 4}
|
||
|
ctx := context.Background()
|
||
|
_, ok, err := db.ValidatorIndex(ctx, pubKey)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if ok {
|
||
|
t.Fatal("Expected validator index to not exist")
|
||
|
}
|
||
|
if err := db.SaveValidatorIndex(ctx, pubKey, validatorIdx); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
retrievedIdx, ok, err := db.ValidatorIndex(ctx, pubKey)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if !ok {
|
||
|
t.Fatal("Expected validator index to have been properly retrieved")
|
||
|
}
|
||
|
if retrievedIdx != validatorIdx {
|
||
|
t.Errorf("Wanted %d, received %d", validatorIdx, retrievedIdx)
|
||
|
}
|
||
|
if err := db.DeleteValidatorIndex(ctx, pubKey); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if db.HasValidatorIndex(ctx, pubKey) {
|
||
|
t.Error("Expected validator index to have been deleted from the db")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestStore_ValidatorLatestVoteCRUD(t *testing.T) {
|
||
|
db := setupDB(t)
|
||
|
defer teardownDB(t, db)
|
||
|
validatorIdx := uint64(100)
|
||
|
latestVote := &pb.ValidatorLatestVote{
|
||
|
Epoch: 1,
|
||
|
Root: []byte("root"),
|
||
|
}
|
||
|
ctx := context.Background()
|
||
|
if err := db.SaveValidatorLatestVote(ctx, validatorIdx, latestVote); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if !db.HasValidatorLatestVote(ctx, validatorIdx) {
|
||
|
t.Error("Expected validator latest vote to exist in the db")
|
||
|
}
|
||
|
retrievedVote, err := db.ValidatorLatestVote(ctx, validatorIdx)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
if !proto.Equal(latestVote, retrievedVote) {
|
||
|
t.Errorf("Wanted %d, received %d", latestVote, retrievedVote)
|
||
|
}
|
||
|
}
|