Amount -> Power. Closes #166

This commit is contained in:
Ethan Buchman
2017-09-21 14:59:27 -04:00
parent 5feeb65cf0
commit 3089bbf2b8
15 changed files with 42 additions and 36 deletions
+8 -2
View File
@@ -18,7 +18,7 @@ import (
// GenesisValidator is an initial validator.
type GenesisValidator struct {
PubKey crypto.PubKey `json:"pub_key"`
Amount int64 `json:"amount"`
Power int64 `json:"power"`
Name string `json:"name"`
}
@@ -44,7 +44,7 @@ func (genDoc *GenesisDoc) SaveAs(file string) error {
func (genDoc *GenesisDoc) ValidatorHash() []byte {
vals := make([]*Validator, len(genDoc.Validators))
for i, v := range genDoc.Validators {
vals[i] = NewValidator(v.PubKey, v.Amount)
vals[i] = NewValidator(v.PubKey, v.Power)
}
vset := NewValidatorSet(vals)
return vset.Hash()
@@ -71,6 +71,12 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
return errors.Errorf("The genesis file must have at least one validator")
}
for _, v := range genDoc.Validators {
if v.Power == 0 {
return errors.Errorf("The genesis file cannot contain validators with no voting power: %v", v)
}
}
if genDoc.GenesisTime.IsZero() {
genDoc.GenesisTime = time.Now()
}
+2 -2
View File
@@ -20,7 +20,7 @@ func TestGenesis(t *testing.T) {
[]byte(`{"chain_id": "mychain", "validators": [{}]`), // missing validators
[]byte(`{"validators":[{"pub_key":
{"type":"ed25519","data":"961EAB8752E51A03618502F55C2B6E09C38C65635C64CCF3173ED452CF86C957"},
"amount":10,"name":""}]}`), // missing chain_id
"power":10,"name":""}]}`), // missing chain_id
}
for _, testCase := range testCases {
@@ -29,7 +29,7 @@ func TestGenesis(t *testing.T) {
}
// test a good one by raw json
genDocBytes := []byte(`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[{"pub_key":{"type":"ed25519","data":"961EAB8752E51A03618502F55C2B6E09C38C65635C64CCF3173ED452CF86C957"},"amount":10,"name":""}],"app_hash":""}`)
genDocBytes := []byte(`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[{"pub_key":{"type":"ed25519","data":"961EAB8752E51A03618502F55C2B6E09C38C65635C64CCF3173ED452CF86C957"},"power":10,"name":""}],"app_hash":""}`)
_, err := GenesisDocFromJSON(genDocBytes)
assert.NoError(t, err, "expected no error for good genDoc json")