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,
})
}
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,
}

View File

@ -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))
}

View File

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

View File

@ -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")
}

View File

@ -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)

View File

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

View File

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