Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gno.land/pkg/gnoland/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestNewAppWithOptions(t *testing.T) {
{"params/vm:gno.land/r/sys/testrealm:bar_uint64", `"1337"`},
{"params/vm:gno.land/r/sys/testrealm:bar_bool", `true`},
{"params/vm:gno.land/r/sys/testrealm:bar_strings", `["some","strings"]`},
{"params/vm:gno.land/r/sys/testrealm:bar_bytes", `"SGkh"`}, // XXX: make this test more readable
{"params/vm:gno.land/r/sys/testrealm:bar_bytes", string([]byte{0x48, 0x69, 0x21})},
}

for _, tc := range tcs {
Expand Down
7 changes: 2 additions & 5 deletions gno.land/pkg/gnoland/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (m *mockParamsKeeper) GetString(ctx sdk.Context, key string, ptr *string)
func (m *mockParamsKeeper) GetInt64(ctx sdk.Context, key string, ptr *int64) {}
func (m *mockParamsKeeper) GetUint64(ctx sdk.Context, key string, ptr *uint64) {}
func (m *mockParamsKeeper) GetBool(ctx sdk.Context, key string, ptr *bool) {}
func (m *mockParamsKeeper) GetBytes(ctx sdk.Context, key string, ptr *[]byte) {}
func (m *mockParamsKeeper) GetBytes(ctx sdk.Context, key string) []byte { return nil }
func (m *mockParamsKeeper) GetStrings(ctx sdk.Context, key string, ptr *[]string) {}

func (m *mockParamsKeeper) SetString(ctx sdk.Context, key string, value string) {}
Expand All @@ -181,10 +181,7 @@ func (m *mockParamsKeeper) SetBool(ctx sdk.Context, key string, value bool)
func (m *mockParamsKeeper) SetBytes(ctx sdk.Context, key string, value []byte) {}
func (m *mockParamsKeeper) SetStrings(ctx sdk.Context, key string, value []string) {}

func (m *mockParamsKeeper) Has(ctx sdk.Context, key string) bool { return false }
func (m *mockParamsKeeper) GetRaw(ctx sdk.Context, key string) []byte { return nil }
func (m *mockParamsKeeper) SetRaw(ctx sdk.Context, key string, value []byte) {}

func (m *mockParamsKeeper) Has(ctx sdk.Context, key string) bool { return false }
func (m *mockParamsKeeper) GetStruct(ctx sdk.Context, key string, strctPtr any) {}
func (m *mockParamsKeeper) SetStruct(ctx sdk.Context, key string, strct any) {}

Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/sdk/params/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (bh paramsHandler) Query(ctx sdk.Context, req abci.RequestQuery) (res abci.
std.ErrUnknownRequest(fmt.Sprintf("module not registered: %q", module)))
return
}
val := bh.params.GetRaw(ctx, rest)
val := bh.params.GetBytes(ctx, rest)
res.Data = val
return

Expand Down
9 changes: 5 additions & 4 deletions tm2/pkg/sdk/params/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"strings"
"testing"

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

abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
bft "github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/sdk"
tu "github.com/gnolang/gno/tm2/pkg/sdk/testutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestInvalidMsg(t *testing.T) {
Expand All @@ -35,7 +36,7 @@ func TestArbitraryParamsQuery(t *testing.T) {
{path: "params/" + dummyModuleName + ":bar_int64", expected: `"-12345"`},
{path: "params/" + dummyModuleName + ":bar_uint64", expected: `"4242"`},
{path: "params/" + dummyModuleName + ":bar_bool", expected: "true"},
{path: "params/" + dummyModuleName + ":bar_bytes", expected: `"YmF6"`},
{path: "params/" + dummyModuleName + ":bar_bytes", expected: `baz`},
}

