Skip to content

Commit

Permalink
apply request finalize, fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mossid committed Oct 6, 2018
1 parent 7a68b37 commit 4bf14c5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
6 changes: 4 additions & 2 deletions cmd/gaia/app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}

Expand Down
28 changes: 12 additions & 16 deletions examples/democoin/x/assoc/validator_set_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package assoc

import (
// "bytes"
"bytes"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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))
}
1 change: 1 addition & 0 deletions x/gov/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
ParamStoreKeyTallyingProcedure = []byte("tallyingprocedure")
)

// Type declaration for parameters
func ParamTable() params.Table {
return params.NewTable(
ParamStoreKeyDepositProcedure, DepositProcedure{},
Expand Down
4 changes: 1 addition & 3 deletions x/params/store/store.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package store

import (
"fmt"
"reflect"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -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")
}

Expand Down
22 changes: 8 additions & 14 deletions x/params/store/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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")
}

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions x/slashing/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
KeySlashFractionDowntime = []byte("SlashFractionDowntime")
)

// ParamTable for slashing module
func ParamTable() params.Table {
return params.NewTable().RegisterParamStruct(&Params{})
}
Expand Down
1 change: 1 addition & 0 deletions x/stake/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
DefaultParamspace = "stake"
)

// ParamTable for stake module
func ParamTable() params.Table {
return params.NewTable().RegisterParamStruct(&types.Params{})
}
Expand Down

0 comments on commit 4bf14c5

Please sign in to comment.