From 6a76047d57f6ba63f57256a8d36c3e670e5fb03f Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Tue, 14 Jan 2020 21:31:55 +0100 Subject: [PATCH] Return empty result for unknown raw key query --- x/wasm/internal/keeper/keeper.go | 11 +++++++---- x/wasm/internal/keeper/querier_test.go | 7 +++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index cd66c93..3d1c98a 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -190,10 +190,13 @@ func (k Keeper) QueryRaw(ctx sdk.Context, contractAddress sdk.AccAddress, key [] } prefixStoreKey := types.GetContractStorePrefixKey(contractAddress) prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey) - return []types.Model{{ - Key: string(key), - Value: string(prefixStore.Get(key)), - }} + if val := prefixStore.Get(key); val != nil { + return []types.Model{{ + Key: string(key), + Value: string(val), + }} + } + return []types.Model{} } func (k Keeper) contractInstance(ctx sdk.Context, contractAddress sdk.AccAddress) (types.CodeInfo, prefix.Store, sdk.Error) { diff --git a/x/wasm/internal/keeper/querier_test.go b/x/wasm/internal/keeper/querier_test.go index c8e0766..7ab6f50 100644 --- a/x/wasm/internal/keeper/querier_test.go +++ b/x/wasm/internal/keeper/querier_test.go @@ -88,10 +88,9 @@ func TestQueryContractState(t *testing.T) { //expModelContains: []model{}, // stopping here as contract internals are not stable }, "query unknown raw key": { - srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw}, - srcReq: abci.RequestQuery{Data: []byte("unknown")}, - expModelLen: 1, - expModelContains: []model{{Key: "unknown", Value: ""}}, + srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw}, + srcReq: abci.RequestQuery{Data: []byte("unknown")}, + expModelLen: 0, }, "query empty raw key": { srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw},