Merge PR #3010: Add Missing genesis checks in Gaia
This commit is contained in:
committed by
Christopher Goes
parent
f11a65dee7
commit
49da96bc09
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
"github.com/cosmos/cosmos-sdk/x/mint"
|
||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -22,12 +24,15 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error {
|
||||
genaccs[i] = NewGenesisAccount(acc)
|
||||
}
|
||||
|
||||
genesisState := GenesisState{
|
||||
Accounts: genaccs,
|
||||
StakeData: stake.DefaultGenesisState(),
|
||||
DistrData: distr.DefaultGenesisState(),
|
||||
SlashingData: slashing.DefaultGenesisState(),
|
||||
}
|
||||
genesisState := NewGenesisState(
|
||||
genaccs,
|
||||
auth.DefaultGenesisState(),
|
||||
stake.DefaultGenesisState(),
|
||||
mint.DefaultGenesisState(),
|
||||
distr.DefaultGenesisState(),
|
||||
gov.DefaultGenesisState(),
|
||||
slashing.DefaultGenesisState(),
|
||||
)
|
||||
|
||||
stateBytes, err := codec.MarshalJSONIndent(gapp.cdc, genesisState)
|
||||
if err != nil {
|
||||
|
||||
+28
-6
@@ -155,20 +155,42 @@ func NewDefaultGenesisState() GenesisState {
|
||||
// TODO: No validators are both bonded and jailed (#2088)
|
||||
// TODO: Error if there is a duplicate validator (#1708)
|
||||
// TODO: Ensure all state machine parameters are in genesis (#1704)
|
||||
func GaiaValidateGenesisState(genesisState GenesisState) (err error) {
|
||||
err = validateGenesisStateAccounts(genesisState.Accounts)
|
||||
func GaiaValidateGenesisState(genesisState GenesisState) error {
|
||||
err := validateGenesisStateAccounts(genesisState.Accounts)
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
// skip stakeData validation as genesis is created from txs
|
||||
if len(genesisState.GenTxs) > 0 {
|
||||
return nil
|
||||
}
|
||||
return stake.ValidateGenesis(genesisState.StakeData)
|
||||
|
||||
err = stake.ValidateGenesis(genesisState.StakeData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = mint.ValidateGenesis(genesisState.MintData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = distr.ValidateGenesis(genesisState.DistrData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = gov.ValidateGenesis(genesisState.GovData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = slashing.ValidateGenesis(genesisState.SlashingData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ensures that there are no duplicate accounts in the genesis state,
|
||||
func validateGenesisStateAccounts(accs []GenesisAccount) (err error) {
|
||||
func validateGenesisStateAccounts(accs []GenesisAccount) error {
|
||||
addrMap := make(map[string]bool, len(accs))
|
||||
for i := 0; i < len(accs); i++ {
|
||||
acc := accs[i]
|
||||
@@ -178,7 +200,7 @@ func validateGenesisStateAccounts(accs []GenesisAccount) (err error) {
|
||||
}
|
||||
addrMap[strAddr] = true
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
// GaiaAppGenState but with JSON
|
||||
|
||||
@@ -172,7 +172,7 @@ func accountInGenesis(genesisState app.GenesisState, key sdk.AccAddress, coins s
|
||||
// Ensure account contains enough funds of default bond denom
|
||||
if coins.AmountOf(bondDenom).GT(acc.Coins.AmountOf(bondDenom)) {
|
||||
return fmt.Errorf(
|
||||
"Account %s is in genesis, but the only has %s%s available to stake, not %s%s",
|
||||
"Account %v is in genesis, but the only has %v%v available to stake, not %v%v",
|
||||
key, acc.Coins.AmountOf(bondDenom), bondDenom, coins.AmountOf(bondDenom), bondDenom,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user