Skip to content

Commit

Permalink
fix(web3-errors): the undefined data in Eip838ExecutionError (#6905) (#…
Browse files Browse the repository at this point in the history
…7147)

* fix(web3-errors): the undefined data in Eip838ExecutionError (#6905)

* fix(web3-errors): handle the undefined data in Eip838ExecutionError constructor(#6433)

* doc: update changelog

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Muhammad Altabba <24407834+Muhammad-Altabba@users.noreply.github.com>
Co-authored-by: Junaid <86780488+jdevcs@users.noreply.github.com>

* changelog update

---------

Co-authored-by: Xu Jianxiang <xjxtju@163.com>
Co-authored-by: Muhammad Altabba <24407834+Muhammad-Altabba@users.noreply.github.com>
Co-authored-by: Oleksii Kosynskyi <oleksii.kosynskyi@gmail.com>
  • Loading branch information
4 people authored Jul 12, 2024
1 parent 463d070 commit 6b80cf0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/web3-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ Documentation:

- Added `InvalidIntegerError` error for fromWei and toWei (#7052)

## [Unreleased]
## [Unreleased]

### Fixed

- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
2 changes: 1 addition & 1 deletion packages/web3-errors/src/errors/contract_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class Eip838ExecutionError extends Web3ContractError {
// error.data, error.data.data or error.data.originalError.data (https://github.com/web3/web3.js/issues/4454#issuecomment-1485953455)
if (typeof error.data === 'object') {
let originalError: { data: string };
if ('originalError' in error.data) {
if (error.data && 'originalError' in error.data) {
originalError = error.data.originalError;
} else {
// Ganache has no `originalError` sub-object unlike others
Expand Down
11 changes: 11 additions & 0 deletions packages/web3-errors/test/unit/__snapshots__/errors.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ exports[`errors Eip838ExecutionError should get the data from error.data.origina
}
`;

exports[`errors Eip838ExecutionError should return correctly when data is undefined 1`] = `
{
"cause": undefined,
"code": undefined,
"data": undefined,
"innerError": undefined,
"message": "Error",
"name": "Eip838ExecutionError",
}
`;

exports[`errors InvalidConnectionError should have valid json structure 1`] = `
{
"cause": undefined,
Expand Down
7 changes: 7 additions & 0 deletions packages/web3-errors/test/unit/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ describe('errors', () => {
} as JsonRpcError<contractErrors.ProviderErrorData>).toJSON(),
).toMatchSnapshot();
});
it('should return correctly when data is undefined', () => {
expect(
new contractErrors.Eip838ExecutionError({
data: undefined,
} as JsonRpcError<contractErrors.ProviderErrorData>).toJSON(),
).toMatchSnapshot();
});
});

describe('ResponseError', () => {
Expand Down

1 comment on commit 6b80cf0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 6b80cf0 Previous: 463d070 Ratio
processingTx 9439 ops/sec (±3.74%) 9085 ops/sec (±3.80%) 0.96
processingContractDeploy 40790 ops/sec (±6.86%) 39873 ops/sec (±6.00%) 0.98
processingContractMethodSend 16075 ops/sec (±6.85%) 15649 ops/sec (±9.76%) 0.97
processingContractMethodCall 26970 ops/sec (±8.10%) 27135 ops/sec (±6.88%) 1.01
abiEncode 43844 ops/sec (±7.10%) 43610 ops/sec (±6.72%) 0.99
abiDecode 30447 ops/sec (±7.63%) 29967 ops/sec (±8.45%) 0.98
sign 1584 ops/sec (±0.51%) 1496 ops/sec (±3.20%) 0.94
verify 358 ops/sec (±2.93%) 374 ops/sec (±0.41%) 1.04

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.