Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC: add data field to RpcError / eth_call error #3547

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/client/src/rpc/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
code: number
message: string
trace?: string
data?: string

Check warning on line 13 in packages/client/src/rpc/helpers.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/rpc/helpers.ts#L13

Added line #L13 was not covered by tests
}

export function callWithStackTrace(handler: Function, debug: boolean) {
Expand All @@ -21,6 +22,7 @@
const e: RpcError = {
code: error.code ?? INTERNAL_ERROR,
message: error.message,
data: error.data,

Check warning on line 25 in packages/client/src/rpc/helpers.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/rpc/helpers.ts#L25

Added line #L25 was not covered by tests
}
if (debug === true) {
e['trace'] = error.stack
Expand Down
7 changes: 7 additions & 0 deletions packages/client/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,13 @@
block,
}
const { execResult } = await vm.evm.runCall(runCallOpts)
if (execResult.exceptionError !== undefined) {
throw {
code: 3,
data: bytesToHex(execResult.returnValue),
message: execResult.exceptionError.error,
}
}

Check warning on line 536 in packages/client/src/rpc/modules/eth.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/rpc/modules/eth.ts#L530-L536

Added lines #L530 - L536 were not covered by tests
return bytesToHex(execResult.returnValue)
}

Expand Down
6 changes: 4 additions & 2 deletions packages/client/test/rpc/eth/call.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
Expand Down
Loading