Skip to content

Commit

Permalink
getRevertReason update for signed Txs (#6497)
Browse files Browse the repository at this point in the history
* checkRevertBeforeSending without v r s part

* unit test

* changelog

* linter fix
  • Loading branch information
jdevcs authored Oct 12, 2023
1 parent 9a5fd87 commit b38f00d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/web3-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ Documentation:
### Fixed

- Ensure provider.supportsSubscriptions exists before watching by subscription (#6440)
- Fixed param sent to `checkRevertBeforeSending` in `sendSignedTransaction`

### Added

Expand Down
5 changes: 4 additions & 1 deletion packages/web3-eth/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) => {
Expand Down

0 comments on commit b38f00d

Please sign in to comment.