mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 09:14:28 +00:00
b030771174
* first version * cli context * fix service * starting change to ccache * ristretto cache * added test * test on evict * remove evict test * test onevict * comment for exported flag * update all span maps on load * fix setup db * span cache added to help flags * start save cache on exit * save cache to db before close * comment fix * fix flags * setup db new * nishant feedback * workspace cr * lint fix * fix calls * start db * fix test * Update slasher/db/db.go Co-Authored-By: Nishant Das <nishdas93@gmail.com> * add flag * nishant feedback * export Config * fix imports * fix imports * fix imports * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * Update slasher/service/service.go Co-Authored-By: terence tsao <terence@prysmaticlabs.com> * remove mod print Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Nishant Das <nish1993@hotmail.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
118 lines
2.3 KiB
Go
118 lines
2.3 KiB
Go
package db
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"testing"
|
|
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
type publicKeyTestStruct struct {
|
|
validatorID uint64
|
|
pk []byte
|
|
}
|
|
|
|
var pkTests []publicKeyTestStruct
|
|
|
|
func init() {
|
|
pkTests = []publicKeyTestStruct{
|
|
{
|
|
validatorID: 1,
|
|
pk: []byte{1, 2, 3},
|
|
},
|
|
{
|
|
validatorID: 2,
|
|
pk: []byte{4, 5, 6},
|
|
},
|
|
{
|
|
validatorID: 3,
|
|
pk: []byte{7, 8, 9},
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestNilDBValidatorPublicKey(t *testing.T) {
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
ctx := cli.NewContext(app, set, nil)
|
|
db := SetupSlasherDB(t, ctx)
|
|
defer TeardownSlasherDB(t, db)
|
|
|
|
validatorID := uint64(1)
|
|
|
|
pk, err := db.ValidatorPubKey(validatorID)
|
|
if err != nil {
|
|
t.Fatal("nil ValidatorPubKey should not return error")
|
|
}
|
|
if pk != nil {
|
|
t.Fatal("ValidatorPubKey should return nil")
|
|
}
|
|
|
|
}
|
|
|
|
func TestSavePubKey(t *testing.T) {
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
ctx := cli.NewContext(app, set, nil)
|
|
db := SetupSlasherDB(t, ctx)
|
|
defer TeardownSlasherDB(t, db)
|
|
|
|
for _, tt := range pkTests {
|
|
err := db.SavePubKey(tt.validatorID, tt.pk)
|
|
if err != nil {
|
|
t.Fatalf("save validator public key failed: %v", err)
|
|
}
|
|
|
|
pk, err := db.ValidatorPubKey(tt.validatorID)
|
|
if err != nil {
|
|
t.Fatalf("failed to get validator public key: %v", err)
|
|
}
|
|
|
|
if pk == nil || !bytes.Equal(pk, tt.pk) {
|
|
t.Fatalf("get should return validator public key: %v", tt.pk)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
func TestDeletePublicKey(t *testing.T) {
|
|
app := cli.NewApp()
|
|
set := flag.NewFlagSet("test", 0)
|
|
ctx := cli.NewContext(app, set, nil)
|
|
db := SetupSlasherDB(t, ctx)
|
|
defer TeardownSlasherDB(t, db)
|
|
|
|
for _, tt := range pkTests {
|
|
|
|
err := db.SavePubKey(tt.validatorID, tt.pk)
|
|
if err != nil {
|
|
t.Fatalf("save validator public key failed: %v", err)
|
|
}
|
|
}
|
|
|
|
for _, tt := range pkTests {
|
|
pk, err := db.ValidatorPubKey(tt.validatorID)
|
|
if err != nil {
|
|
t.Fatalf("failed to get validator public key: %v", err)
|
|
}
|
|
|
|
if pk == nil || !bytes.Equal(pk, tt.pk) {
|
|
t.Fatalf("get should return validator public key: %v", pk)
|
|
}
|
|
err = db.DeletePubKey(tt.validatorID)
|
|
if err != nil {
|
|
t.Fatalf("delete validator public key: %v", err)
|
|
}
|
|
pk, err = db.ValidatorPubKey(tt.validatorID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if pk != nil {
|
|
t.Errorf("Expected validator public key to be deleted, received: %v", pk)
|
|
}
|
|
|
|
}
|
|
|
|
}
|