From b3af0bdf41c86ea6ff247e96fe3d5d10f521b7cc Mon Sep 17 00:00:00 2001 From: lumtis Date: Tue, 31 Oct 2023 17:49:17 -0700 Subject: [PATCH] include reason in tx reverts --- x/fungible/keeper/evm.go | 10 +++++++++- x/fungible/keeper/evm_test.go | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/x/fungible/keeper/evm.go b/x/fungible/keeper/evm.go index 8606804bea..f0683deb60 100644 --- a/x/fungible/keeper/evm.go +++ b/x/fungible/keeper/evm.go @@ -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 } diff --git a/x/fungible/keeper/evm_test.go b/x/fungible/keeper/evm_test.go index e7cf9b91e4..80bd42a2f3 100644 --- a/x/fungible/keeper/evm_test.go +++ b/x/fungible/keeper/evm_test.go @@ -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, @@ -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(