mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
49a0d3caf0
* Fix a few deps to work with go.mod, check in generated files * Update Gossipsub to 1.1 (#5998) * update libs * add new validators * add new deps * new set of deps * tls * further fix gossip update * get everything to build * clean up * gaz * fix build * fix all tests * add deps to images * imports Co-authored-by: rauljordan <raul@prysmaticlabs.com> * Beacon chain builds with go build * fix bazel * fix dep * lint * Add github action for testing go * on PR for any branch * fix libp2p test failure * Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test * Revert "Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test" This reverts commit 43676894ab01f03fe90a9b8ee3ecfbc2ec1ec4e4. * Compute and set proposer index instead of hard code * Add back go mod/sum, fix deps * go build ./... * Temporarily skip two tests * Fix kafka confluent patch * Fix kafka confluent patch * fix kafka build * fix kafka * Add info in DEPENDENCIES. Added a stub link for Why Bazel? until https://github.com/prysmaticlabs/documentation/issues/138 * Update fuzz ssz files as well * Update fuzz ssz files as well * getting closer * rollback rules_go and gazelle * fix gogo protobuf * install librdkafka-dev as part of github actions * Update kafka to a recent version where librkafkfa is not required for go modules * clarify comment * fix kafka build * disable go tests * comment * Fix geth dependencies for end to end * rename word * lint * fix docker Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: rauljordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
116 lines
2.3 KiB
Go
116 lines
2.3 KiB
Go
package kv
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"flag"
|
|
"testing"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
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.App{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
db := setupDB(t, cli.NewContext(&app, set, nil))
|
|
ctx := context.Background()
|
|
|
|
validatorID := uint64(1)
|
|
|
|
pk, err := db.ValidatorPubKey(ctx, 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.App{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
db := setupDB(t, cli.NewContext(&app, set, nil))
|
|
ctx := context.Background()
|
|
|
|
for _, tt := range pkTests {
|
|
err := db.SavePubKey(ctx, tt.validatorID, tt.pk)
|
|
if err != nil {
|
|
t.Fatalf("save validator public key failed: %v", err)
|
|
}
|
|
|
|
pk, err := db.ValidatorPubKey(ctx, 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.App{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
db := setupDB(t, cli.NewContext(&app, set, nil))
|
|
ctx := context.Background()
|
|
|
|
for _, tt := range pkTests {
|
|
|
|
err := db.SavePubKey(ctx, tt.validatorID, tt.pk)
|
|
if err != nil {
|
|
t.Fatalf("save validator public key failed: %v", err)
|
|
}
|
|
}
|
|
|
|
for _, tt := range pkTests {
|
|
pk, err := db.ValidatorPubKey(ctx, 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(ctx, tt.validatorID)
|
|
if err != nil {
|
|
t.Fatalf("delete validator public key: %v", err)
|
|
}
|
|
pk, err = db.ValidatorPubKey(ctx, tt.validatorID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if pk != nil {
|
|
t.Errorf("Expected validator public key to be deleted, received: %v", pk)
|
|
}
|
|
|
|
}
|
|
|
|
}
|