diff --git a/packages/client/src/rpc/helpers.ts b/packages/client/src/rpc/helpers.ts index 99528f452a..75f282dbdf 100644 --- a/packages/client/src/rpc/helpers.ts +++ b/packages/client/src/rpc/helpers.ts @@ -10,6 +10,7 @@ type RpcError = { code: number message: string trace?: string + data?: string } export function callWithStackTrace(handler: Function, debug: boolean) { @@ -21,6 +22,7 @@ export function callWithStackTrace(handler: Function, debug: boolean) { const e: RpcError = { code: error.code ?? INTERNAL_ERROR, message: error.message, + data: error.data, } if (debug === true) { e['trace'] = error.stack diff --git a/packages/client/src/rpc/modules/eth.ts b/packages/client/src/rpc/modules/eth.ts index e874293daf..86d303501c 100644 --- a/packages/client/src/rpc/modules/eth.ts +++ b/packages/client/src/rpc/modules/eth.ts @@ -527,6 +527,13 @@ export class Eth { block, } const { execResult } = await vm.evm.runCall(runCallOpts) + if (execResult.exceptionError !== undefined) { + throw { + code: 3, + data: bytesToHex(execResult.returnValue), + message: execResult.exceptionError.error, + } + } return bytesToHex(execResult.returnValue) } diff --git a/packages/client/test/rpc/eth/call.spec.ts b/packages/client/test/rpc/eth/call.spec.ts index 53cdad15a1..98ff195b83 100644 --- a/packages/client/test/rpc/eth/call.spec.ts +++ b/packages/client/test/rpc/eth/call.spec.ts @@ -101,15 +101,17 @@ describe(method, () => { { ...estimateTxData, gas: estimateTxData.gasLimit }, 'latest', ]) + assert.equal(res.error.code, 3, 'should return the correct error code') assert.equal( - res.result, + res.error.data, bytesToHex(execResult.returnValue), 'should return the correct return value', ) res = await rpc.request(method, [{ ...estimateTxData }, 'latest']) + assert.equal(res.error.code, 3, 'should return the correct error code') assert.equal( - res.result, + res.error.data, bytesToHex(execResult.returnValue), 'should return the correct return value with no gas limit provided', )