Return empty result for unknown raw key query

This commit is contained in:
Alex Peters 2020-01-14 21:31:55 +01:00
parent 1874a6c580
commit 6a76047d57
No known key found for this signature in database
GPG Key ID: BD28388D49EE708D
2 changed files with 10 additions and 8 deletions

View File

@ -190,10 +190,13 @@ func (k Keeper) QueryRaw(ctx sdk.Context, contractAddress sdk.AccAddress, key []
} }
prefixStoreKey := types.GetContractStorePrefixKey(contractAddress) prefixStoreKey := types.GetContractStorePrefixKey(contractAddress)
prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey) prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey)
return []types.Model{{ if val := prefixStore.Get(key); val != nil {
Key: string(key), return []types.Model{{
Value: string(prefixStore.Get(key)), 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) { func (k Keeper) contractInstance(ctx sdk.Context, contractAddress sdk.AccAddress) (types.CodeInfo, prefix.Store, sdk.Error) {

View File

@ -88,10 +88,9 @@ func TestQueryContractState(t *testing.T) {
//expModelContains: []model{}, // stopping here as contract internals are not stable //expModelContains: []model{}, // stopping here as contract internals are not stable
}, },
"query unknown raw key": { "query unknown raw key": {
srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw}, srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw},
srcReq: abci.RequestQuery{Data: []byte("unknown")}, srcReq: abci.RequestQuery{Data: []byte("unknown")},
expModelLen: 1, expModelLen: 0,
expModelContains: []model{{Key: "unknown", Value: ""}},
}, },
"query empty raw key": { "query empty raw key": {
srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw}, srcPath: []string{QueryGetContractState, addr.String(), QueryMethodContractStateRaw},