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] 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) => {