Skip to content

Commit

Permalink
x/params/types: make KeyTable.RegisterType fully dereference pointers (
Browse files Browse the repository at this point in the history
…cosmos#6915)

Use a for loop to correctly and fully dereference and
extract the type for the type of ParamSetPair.Value.

Fixes cosmos#6785

Co-authored-by: Alexander Bezobchuk <[email protected]>
  • Loading branch information
odeke-em and alexanderbez authored Aug 2, 2020
1 parent c7c66f8 commit 10d330e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions x/params/types/deref_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package types

import (
"reflect"
"testing"

"github.com/stretchr/testify/require"
)

func TestKeyTableUnfurlsPointers(t *testing.T) {
tbl := NewKeyTable()
validator := func(_ interface{}) error {
return nil
}
tbl = tbl.RegisterType(ParamSetPair{
Key: []byte("key"),
Value: (*****string)(nil),
ValidatorFn: validator,
})

got := tbl.m["key"]
want := attribute{
vfn: validator,
ty: reflect.ValueOf("").Type(),
}
require.Equal(t, got.ty, want.ty)
}
2 changes: 1 addition & 1 deletion x/params/types/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (t KeyTable) RegisterType(psp ParamSetPair) KeyTable {
rty := reflect.TypeOf(psp.Value)

// indirect rty if it is a pointer
if rty.Kind() == reflect.Ptr {
for rty.Kind() == reflect.Ptr {
rty = rty.Elem()
}

Expand Down

0 comments on commit 10d330e

Please sign in to comment.