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

sendTransaction and sendSignedTransaction Error Refactors #5854

Merged
merged 69 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
43d93de
Add payload as optional argument for InvalidResponseError
spacesailor24 Feb 22, 2023
db9cb50
Init Transaction Error Scenarios tests
spacesailor24 Feb 22, 2023
8eb82ba
Init ERR_TX_REVERT_TRANSACTION_CUSTOM_ERROR
spacesailor24 Feb 22, 2023
e4a2891
WIP
spacesailor24 Feb 22, 2023
36c9b0d
WIP
spacesailor24 Feb 23, 2023
2378e6a
Update TransactionRevertedWithoutReasonError to handle receipts objec…
spacesailor24 Feb 24, 2023
044fea2
Update sendTransaction revert tests
spacesailor24 Feb 24, 2023
3a12870
Add contractAbi argument to getTransactionError
spacesailor24 Feb 24, 2023
63554f2
sendTransation emits error for ContractExecutionError
spacesailor24 Feb 24, 2023
8c33881
Add ContractExecutionError to SendTransactionEvents. Add contractAbi …
spacesailor24 Feb 24, 2023
853d0b2
Replace use of contractExecutionError sendTransaction event with error
spacesailor24 Feb 24, 2023
bd4ff70
Update contract_methods reverts test
spacesailor24 Feb 24, 2023
75a99f2
Merge branch '4.x' into wyatt/4.x/5840-requstmanger-return-errors
spacesailor24 Feb 24, 2023
d075a86
Update web3-errors test
spacesailor24 Feb 24, 2023
2b59dc6
Update expected error mesage for contract_deploy_test
spacesailor24 Feb 24, 2023
7e830d2
Add expectedErrorObject based on test backend
spacesailor24 Feb 24, 2023
91a4e6f
Correct web3-errors test snapshots
spacesailor24 Feb 24, 2023
ff142e0
fix (#5869)
avkos Feb 24, 2023
8948973
5747 codecov (#5843)
jdevcs Feb 28, 2023
c39aab2
ens system tests (#5849)
nikoulai Feb 28, 2023
3cb0a27
Disconnect function doesn't exists in types of currentProvider (#5865)
avkos Feb 28, 2023
c951bb7
Nikos/fix ens event test (#5880)
nikoulai Mar 1, 2023
b2c21b2
update event emitter geth ipc tests (#5874)
Mar 1, 2023
af78858
4.x issue stale conf (#5878)
jdevcs Mar 2, 2023
77d6fa0
Add documentation for catching provider events (#5886)
Muhammad-Altabba Mar 6, 2023
e5c59af
Fixing tests for WS and IPC
spacesailor24 Feb 24, 2023
de1fe5e
Remove jest specific test code that doesn't work in Cypress
spacesailor24 Feb 24, 2023
f334a9e
Remove jest specific test code that doesn't work in Cypress
spacesailor24 Feb 24, 2023
71e8f1b
Remove jest specific test code
spacesailor24 Feb 24, 2023
de2f1cf
Add toLowerCase for address
spacesailor24 Feb 24, 2023
4205577
Rename TransactionRevertError to TransactionRevertInstructionError
spacesailor24 Feb 25, 2023
a66aaf0
Add beforeAll for Transaction Error Scenario tests
spacesailor24 Feb 25, 2023
284f4ad
Add Transaction Error Scenario tests for call
spacesailor24 Feb 25, 2023
19aadcc
Add support for handleRevert in sendTransaction for geth
spacesailor24 Feb 25, 2023
5376bc8
Update tests and add test to verify event error is same as thrown error
spacesailor24 Feb 25, 2023
662a390
Correct test expected data
spacesailor24 Feb 25, 2023
81be9d8
Remove message from expectedThrownError for sendTransaction tests
spacesailor24 Feb 25, 2023
0f655a5
Add error refactors to sendSignedTransaction and init tests
spacesailor24 Feb 25, 2023
a1d1a56
Remove call Transaction Error Scenario tests
spacesailor24 Feb 25, 2023
d7ce12f
Fix type error
spacesailor24 Feb 25, 2023
dc03c22
Fix nonce issue in tests
spacesailor24 Feb 25, 2023
32add6d
Fix error parsing bug for web3Eth.sendSignedTransaction
spacesailor24 Mar 1, 2023
66b7377
Update expected error for send_signed_transaction error tests
spacesailor24 Mar 1, 2023
b998f8f
Revert ResponseError change to maintain 1.x parity
spacesailor24 Mar 2, 2023
35293d6
Add web3-errors test for TransactionRevertWithCustomError
spacesailor24 Mar 2, 2023
68efd93
Update expected error message for RespnoseError in web3-eth-contract …
spacesailor24 Mar 2, 2023
d6fc658
Add example to dev comment for sendSignedTransaction
spacesailor24 Mar 2, 2023
3d3e7bc
Removed implemented TODO in packages/web3-eth/src/utils/get_transacti…
spacesailor24 Mar 2, 2023
64a3e1f
Update CHANGELOGs
spacesailor24 Mar 2, 2023
fedc918
Update CHANGELOG.md
spacesailor24 Mar 2, 2023
c54d2b9
Init get_transaction_error tests
spacesailor24 Mar 2, 2023
683515c
Add mock to getRevertReason for get_transaction_error tests
spacesailor24 Mar 2, 2023
547f9be
Init getRevertReason tests and parseTransactionError tests
spacesailor24 Mar 2, 2023
9e3c637
Add check for revert before sending tx
spacesailor24 Mar 3, 2023
f4f43f8
Update web3-plugin-example test to account for getRevertReason check
spacesailor24 Mar 7, 2023
d72206c
Turn off checkRevertBeforeSending for sendFewTxes helper
spacesailor24 Mar 7, 2023
2b816bf
Fix test data for send_signed_transaction tests
spacesailor24 Mar 7, 2023
c4180b6
Fix bug in get_transaction_error
spacesailor24 Mar 7, 2023
306b650
Fix send_transaction error test
spacesailor24 Mar 7, 2023
76ee3da
Add checkRevertBeforeSending: false to sendTransaction calls in Contr…
spacesailor24 Mar 7, 2023
bcffc9f
Add checkRevertBeforeSending: false for send tx test helpers
spacesailor24 Mar 7, 2023
2828b41
Remove getRevertReason mock
spacesailor24 Mar 8, 2023
5838adf
A fix at `IpcProvider` and few changes at `SocketProvider` and its de…
Muhammad-Altabba Mar 7, 2023
e79e59f
Fix failed tx test for ganache
spacesailor24 Mar 8, 2023
a2175ff
Update expected transaction errors for ganache
spacesailor24 Mar 9, 2023
5cbb9bf
Fix method handler crashed (#5905)
avkos Mar 8, 2023
e267663
Test fix
spacesailor24 Mar 9, 2023
2662eaf
Use `v1` instead of Short Sha for cloudflare/pages-action (#5909)
Muhammad-Altabba Mar 9, 2023
c216751
Merge branch '4.x' into wyatt/4.x/5840-requstmanger-return-errors
spacesailor24 Mar 9, 2023
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
Prev Previous commit
Next Next commit
Init getRevertReason tests and parseTransactionError tests
  • Loading branch information
spacesailor24 committed Mar 9, 2023
commit 547f9bedf97c3cb4ac53f1f85f4f44ee32f95969
125 changes: 125 additions & 0 deletions packages/web3-eth/test/unit/utils/get_revert_reason.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { Web3Context } from 'web3-core';
import { DEFAULT_RETURN_FORMAT } from 'web3-utils';

import * as RpcMethodWrappers from '../../../src/rpc_method_wrappers';
import * as GetRevertReason from '../../../src/utils/get_revert_reason';
import { SimpleRevertAbi } from '../../fixtures/simple_revert';

describe('getRevertReason', () => {
const web3Context = new Web3Context();

it('should use the call rpc wrapper', async () => {
const callSpy = jest.spyOn(RpcMethodWrappers, 'call').mockImplementation();

const transaction = {
from: '0x4fec0a51024b13030d26e70904b066c6d41157a5',
to: '0x36361143b7e2c676f8ccd67743a89d26437f0529',
data: '0x819f48fe',
gasPrice: '0x15ab8f14',
maxPriorityFeePerGas: undefined,
maxFeePerGas: undefined,
};

await GetRevertReason.getRevertReason(web3Context, transaction);

expect(callSpy).toHaveBeenCalledWith(
web3Context,
transaction,
web3Context.defaultBlock,
DEFAULT_RETURN_FORMAT,
);
});

it('should return undefined', async () => {
jest.spyOn(RpcMethodWrappers, 'call').mockResolvedValueOnce(
'0x000000000000000000000000000000000000000000000000000000000000000a',
);

const transaction = {
from: '0x4fec0a51024b13030d26e70904b066c6d41157a5',
to: '0x36361143b7e2c676f8ccd67743a89d26437f0529',
data: '0x819f48fe',
gasPrice: '0x15ab8f14',
maxPriorityFeePerGas: undefined,
maxFeePerGas: undefined,
};

const result = await GetRevertReason.getRevertReason(web3Context, transaction);

expect(result).toBeUndefined();
});

it('should call parseTransactionError without contractAbi', async () => {
const expectedError = {
jsonrpc: '2.0',
id: 1,
error: {
code: -32000,
message:
'err: insufficient funds for gas * price + value: address 0x0000000000000000000000000000000000000000 have 66 want 9983799287684 (supplied gas 26827)',
},
};
const parseTransactionErrorSpy = jest
.spyOn(GetRevertReason, 'parseTransactionError')
.mockImplementation();
jest.spyOn(RpcMethodWrappers, 'call').mockRejectedValueOnce(expectedError);

const transaction = {
from: '0x4fec0a51024b13030d26e70904b066c6d41157a5',
to: '0x36361143b7e2c676f8ccd67743a89d26437f0529',
data: '0x819f48fe',
gasPrice: '0x15ab8f14',
maxPriorityFeePerGas: undefined,
maxFeePerGas: undefined,
};

await GetRevertReason.getRevertReason(web3Context, transaction);

expect(parseTransactionErrorSpy).toHaveBeenCalledWith(expectedError, undefined);
});

it('should call parseTransactionError with contractAbi', async () => {
const expectedError = {
jsonrpc: '2.0',
id: 1,
error: {
code: -32000,
message:
'err: insufficient funds for gas * price + value: address 0x0000000000000000000000000000000000000000 have 66 want 9983799287684 (supplied gas 26827)',
},
};
const parseTransactionErrorSpy = jest
.spyOn(GetRevertReason, 'parseTransactionError')
.mockImplementation();
jest.spyOn(RpcMethodWrappers, 'call').mockRejectedValueOnce(expectedError);

const transaction = {
from: '0x4fec0a51024b13030d26e70904b066c6d41157a5',
to: '0x36361143b7e2c676f8ccd67743a89d26437f0529',
data: '0x819f48fe',
gasPrice: '0x15ab8f14',
maxPriorityFeePerGas: undefined,
maxFeePerGas: undefined,
};

await GetRevertReason.getRevertReason(web3Context, transaction, SimpleRevertAbi);

expect(parseTransactionErrorSpy).toHaveBeenCalledWith(expectedError, SimpleRevertAbi);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { ContractExecutionError, InvalidResponseError } from 'web3-errors';

import { parseTransactionError } from '../../../src/utils/get_revert_reason';
import { SimpleRevertAbi } from '../../fixtures/simple_revert';

describe('parseTransactionError', () => {
it('should return object of type RevertReason', () => {
const error = new ContractExecutionError({
code: 3,
message: 'execution reverted: This is a send revert',
data: '0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000155468697320697320612073656e64207265766572740000000000000000000000',
});

const result = parseTransactionError(error);
expect(result).toStrictEqual({
reason: 'execution reverted: This is a send revert',
signature: '0x08c379a0',
data: '000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000155468697320697320612073656e64207265766572740000000000000000000000',
});
});

it('should return object of type RevertReasonWithCustomError', () => {
const error = new ContractExecutionError({
code: 3,
message: 'execution reverted',
data: '0xc85bda60000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001c5468697320697320616e206572726f72207769746820706172616d7300000000',
});

const result = parseTransactionError(error, SimpleRevertAbi);
expect(result).toStrictEqual({
reason: 'execution reverted',
signature: '0xc85bda60',
data: '000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001c5468697320697320616e206572726f72207769746820706172616d7300000000',
customErrorName: 'ErrorWithParams',
customErrorDecodedSignature: 'ErrorWithParams(uint256,string)',
customErrorArguments: {
'0': BigInt(42),
'1': 'This is an error with params',
__length__: 2,
code: BigInt(42),
message: 'This is an error with params',
},
});
});

it('should return object of type string', () => {
const error = new InvalidResponseError({
jsonrpc: '2.0',
id: '3f839900-afdd-4553-bca7-b4e2b835c687',
error: { code: -32000, message: 'intrinsic gas too low' },
});

const result = parseTransactionError(error);
expect(result).toBe('intrinsic gas too low');
});

it('should throw an error', () => {
const error = new InvalidResponseError([
{
jsonrpc: '2.0',
id: '3f839900-afdd-4553-bca7-b4e2b835c687',
error: { code: -32000, message: 'intrinsic gas too low' },
},
{
jsonrpc: '2.0',
id: '3f839900-afdd-4553-bca7-b4e2b835c687',
error: { code: -32000, message: 'intrinsic gas too low' },
},
]);

expect(() => parseTransactionError(error)).toThrowError(error);
});
});