Skip to content

Commit 53f8ecc

Browse files
authored
Return array of numbers in eth_feeHistory response (#854)
* edit constants Signed-off-by: georgi-l95 <[email protected]> fix test Signed-off-by: georgi-l95 <[email protected]> * fix test Signed-off-by: georgi-l95 <[email protected]> --------- Signed-off-by: georgi-l95 <[email protected]>
1 parent 69ffaca commit 53f8ecc

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

docs/openrpc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@
160160
"description": "An array of gas used ratio.",
161161
"type": "array",
162162
"items": {
163-
"title": "hex encoded unsigned integer",
164-
"type": "string",
165-
"pattern": "^0x([1-9a-f]+[0-9a-f]*|0|0.8)$"
163+
"title": "floating point number",
164+
"type": "number",
165+
"pattern": "^([0-9].[0-9]*|0)$"
166166
}
167167
},
168168
"baseFeePerGas": {

packages/relay/src/lib/eth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class EthImpl implements Eth {
5555
static gasTxBaseCost = EthImpl.numberTo0x(constants.TX_BASE_COST);
5656
static ethTxType = 'EthereumTransaction';
5757
static ethEmptyTrie = '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421';
58-
static defaultGasUsedRatio = EthImpl.numberTo0x(0.5);
58+
static defaultGasUsedRatio = 0.5;
5959
static feeHistoryZeroBlockCountResponse = { gasUsedRatio: null, oldestBlock: EthImpl.zeroHex };
6060
static feeHistoryEmptyResponse = { baseFeePerGas: [], gasUsedRatio: [], reward: [], oldestBlock: EthImpl.zeroHex };
6161
static redirectBytecodePrefix = '6080604052348015600f57600080fd5b506000610167905077618dc65e';
@@ -221,7 +221,7 @@ export class EthImpl implements Eth {
221221
const shouldIncludeRewards = Array.isArray(rewardPercentiles) && rewardPercentiles.length > 0;
222222
const feeHistory = {
223223
baseFeePerGas: [] as string[],
224-
gasUsedRatio: [] as string[],
224+
gasUsedRatio: [] as number[],
225225
oldestBlock: EthImpl.numberTo0x(oldestBlockNumber),
226226
};
227227

packages/relay/tests/lib/eth.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ describe('Eth calls using MirrorNode', async function () {
20412041
expect(feeHistory['baseFeePerGas'][0]).to.equal('0x870ab1a800');
20422042
expect(feeHistory['baseFeePerGas'][1]).to.equal('0x84b6a5c400');
20432043
expect(feeHistory['baseFeePerGas'][2]).to.equal('0x84b6a5c400');
2044-
expect(feeHistory['gasUsedRatio'][0]).to.equal(`0x${gasUsedRatio.toString(16)}`);
2044+
expect(feeHistory['gasUsedRatio'][0]).to.equal(gasUsedRatio);
20452045
expect(feeHistory['oldestBlock']).to.equal(`0x${previousBlock.number.toString(16)}`);
20462046
const rewards = feeHistory['reward'][0];
20472047
expect(rewards[0]).to.equal('0x0');
@@ -2159,7 +2159,7 @@ describe('Eth calls using MirrorNode', async function () {
21592159

21602160
expect(firstFeeHistory).to.exist;
21612161
expect(firstFeeHistory['baseFeePerGas'][0]).to.equal('0x84b6a5c400');
2162-
expect(firstFeeHistory['gasUsedRatio'][0]).to.equal(`0x${gasUsedRatio.toString(16)}`);
2162+
expect(firstFeeHistory['gasUsedRatio'][0]).to.equal(gasUsedRatio);
21632163
expect(firstFeeHistory['oldestBlock']).to.equal(`0x${latestBlock.number.toString(16)}`);
21642164

21652165
expect(firstFeeHistory).to.equal(secondFeeHistory);
@@ -2184,7 +2184,7 @@ describe('Eth calls using MirrorNode', async function () {
21842184
expect(feeHistory).to.exist;
21852185

21862186
expect(feeHistory['baseFeePerGas'][0]).to.equal(fauxGasWeiBarHex);
2187-
expect(feeHistory['gasUsedRatio'][0]).to.equal(`0x${gasUsedRatio.toString(16)}`);
2187+
expect(feeHistory['gasUsedRatio'][0]).to.equal(gasUsedRatio);
21882188
expect(feeHistory['oldestBlock']).to.equal(`0x${latestBlock.number.toString(16)}`);
21892189
const rewards = feeHistory['reward'][0];
21902190
expect(rewards[0]).to.equal('0x0');
@@ -2209,7 +2209,7 @@ describe('Eth calls using MirrorNode', async function () {
22092209
const feeHistory = await ethImpl.feeHistory(1, 'latest', null);
22102210

22112211
expect(feeHistory['baseFeePerGas'][0]).to.equal(fauxGasWeiBarHex);
2212-
expect(feeHistory['gasUsedRatio'][0]).to.equal(`0x${gasUsedRatio.toString(16)}`);
2212+
expect(feeHistory['gasUsedRatio'][0]).to.equal(gasUsedRatio);
22132213
expect(feeHistory['oldestBlock']).to.equal(`0x${latestBlock.number.toString(16)}`);
22142214
});
22152215

packages/server/tests/helpers/assertions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export default class Assertions {
185185

186186
expect(res.oldestBlock, "Assert feeHistory: 'oldestBlock' should equal passed expected value").to.equal(expected.oldestBlock);
187187

188-
res.gasUsedRatio.map((gasRatio: string) => expect(gasRatio, "Assert feeHistory: 'gasRatio' should equal 'defaultGasUsed'").to.equal(`0x${Assertions.defaultGasUsed.toString(16)}`));
188+
res.gasUsedRatio.map((gasRatio: string) => expect(gasRatio, "Assert feeHistory: 'gasRatio' should equal 'defaultGasUsed'").to.equal(Assertions.defaultGasUsed));
189189

190190
if (expected.checkReward) {
191191
expect(res.reward, "Assert feeHistory: 'reward' should exist and be an Array").to.exist.to.be.an('Array');

0 commit comments

Comments
 (0)