Skip to content

Commit

Permalink
Merge branch '4.x' into 6599-implement-providergetfeedata
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba authored Feb 15, 2024
2 parents bb035dd + e774646 commit d9bb9f7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 53 deletions.
4 changes: 2 additions & 2 deletions packages/web3-eth/src/web3_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
* @returns The current fee data.
*
* ```ts
* web3.eth.getFeeData().then(console.log);
* web3.eth.calculateFeeData().then(console.log);
* > {
* gasPrice: 20000000000n,
* maxFeePerGas: 20000000000n,
* maxPriorityFeePerGas: 20000000000n,
* baseFeePerGas: 20000000000n
* }
*
* web3.eth.getFeeData(ethUnitMap.Gwei, 2n).then(console.log);
* web3.eth.calculateFeeData(ethUnitMap.Gwei, 2n).then(console.log);
* > {
* gasPrice: 20000000000n,
* maxFeePerGas: 40000000000n,
Expand Down
117 changes: 66 additions & 51 deletions packages/web3-eth/test/integration/web3_eth/send_transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ import {
createTempAccount,
getSystemTestBackend,
getSystemTestProvider,
isGeth,
itIf,
BACKEND
BACKEND,
} from '../../fixtures/system_test_utils';
import { SimpleRevertAbi, SimpleRevertDeploymentData } from '../../fixtures/simple_revert';

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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()',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -697,7 +712,7 @@ describe('Web3Eth.sendTransaction', () => {
signature: '0x08c379a0',
data: '000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000155468697320697320612073656e64207265766572740000000000000000000000',
};

await expect(
web3Eth
.sendTransaction(transaction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

1 comment on commit d9bb9f7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: d9bb9f7 Previous: 6c075db Ratio
processingTx 9074 ops/sec (±4.57%) 9301 ops/sec (±4.81%) 1.03
processingContractDeploy 42050 ops/sec (±6.86%) 39129 ops/sec (±7.62%) 0.93
processingContractMethodSend 18736 ops/sec (±8.65%) 19443 ops/sec (±5.19%) 1.04
processingContractMethodCall 39021 ops/sec (±5.96%) 38971 ops/sec (±6.34%) 1.00
abiEncode 46320 ops/sec (±7.12%) 44252 ops/sec (±6.92%) 0.96
abiDecode 31410 ops/sec (±8.47%) 30419 ops/sec (±8.89%) 0.97
sign 1649 ops/sec (±3.83%) 1656 ops/sec (±4.08%) 1.00
verify 377 ops/sec (±0.68%) 373 ops/sec (±0.78%) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.