From b38f00dc02fa60e23d24d5e99137e1afa003f059 Mon Sep 17 00:00:00 2001 From: Junaid <86780488+jdevcs@users.noreply.github.com> Date: Thu, 12 Oct 2023 17:00:05 +0200 Subject: [PATCH 1/2] getRevertReason update for signed Txs (#6497) * checkRevertBeforeSending without v r s part * unit test * changelog * linter fix --- packages/web3-eth/CHANGELOG.md | 1 + packages/web3-eth/src/rpc_method_wrappers.ts | 5 ++- .../send_signed_transaction.test.ts | 37 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index 8ebcda52b5f..9a0c99f76f2 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -200,6 +200,7 @@ Documentation: ### Fixed - Ensure provider.supportsSubscriptions exists before watching by subscription (#6440) +- Fixed param sent to `checkRevertBeforeSending` in `sendSignedTransaction` ### Added diff --git a/packages/web3-eth/src/rpc_method_wrappers.ts b/packages/web3-eth/src/rpc_method_wrappers.ts index 542b1b36d88..9a36f2dc405 100644 --- a/packages/web3-eth/src/rpc_method_wrappers.ts +++ b/packages/web3-eth/src/rpc_method_wrappers.ts @@ -627,8 +627,11 @@ export function sendSignedTransaction< }; try { + const { v , r , s, + ...txWithoutSigParams} = unSerializedTransactionWithFrom; + await sendTxHelper.checkRevertBeforeSending( - unSerializedTransactionWithFrom as TransactionCall, + txWithoutSigParams as TransactionCall, ); sendTxHelper.emitSending(signedTransactionFormattedHex); diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/send_signed_transaction.test.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/send_signed_transaction.test.ts index 9cdb71a7019..4a741c46646 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/send_signed_transaction.test.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/send_signed_transaction.test.ts @@ -28,6 +28,7 @@ import { testData, } from './fixtures/send_signed_transaction'; import { transactionReceiptSchema } from '../../../src/schemas'; +import { SendTxHelper } from '../../../src/utils/send_tx_helper'; jest.mock('web3-rpc-methods'); jest.mock('../../../src/utils/wait_for_transaction_receipt'); @@ -45,6 +46,42 @@ describe('sendTransaction', () => { afterEach(() => jest.resetAllMocks()); + it.each(testData)( + `should remove signature part in transaction before checkRevertBeforeSending`, + async (_, inputSignedTransaction) => { + ( + WaitForTransactionReceipt.waitForTransactionReceipt as jest.Mock + ).mockResolvedValueOnce(expectedTransactionReceipt); + + const checkRevertBeforeSendingSpy = jest.fn().mockImplementation((transaction) => { + expect(transaction).toBeDefined(); + + // verify signature part is removed before sending to revert check function + expect(transaction).not.toHaveProperty('v'); + expect(transaction).not.toHaveProperty('r'); + expect(transaction).not.toHaveProperty('s'); + }); + + SendTxHelper.prototype.checkRevertBeforeSending = checkRevertBeforeSendingSpy; + + const inputSignedTransactionFormatted = format( + { format: 'bytes' }, + inputSignedTransaction, + DEFAULT_RETURN_FORMAT, + ); + await sendSignedTransaction(web3Context, inputSignedTransaction, DEFAULT_RETURN_FORMAT); + + // verify original tx params are intact + expect(ethRpcMethods.sendRawTransaction).toHaveBeenCalledWith( + web3Context.requestManager, + inputSignedTransactionFormatted, + ); + + expect(checkRevertBeforeSendingSpy).toHaveBeenCalledTimes(1); + + }, + ); + it.each(testData)( `sending event should emit with inputSignedTransaction\n ${testMessage}`, async (_, inputSignedTransaction) => { From 6e43d1b78940d795c22d62fc431e09d10ffcab92 Mon Sep 17 00:00:00 2001 From: xiaolou86 <20718693+xiaolou86@users.noreply.github.com> Date: Fri, 13 Oct 2023 02:08:51 +0800 Subject: [PATCH 2/2] Fix typos (#6494) --- .../guides/web3_upgrade_guide/1.x/web3_eth_migration_guide.md | 4 ++-- docs/src/theme/SearchBar/algolia.css | 2 +- packages/web3-eth/test/e2e/e2e_utils.ts | 2 +- packages/web3/test/e2e/e2e_utils.ts | 2 +- scripts/test-runner.sh | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/docs/guides/web3_upgrade_guide/1.x/web3_eth_migration_guide.md b/docs/docs/guides/web3_upgrade_guide/1.x/web3_eth_migration_guide.md index e97578d1c84..10b57e1d261 100644 --- a/docs/docs/guides/web3_upgrade_guide/1.x/web3_eth_migration_guide.md +++ b/docs/docs/guides/web3_upgrade_guide/1.x/web3_eth_migration_guide.md @@ -176,7 +176,7 @@ await web3.eth.getFeeHistory('0x1', 'latest', []); #### sending -- In 1.x, the event listener would receive a `payload` object as an argument. In 4.x, just the sent transaction object is recieved +- In 1.x, the event listener would receive a `payload` object as an argument. In 4.x, just the sent transaction object is received ```typescript // in 1.x @@ -211,7 +211,7 @@ web3.eth.sendTransaction({ ... }).on('sending', (sendTransactionObject) => { ... #### sent -- In 1.x, the event listener would receive a `payload` object as an argument. In 4.x just the sent transaction object is recieved +- In 1.x, the event listener would receive a `payload` object as an argument. In 4.x just the sent transaction object is received ```typescript // in 1.x diff --git a/docs/src/theme/SearchBar/algolia.css b/docs/src/theme/SearchBar/algolia.css index c5590cfa486..8c3782ba827 100644 --- a/docs/src/theme/SearchBar/algolia.css +++ b/docs/src/theme/SearchBar/algolia.css @@ -10,7 +10,7 @@ .algolia-docsearch-suggestion--highlight { color: #3a33d1; } -/* Highligted search terms in the main category headers */ +/* Highlighted search terms in the main category headers */ .algolia-docsearch-suggestion--category-header .algolia-docsearch-suggestion--highlight { background-color: #4d47d5; diff --git a/packages/web3-eth/test/e2e/e2e_utils.ts b/packages/web3-eth/test/e2e/e2e_utils.ts index 6cc6d49e60e..56989fc927d 100644 --- a/packages/web3-eth/test/e2e/e2e_utils.ts +++ b/packages/web3-eth/test/e2e/e2e_utils.ts @@ -28,7 +28,7 @@ import { getSystemTestBackend } from '../fixtures/system_test_utils'; import secrets from '../../../../.secrets.json'; export const getSystemE2ETestProvider = (): string => { - if (process.env.WEB3_SYTEM_TEST_MODE === 'http') { + if (process.env.WEB3_SYSTEM_TEST_MODE === 'http') { return getSystemTestBackend() === 'sepolia' ? process.env.INFURA_SEPOLIA_HTTP ?? secrets.SEPOLIA.HTTP : process.env.INFURA_MAINNET_HTTP ?? secrets.MAINNET.HTTP; diff --git a/packages/web3/test/e2e/e2e_utils.ts b/packages/web3/test/e2e/e2e_utils.ts index 8001e72fc55..cfb680d8b81 100644 --- a/packages/web3/test/e2e/e2e_utils.ts +++ b/packages/web3/test/e2e/e2e_utils.ts @@ -28,7 +28,7 @@ import { getSystemTestBackend } from '../shared_fixtures/system_tests_utils'; import secrets from '../../../../.secrets.json'; export const getSystemE2ETestProvider = (): string => { - if (process.env.WEB3_SYTEM_TEST_MODE === 'http') { + if (process.env.WEB3_SYSTEM_TEST_MODE === 'http') { return getSystemTestBackend() === 'sepolia' ? process.env.INFURA_SEPOLIA_HTTP ?? secrets.SEPOLIA.HTTP : process.env.INFURA_MAINNET_HTTP ?? secrets.MAINNET.HTTP; diff --git a/scripts/test-runner.sh b/scripts/test-runner.sh index 5b60f75b59f..cdb3798e461 100755 --- a/scripts/test-runner.sh +++ b/scripts/test-runner.sh @@ -38,7 +38,7 @@ fi echo "Node software used for tests: " $BACKEND echo "Node running on: " "$MODE://127.0.0.1:$WEB3_SYSTEM_TEST_PORT" -export WEB3_SYTEM_TEST_MODE=$MODE +export WEB3_SYSTEM_TEST_MODE=$MODE export WEB3_SYSTEM_TEST_PROVIDER="$MODE://127.0.0.1:$WEB3_SYSTEM_TEST_PORT" export WEB3_SYSTEM_TEST_BACKEND=$BACKEND export WEB3_SYSTEM_TEST_ENGINE=$ENGINE