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"
|
prefix = "github.com/prysmaticlabs/prysm"
|
||||||
|
|
||||||
|
exports_files(["genesis.json"])
|
||||||
|
|
||||||
# gazelle:prefix github.com/prysmaticlabs/prysm
|
# gazelle:prefix github.com/prysmaticlabs/prysm
|
||||||
gazelle(
|
gazelle(
|
||||||
name = "gazelle",
|
name = "gazelle",
|
||||||
|
@ -29,11 +29,11 @@ go_test(
|
|||||||
"genesis_json_test.go",
|
"genesis_json_test.go",
|
||||||
"shuffle_test.go",
|
"shuffle_test.go",
|
||||||
],
|
],
|
||||||
|
data = ["//:genesis.json"],
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//proto/beacon/p2p/v1:go_default_library",
|
"//proto/beacon/p2p/v1:go_default_library",
|
||||||
"//shared/params:go_default_library",
|
"//shared/params:go_default_library",
|
||||||
"@com_github_ethereum_go_ethereum//common: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
|
// InitialValidatorRegistryFromJSON retrieves the validator set that is stored in
|
||||||
// genesis.json.
|
// genesis.json.
|
||||||
func InitialValidatorRegistryFromJSON(genesisJSONPath string) ([]*pb.ValidatorRecord, error) {
|
func InitialValidatorRegistryFromJSON(genesisJSONPath string) ([]*pb.ValidatorRecord, error) {
|
||||||
// #nosec G304
|
|
||||||
// genesisJSONPath is a user input for the path of genesis.json.
|
// genesisJSONPath is a user input for the path of genesis.json.
|
||||||
// Ex: /path/to/my/genesis.json.
|
// Ex: /path/to/my/genesis.json.
|
||||||
f, err := os.Open(genesisJSONPath)
|
f, err := os.Open(genesisJSONPath) // #nosec
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/jsonpb"
|
|
||||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||||
"github.com/prysmaticlabs/prysm/shared/params"
|
"github.com/prysmaticlabs/prysm/shared/params"
|
||||||
)
|
)
|
||||||
@ -21,39 +22,31 @@ func TestInitGenesisJsonFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInitGenesisJson(t *testing.T) {
|
func TestInitGenesisJson(t *testing.T) {
|
||||||
fname := "/genesis.json"
|
// Support running this test via bazel or go test.
|
||||||
pwd, _ := os.Getwd()
|
var fNamePath string
|
||||||
fnamePath := pwd + fname
|
if os.Getenv("RUNFILES_DIR") != "" {
|
||||||
os.Remove(fnamePath)
|
fNamePath = fmt.Sprintf("%s/%s/%s",
|
||||||
|
os.Getenv("RUNFILES_DIR"),
|
||||||
|
os.Getenv("TEST_WORKSPACE"),
|
||||||
|
"/genesis.json",
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
fNamePath = "../../genesis.json"
|
||||||
|
}
|
||||||
|
|
||||||
params.UseDemoBeaconConfig()
|
params.UseDemoBeaconConfig()
|
||||||
stateJSON := &pb.BeaconState{
|
state := &pb.BeaconState{
|
||||||
LastStateRecalculationSlot: 0,
|
|
||||||
JustifiedStreak: 1,
|
|
||||||
LastFinalizedSlot: 99,
|
|
||||||
ValidatorRegistry: []*pb.ValidatorRecord{
|
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 {
|
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{}
|
if !reflect.DeepEqual(state.ValidatorRegistry[0], validators[0]) {
|
||||||
err = ma.Marshal(f, stateJSON)
|
t.Error("Validator registry mismatched")
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("can't marshal file %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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",
|
"pubkey": "QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFB",
|
||||||
"balance": "32000000000",
|
"balance": "32000000000",
|
||||||
"exitSlot": "999999999999999999",
|
|
||||||
"status": "1"
|
"status": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pubkey": "QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJC",
|
"pubkey": "QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJC",
|
||||||
"balance": "32000000000",
|
"balance": "32000000000",
|
||||||
"exitSlot": "999999999999999999",
|
|
||||||
"status": "1"
|
"status": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pubkey": "Q0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0ND",
|
"pubkey": "Q0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0ND",
|
||||||
"balance": "32000000000",
|
"balance": "32000000000",
|
||||||
"exitSlot": "999999999999999999",
|
|
||||||
"status": "1"
|
"status": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pubkey": "RERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERE",
|
"pubkey": "RERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERE",
|
||||||
"balance": "32000000000",
|
"balance": "32000000000",
|
||||||
"exitSlot": "999999999999999999",
|
|
||||||
"status": "1"
|
"status": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pubkey": "RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVF",
|
"pubkey": "RUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVF",
|
||||||
"balance": "32000000000",
|
"balance": "32000000000",
|
||||||
"exitSlot": "999999999999999999",
|
|
||||||
"status": "1"
|
"status": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pubkey": "RkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZG",
|
"pubkey": "RkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZG",
|
||||||
"balance": "32000000000",
|
"balance": "32000000000",
|
||||||
"exitSlot": "999999999999999999",
|
|
||||||
"status": "1"
|
"status": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pubkey": "R0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dH",
|
"pubkey": "R0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dH",
|
||||||
"balance": "32000000000",
|
"balance": "32000000000",
|
||||||
"exitSlot": "999999999999999999",
|
|
||||||
"status": "1"
|
"status": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pubkey": "SEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhI",
|
"pubkey": "SEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhI",
|
||||||
"balance": "32000000000",
|
"balance": "32000000000",
|
||||||
"exitSlot": "999999999999999999",
|
|
||||||
"status": "1"
|
"status": "1"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user