apply request finalize, fix lint

This commit is contained in:
mossid 2018-10-07 01:08:49 +09:00
parent 7a68b376bd
commit 4bf14c5650
7 changed files with 28 additions and 35 deletions

View File

@ -53,9 +53,11 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
Coins: coins, Coins: coins,
}) })
} }
govGenesis := gov.DefaultGenesisState()
// Default genesis state // Default genesis state
govGenesis := gov.DefaultGenesisState()
stakeGenesis := stake.DefaultGenesisState() stakeGenesis := stake.DefaultGenesisState()
slashingGenesis := slashing.DefaultGenesisState()
var validators []stake.Validator var validators []stake.Validator
var delegations []stake.Delegation var delegations []stake.Delegation
// XXX Try different numbers of initially bonded validators // XXX Try different numbers of initially bonded validators
@ -77,7 +79,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
genesis := GenesisState{ genesis := GenesisState{
Accounts: genesisAccounts, Accounts: genesisAccounts,
StakeData: stakeGenesis, StakeData: stakeGenesis,
SlashingData: slashing.DefaultGenesisState(), SlashingData: slashingGenesis,
GovData: govGenesis, GovData: govGenesis,
} }

View File

@ -1,7 +1,7 @@
package assoc package assoc
import ( import (
// "bytes" "bytes"
"testing" "testing"
"github.com/stretchr/testify/require" "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, addr1), valset.Validator(ctx, addr1))
require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2)) require.Equal(t, base.Validator(ctx, addr2), valset.Validator(ctx, addr2))
// XXX: Will be fixed by #2248 assocs := valset.Associations(ctx, addr1)
// Associations is broken because of prefixstore iterator 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, addr1, assoc2))
require.False(t, valset.Associate(ctx, addr2, assoc1)) require.False(t, valset.Associate(ctx, addr2, assoc1))
valset.Dissociate(ctx, addr1, assoc1) valset.Dissociate(ctx, addr1, assoc1)
valset.Dissociate(ctx, addr2, assoc2) valset.Dissociate(ctx, addr2, assoc2)
require.Equal(t, base.Validator(ctx, addr1), valset.Validator(ctx, addr1)) 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, addr2), valset.Validator(ctx, addr2))
require.Nil(t, valset.Validator(ctx, assoc1)) require.Nil(t, valset.Validator(ctx, assoc1))
require.Nil(t, valset.Validator(ctx, assoc2)) require.Nil(t, valset.Validator(ctx, assoc2))
*/
} }

View File

@ -19,6 +19,7 @@ var (
ParamStoreKeyTallyingProcedure = []byte("tallyingprocedure") ParamStoreKeyTallyingProcedure = []byte("tallyingprocedure")
) )
// Type declaration for parameters
func ParamTable() params.Table { func ParamTable() params.Table {
return params.NewTable( return params.NewTable(
ParamStoreKeyDepositProcedure, DepositProcedure{}, ParamStoreKeyDepositProcedure, DepositProcedure{},

View File

@ -1,7 +1,6 @@
package store package store
import ( import (
"fmt"
"reflect" "reflect"
"github.com/cosmos/cosmos-sdk/codec" "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{}) { func (s Store) Set(ctx sdk.Context, key []byte, param interface{}) {
store := s.kvStore(ctx) store := s.kvStore(ctx)
ty, ok := s.table.m[string(key)] ty, ok := s.table[string(key)]
if !ok { if !ok {
fmt.Println(string(key), ty, param, reflect.TypeOf(param))
panic("Parameter not registered") panic("Parameter not registered")
} }

View File

@ -4,20 +4,16 @@ import (
"reflect" "reflect"
) )
type Table struct { // Table stores appropriate type for each parameter key
m map[string]reflect.Type type Table map[string]reflect.Type
sealed bool
}
// Constructs new table
func NewTable(keytypes ...interface{}) (res Table) { func NewTable(keytypes ...interface{}) (res Table) {
if len(keytypes)%2 != 0 { if len(keytypes)%2 != 0 {
panic("odd number arguments in NewTypeTable") panic("odd number arguments in NewTypeTable")
} }
res = Table{ res = make(map[string]reflect.Type)
m: make(map[string]reflect.Type),
sealed: false,
}
for i := 0; i < len(keytypes); i += 2 { for i := 0; i < len(keytypes); i += 2 {
res = res.RegisterType(keytypes[i].([]byte), keytypes[i+1]) res = res.RegisterType(keytypes[i].([]byte), keytypes[i+1])
@ -26,13 +22,10 @@ func NewTable(keytypes ...interface{}) (res Table) {
return return
} }
// Register single key-type pair
func (t Table) RegisterType(key []byte, ty interface{}) Table { func (t Table) RegisterType(key []byte, ty interface{}) Table {
if t.sealed {
panic("RegisterType() on sealed Table")
}
keystr := string(key) keystr := string(key)
if _, ok := t.m[keystr]; ok { if _, ok := t[keystr]; ok {
panic("duplicate parameter key") panic("duplicate parameter key")
} }
@ -43,11 +36,12 @@ func (t Table) RegisterType(key []byte, ty interface{}) Table {
rty = rty.Elem() rty = rty.Elem()
} }
t.m[keystr] = rty t[keystr] = rty
return t return t
} }
// Register multiple pairs from ParamStruct
func (t Table) RegisterParamStruct(ps ParamStruct) Table { func (t Table) RegisterParamStruct(ps ParamStruct) Table {
for _, kvp := range ps.KeyValuePairs() { for _, kvp := range ps.KeyValuePairs() {
t = t.RegisterType(kvp.Key, kvp.Value) t = t.RegisterType(kvp.Key, kvp.Value)

View File

@ -23,6 +23,7 @@ var (
KeySlashFractionDowntime = []byte("SlashFractionDowntime") KeySlashFractionDowntime = []byte("SlashFractionDowntime")
) )
// ParamTable for slashing module
func ParamTable() params.Table { func ParamTable() params.Table {
return params.NewTable().RegisterParamStruct(&Params{}) return params.NewTable().RegisterParamStruct(&Params{})
} }

View File

@ -13,6 +13,7 @@ const (
DefaultParamspace = "stake" DefaultParamspace = "stake"
) )
// ParamTable for stake module
func ParamTable() params.Table { func ParamTable() params.Table {
return params.NewTable().RegisterParamStruct(&types.Params{}) return params.NewTable().RegisterParamStruct(&types.Params{})
} }