diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index a74dad67ed..c55b494485 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -360,15 +360,14 @@ func (b *SimulatedBackend) CallContract(ctx context.Context, call ethereum.CallM if err != nil { return nil, err } - // If the result contains a revert reason, unpack and return it. + // If the result contains a revert reason, try to unpack and return it. if res.Err != nil && len(res.Revert()) > 0 { reason, err := abi.UnpackRevert(res.Revert()) - if err != nil { - return nil, err + if err == nil { + return nil, fmt.Errorf("execution reverted: %v", reason) } - return nil, fmt.Errorf("execution reverted: %v", reason) } - return res.Return(), nil + return res.Return(), res.Err } // PendingCallContract executes a contract call on the pending state. @@ -381,15 +380,14 @@ func (b *SimulatedBackend) PendingCallContract(ctx context.Context, call ethereu if err != nil { return nil, err } - // If the result contains a revert reason, unpack and return it. + // If the result contains a revert reason, try to unpack and return it. if res.Err != nil && len(res.Revert()) > 0 { reason, err := abi.UnpackRevert(res.Revert()) - if err != nil { - return nil, err + if err == nil { + return nil, fmt.Errorf("execution reverted: %v", reason) } - return nil, fmt.Errorf("execution reverted: %v", reason) } - return res.Return(), nil + return res.Return(), res.Err } // PendingNonceAt implements PendingStateReader.PendingNonceAt, retrieving diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index e49e2e136a..563250ea1e 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -861,15 +861,14 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo if evm.Cancelled() { return nil, fmt.Errorf("execution aborted (timeout = %v)", timeout) } - // If the result contains a revert reason, unpack and return it. - if result.Err != nil && len(result.Revert()) > 0 { - reason, err := abi.UnpackRevert(result.Revert()) - if err != nil { - return nil, err + // If the result contains a revert reason, try to unpack and return it. + if res.Err != nil && len(res.Revert()) > 0 { + reason, err := abi.UnpackRevert(res.Revert()) + if err == nil { + return nil, fmt.Errorf("execution reverted: %v", reason) } - return nil, fmt.Errorf("execution reverted: %v", reason) } - return result, err + return result, res.Err } // Call executes the given transaction on the state for the given block number.