mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Updated Genesis JSON and Fixed Test (#1044)
This commit is contained in:
parent
d3055531b9
commit
3e8c2b2957
@ -5,6 +5,8 @@ load("@io_kubernetes_build//defs:run_in_workspace.bzl", "workspace_binary")
|
||||
|
||||
prefix = "github.com/prysmaticlabs/prysm"
|
||||
|
||||
exports_files(["genesis.json"])
|
||||
|
||||
# gazelle:prefix github.com/prysmaticlabs/prysm
|
||||
gazelle(
|
||||
name = "gazelle",
|
||||
|
@ -29,11 +29,11 @@ go_test(
|
||||
"genesis_json_test.go",
|
||||
"shuffle_test.go",
|
||||
],
|
||||
data = ["//:genesis.json"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//proto/beacon/p2p/v1:go_default_library",
|
||||
"//shared/params:go_default_library",
|
||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||
"@com_github_gogo_protobuf//jsonpb:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -11,10 +11,9 @@ import (
|
||||
// InitialValidatorRegistryFromJSON retrieves the validator set that is stored in
|
||||
// genesis.json.
|
||||
func InitialValidatorRegistryFromJSON(genesisJSONPath string) ([]*pb.ValidatorRecord, error) {
|
||||
// #nosec G304
|
||||
// genesisJSONPath is a user input for the path of genesis.json.
|
||||
// Ex: /path/to/my/genesis.json.
|
||||
f, err := os.Open(genesisJSONPath)
|
||||
f, err := os.Open(genesisJSONPath) // #nosec
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/jsonpb"
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
@ -21,39 +22,31 @@ func TestInitGenesisJsonFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInitGenesisJson(t *testing.T) {
|
||||
fname := "/genesis.json"
|
||||
pwd, _ := os.Getwd()
|
||||
fnamePath := pwd + fname
|
||||
os.Remove(fnamePath)
|
||||
// Support running this test via bazel or go test.
|
||||
var fNamePath string
|
||||
if os.Getenv("RUNFILES_DIR") != "" {
|
||||
fNamePath = fmt.Sprintf("%s/%s/%s",
|
||||
os.Getenv("RUNFILES_DIR"),
|
||||
os.Getenv("TEST_WORKSPACE"),
|
||||
"/genesis.json",
|
||||
)
|
||||
} else {
|
||||
fNamePath = "../../genesis.json"
|
||||
}
|
||||
|
||||
params.UseDemoBeaconConfig()
|
||||
stateJSON := &pb.BeaconState{
|
||||
LastStateRecalculationSlot: 0,
|
||||
JustifiedStreak: 1,
|
||||
LastFinalizedSlot: 99,
|
||||
state := &pb.BeaconState{
|
||||
ValidatorRegistry: []*pb.ValidatorRecord{
|
||||
{Pubkey: []byte{}, Balance: 32, Status: uint64(params.Active)},
|
||||
{Pubkey: []byte("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), Balance: 32000000000, Status: uint64(params.Active)},
|
||||
},
|
||||
}
|
||||
os.Create(fnamePath)
|
||||
f, err := os.OpenFile(fnamePath, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||
|
||||
validators, err := InitialValidatorRegistryFromJSON(fNamePath)
|
||||
if err != nil {
|
||||
t.Fatalf("can't open file %v", err)
|
||||
t.Fatalf("Reading validatory registry from genesis.json failed %v", err)
|
||||
}
|
||||
|
||||
ma := jsonpb.Marshaler{}
|
||||
err = ma.Marshal(f, stateJSON)
|
||||
if err != nil {
|
||||
t.Fatalf("can't marshal file %v", err)
|
||||
if !reflect.DeepEqual(state.ValidatorRegistry[0], validators[0]) {
|
||||
t.Error("Validator registry mismatched")
|
||||
}
|
||||
|
||||
validators, err := InitialValidatorRegistryFromJSON(fnamePath)
|
||||
if err != nil {
|
||||
t.Fatalf("genesis.json failed %v", err)
|
||||
}
|
||||
|
||||
if validators[0].Status != 1 {
|
||||
t.Errorf("Failed to load of genesis json")
|
||||
}
|
||||
os.Remove(fnamePath)
|
||||
}
|
||||
|
10
genesis.json
10
genesis.json
@ -1,51 +1,43 @@
|
||||
{
|
||||
"validators": [
|
||||
"validatorRegistry": [
|
||||
{
|
||||
"pubkey": "QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB",
|
||||
"balance": "32000000000",
|
||||
"exitSlot": "999999999999999999",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"pubkey": "QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJC",
|
||||
"balance": "32000000000",
|
||||
"exitSlot": "999999999999999999",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"pubkey": "Q0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0ND",
|
||||
"balance": "32000000000",
|
||||
"exitSlot": "999999999999999999",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"pubkey": "RERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERE",
|
||||
"balance": "32000000000",
|
||||
"exitSlot": "999999999999999999",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"pubkey": "RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVF",
|
||||
"balance": "32000000000",
|
||||
"exitSlot": "999999999999999999",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"pubkey": "RkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZG",
|
||||
"balance": "32000000000",
|
||||
"exitSlot": "999999999999999999",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"pubkey": "R0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dH",
|
||||
"balance": "32000000000",
|
||||
"exitSlot": "999999999999999999",
|
||||
"status": "1"
|
||||
},
|
||||
{
|
||||
"pubkey": "SEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhI",
|
||||
"balance": "32000000000",
|
||||
"exitSlot": "999999999999999999",
|
||||
"status": "1"
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user