-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '4.x' into ok/6746-Web3.js-Adapter-for-Wagmi-Implementation
- Loading branch information
Showing
6 changed files
with
264 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/web3-eth/test/unit/web3_eth_calculate_fee_data.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
This file is part of web3.js. | ||
web3.js is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
web3.js is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with web3.js. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { ethRpcMethods } from 'web3-rpc-methods'; | ||
|
||
import Web3Eth from '../../src/index'; | ||
|
||
jest.mock('web3-rpc-methods'); | ||
|
||
describe('Web3Eth.calculateFeeData', () => { | ||
let web3Eth: Web3Eth; | ||
|
||
beforeAll(() => { | ||
web3Eth = new Web3Eth('http://127.0.0.1:8545'); | ||
}); | ||
|
||
it('should return call getBlockByNumber, getGasPrice and getMaxPriorityFeePerGas', async () => { | ||
await web3Eth.calculateFeeData(); | ||
// web3Eth.getBlock = jest.fn(); | ||
expect(ethRpcMethods.getBlockByNumber).toHaveBeenCalledWith( | ||
web3Eth.requestManager, | ||
'latest', | ||
false, | ||
); | ||
expect(ethRpcMethods.getGasPrice).toHaveBeenCalledWith(web3Eth.requestManager); | ||
expect(ethRpcMethods.getMaxPriorityFeePerGas).toHaveBeenCalledWith(web3Eth.requestManager); | ||
}); | ||
|
||
it('should calculate fee data', async () => { | ||
const gasPrice = BigInt(20 * 1000); | ||
const baseFeePerGas = BigInt(1000); | ||
const maxPriorityFeePerGas = BigInt(100); | ||
const baseFeePerGasFactor = BigInt(3); | ||
|
||
jest.spyOn(ethRpcMethods, 'getBlockByNumber').mockReturnValueOnce({ baseFeePerGas } as any); | ||
jest.spyOn(ethRpcMethods, 'getGasPrice').mockReturnValueOnce(gasPrice as any); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
jest | ||
.spyOn(ethRpcMethods, 'getMaxPriorityFeePerGas') | ||
.mockReturnValueOnce(maxPriorityFeePerGas as any); | ||
|
||
const feeData = await web3Eth.calculateFeeData(baseFeePerGasFactor, maxPriorityFeePerGas); | ||
expect(feeData).toMatchObject({ | ||
gasPrice, | ||
maxFeePerGas: baseFeePerGas * baseFeePerGasFactor + maxPriorityFeePerGas, | ||
maxPriorityFeePerGas, | ||
baseFeePerGas, | ||
}); | ||
}); | ||
|
||
it('should calculate fee data based on `alternativeMaxPriorityFeePerGas` if `getMaxPriorityFeePerGas` did not return a value', async () => { | ||
const gasPrice = BigInt(20 * 1000); | ||
const baseFeePerGas = BigInt(1000); | ||
const alternativeMaxPriorityFeePerGas = BigInt(700); | ||
const baseFeePerGasFactor = BigInt(3); | ||
|
||
jest.spyOn(ethRpcMethods, 'getBlockByNumber').mockReturnValueOnce({ baseFeePerGas } as any); | ||
jest.spyOn(ethRpcMethods, 'getGasPrice').mockReturnValueOnce(gasPrice as any); | ||
const feeData = await web3Eth.calculateFeeData( | ||
baseFeePerGasFactor, | ||
alternativeMaxPriorityFeePerGas, | ||
); | ||
expect(feeData).toMatchObject({ | ||
gasPrice, | ||
maxFeePerGas: baseFeePerGas * baseFeePerGasFactor + alternativeMaxPriorityFeePerGas, | ||
maxPriorityFeePerGas: alternativeMaxPriorityFeePerGas, | ||
baseFeePerGas, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7743e71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
processingTx
9477
ops/sec (±4.18%
)9301
ops/sec (±4.81%
)0.98
processingContractDeploy
39486
ops/sec (±6.63%
)39129
ops/sec (±7.62%
)0.99
processingContractMethodSend
19671
ops/sec (±7.30%
)19443
ops/sec (±5.19%
)0.99
processingContractMethodCall
39573
ops/sec (±5.40%
)38971
ops/sec (±6.34%
)0.98
abiEncode
46558
ops/sec (±6.44%
)44252
ops/sec (±6.92%
)0.95
abiDecode
31148
ops/sec (±7.68%
)30419
ops/sec (±8.89%
)0.98
sign
1645
ops/sec (±3.36%
)1656
ops/sec (±4.08%
)1.01
verify
381
ops/sec (±0.58%
)373
ops/sec (±0.78%
)0.98
This comment was automatically generated by workflow using github-action-benchmark.