Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark QuerySmart contract error as deterministic #1904

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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.Equal(t, "Generic error: Querier contract error: reply 1 not found: query wasm contract failed: query wasm contract failed", err.Error())
chipshort marked this conversation as resolved.
Show resolved Hide resolved
}
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