diff --git a/packages/web3-eth/src/web3_eth.ts b/packages/web3-eth/src/web3_eth.ts index 93693490dae..3c1165b0e3c 100644 --- a/packages/web3-eth/src/web3_eth.ts +++ b/packages/web3-eth/src/web3_eth.ts @@ -270,7 +270,7 @@ export class Web3Eth extends Web3Context { * gasPrice: 20000000000n, * maxFeePerGas: 20000000000n, @@ -278,7 +278,7 @@ export class Web3Eth extends Web3Context { * gasPrice: 20000000000n, * maxFeePerGas: 40000000000n, diff --git a/packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts b/packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts index c1693fd7f68..9018381bd6a 100644 --- a/packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts +++ b/packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts @@ -37,8 +37,9 @@ import { createTempAccount, getSystemTestBackend, getSystemTestProvider, + isGeth, itIf, - BACKEND + BACKEND, } from '../../fixtures/system_test_utils'; import { SimpleRevertAbi, SimpleRevertDeploymentData } from '../../fixtures/simple_revert'; @@ -89,9 +90,7 @@ describe('Web3Eth.sendTransaction', () => { expect(response.status).toBe(BigInt(1)); expect(response.events).toBeUndefined(); - const minedTransactionData = await web3EthWithWallet.getTransaction( - response.transactionHash, - ); + const minedTransactionData = await web3EthWithWallet.getTransaction(response.transactionHash); expect(minedTransactionData).toMatchObject({ from: tempAcc.address, @@ -120,9 +119,7 @@ describe('Web3Eth.sendTransaction', () => { expect(response.status).toBe(BigInt(1)); expect(response.events).toBeUndefined(); - const minedTransactionData = await web3EthWithWallet.getTransaction( - response.transactionHash, - ); + const minedTransactionData = await web3EthWithWallet.getTransaction(response.transactionHash); expect(minedTransactionData).toMatchObject({ from: tempAcc.address, @@ -155,9 +152,7 @@ describe('Web3Eth.sendTransaction', () => { expect(response.status).toBe(BigInt(1)); expect(response.events).toBeUndefined(); - const minedTransactionData = await web3EthWithWallet.getTransaction( - response.transactionHash, - ); + const minedTransactionData = await web3EthWithWallet.getTransaction(response.transactionHash); expect(minedTransactionData).toMatchObject({ from: tempAcc.address, @@ -411,6 +406,29 @@ describe('Web3Eth.sendTransaction', () => { expect(minedTransactionData).toMatchObject(transaction); }); + itIf(isGeth)( + 'should send type 0x2 transaction with maxPriorityFeePerGas got from await web3Eth.getMaxPriorityFeePerGas()', + async () => { + const transaction: Transaction = { + from: tempAcc.address, + to: '0x0000000000000000000000000000000000000000', + value: BigInt(1), + maxPriorityFeePerGas: await web3Eth.getMaxPriorityFeePerGas(), + }; + const response = await web3Eth.sendTransaction(transaction); + + // eslint-disable-next-line jest/no-standalone-expect + expect(response.events).toBeUndefined(); + // eslint-disable-next-line jest/no-standalone-expect + expect(response.type).toBe(BigInt(2)); + // eslint-disable-next-line jest/no-standalone-expect + expect(response.status).toBe(BigInt(1)); + const minedTransactionData = await web3Eth.getTransaction(response.transactionHash); + // eslint-disable-next-line jest/no-standalone-expect + expect(minedTransactionData).toMatchObject(transaction); + }, + ); + describe('Transaction PromiEvents', () => { let transaction: Transaction; @@ -516,12 +534,9 @@ describe('Web3Eth.sendTransaction', () => { from: tempAcc.address, data: SimpleRevertDeploymentData, }; - simpleRevertDeployTransaction.gas = await web3Eth.estimateGas( - simpleRevertDeployTransaction, - ); - simpleRevertContractAddress = ( - await web3Eth.sendTransaction(simpleRevertDeployTransaction) - ).contractAddress as Address; + simpleRevertDeployTransaction.gas = await web3Eth.estimateGas(simpleRevertDeployTransaction); + simpleRevertContractAddress = (await web3Eth.sendTransaction(simpleRevertDeployTransaction)) + .contractAddress as Address; }); it('Should throw TransactionRevertInstructionError because gas too low', async () => { @@ -540,51 +555,51 @@ describe('Web3Eth.sendTransaction', () => { ? 'err: intrinsic gas too low: have 1, want 21000 (supplied gas 1)' : 'base fee exceeds gas limit', }; - - if(getSystemTestBackend() !== BACKEND.HARDHAT){ + + if (getSystemTestBackend() !== BACKEND.HARDHAT) { await expect( web3Eth .sendTransaction(transaction) .on('error', error => expect(error).toMatchObject(expectedThrownError)), ).rejects.toMatchObject(expectedThrownError); } else { - try { await web3Eth.sendTransaction(transaction); - } catch (error) { + } catch (error) { expect((error as any).name).toEqual(expectedThrownError.name); expect((error as any).code).toEqual(expectedThrownError.code); expect((error as any).reason).toContain(expectedThrownError.reason); - } + } } }); - itIf(getSystemTestBackend() !== BACKEND.HARDHAT)('Should throw TransactionRevertInstructionError because insufficient funds', async () => { - const transaction: Transaction = { - from: tempAcc.address, - to: '0x0000000000000000000000000000000000000000', - value: BigInt('99999999999999999999999999999999999999999999999999999999999999999'), - }; - - const expectedThrownError = { - name: 'TransactionRevertInstructionError', - message: 'Transaction has been reverted by the EVM', - code: 402, - reason: - getSystemTestBackend() === BACKEND.GETH - ? expect.stringContaining( - 'err: insufficient funds for gas * price + value: address', - ) - : 'VM Exception while processing transaction: insufficient balance', - }; - - // eslint-disable-next-line jest/no-standalone-expect - await expect( - web3Eth - .sendTransaction(transaction) - // eslint-disable-next-line jest/no-standalone-expect - .on('error', error => expect(error).toMatchObject(expectedThrownError)), - ).rejects.toMatchObject(expectedThrownError); - }); + itIf(getSystemTestBackend() !== BACKEND.HARDHAT)( + 'Should throw TransactionRevertInstructionError because insufficient funds', + async () => { + const transaction: Transaction = { + from: tempAcc.address, + to: '0x0000000000000000000000000000000000000000', + value: BigInt('99999999999999999999999999999999999999999999999999999999999999999'), + }; + + const expectedThrownError = { + name: 'TransactionRevertInstructionError', + message: 'Transaction has been reverted by the EVM', + code: 402, + reason: + getSystemTestBackend() === BACKEND.GETH + ? expect.stringContaining('err: insufficient funds for gas * price + value: address') + : 'VM Exception while processing transaction: insufficient balance', + }; + + // eslint-disable-next-line jest/no-standalone-expect + await expect( + web3Eth + .sendTransaction(transaction) + // eslint-disable-next-line jest/no-standalone-expect + .on('error', error => expect(error).toMatchObject(expectedThrownError)), + ).rejects.toMatchObject(expectedThrownError); + }, + ); it('Should throw TransactionRevertInstructionError because of contract revert and return revert reason', async () => { const transaction: Transaction = { @@ -629,7 +644,7 @@ describe('Web3Eth.sendTransaction', () => { reason: getSystemTestBackend() === BACKEND.GETH ? 'execution reverted' - : "Error: VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0x72090e4d)", + : 'Error: VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0x72090e4d)', signature: '0x72090e4d', customErrorName: 'ErrorWithNoParams', customErrorDecodedSignature: 'ErrorWithNoParams()', @@ -659,7 +674,7 @@ describe('Web3Eth.sendTransaction', () => { reason: getSystemTestBackend() === BACKEND.GETH ? 'execution reverted' - : "Error: VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0xc85bda60000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001c5468697320697320616e206572726f72207769746820706172616d7300000000)", + : 'Error: VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0xc85bda60000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001c5468697320697320616e206572726f72207769746820706172616d7300000000)', signature: '0xc85bda60', data: '000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001c5468697320697320616e206572726f72207769746820706172616d7300000000', customErrorName: 'ErrorWithParams', @@ -697,7 +712,7 @@ describe('Web3Eth.sendTransaction', () => { signature: '0x08c379a0', data: '000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000155468697320697320612073656e64207265766572740000000000000000000000', }; - + await expect( web3Eth .sendTransaction(transaction) diff --git a/packages/web3-eth/test/unit/web3_eth_methods_no_parameters.test.ts b/packages/web3-eth/test/unit/web3_eth_methods_no_parameters.test.ts index 6865188b456..a66a1ecdd46 100644 --- a/packages/web3-eth/test/unit/web3_eth_methods_no_parameters.test.ts +++ b/packages/web3-eth/test/unit/web3_eth_methods_no_parameters.test.ts @@ -76,5 +76,10 @@ describe('web3_eth_methods_no_parameters', () => { await web3Eth.getNodeInfo(); expect(ethRpcMethods.getNodeInfo).toHaveBeenCalledWith(web3Eth.requestManager); }); + + it('getMaxPriorityFeePerGas', async () => { + await web3Eth.getMaxPriorityFeePerGas(); + expect(ethRpcMethods.getMaxPriorityFeePerGas).toHaveBeenCalledWith(web3Eth.requestManager); + }); }); });