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
|
||||||
terraform.tfstate.backup
|
terraform.tfstate.backup
|
||||||
terraform.tfstate.d
|
terraform.tfstate.d
|
||||||
|
|
||||||
|
.vscode
|
@ -25,7 +25,7 @@ type GenesisDoc struct {
|
|||||||
GenesisTime time.Time `json:"genesis_time"`
|
GenesisTime time.Time `json:"genesis_time"`
|
||||||
ChainID string `json:"chain_id"`
|
ChainID string `json:"chain_id"`
|
||||||
ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"`
|
ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"`
|
||||||
Validators []GenesisValidator `json:"validators"`
|
Validators []GenesisValidator `json:"validators,omitempty"`
|
||||||
AppHash cmn.HexBytes `json:"app_hash"`
|
AppHash cmn.HexBytes `json:"app_hash"`
|
||||||
AppState json.RawMessage `json:"app_state,omitempty"`
|
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 {
|
for _, v := range genDoc.Validators {
|
||||||
if v.Power == 0 {
|
if v.Power == 0 {
|
||||||
return cmn.NewError("The genesis file cannot contain validators with no voting power: %v", v)
|
return cmn.NewError("The genesis file cannot contain validators with no voting power: %v", v)
|
||||||
|
@ -17,12 +17,11 @@ func TestGenesisBad(t *testing.T) {
|
|||||||
[]byte{}, // empty
|
[]byte{}, // empty
|
||||||
[]byte{1, 1, 1, 1, 1}, // junk
|
[]byte{1, 1, 1, 1, 1}, // junk
|
||||||
[]byte(`{}`), // empty
|
[]byte(`{}`), // empty
|
||||||
[]byte(`{"chain_id":"mychain"}`), // missing validators
|
[]byte(`{"chain_id":"mychain","validators":[{}]}`), // invalid validator
|
||||||
[]byte(`{"chain_id":"mychain","validators":[]}`), // missing validators
|
// missing pub_key type
|
||||||
[]byte(`{"chain_id":"mychain","validators":[{}]}`), // missing validators
|
[]byte(`{"validators":[{"pub_key":{"value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||||
[]byte(`{"chain_id":"mychain","validators":null}`), // missing validators
|
// missing chain_id
|
||||||
[]byte(`{"chain_id":"mychain"}`), // missing validators
|
[]byte(`{"validators":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||||
[]byte(`{"validators":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`), // missing chain_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
@ -62,6 +61,19 @@ func TestGenesisGood(t *testing.T) {
|
|||||||
assert.NoError(t, err, "error marshalling genDoc")
|
assert.NoError(t, err, "error marshalling genDoc")
|
||||||
genDoc, err = GenesisDocFromJSON(genDocBytes)
|
genDoc, err = GenesisDocFromJSON(genDocBytes)
|
||||||
assert.Error(t, err, "expected error for genDoc json with block size of 0")
|
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) {
|
func TestGenesisSaveAs(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user