mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
types: allow genesis file to have 0 validators (#2148)
* fixing issue 2015 * Remove comments for code review * Update tests
This commit is contained in:
parent
89668c3179
commit
0f931eeb10
2
.gitignore
vendored
2
.gitignore
vendored
@ -37,3 +37,5 @@ addrbook.json
|
||||
terraform.tfstate
|
||||
terraform.tfstate.backup
|
||||
terraform.tfstate.d
|
||||
|
||||
.vscode
|
@ -25,7 +25,7 @@ type GenesisDoc struct {
|
||||
GenesisTime time.Time `json:"genesis_time"`
|
||||
ChainID string `json:"chain_id"`
|
||||
ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"`
|
||||
Validators []GenesisValidator `json:"validators"`
|
||||
Validators []GenesisValidator `json:"validators,omitempty"`
|
||||
AppHash cmn.HexBytes `json:"app_hash"`
|
||||
AppState json.RawMessage `json:"app_state,omitempty"`
|
||||
}
|
||||
@ -65,10 +65,6 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
||||
}
|
||||
}
|
||||
|
||||
if len(genDoc.Validators) == 0 {
|
||||
return cmn.NewError("The genesis file must have at least one validator")
|
||||
}
|
||||
|
||||
for _, v := range genDoc.Validators {
|
||||
if v.Power == 0 {
|
||||
return cmn.NewError("The genesis file cannot contain validators with no voting power: %v", v)
|
||||
|
@ -14,15 +14,14 @@ import (
|
||||
func TestGenesisBad(t *testing.T) {
|
||||
// test some bad ones from raw json
|
||||
testCases := [][]byte{
|
||||
[]byte{}, // empty
|
||||
[]byte{1, 1, 1, 1, 1}, // junk
|
||||
[]byte(`{}`), // empty
|
||||
[]byte(`{"chain_id":"mychain"}`), // missing validators
|
||||
[]byte(`{"chain_id":"mychain","validators":[]}`), // missing validators
|
||||
[]byte(`{"chain_id":"mychain","validators":[{}]}`), // missing validators
|
||||
[]byte(`{"chain_id":"mychain","validators":null}`), // missing validators
|
||||
[]byte(`{"chain_id":"mychain"}`), // missing validators
|
||||
[]byte(`{"validators":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`), // missing chain_id
|
||||
[]byte{}, // empty
|
||||
[]byte{1, 1, 1, 1, 1}, // junk
|
||||
[]byte(`{}`), // empty
|
||||
[]byte(`{"chain_id":"mychain","validators":[{}]}`), // invalid validator
|
||||
// missing pub_key type
|
||||
[]byte(`{"validators":[{"pub_key":{"value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||
// missing chain_id
|
||||
[]byte(`{"validators":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
@ -62,6 +61,19 @@ func TestGenesisGood(t *testing.T) {
|
||||
assert.NoError(t, err, "error marshalling genDoc")
|
||||
genDoc, err = GenesisDocFromJSON(genDocBytes)
|
||||
assert.Error(t, err, "expected error for genDoc json with block size of 0")
|
||||
|
||||
// Genesis doc from raw json
|
||||
missingValidatorsTestCases := [][]byte{
|
||||
[]byte(`{"chain_id":"mychain"}`), // missing validators
|
||||
[]byte(`{"chain_id":"mychain","validators":[]}`), // missing validators
|
||||
[]byte(`{"chain_id":"mychain","validators":null}`), // nil validator
|
||||
[]byte(`{"chain_id":"mychain"}`), // missing validators
|
||||
}
|
||||
|
||||
for _, tc := range missingValidatorsTestCases {
|
||||
_, err := GenesisDocFromJSON(tc)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenesisSaveAs(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user