diff --git a/cmd/gaia/app/sim_test.go b/cmd/gaia/app/sim_test.go index c6ede65a4564..704e45debc32 100644 --- a/cmd/gaia/app/sim_test.go +++ b/cmd/gaia/app/sim_test.go @@ -53,9 +53,11 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage { Coins: coins, }) } - govGenesis := gov.DefaultGenesisState() + // Default genesis state + govGenesis := gov.DefaultGenesisState() stakeGenesis := stake.DefaultGenesisState() + slashingGenesis := slashing.DefaultGenesisState() var validators []stake.Validator var delegations []stake.Delegation // XXX Try different numbers of initially bonded validators @@ -77,7 +79,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage { genesis := GenesisState{ Accounts: genesisAccounts, StakeData: stakeGenesis, - SlashingData: slashing.DefaultGenesisState(), + SlashingData: slashingGenesis, GovData: govGenesis, } diff --git a/examples/democoin/x/assoc/validator_set_test.go b/examples/democoin/x/assoc/validator_set_test.go index 8202a377479c..9fc6526f8d3e 100644 --- a/examples/democoin/x/assoc/validator_set_test.go +++ b/examples/democoin/x/assoc/validator_set_test.go @@ -1,7 +1,7 @@ package assoc import ( - // "bytes" + "bytes" "testing" "github.com/stretchr/testify/require" @@ -53,23 +53,19 @@ func TestValidatorSet(t *testing.T) { require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) - // XXX: Will be fixed by #2248 - // Associations is broken because of prefixstore iterator - /* - assocs := valset.Associations(ctx, addr1) - require.Equal(t, 1, len(assocs)) - require.True(t, bytes.Equal(assoc1, assocs[0])) + assocs := valset.Associations(ctx, addr1) + require.Equal(t, 1, len(assocs)) + require.True(t, bytes.Equal(assoc1, assocs[0])) - require.False(t, valset.Associate(ctx, addr1, assoc2)) - require.False(t, valset.Associate(ctx, addr2, assoc1)) + require.False(t, valset.Associate(ctx, addr1, assoc2)) + require.False(t, valset.Associate(ctx, addr2, assoc1)) - valset.Dissociate(ctx, addr1, assoc1) - valset.Dissociate(ctx, addr2, assoc2) + valset.Dissociate(ctx, addr1, assoc1) + valset.Dissociate(ctx, addr2, assoc2) - require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) - require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) + require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) + require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) - require.Nil(t, valset.Validator(ctx, assoc1)) - require.Nil(t, valset.Validator(ctx, assoc2)) - */ + require.Nil(t, valset.Validator(ctx, assoc1)) + require.Nil(t, valset.Validator(ctx, assoc2)) } diff --git a/x/gov/keeper.go b/x/gov/keeper.go index a4cc209f6098..f231892add88 100644 --- a/x/gov/keeper.go +++ b/x/gov/keeper.go @@ -19,6 +19,7 @@ var ( ParamStoreKeyTallyingProcedure = []byte("tallyingprocedure") ) +// Type declaration for parameters func ParamTable() params.Table { return params.NewTable( ParamStoreKeyDepositProcedure, DepositProcedure{}, diff --git a/x/params/store/store.go b/x/params/store/store.go index 22d5e701e723..95001b544f71 100644 --- a/x/params/store/store.go +++ b/x/params/store/store.go @@ -1,7 +1,6 @@ package store import ( - "fmt" "reflect" "github.com/cosmos/cosmos-sdk/codec" @@ -101,9 +100,8 @@ func (s Store) Modified(ctx sdk.Context, key []byte) bool { func (s Store) Set(ctx sdk.Context, key []byte, param interface{}) { store := s.kvStore(ctx) - ty, ok := s.table.m[string(key)] + ty, ok := s.table[string(key)] if !ok { - fmt.Println(string(key), ty, param, reflect.TypeOf(param)) panic("Parameter not registered") } diff --git a/x/params/store/table.go b/x/params/store/table.go index bab5ca18eed0..f90b85a3a4df 100644 --- a/x/params/store/table.go +++ b/x/params/store/table.go @@ -4,20 +4,16 @@ import ( "reflect" ) -type Table struct { - m map[string]reflect.Type - sealed bool -} +// Table stores appropriate type for each parameter key +type Table map[string]reflect.Type +// Constructs new table func NewTable(keytypes ...interface{}) (res Table) { if len(keytypes)%2 != 0 { panic("odd number arguments in NewTypeTable") } - res = Table{ - m: make(map[string]reflect.Type), - sealed: false, - } + res = make(map[string]reflect.Type) for i := 0; i < len(keytypes); i += 2 { res = res.RegisterType(keytypes[i].([]byte), keytypes[i+1]) @@ -26,13 +22,10 @@ func NewTable(keytypes ...interface{}) (res Table) { return } +// Register single key-type pair func (t Table) RegisterType(key []byte, ty interface{}) Table { - if t.sealed { - panic("RegisterType() on sealed Table") - } - keystr := string(key) - if _, ok := t.m[keystr]; ok { + if _, ok := t[keystr]; ok { panic("duplicate parameter key") } @@ -43,11 +36,12 @@ func (t Table) RegisterType(key []byte, ty interface{}) Table { rty = rty.Elem() } - t.m[keystr] = rty + t[keystr] = rty return t } +// Register multiple pairs from ParamStruct func (t Table) RegisterParamStruct(ps ParamStruct) Table { for _, kvp := range ps.KeyValuePairs() { t = t.RegisterType(kvp.Key, kvp.Value) diff --git a/x/slashing/params.go b/x/slashing/params.go index e6d0945a2d86..f0a411a7e54f 100644 --- a/x/slashing/params.go +++ b/x/slashing/params.go @@ -23,6 +23,7 @@ var ( KeySlashFractionDowntime = []byte("SlashFractionDowntime") ) +// ParamTable for slashing module func ParamTable() params.Table { return params.NewTable().RegisterParamStruct(&Params{}) } diff --git a/x/stake/keeper/params.go b/x/stake/keeper/params.go index ba6cd7416dfd..ce447be5409f 100644 --- a/x/stake/keeper/params.go +++ b/x/stake/keeper/params.go @@ -13,6 +13,7 @@ const ( DefaultParamspace = "stake" ) +// ParamTable for stake module func ParamTable() params.Table { return params.NewTable().RegisterParamStruct(&types.Params{}) }