Add extra error for wasmvm errors
This commit is contained in:
@@ -321,7 +321,7 @@ func (k Keeper) instantiate(
|
||||
res, gasUsed, err := k.wasmVM.Instantiate(codeInfo.CodeHash, env, info, initMsg, vmStore, cosmwasmAPI, querier, k.gasMeter(sdkCtx), gas, costJSONDeserialization)
|
||||
k.consumeRuntimeGas(sdkCtx, gasUsed)
|
||||
if err != nil {
|
||||
return nil, nil, errorsmod.Wrap(types.ErrInstantiateFailed, err.Error())
|
||||
return nil, nil, errorsmod.Wrap(types.ErrVMError, err.Error())
|
||||
}
|
||||
if res.Err != "" {
|
||||
return nil, nil, errorsmod.Wrap(types.ErrInstantiateFailed, res.Err)
|
||||
@@ -334,7 +334,7 @@ func (k Keeper) instantiate(
|
||||
// check for IBC flag
|
||||
report, err := k.wasmVM.AnalyzeCode(codeInfo.CodeHash)
|
||||
if err != nil {
|
||||
return nil, nil, errorsmod.Wrap(types.ErrInstantiateFailed, err.Error())
|
||||
return nil, nil, errorsmod.Wrap(types.ErrVMError, err.Error())
|
||||
}
|
||||
if report.HasIBCEntryPoints {
|
||||
// register IBC port
|
||||
@@ -405,7 +405,7 @@ func (k Keeper) execute(ctx context.Context, contractAddress, caller sdk.AccAddr
|
||||
res, gasUsed, execErr := k.wasmVM.Execute(codeInfo.CodeHash, env, info, msg, prefixStore, cosmwasmAPI, querier, k.gasMeter(sdkCtx), gas, costJSONDeserialization)
|
||||
k.consumeRuntimeGas(sdkCtx, gasUsed)
|
||||
if execErr != nil {
|
||||
return nil, errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error())
|
||||
return nil, errorsmod.Wrap(types.ErrVMError, execErr.Error())
|
||||
}
|
||||
if res.Err != "" {
|
||||
return nil, errorsmod.Wrap(types.ErrExecuteFailed, res.Err)
|
||||
@@ -458,7 +458,7 @@ func (k Keeper) migrate(
|
||||
// check for IBC flag
|
||||
switch report, err := k.wasmVM.AnalyzeCode(newCodeInfo.CodeHash); {
|
||||
case err != nil:
|
||||
return nil, errorsmod.Wrap(types.ErrMigrationFailed, err.Error())
|
||||
return nil, errorsmod.Wrap(types.ErrVMError, err.Error())
|
||||
case !report.HasIBCEntryPoints && contractInfo.IBCPortID != "":
|
||||
// prevent update to non ibc contract
|
||||
return nil, errorsmod.Wrap(types.ErrMigrationFailed, "requires ibc callbacks")
|
||||
@@ -482,7 +482,7 @@ func (k Keeper) migrate(
|
||||
res, gasUsed, err := k.wasmVM.Migrate(newCodeInfo.CodeHash, env, msg, vmStore, cosmwasmAPI, &querier, k.gasMeter(sdkCtx), gas, costJSONDeserialization)
|
||||
k.consumeRuntimeGas(sdkCtx, gasUsed)
|
||||
if err != nil {
|
||||
return nil, errorsmod.Wrap(types.ErrMigrationFailed, err.Error())
|
||||
return nil, errorsmod.Wrap(types.ErrVMError, err.Error())
|
||||
}
|
||||
if res.Err != "" {
|
||||
return nil, errorsmod.Wrap(types.ErrMigrationFailed, res.Err)
|
||||
@@ -547,7 +547,7 @@ func (k Keeper) Sudo(ctx context.Context, contractAddress sdk.AccAddress, msg []
|
||||
res, gasUsed, execErr := k.wasmVM.Sudo(codeInfo.CodeHash, env, msg, prefixStore, cosmwasmAPI, querier, k.gasMeter(sdkCtx), gas, costJSONDeserialization)
|
||||
k.consumeRuntimeGas(sdkCtx, gasUsed)
|
||||
if execErr != nil {
|
||||
return nil, errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error())
|
||||
return nil, errorsmod.Wrap(types.ErrVMError, execErr.Error())
|
||||
}
|
||||
if res.Err != "" {
|
||||
return nil, errorsmod.Wrap(types.ErrExecuteFailed, res.Err)
|
||||
@@ -587,7 +587,7 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply was
|
||||
res, gasUsed, execErr := k.wasmVM.Reply(codeInfo.CodeHash, env, reply, prefixStore, cosmwasmAPI, querier, k.gasMeter(ctx), gas, costJSONDeserialization)
|
||||
k.consumeRuntimeGas(ctx, gasUsed)
|
||||
if execErr != nil {
|
||||
return nil, errorsmod.Wrap(types.ErrExecuteFailed, execErr.Error())
|
||||
return nil, errorsmod.Wrap(types.ErrVMError, execErr.Error())
|
||||
}
|
||||
if res.Err != "" {
|
||||
return nil, errorsmod.Wrap(types.ErrExecuteFailed, res.Err)
|
||||
@@ -773,7 +773,7 @@ func (k Keeper) QuerySmart(ctx context.Context, contractAddr sdk.AccAddress, req
|
||||
queryResult, gasUsed, qErr := k.wasmVM.Query(codeInfo.CodeHash, env, req, prefixStore, cosmwasmAPI, querier, k.gasMeter(sdkCtx), k.runtimeGasForContract(sdkCtx), costJSONDeserialization)
|
||||
k.consumeRuntimeGas(sdkCtx, gasUsed)
|
||||
if qErr != nil {
|
||||
return nil, errorsmod.Wrap(types.ErrQueryFailed, qErr.Error())
|
||||
return nil, errorsmod.Wrap(types.ErrVMError, qErr.Error())
|
||||
}
|
||||
if queryResult.Err != "" {
|
||||
return nil, errorsmod.Wrap(types.ErrQueryFailed, queryResult.Err)
|
||||
|
||||
@@ -1023,9 +1023,9 @@ func TestExecuteWithPanic(t *testing.T) {
|
||||
// let's make sure we get a reasonable error, no panic/crash
|
||||
_, err = keepers.ContractKeeper.Execute(ctx, addr, fred, []byte(`{"panic":{}}`), topUp)
|
||||
require.Error(t, err)
|
||||
require.True(t, errors.Is(err, types.ErrExecuteFailed))
|
||||
require.True(t, errors.Is(err, types.ErrVMError))
|
||||
// test with contains as "Display" implementation of the Wasmer "RuntimeError" is different for Mac and Linux
|
||||
assert.Contains(t, err.Error(), "Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: Aborted: panicked at 'This page intentionally faulted', src/contract.rs:169:5: execute wasm contract failed")
|
||||
assert.Contains(t, err.Error(), "Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: Aborted: panicked at 'This page intentionally faulted', src/contract.rs:169:5: wasmvm error")
|
||||
}
|
||||
|
||||
func TestExecuteWithCpuLoop(t *testing.T) {
|
||||
@@ -1251,7 +1251,7 @@ func TestMigrate(t *testing.T) {
|
||||
initMsg: initMsgBz,
|
||||
fromCodeID: originalCodeID,
|
||||
toCodeID: originalCodeID,
|
||||
expErr: types.ErrMigrationFailed,
|
||||
expErr: types.ErrVMError,
|
||||
},
|
||||
"fail when no IBC callbacks": {
|
||||
admin: fred,
|
||||
|
||||
@@ -264,7 +264,7 @@ 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,
|
||||
expectedGas: 10*(GasWork2k+GasReturnHashed) + 3124,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ func TestRustPanicIsHandled(t *testing.T) {
|
||||
// when panic is triggered
|
||||
msg := []byte(`{"panic":{}}`)
|
||||
gotData, err := keeper.Execute(ctx, contractAddr, creator, msg, nil)
|
||||
require.ErrorIs(t, err, types.ErrExecuteFailed)
|
||||
require.ErrorIs(t, err, types.ErrVMError)
|
||||
assert.Contains(t, err.Error(), "panicked at 'This page intentionally faulted'")
|
||||
assert.Nil(t, gotData)
|
||||
}
|
||||
|
||||
@@ -86,6 +86,9 @@ var (
|
||||
ErrNoSuchCodeFn = WasmVMFlavouredErrorFactory(errorsmod.Register(DefaultCodespace, 28, "no such code"),
|
||||
func(id uint64) error { return wasmvmtypes.NoSuchCode{CodeID: id} },
|
||||
)
|
||||
|
||||
// ErrVMError means an error occurred in wasmvm (not in the contract itself, but in the host environment)
|
||||
ErrVMError = errorsmod.Register(DefaultCodespace, 29, "wasmvm error")
|
||||
)
|
||||
|
||||
// WasmVMErrorable mapped error type in wasmvm and are not redacted
|
||||
|
||||
Reference in New Issue
Block a user