11// SPDX-License-Identifier: Apache-2.0
22
3+ import { predefined } from '@hashgraph/json-rpc-relay/dist' ;
34import { expect , use } from 'chai' ;
4- import sinon from 'sinon' ;
55import chaiAsPromised from 'chai-as-promised' ;
6+ import sinon from 'sinon' ;
67
7- import constants from '../../../src/lib/constants ' ;
8+ import { numberTo0x } from '../../../src/formatters ' ;
89import { SDKClient } from '../../../src/lib/clients' ;
10+ import constants from '../../../src/lib/constants' ;
11+ import { RequestDetails } from '../../../src/lib/types' ;
12+ import { overrideEnvsInMochaDescribe } from '../../helpers' ;
913import {
1014 BASE_FEE_PER_GAS_HEX ,
1115 BLOCK_NUMBER_2 ,
@@ -16,19 +20,15 @@ import {
1620 GAS_USED_RATIO ,
1721 NOT_FOUND_RES ,
1822} from './eth-config' ;
19- import { numberTo0x } from '../../../src/formatters' ;
2023import { generateEthTestEnv } from './eth-helpers' ;
21- import { overrideEnvsInMochaDescribe } from '../../helpers' ;
22- import { RequestDetails } from '../../../src/lib/types' ;
23-
2424use ( chaiAsPromised ) ;
2525
2626let sdkClientStub : sinon . SinonStubbedInstance < SDKClient > ;
2727let getSdkClientStub : sinon . SinonStub ;
2828
2929describe ( '@ethFeeHistory using MirrorNode' , async function ( ) {
3030 this . timeout ( 10000 ) ;
31- let { restMock, hapiServiceInstance, ethImpl, cacheService } = generateEthTestEnv ( ) ;
31+ const { restMock, hapiServiceInstance, ethImpl, cacheService } = generateEthTestEnv ( ) ;
3232
3333 const requestDetails = new RequestDetails ( { requestId : 'eth_feeHistoryTest' , ipAddress : '0.0.0.0' } ) ;
3434
@@ -65,14 +65,18 @@ describe('@ethFeeHistory using MirrorNode', async function () {
6565 restMock . onGet ( BLOCKS_LIMIT_ORDER_URL ) . reply ( 200 , JSON . stringify ( { blocks : [ latestBlock ] } ) ) ;
6666 restMock . onGet ( `blocks/${ previousBlock . number } ` ) . reply ( 200 , JSON . stringify ( previousBlock ) ) ;
6767 restMock . onGet ( `blocks/${ latestBlock . number } ` ) . reply ( 200 , JSON . stringify ( latestBlock ) ) ;
68- restMock . onGet ( `network/fees?timestamp=lte:${ previousBlock . timestamp . to } ` ) . reply ( 200 , JSON . stringify ( previousFees ) ) ;
68+ restMock
69+ . onGet ( `network/fees?timestamp=lte:${ previousBlock . timestamp . to } ` )
70+ . reply ( 200 , JSON . stringify ( previousFees ) ) ;
6971 restMock . onGet ( `network/fees?timestamp=lte:${ latestBlock . timestamp . to } ` ) . reply ( 200 , JSON . stringify ( latestFees ) ) ;
7072 } ) ;
7173
7274 it ( 'eth_feeHistory' , async function ( ) {
7375 const updatedFees = previousFees ;
7476 previousFees . fees [ 2 ] . gas += 1 ;
75- restMock . onGet ( `network/fees?timestamp=lte:${ previousBlock . timestamp . to } ` ) . reply ( 200 , JSON . stringify ( updatedFees ) ) ;
77+ restMock
78+ . onGet ( `network/fees?timestamp=lte:${ previousBlock . timestamp . to } ` )
79+ . reply ( 200 , JSON . stringify ( updatedFees ) ) ;
7680 const feeHistory = await ethImpl . feeHistory ( 2 , 'latest' , [ 25 , 75 ] , requestDetails ) ;
7781
7882 expect ( feeHistory ) . to . exist ;
@@ -131,7 +135,9 @@ describe('@ethFeeHistory using MirrorNode', async function () {
131135 const maxResultsCap = Number ( constants . DEFAULT_FEE_HISTORY_MAX_RESULTS ) ;
132136
133137 restMock . onGet ( BLOCKS_LIMIT_ORDER_URL ) . reply ( 200 , JSON . stringify ( { blocks : [ { ...DEFAULT_BLOCK , number : 10 } ] } ) ) ;
134- restMock . onGet ( `network/fees?timestamp=lte:${ DEFAULT_BLOCK . timestamp . to } ` ) . reply ( 200 , JSON . stringify ( DEFAULT_NETWORK_FEES ) ) ;
138+ restMock
139+ . onGet ( `network/fees?timestamp=lte:${ DEFAULT_BLOCK . timestamp . to } ` )
140+ . reply ( 200 , JSON . stringify ( DEFAULT_NETWORK_FEES ) ) ;
135141 Array . from ( Array ( 11 ) . keys ( ) ) . map ( ( blockNumber ) =>
136142 restMock . onGet ( `blocks/${ blockNumber } ` ) . reply ( 200 , JSON . stringify ( { ...DEFAULT_BLOCK , number : blockNumber } ) ) ,
137143 ) ;
@@ -181,7 +187,9 @@ describe('@ethFeeHistory using MirrorNode', async function () {
181187 sdkClientStub . getTinyBarGasFee . resolves ( fauxGasTinyBars ) ;
182188 restMock . onGet ( BLOCKS_LIMIT_ORDER_URL ) . reply ( 200 , JSON . stringify ( { blocks : [ latestBlock ] } ) ) ;
183189 restMock . onGet ( `blocks/${ latestBlock . number } ` ) . reply ( 200 , JSON . stringify ( latestBlock ) ) ;
184- restMock . onGet ( `network/fees?timestamp=lte:${ latestBlock . timestamp . to } ` ) . reply ( 404 , JSON . stringify ( NOT_FOUND_RES ) ) ;
190+ restMock
191+ . onGet ( `network/fees?timestamp=lte:${ latestBlock . timestamp . to } ` )
192+ . reply ( 404 , JSON . stringify ( NOT_FOUND_RES ) ) ;
185193 restMock . onGet ( 'network/fees' ) . reply ( 200 , JSON . stringify ( DEFAULT_NETWORK_FEES ) ) ;
186194 } ) ;
187195
@@ -316,4 +324,29 @@ describe('@ethFeeHistory using MirrorNode', async function () {
316324 expect ( feeHistoryUsingCache [ 'baseFeePerGas' ] . length ) . to . eq ( countBlocks + 1 ) ;
317325 } ) ;
318326 } ) ;
327+
328+ describe ( 'eth_feeHistory with rewardPercentiles' , function ( ) {
329+ it ( 'should execute eth_feeHistory with valid rewardPercentiles whose size is less than 100' , async function ( ) {
330+ const feeHistory = await ethImpl . feeHistory ( 1 , 'latest' , [ 25 , 75 ] , requestDetails ) ;
331+ expect ( feeHistory ) . to . exist ;
332+ } ) ;
333+
334+ it ( 'should throw INVALID_PARAMETER when rewardPercentiles size is greater than 100' , async function ( ) {
335+ const invalidSize = 101 ;
336+
337+ const jsonRpcError = predefined . INVALID_PARAMETER (
338+ 2 ,
339+ `Reward percentiles size ${ invalidSize } is greater than the maximum allowed size ${ constants . FEE_HISTORY_REWARD_PERCENTILES_MAX_SIZE } ` ,
340+ ) ;
341+
342+ await expect (
343+ ethImpl . feeHistory (
344+ 1 ,
345+ 'latest' ,
346+ Array . from ( { length : invalidSize } , ( _ , i ) => i ) ,
347+ requestDetails ,
348+ ) ,
349+ ) . to . eventually . rejectedWith ( jsonRpcError . message ) ;
350+ } ) ;
351+ } ) ;
319352} ) ;
0 commit comments