Skip to content

Commit

Permalink
include reason in tx reverts
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Nov 1, 2023
1 parent 1d5cf64 commit b3af0bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion x/fungible/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,15 @@ func (k Keeper) CallEVM(
k.Logger(ctx).Debug("calling EVM", "from", from, "contract", contract, "value", value, "method", method)
resp, err := k.CallEVMWithData(ctx, from, &contract, data, commit, noEthereumTxEvent, value, gasLimit)
if err != nil {
return resp, cosmoserrors.Wrapf(err, "contract call failed: method '%s', contract '%s'", method, contract)
errMes := fmt.Sprintf("contract call failed: method '%s', contract '%s'", method, contract.Hex())

// if it is a revert error then add the revert reason to the error message
revertErr, ok := err.(*evmtypes.RevertError)
if ok {
errMes = fmt.Sprintf("%s, reason: %v", errMes, revertErr.ErrorData())
}

return resp, cosmoserrors.Wrapf(err, errMes)
}
return resp, nil
}
Expand Down
5 changes: 5 additions & 0 deletions x/fungible/keeper/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ func TestKeeper_CallEVMWithData(t *testing.T) {
require.Nil(t, res)
require.True(t, types.IsContractReverted(res, err))

// check reason is included for revert error
// 0xbfb4ebcf is the hash of "Foo()"
require.Contains(t, err.Error(), "reason: 0xbfb4ebcf")

res, err = k.CallEVM(
ctx,
*abi,
Expand Down Expand Up @@ -396,6 +400,7 @@ func TestKeeper_CallEVMWithData(t *testing.T) {
require.Nil(t, res)
require.Error(t, err)
require.False(t, types.IsContractReverted(res, err))
require.NotContains(t, err.Error(), "reason:")

// No revert with successfull call
res, err = k.CallEVM(
Expand Down

0 comments on commit b3af0bd

Please sign in to comment.