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

View File

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