for _, tc := range tcs {
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestModuleParamsQuery(t *testing.T) {
{path: "params/params_test:foo/bar.int64", expected: `"-12345"`},
{path: "params/params_test:foo/bar.uint64", expected: `"4242"`},
{path: "params/params_test:foo/bar.bool", expected: "true"},
{path: "params/params_test:foo/bar.bytes", expected: `"YmF6"`},
{path: "params/params_test:foo/bar.bytes", expected: `baz`},
}

for _, tc := range tcs {
Expand Down
34 changes: 7 additions & 27 deletions tm2/pkg/sdk/params/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ type ParamsKeeperI interface {
GetInt64(ctx sdk.Context, key string, ptr *int64)
GetUint64(ctx sdk.Context, key string, ptr *uint64)
GetBool(ctx sdk.Context, key string, ptr *bool)
GetBytes(ctx sdk.Context, key string, ptr *[]byte)
GetStrings(ctx sdk.Context, key string, ptr *[]string)

SetString(ctx sdk.Context, key string, value string)
SetInt64(ctx sdk.Context, key string, value int64)
SetUint64(ctx sdk.Context, key string, value uint64)
SetBool(ctx sdk.Context, key string, value bool)
SetBytes(ctx sdk.Context, key string, value []byte)
SetStrings(ctx sdk.Context, key string, value []string)

Has(ctx sdk.Context, key string) bool
GetRaw(ctx sdk.Context, key string) []byte
SetRaw(ctx sdk.Context, key string, value []byte)
GetBytes(ctx sdk.Context, key string) []byte
SetBytes(ctx sdk.Context, key string, value []byte)

GetStruct(ctx sdk.Context, key string, strctPtr any)
SetStruct(ctx sdk.Context, key string, strct any)
Expand Down Expand Up @@ -126,8 +124,8 @@ func (pk ParamsKeeper) GetUint64(ctx sdk.Context, key string, ptr *uint64) {
pk.getIfExists(ctx, key, ptr)
}

func (pk ParamsKeeper) GetBytes(ctx sdk.Context, key string, ptr *[]byte) {
pk.getIfExists(ctx, key, ptr)
func (pk ParamsKeeper) GetBytes(ctx sdk.Context, key string) []byte {
return ctx.Store(pk.key).Get(storeKey(key))
}

func (pk ParamsKeeper) GetStrings(ctx sdk.Context, key string, ptr *[]string) {
Expand All @@ -151,23 +149,13 @@ func (pk ParamsKeeper) SetUint64(ctx sdk.Context, key string, value uint64) {
}

func (pk ParamsKeeper) SetBytes(ctx sdk.Context, key string, value []byte) {
pk.set(ctx, key, value)
ctx.Store(pk.key).Set(storeKey(key), value)
}

func (pk ParamsKeeper) SetStrings(ctx sdk.Context, key string, value []string) {
pk.set(ctx, key, value)
}

func (pk ParamsKeeper) GetRaw(ctx sdk.Context, key string) []byte {
stor := ctx.Store(pk.key)
return stor.Get(storeKey(key))
}

func (pk ParamsKeeper) SetRaw(ctx sdk.Context, key string, value []byte) {
stor := ctx.Store(pk.key)
stor.Set(storeKey(key), value)
}

func (pk ParamsKeeper) GetStruct(ctx sdk.Context, key string, strctPtr any) {
parts := strings.Split(key, ":")
if len(parts) != 2 {
Expand Down Expand Up @@ -299,8 +287,8 @@ func (ppk prefixParamsKeeper) GetBool(ctx sdk.Context, key string, ptr *bool) {
ppk.pk.GetBool(ctx, ppk.prefixed(key), ptr)
}

func (ppk prefixParamsKeeper) GetBytes(ctx sdk.Context, key string, ptr *[]byte) {
ppk.pk.GetBytes(ctx, ppk.prefixed(key), ptr)
func (ppk prefixParamsKeeper) GetBytes(ctx sdk.Context, key string) []byte {
return ppk.pk.GetBytes(ctx, ppk.prefixed(key))
}

func (ppk prefixParamsKeeper) GetStrings(ctx sdk.Context, key string, ptr *[]string) {
Expand Down Expand Up @@ -335,14 +323,6 @@ func (ppk prefixParamsKeeper) Has(ctx sdk.Context, key string) bool {
return ppk.pk.Has(ctx, ppk.prefixed(key))
}

func (ppk prefixParamsKeeper) GetRaw(ctx sdk.Context, key string) []byte {
return ppk.pk.GetRaw(ctx, ppk.prefixed(key))
}

func (ppk prefixParamsKeeper) SetRaw(ctx sdk.Context, key string, value []byte) {
ppk.pk.SetRaw(ctx, ppk.prefixed(key), value)
}

func (ppk prefixParamsKeeper) GetStruct(ctx sdk.Context, key string, paramPtr any) {
ppk.pk.GetStruct(ctx, ppk.prefixed(key), paramPtr)
}
Expand Down
7 changes: 4 additions & 3 deletions tm2/pkg/sdk/params/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"reflect"
"testing"

"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/stretchr/testify/require"

"github.com/gnolang/gno/tm2/pkg/amino"
)

func TestKeeper(t *testing.T) {
Expand Down Expand Up @@ -44,7 +45,7 @@ func TestKeeper(t *testing.T) {
require.NotPanics(t, func() { keeper.GetBool(ctx, "param2", &param2) })
require.NotPanics(t, func() { keeper.GetUint64(ctx, "param3", &param3) })
require.NotPanics(t, func() { keeper.GetInt64(ctx, "param4", &param4) })
require.NotPanics(t, func() { keeper.GetBytes(ctx, "param5", &param5) })
require.NotPanics(t, func() { param5 = keeper.GetBytes(ctx, "param5") })

require.Equal(t, param1, "foo")
require.Equal(t, param2, true)
Expand All @@ -69,7 +70,7 @@ func TestKeeper(t *testing.T) {
require.NotPanics(t, func() { keeper.GetBool(ctx, "param2", &param2) })
require.NotPanics(t, func() { keeper.GetUint64(ctx, "param3", &param3) })
require.NotPanics(t, func() { keeper.GetInt64(ctx, "param4", &param4) })
require.NotPanics(t, func() { keeper.GetBytes(ctx, "param5", &param5) })
require.NotPanics(t, func() { param5 = keeper.GetBytes(ctx, "param5") })

require.Equal(t, param1, "bar")
require.Equal(t, param2, false)
Expand Down
Loading