Skip to content

Commit

Permalink
Merge pull request #1904 from CosmWasm/mark-query-deterministic
Browse files Browse the repository at this point in the history
Mark QuerySmart contract error as deterministic
  • Loading branch information
chipshort authored Jun 19, 2024
2 parents de9c002 + 5465e8c commit ff0a43b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
35 changes: 35 additions & 0 deletions x/wasm/keeper/contract_keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/CosmWasm/wasmd/x/wasm/keeper/testdata"
"github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
"github.com/CosmWasm/wasmd/x/wasm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/v2/types"
)

func TestInstantiate2(t *testing.T) {
Expand Down Expand Up @@ -169,3 +171,36 @@ func TestInstantiate2(t *testing.T) {
})
}
}

func TestQuerierError(t *testing.T) {
parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities)
parentCtx = parentCtx.WithGasMeter(storetypes.NewInfiniteGasMeter())

contract := InstantiateReflectExampleContract(t, parentCtx, keepers)

// this query will fail in the contract because there is no such reply
erroringQuery := testdata.ReflectQueryMsg{
SubMsgResult: &testdata.SubCall{
ID: 1,
},
}
// we make the reflect contract run the erroring query to check if our error stays
queryType := testdata.ReflectQueryMsg{
Chain: &testdata.ChainQuery{
Request: &wasmvmtypes.QueryRequest{
Wasm: &wasmvmtypes.WasmQuery{
Smart: &wasmvmtypes.SmartQuery{
ContractAddr: contract.Contract.String(),
Msg: mustMarshal(t, erroringQuery),
},
},
},
},
}
query := mustMarshal(t, queryType)
_, err := keepers.WasmKeeper.QuerySmart(parentCtx, contract.Contract, query)
require.Error(t, err)

// we expect the contract's "reply 1 not found" to be in there
assert.Contains(t, err.Error(), "reply 1 not found")
}
2 changes: 1 addition & 1 deletion x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ func (k Keeper) QuerySmart(ctx context.Context, contractAddr sdk.AccAddress, req
return nil, errorsmod.Wrap(types.ErrVMError, qErr.Error())
}
if queryResult.Err != "" {
return nil, errorsmod.Wrap(types.ErrQueryFailed, queryResult.Err)
return nil, types.MarkErrorDeterministic(errorsmod.Wrap(types.ErrQueryFailed, queryResult.Err))
}
return queryResult.Ok, nil
}
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/recurse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ func TestLimitRecursiveQueryGas(t *testing.T) {
},
expectQueriesFromContract: 10,
expectOutOfGas: false,
expectError: "query wasm contract failed", // Error we get from the contract instance doing the failing query, not wasmd
expectedGas: 10*(GasWork2k+GasReturnHashed) - 249,
expectError: "query wasm contract failed", // Error we get from the contract instance doing the failing query, not wasmd
expectedGas: 10*(GasWork2k+GasReturnHashed) + 3124, // lots of additional gas for long error message
},
}

Expand Down

0 comments on commit ff0a43b

Please sign in to comment.