Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 29febb8

Browse files
spacesailor24brg8
andauthored
Add block tag support for eth_feeHistory (#4224)
* Accept predefined block numbers for eth_feeHistory (#4213) * Accept predefined block numbers for eth_feeHistory * Update feeHistory tests to reflect new input formatter Co-authored-by: Wyatt Barnes <[email protected]> * Add block tag tests * Update CHANGELOG * Replace inputFormatter with null to match existing code Co-authored-by: brg8 <[email protected]>
1 parent c474f8f commit 29febb8

File tree

3 files changed

+114
-2
lines changed

3 files changed

+114
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,5 @@ Released with 1.0.0-beta.37 code base.
424424

425425
- `maxPriorityFeePerGas` and `maxFeePerGas` now included in `_txInputFormatter` (#4217)
426426
- If `maxPriorityFeePerGas` of `maxFeePerGas` present `_txInputFormatter` deletes `tx.gasPrice` (fixes #4211) (#4217)
427+
- Add block tag support (e.g. `latest`, `pending`, `earliest`) to `getFeeHistory` (#4224)
427428
- Support for EIP-1559 to `web3.eth.sendTransaction` (#4220)

packages/web3-eth/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ var Eth = function Eth() {
389389
name: 'getFeeHistory',
390390
call: 'eth_feeHistory',
391391
params: 3,
392-
inputFormatter: [utils.toNumber, utils.toHex, function(value) {return value}]
392+
inputFormatter: [utils.toNumber, formatter.inputBlockNumberFormatter, null]
393393
}),
394394
new Method({
395395
name: 'getAccounts',

test/eth.feeHistory.js

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var methodCall = 'eth_feeHistory';
88
var tests = [
99
{
1010
args: [4, "0xA30953", []],
11-
formattedArgs: [4, "0xA30953", []],
11+
formattedArgs: [4, "0xa30953", []],
1212
result: {
1313
"baseFeePerGas": [
1414
"0xa",
@@ -116,6 +116,117 @@ var tests = [
116116
"oldestBlock": 10684752
117117
},
118118
call: methodCall
119+
},
120+
{
121+
args: [4, 'latest', []],
122+
formattedArgs: [4, 'latest', []],
123+
result: {
124+
"baseFeePerGas": [
125+
"0xa",
126+
"0x9",
127+
"0x8",
128+
"0x9",
129+
"0x9"
130+
],
131+
"gasUsedRatio": [
132+
0.003920375,
133+
0.002625,
134+
0.904999125,
135+
0.348347625
136+
],
137+
"oldestBlock": 10684752
138+
},
139+
formattedResult: {
140+
"baseFeePerGas": [
141+
"0xa",
142+
"0x9",
143+
"0x8",
144+
"0x9",
145+
"0x9"
146+
],
147+
"gasUsedRatio": [
148+
0.003920375,
149+
0.002625,
150+
0.904999125,
151+
0.348347625
152+
],
153+
"oldestBlock": 10684752
154+
},
155+
call: methodCall
156+
},
157+
{
158+
args: [4, 'earliest', []],
159+
formattedArgs: [4, 'earliest', []],
160+
result: {
161+
"baseFeePerGas": [
162+
"0xa",
163+
"0x9",
164+
"0x8",
165+
"0x9",
166+
"0x9"
167+
],
168+
"gasUsedRatio": [
169+
0.003920375,
170+
0.002625,
171+
0.904999125,
172+
0.348347625
173+
],
174+
"oldestBlock": 10684752
175+
},
176+
formattedResult: {
177+
"baseFeePerGas": [
178+
"0xa",
179+
"0x9",
180+
"0x8",
181+
"0x9",
182+
"0x9"
183+
],
184+
"gasUsedRatio": [
185+
0.003920375,
186+
0.002625,
187+
0.904999125,
188+
0.348347625
189+
],
190+
"oldestBlock": 10684752
191+
},
192+
call: methodCall
193+
},
194+
{
195+
args: [4, 'pending', []],
196+
formattedArgs: [4, 'pending', []],
197+
result: {
198+
"baseFeePerGas": [
199+
"0xa",
200+
"0x9",
201+
"0x8",
202+
"0x9",
203+
"0x9"
204+
],
205+
"gasUsedRatio": [
206+
0.003920375,
207+
0.002625,
208+
0.904999125,
209+
0.348347625
210+
],
211+
"oldestBlock": 10684752
212+
},
213+
formattedResult: {
214+
"baseFeePerGas": [
215+
"0xa",
216+
"0x9",
217+
"0x8",
218+
"0x9",
219+
"0x9"
220+
],
221+
"gasUsedRatio": [
222+
0.003920375,
223+
0.002625,
224+
0.904999125,
225+
0.348347625
226+
],
227+
"oldestBlock": 10684752
228+
},
229+
call: methodCall
119230
}
120231
];
121232

0 commit comments

Comments
 (0)