mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 05:38:55 +00:00
85653335f1
* Standardize params for BeaconChain and Validator projects * gofmt * various changes to bring up to standards * lint * linter 2, not sure why travis complains * revert service_test.go
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/gogo/protobuf/jsonpb"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
func TestInitGenesisJsonFailure(t *testing.T) {
|
|
fname := "/genesis.json"
|
|
pwd, _ := os.Getwd()
|
|
fnamePath := pwd + fname
|
|
|
|
_, err := InitialValidatorsFromJSON(fnamePath)
|
|
if err == nil {
|
|
t.Fatalf("genesis.json should have failed %v", err)
|
|
}
|
|
}
|
|
|
|
func TestInitGenesisJson(t *testing.T) {
|
|
fname := "/genesis.json"
|
|
pwd, _ := os.Getwd()
|
|
fnamePath := pwd + fname
|
|
os.Remove(fnamePath)
|
|
|
|
params.UseDemoBeaconConfig()
|
|
cStateJSON := &pb.CrystallizedState{
|
|
LastStateRecalculationSlot: 0,
|
|
JustifiedStreak: 1,
|
|
LastFinalizedSlot: 99,
|
|
Validators: []*pb.ValidatorRecord{
|
|
{Pubkey: []byte{}, Balance: 32, Status: uint64(params.Active)},
|
|
},
|
|
}
|
|
os.Create(fnamePath)
|
|
f, err := os.OpenFile(fnamePath, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
|
if err != nil {
|
|
t.Fatalf("can't open file %v", err)
|
|
}
|
|
|
|
ma := jsonpb.Marshaler{}
|
|
err = ma.Marshal(f, cStateJSON)
|
|
if err != nil {
|
|
t.Fatalf("can't marshal file %v", err)
|
|
}
|
|
|
|
validators, err := InitialValidatorsFromJSON(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)
|
|
}
|