-
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.
6801 Fill gas price when baseFeePerGas==='0x0' (#7050)
* Fix gas price filling * fix * fix build * fix lint * add unit test * add unit test * changelog
- Loading branch information
Showing
4 changed files
with
72 additions
and
5 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
58 changes: 58 additions & 0 deletions
58
packages/web3-eth/test/unit/utils/get_transaction_gas_pricing.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,58 @@ | ||
/* | ||
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 { Web3Context } from 'web3-core'; | ||
|
||
import { FMT_BYTES, FMT_NUMBER } from 'web3-types'; | ||
import * as RpcMethodWrappers from '../../../src/rpc_method_wrappers'; | ||
import { getTransactionGasPricing } from '../../../src/utils/get_transaction_gas_pricing'; | ||
|
||
describe('getTransactionGasPricing', () => { | ||
const web3Context = new Web3Context(); | ||
|
||
it('should use the call rpc wrapper', async () => { | ||
const gasPrice = '0x123456'; | ||
const gasPriceSpy = jest | ||
.spyOn(RpcMethodWrappers, 'getGasPrice') | ||
.mockImplementation(async () => gasPrice); | ||
const getBlockSpy = jest | ||
.spyOn(RpcMethodWrappers, 'getBlock') | ||
// @ts-expect-error only for testing purposes | ||
.mockImplementation(async () => ({ | ||
baseFeePerGas: '0x0', | ||
})); | ||
|
||
const transaction = { | ||
from: '0x4fec0a51024b13030d26e70904b066c6d41157a5', | ||
to: '0x36361143b7e2c676f8ccd67743a89d26437f0529', | ||
data: '0x819f48fe', | ||
type: '0x2', | ||
}; | ||
|
||
const res = await getTransactionGasPricing(transaction, web3Context, { | ||
number: FMT_NUMBER.HEX, | ||
bytes: FMT_BYTES.HEX, | ||
}); | ||
|
||
expect(getBlockSpy).toHaveBeenCalled(); | ||
expect(gasPriceSpy).toHaveBeenCalled(); | ||
expect(res).toEqual({ | ||
gasPrice: undefined, | ||
maxPriorityFeePerGas: gasPrice, | ||
maxFeePerGas: gasPrice, | ||
}); | ||
}); | ||
}); |
f4e55bd
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
9157
ops/sec (±3.53%
)9220
ops/sec (±3.39%
)1.01
processingContractDeploy
39854
ops/sec (±6.49%
)37127
ops/sec (±6.27%
)0.93
processingContractMethodSend
19031
ops/sec (±8.97%
)19169
ops/sec (±7.11%
)1.01
processingContractMethodCall
37579
ops/sec (±6.24%
)37740
ops/sec (±5.81%
)1.00
abiEncode
42781
ops/sec (±6.77%
)42093
ops/sec (±6.98%
)0.98
abiDecode
29806
ops/sec (±7.94%
)28578
ops/sec (±7.99%
)0.96
sign
1522
ops/sec (±3.29%
)1542
ops/sec (±0.87%
)1.01
verify
368
ops/sec (±0.73%
)360
ops/sec (±0.57%
)0.98
This comment was automatically generated by workflow using github-action-benchmark.
f4e55bd
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
9252
ops/sec (±3.66%
)9220
ops/sec (±3.39%
)1.00
processingContractDeploy
40465
ops/sec (±5.98%
)37127
ops/sec (±6.27%
)0.92
processingContractMethodSend
20094
ops/sec (±7.18%
)19169
ops/sec (±7.11%
)0.95
processingContractMethodCall
40512
ops/sec (±6.70%
)37740
ops/sec (±5.81%
)0.93
abiEncode
45046
ops/sec (±7.60%
)42093
ops/sec (±6.98%
)0.93
abiDecode
30062
ops/sec (±7.63%
)28578
ops/sec (±7.99%
)0.95
sign
1545
ops/sec (±3.45%
)1542
ops/sec (±0.87%
)1.00
verify
381
ops/sec (±0.59%
)360
ops/sec (±0.57%
)0.94
This comment was automatically generated by workflow using github-action-benchmark.