mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 19:51:20 +00:00
7cc32c4dda
* remove unused code * remove defer use in loop * Remove unused methods and constants * gofmt and gaz * nilness check * remove unused args * Add TODO for refactoring subscribeWithBase to remove unused arg. It seems too involved to include in this sweeping PR. https://github.com/prysmaticlabs/prysm/issues/7437 * replace empty slice declaration * Remove unnecessary type conversions * remove redundant type declaration * rename receivers to be consistent * Remove bootnode query tool. It is now obsolete by discv5 * Remove relay node. It is no longer used or supported * Revert "Remove relay node. It is no longer used or supported" This reverts commit 4bd7717334dad85ef4766ed9bc4da711fb5fa810. * Delete unused test directory * Delete unsupported gcp startup script * Delete old k8s script * build fixes * fix build * go mod tidy * revert slasher/db/kv/block_header.go * fix build * remove redundant nil check * combine func args Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
84 lines
1.9 KiB
Go
84 lines
1.9 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
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) {
|
|
|
|
db := setupDB(t)
|
|
ctx := context.Background()
|
|
|
|
validatorID := uint64(1)
|
|
|
|
pk, err := db.ValidatorPubKey(ctx, validatorID)
|
|
require.NoError(t, err, "Nil ValidatorPubKey should not return error")
|
|
require.DeepEqual(t, ([]uint8)(nil), pk)
|
|
}
|
|
|
|
func TestSavePubKey(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
ctx := context.Background()
|
|
|
|
for _, tt := range pkTests {
|
|
err := db.SavePubKey(ctx, tt.validatorID, tt.pk)
|
|
require.NoError(t, err, "Save validator public key failed")
|
|
|
|
pk, err := db.ValidatorPubKey(ctx, tt.validatorID)
|
|
require.NoError(t, err, "Failed to get validator public key")
|
|
require.NotNil(t, pk)
|
|
require.DeepEqual(t, tt.pk, pk, "Should return validator public key")
|
|
}
|
|
}
|
|
|
|
func TestDeletePublicKey(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
ctx := context.Background()
|
|
|
|
for _, tt := range pkTests {
|
|
require.NoError(t, db.SavePubKey(ctx, tt.validatorID, tt.pk), "Save validator public key failed")
|
|
}
|
|
|
|
for _, tt := range pkTests {
|
|
pk, err := db.ValidatorPubKey(ctx, tt.validatorID)
|
|
require.NoError(t, err, "Failed to get validator public key")
|
|
require.NotNil(t, pk)
|
|
require.DeepEqual(t, tt.pk, pk, "Should return validator public key")
|
|
|
|
err = db.DeletePubKey(ctx, tt.validatorID)
|
|
require.NoError(t, err, "Delete validator public key")
|
|
pk, err = db.ValidatorPubKey(ctx, tt.validatorID)
|
|
require.NoError(t, err)
|
|
require.DeepEqual(t, []byte(nil), pk, "Expected validator public key to be deleted")
|
|
}
|
|
}
|