From a6285b092b896498d567d5e3a5eff5d800683264 Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Sat, 21 Dec 2024 03:22:17 +0100 Subject: [PATCH] fix: resolve type warnings for ConfigService.get() - Ensured type consistency in all affected test cases. - Removed unnecessary type casting or added necessary casting. Signed-off-by: belloibrahv --- .../src/services/globalConfig.ts | 4 +- .../tests/src/services/configService.spec.ts | 3 +- .../tests/src/services/loggerService.spec.ts | 5 +- .../hbarSpendingPlanConfigService.spec.ts | 9 +-- packages/relay/tests/lib/eth/eth-config.ts | 8 ++- packages/relay/tests/lib/eth/eth-helpers.ts | 3 +- .../relay/tests/lib/eth/eth_common.spec.ts | 8 ++- .../lib/eth/eth_sendRawTransaction.spec.ts | 5 +- .../relay/tests/lib/ethGetBlockBy.spec.ts | 3 +- packages/relay/tests/lib/hapiService.spec.ts | 41 ++++++++---- .../relay/tests/lib/mirrorNodeClient.spec.ts | 9 +-- packages/relay/tests/lib/net.spec.ts | 5 +- packages/relay/tests/lib/openrpc.spec.ts | 4 +- packages/relay/tests/lib/poller.spec.ts | 12 ++-- packages/relay/tests/lib/precheck.spec.ts | 3 +- packages/relay/tests/lib/sdkClient.spec.ts | 29 ++++---- .../lib/services/debugService/debug.spec.ts | 20 +++--- .../tests/lib/services/eth/filter.spec.ts | 16 +++-- .../hbarLimitService/hbarLimitService.spec.ts | 7 +- .../metricService/metricService.spec.ts | 9 +-- packages/relay/tests/lib/utils.spec.ts | 5 +- packages/relay/tests/lib/web3.spec.ts | 6 +- .../tests/acceptance/conformityTests.spec.ts | 7 +- .../tests/acceptance/hbarLimiter.spec.ts | 21 +++--- .../server/tests/acceptance/index.spec.ts | 66 +++++++++---------- .../tests/acceptance/rateLimiter.spec.ts | 12 ++-- .../tests/acceptance/rpc_batch1.spec.ts | 7 +- .../tests/acceptance/rpc_batch2.spec.ts | 7 +- .../tests/acceptance/rpc_batch3.spec.ts | 11 ++-- .../tests/acceptance/serverConfig.spec.ts | 8 ++- .../server/tests/integration/server.spec.ts | 48 +++++++------- .../tests/acceptance/batchRequest.spec.ts | 8 ++- .../acceptance/getTransactionByHash.spec.ts | 18 ++--- .../acceptance/getTransactionCount.spec.ts | 18 ++--- .../acceptance/getTransactionReceipt.spec.ts | 18 ++--- .../ws-server/tests/acceptance/index.spec.ts | 54 +++++++-------- .../tests/acceptance/rateLimiter.spec.ts | 14 ++-- .../acceptance/sendRawTransaction.spec.ts | 20 +++--- .../tests/acceptance/subscribe.spec.ts | 38 ++++++----- .../acceptance/subscribeNewHeads.spec.ts | 7 +- 40 files changed, 334 insertions(+), 262 deletions(-) diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index f44eda0c8b..9a28a7ce1d 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -18,6 +18,8 @@ * */ +import { ConfigName } from './configName'; + export interface ConfigProperty { envName: string; type: string; @@ -26,7 +28,7 @@ export interface ConfigProperty { } export class GlobalConfig { - public static readonly ENTRIES: Record = { + public static readonly ENTRIES: Record = { BATCH_REQUESTS_ENABLED: { envName: 'BATCH_REQUESTS_ENABLED', type: 'boolean', diff --git a/packages/config-service/tests/src/services/configService.spec.ts b/packages/config-service/tests/src/services/configService.spec.ts index ab7e062d7b..023dd5f35c 100644 --- a/packages/config-service/tests/src/services/configService.spec.ts +++ b/packages/config-service/tests/src/services/configService.spec.ts @@ -21,6 +21,7 @@ import chai, { expect } from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { ConfigService } from '../../../src/services'; +import { ConfigName } from '../../../src/services/configName'; chai.use(chaiAsPromised); @@ -49,7 +50,7 @@ describe('ConfigService tests', async function () { }); it('should be able to get existing env var', async () => { - const res = ConfigService.get('CHAIN_ID'); + const res = ConfigService.get(ConfigName.CHAIN_ID); expect(res).to.equal('0x12a'); }); diff --git a/packages/config-service/tests/src/services/loggerService.spec.ts b/packages/config-service/tests/src/services/loggerService.spec.ts index e33faa0f14..71ee309e98 100644 --- a/packages/config-service/tests/src/services/loggerService.spec.ts +++ b/packages/config-service/tests/src/services/loggerService.spec.ts @@ -24,6 +24,7 @@ import crypto from 'crypto'; import { ConfigService } from '../../../src/services'; import { LoggerService } from '../../../src/services/loggerService'; import { GlobalConfig } from '../../../dist/services/globalConfig'; +import { ConfigName } from '../../../src/services/configName'; chai.use(chaiAsPromised); @@ -47,8 +48,8 @@ describe('LoggerService tests', async function () { }); it('should be able to return plain information', async () => { - const envName = GlobalConfig.ENTRIES.CHAIN_ID.envName; - const res = ConfigService.get(envName); + const envName = ConfigName.CHAIN_ID; + const res = ConfigService.get(envName) as string; expect(LoggerService.maskUpEnv(envName, res)).to.equal(`${envName} = ${res}`); }); diff --git a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts index e33f77c8ec..fa96880155 100644 --- a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts +++ b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts @@ -1,8 +1,8 @@ -/* +/*- * * Hedera JSON RPC Relay * - * Copyright (C) 2022-2024 Hedera Hashgraph, LLC + * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import pino, { Logger } from 'pino'; import { Registry } from 'prom-client'; import sinon from 'sinon'; +import { ConfigName } from '../../../../config-service/src/services/configName'; import { HbarSpendingPlanConfigService } from '../../../src/lib/config/hbarSpendingPlanConfigService'; import { EvmAddressHbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; import { HbarSpendingPlanRepository } from '../../../src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository'; @@ -112,7 +113,7 @@ describe('HbarSpendingPlanConfigService', function () { }); after(async function () { - if (ConfigService.get('REDIS_ENABLED')) { + if (ConfigService.get(ConfigName.REDIS_ENABLED)) { await cacheService.disconnectRedisClient(); } }); @@ -392,7 +393,7 @@ describe('HbarSpendingPlanConfigService', function () { it('should not delete pre-configured spending plans after default cache TTL expires', async function () { await hbarSpendingPlanConfigService.populatePreconfiguredSpendingPlans(); - await new Promise((resolve) => setTimeout(resolve, Number(ConfigService.get('CACHE_TTL')))); + await new Promise((resolve) => setTimeout(resolve, Number(ConfigService.get(ConfigName.CACHE_TTL)))); await verifySpendingPlans(spendingPlansConfig); }); diff --git a/packages/relay/tests/lib/eth/eth-config.ts b/packages/relay/tests/lib/eth/eth-config.ts index 98077f00fd..1e669dde2c 100644 --- a/packages/relay/tests/lib/eth/eth-config.ts +++ b/packages/relay/tests/lib/eth/eth-config.ts @@ -19,6 +19,10 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; + +import { ConfigName } from '../../../../config-service/src/services/configName'; +import { nanOrNumberTo0x,numberTo0x } from '../../../dist/formatters'; +import constants from '../../../src/lib/constants'; import { defaultDetailedContractResultByHash, defaultEvmAddress, @@ -29,8 +33,6 @@ import { mockData, toHex, } from '../../helpers'; -import { numberTo0x, nanOrNumberTo0x } from '../../../dist/formatters'; -import constants from '../../../src/lib/constants'; export const BLOCK_TRANSACTION_COUNT = 77; export const GAS_USED_1 = 200000; @@ -119,7 +121,7 @@ export const CONTRACT_RESULT_MOCK = { }; export const CONTRACT_CALL_DATA = '0xef641f44'; -export const ETH_FEE_HISTORY_VALUE = ConfigService.get('ETH_FEE_HISTORY_FIXED') ?? true; +export const ETH_FEE_HISTORY_VALUE = ConfigService.get(ConfigName.ETH_FEE_HISTORY_FIXED) ?? true; export const BLOCK_HASH_PREV_TRIMMED = '0xf7d6481f659c866c35391ee230c374f163642ebf13a5e604e04a95a9ca48a298'; export const BLOCK_NUMBER_HEX = `0x${BLOCK_NUMBER.toString(16)}`; export const MAX_GAS_LIMIT = 250000; diff --git a/packages/relay/tests/lib/eth/eth-helpers.ts b/packages/relay/tests/lib/eth/eth-helpers.ts index 58295adc8a..f2fd6601e2 100644 --- a/packages/relay/tests/lib/eth/eth-helpers.ts +++ b/packages/relay/tests/lib/eth/eth-helpers.ts @@ -24,6 +24,7 @@ import EventEmitter from 'events'; import pino from 'pino'; import { register, Registry } from 'prom-client'; +import { ConfigName } from '../../../../config-service/src/services/configName'; import { ConfigServiceTestHelper } from '../../../../config-service/tests/configServiceTestHelper'; import { MirrorNodeClient } from '../../../src/lib/clients/mirrorNodeClient'; import constants from '../../../src/lib/constants'; @@ -55,7 +56,7 @@ export function generateEthTestEnv(fixedFeeHistory = false) { const cacheService = new CacheService(logger.child({ name: `cache` }), registry); // @ts-ignore const mirrorNodeInstance = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL') || '', + ConfigService.get(ConfigName.MIRROR_NODE_URL) as string || '', logger.child({ name: `mirror-node` }), registry, cacheService, diff --git a/packages/relay/tests/lib/eth/eth_common.spec.ts b/packages/relay/tests/lib/eth/eth_common.spec.ts index 9fc13ccf25..94f0f51825 100644 --- a/packages/relay/tests/lib/eth/eth_common.spec.ts +++ b/packages/relay/tests/lib/eth/eth_common.spec.ts @@ -20,9 +20,11 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { expect, use } from 'chai'; -import { Registry } from 'prom-client'; -import pino from 'pino'; import chaiAsPromised from 'chai-as-promised'; +import pino from 'pino'; +import { Registry } from 'prom-client'; + +import { ConfigName } from '../../../../config-service/src/services/configName'; import { RelayImpl } from '../../../src'; import { RequestDetails } from '../../../src/lib/types'; @@ -42,7 +44,7 @@ describe('@ethCommon', async function () { it('should execute "eth_chainId"', async function () { const chainId = Relay.eth().chainId(requestDetails); - expect(chainId).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(chainId).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); }); it('should execute "eth_accounts"', async function () { diff --git a/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts b/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts index 28970ef870..7fb81b5409 100644 --- a/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts +++ b/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts @@ -37,6 +37,7 @@ import pino from 'pino'; import { Counter } from 'prom-client'; import sinon, { useFakeTimers } from 'sinon'; +import { ConfigName } from '../../../../config-service/src/services/configName'; import { Eth, JsonRpcError, predefined } from '../../../src'; import { formatTransactionIdWithoutQueryParams } from '../../../src/formatters'; import { SDKClient } from '../../../src/lib/clients'; @@ -115,7 +116,7 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function () }, }; const transaction = { - chainId: Number(ConfigService.get('CHAIN_ID') || 0x12a), + chainId: Number(ConfigService.get(ConfigName.CHAIN_ID) || 0x12a), to: ACCOUNT_ADDRESS_1, from: accountAddress, value, @@ -135,7 +136,7 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function () }, receiver_sig_required: false, }; - const useAsyncTxProcessing = ConfigService.get('USE_ASYNC_TX_PROCESSING') as boolean; + const useAsyncTxProcessing = ConfigService.get(ConfigName.USE_ASYNC_TX_PROCESSING) as boolean; beforeEach(() => { clock = useFakeTimers(); diff --git a/packages/relay/tests/lib/ethGetBlockBy.spec.ts b/packages/relay/tests/lib/ethGetBlockBy.spec.ts index f3e9e7d2bd..0a18219ee4 100644 --- a/packages/relay/tests/lib/ethGetBlockBy.spec.ts +++ b/packages/relay/tests/lib/ethGetBlockBy.spec.ts @@ -39,6 +39,7 @@ import HAPIService from '../../src/lib/services/hapiService/hapiService'; import { HbarLimitService } from '../../src/lib/services/hbarLimitService'; import { RequestDetails } from '../../src/lib/types'; import { defaultDetailedContractResults, overrideEnvsInMochaDescribe, useInMemoryRedisServer } from '../helpers'; +import { ConfigName } from '../../../config-service/src/services/configName'; use(chaiAsPromised); @@ -128,7 +129,7 @@ describe('eth_getBlockBy', async function () { // @ts-ignore mirrorNodeInstance = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL') ?? '', + (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) ?? '', logger.child({ name: `mirror-node` }), registry, cacheService, diff --git a/packages/relay/tests/lib/hapiService.spec.ts b/packages/relay/tests/lib/hapiService.spec.ts index d93b6d07d5..0dd879c968 100644 --- a/packages/relay/tests/lib/hapiService.spec.ts +++ b/packages/relay/tests/lib/hapiService.spec.ts @@ -25,6 +25,7 @@ import EventEmitter from 'events'; import pino from 'pino'; import { register, Registry } from 'prom-client'; +import { ConfigName } from '../../../config-service/src/services/configName'; import { SDKClient } from '../../src/lib/clients'; import constants from '../../src/lib/constants'; import { EvmAddressHbarSpendingPlanRepository } from '../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; @@ -85,7 +86,9 @@ describe('HAPI Service', async function () { withOverriddenEnvsInMochaTest({ HAPI_CLIENT_TRANSACTION_RESET: 2 }, () => { it('should be able to reinitialise SDK instance upon reaching transaction limit', async function () { hapiService = new HAPIService(logger, registry, cacheService, eventEmitter, hbarLimitService); - expect(hapiService.getTransactionCount()).to.eq(parseInt(ConfigService.get('HAPI_CLIENT_TRANSACTION_RESET')!)); + expect(hapiService.getTransactionCount()).to.eq( + parseInt(ConfigService.get(ConfigName.HAPI_CLIENT_TRANSACTION_RESET)! as string), + ); const oldClientInstance = hapiService.getMainClientInstance(); let oldSDKInstance = hapiService.getSDKClient(); // decrease transaction limit by taking the instance @@ -97,7 +100,7 @@ describe('HAPI Service', async function () { expect(oldSDKInstance).to.not.be.equal(newSDKInstance); expect(oldClientInstance).to.not.be.equal(newClientInstance); expect(hapiService.getTransactionCount()).to.eq( - parseInt(ConfigService.get('HAPI_CLIENT_TRANSACTION_RESET')!) - 1, + parseInt(ConfigService.get(ConfigName.HAPI_CLIENT_TRANSACTION_RESET)! as string) - 1, ); // one less because we took the instance once and decreased the counter }); }); @@ -105,7 +108,9 @@ describe('HAPI Service', async function () { withOverriddenEnvsInMochaTest({ HAPI_CLIENT_DURATION_RESET: 100 }, () => { it('should be able to reinitialise SDK instance upon reaching time limit', async function () { hapiService = new HAPIService(logger, registry, cacheService, eventEmitter, hbarLimitService); - expect(hapiService.getTimeUntilReset()).to.eq(parseInt(ConfigService.get('HAPI_CLIENT_DURATION_RESET')!)); + expect(hapiService.getTimeUntilReset()).to.eq( + parseInt(ConfigService.get(ConfigName.HAPI_CLIENT_DURATION_RESET)! as string), + ); const oldClientInstance = hapiService.getMainClientInstance(); await new Promise((r) => setTimeout(r, 200)); // await to reach time limit @@ -113,7 +118,9 @@ describe('HAPI Service', async function () { const newSDKInstance = hapiService.getSDKClient(); const newClientInstance = hapiService.getMainClientInstance(); - expect(hapiService.getTimeUntilReset()).to.eq(parseInt(ConfigService.get('HAPI_CLIENT_DURATION_RESET')!)); + expect(hapiService.getTimeUntilReset()).to.eq( + parseInt(ConfigService.get(ConfigName.HAPI_CLIENT_DURATION_RESET)! as string), + ); expect(oldSDKInstance).to.not.be.equal(newSDKInstance); expect(oldClientInstance).to.not.be.equal(newClientInstance); }); @@ -122,7 +129,9 @@ describe('HAPI Service', async function () { withOverriddenEnvsInMochaTest({ HAPI_CLIENT_ERROR_RESET: '[50]' }, () => { it('should be able to reinitialise SDK instance upon error status code encounter', async function () { hapiService = new HAPIService(logger, registry, cacheService, eventEmitter, hbarLimitService); - expect(hapiService.getErrorCodes()[0]).to.eq(JSON.parse(ConfigService.get('HAPI_CLIENT_ERROR_RESET')!)[0]); + expect(hapiService.getErrorCodes()[0]).to.eq( + JSON.parse(ConfigService.get(ConfigName.HAPI_CLIENT_ERROR_RESET)! as string)[0], + ); const oldClientInstance = hapiService.getMainClientInstance(); const oldSDKInstance = hapiService.getSDKClient(); @@ -132,7 +141,9 @@ describe('HAPI Service', async function () { expect(oldSDKInstance).to.not.be.equal(newSDKInstance); expect(oldClientInstance).to.not.be.equal(newClientInstance); - expect(hapiService.getErrorCodes()[0]).to.eq(JSON.parse(ConfigService.get('HAPI_CLIENT_ERROR_RESET')!)[0]); + expect(hapiService.getErrorCodes()[0]).to.eq( + JSON.parse(ConfigService.get(ConfigName.HAPI_CLIENT_ERROR_RESET)! as string)[0], + ); }); }); @@ -146,17 +157,23 @@ describe('HAPI Service', async function () { it('should be able to reset all counter upon reinitialization of the SDK Client', async function () { hapiService = new HAPIService(logger, registry, cacheService, eventEmitter, hbarLimitService); - expect(hapiService.getErrorCodes()[0]).to.eq(JSON.parse(ConfigService.get('HAPI_CLIENT_ERROR_RESET')!)[0]); + expect(hapiService.getErrorCodes()[0]).to.eq( + JSON.parse(ConfigService.get(ConfigName.HAPI_CLIENT_ERROR_RESET)! as string)[0], + ); const oldClientInstance = hapiService.getMainClientInstance(); const oldSDKInstance = hapiService.getSDKClient(); hapiService.decrementErrorCounter(errorStatus); const newSDKInstance = hapiService.getSDKClient(); const newClientInstance = hapiService.getMainClientInstance(); - expect(hapiService.getTimeUntilReset()).to.eq(parseInt(ConfigService.get('HAPI_CLIENT_DURATION_RESET')!)); - expect(hapiService.getErrorCodes()[0]).to.eq(JSON.parse(ConfigService.get('HAPI_CLIENT_ERROR_RESET')!)[0]); + expect(hapiService.getTimeUntilReset()).to.eq( + parseInt(ConfigService.get(ConfigName.HAPI_CLIENT_DURATION_RESET)! as string), + ); + expect(hapiService.getErrorCodes()[0]).to.eq( + JSON.parse(ConfigService.get(ConfigName.HAPI_CLIENT_ERROR_RESET)! as string)[0], + ); expect(hapiService.getTransactionCount()).to.eq( - parseInt(ConfigService.get('HAPI_CLIENT_TRANSACTION_RESET')!) - 1, + parseInt(ConfigService.get(ConfigName.HAPI_CLIENT_TRANSACTION_RESET)! as string) - 1, ); // one less because we took the instance once and decreased the counter expect(oldSDKInstance).to.not.be.equal(newSDKInstance); expect(oldClientInstance).to.not.be.equal(newClientInstance); @@ -204,7 +221,9 @@ describe('HAPI Service', async function () { () => { it('should not be able to reinitialise and decrement counters, if it is disabled', async function () { hapiService = new HAPIService(logger, registry, cacheService, eventEmitter, hbarLimitService); - expect(hapiService.getTransactionCount()).to.eq(parseInt(ConfigService.get('HAPI_CLIENT_TRANSACTION_RESET')!)); + expect(hapiService.getTransactionCount()).to.eq( + parseInt(ConfigService.get(ConfigName.HAPI_CLIENT_TRANSACTION_RESET)! as string), + ); const oldClientInstance = hapiService.getMainClientInstance(); const oldSDKInstance = hapiService.getSDKClient(); diff --git a/packages/relay/tests/lib/mirrorNodeClient.spec.ts b/packages/relay/tests/lib/mirrorNodeClient.spec.ts index 9e9d2fda21..453cad81a4 100644 --- a/packages/relay/tests/lib/mirrorNodeClient.spec.ts +++ b/packages/relay/tests/lib/mirrorNodeClient.spec.ts @@ -35,6 +35,7 @@ const registry = new Registry(); import { MirrorNodeTransactionRecord, RequestDetails } from '../../src/lib/types'; import { SDKClientError } from '../../src/lib/errors/SDKClientError'; import { BigNumber } from 'bignumber.js'; +import { ConfigName } from '../../../config-service/src/services/configName'; const logger = pino(); const noTransactions = '?transactions=false'; @@ -63,7 +64,7 @@ describe('MirrorNodeClient', async function () { cacheService = new CacheService(logger.child({ name: `cache` }), registry); mirrorNodeInstance = new MirrorNodeClient( // @ts-ignore - ConfigService.get('MIRROR_NODE_URL') || '', + ConfigService.get(ConfigName.MIRROR_NODE_URL) || '', logger.child({ name: `mirror-node` }), registry, cacheService, @@ -140,7 +141,7 @@ describe('MirrorNodeClient', async function () { it('`restUrl` is exposed and correct', async () => { // @ts-ignore - const domain = (ConfigService.get('MIRROR_NODE_URL') || '').replace(/^https?:\/\//, ''); + const domain = (ConfigService.get(ConfigName.MIRROR_NODE_URL) || '').replace(/^https?:\/\//, ''); const prodMirrorNodeInstance = new MirrorNodeClient( domain, logger.child({ name: `mirror-node` }), @@ -167,14 +168,14 @@ describe('MirrorNodeClient', async function () { withOverriddenEnvsInMochaTest({ MIRROR_NODE_URL_HEADER_X_API_KEY: 'abc123iAManAPIkey' }, () => { it('Can provide custom x-api-key header', async () => { const mirrorNodeInstanceOverridden = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL') || '', + (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) || '', logger.child({ name: `mirror-node` }), registry, cacheService, ); const axiosHeaders = mirrorNodeInstanceOverridden.getMirrorNodeRestInstance().defaults.headers.common; expect(axiosHeaders).has.property('x-api-key'); - expect(axiosHeaders['x-api-key']).to.eq(ConfigService.get('MIRROR_NODE_URL_HEADER_X_API_KEY')); + expect(axiosHeaders['x-api-key']).to.eq(ConfigService.get(ConfigName.MIRROR_NODE_URL_HEADER_X_API_KEY)); }); }); diff --git a/packages/relay/tests/lib/net.spec.ts b/packages/relay/tests/lib/net.spec.ts index 8458d19d10..8b9702e81a 100644 --- a/packages/relay/tests/lib/net.spec.ts +++ b/packages/relay/tests/lib/net.spec.ts @@ -25,6 +25,7 @@ import { Registry } from 'prom-client'; import { RelayImpl } from '../../src/lib/relay'; import constants from '../../src/lib/constants'; import { withOverriddenEnvsInMochaTest } from '../helpers'; +import { ConfigName } from '../../../config-service/src/services/configName'; const logger = pino(); let Relay; @@ -40,8 +41,8 @@ describe('Net', async function () { }); it('should execute "net_version"', function () { - const hederaNetwork: string = (ConfigService.get('HEDERA_NETWORK') || '{}').toLowerCase(); - let expectedNetVersion = ConfigService.get('CHAIN_ID') || constants.CHAIN_IDS[hederaNetwork] || '298'; + const hederaNetwork: string = ((ConfigService.get(ConfigName.HEDERA_NETWORK) as string) || '{}').toLowerCase(); + let expectedNetVersion = ConfigService.get(ConfigName.CHAIN_ID) || constants.CHAIN_IDS[hederaNetwork] || '298'; if (expectedNetVersion.startsWith('0x')) expectedNetVersion = parseInt(expectedNetVersion, 16).toString(); const actualNetVersion = Relay.net().version(); diff --git a/packages/relay/tests/lib/openrpc.spec.ts b/packages/relay/tests/lib/openrpc.spec.ts index 1ca3274505..ef71c033d8 100644 --- a/packages/relay/tests/lib/openrpc.spec.ts +++ b/packages/relay/tests/lib/openrpc.spec.ts @@ -33,6 +33,7 @@ import { register, Registry } from 'prom-client'; import sinon from 'sinon'; import openRpcSchema from '../../../../docs/openrpc.json'; +import { ConfigName } from '../../../config-service/src/services/configName'; import { RelayImpl } from '../../src'; import { numberTo0x } from '../../src/formatters'; import { SDKClient } from '../../src/lib/clients'; @@ -76,7 +77,6 @@ import { signedTransactionHash, } from '../helpers'; import { CONTRACT_RESULT_MOCK, NOT_FOUND_RES } from './eth/eth-config'; - const logger = pino(); const registry = new Registry(); const Relay = new RelayImpl(logger, registry); @@ -122,7 +122,7 @@ describe('Open RPC Specification', function () { const cacheService = new CacheService(logger.child({ name: `cache` }), registry); // @ts-ignore mirrorNodeInstance = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL') || '', + (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) || '', logger.child({ name: `mirror-node` }), registry, cacheService, diff --git a/packages/relay/tests/lib/poller.spec.ts b/packages/relay/tests/lib/poller.spec.ts index 245e302e84..f94d04a1e8 100644 --- a/packages/relay/tests/lib/poller.spec.ts +++ b/packages/relay/tests/lib/poller.spec.ts @@ -19,12 +19,14 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; -import { EthImpl } from '../../src/lib/eth'; import { expect } from 'chai'; import pino from 'pino'; -import { Poller } from '../../src/lib/poller'; -import sinon from 'sinon'; import { Registry } from 'prom-client'; +import sinon from 'sinon'; + +import { ConfigName } from '../../../config-service/src/services/configName'; +import { EthImpl } from '../../src/lib/eth'; +import { Poller } from '../../src/lib/poller'; const logger = pino({ level: 'trace' }); @@ -187,7 +189,9 @@ describe('Polling', async function () { ), ).to.equal(true); expect( - loggerSpy.calledWith(`Poller: Starting polling with interval=${ConfigService.get('WS_POLLING_INTERVAL')}`), + loggerSpy.calledWith( + `Poller: Starting polling with interval=${ConfigService.get(ConfigName.WS_POLLING_INTERVAL)}`, + ), ).to.equal(true); }); diff --git a/packages/relay/tests/lib/precheck.spec.ts b/packages/relay/tests/lib/precheck.spec.ts index 46a70bc3a3..e97aee8ab3 100644 --- a/packages/relay/tests/lib/precheck.spec.ts +++ b/packages/relay/tests/lib/precheck.spec.ts @@ -27,6 +27,7 @@ import { ethers, Transaction } from 'ethers'; import pino from 'pino'; import { Registry } from 'prom-client'; +import { ConfigName } from '../../../config-service/src/services/configName'; import { JsonRpcError, predefined } from '../../src'; import { MirrorNodeClient } from '../../src/lib/clients'; import constants from '../../src/lib/constants'; @@ -106,7 +107,7 @@ describe('Precheck', async function () { // @ts-ignore const mirrorNodeInstance = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL')!, + ConfigService.get(ConfigName.MIRROR_NODE_URL)! as string, logger.child({ name: `mirror-node` }), registry, new CacheService(logger.child({ name: `cache` }), registry), diff --git a/packages/relay/tests/lib/sdkClient.spec.ts b/packages/relay/tests/lib/sdkClient.spec.ts index 43e26cc3d4..c4dbd97998 100644 --- a/packages/relay/tests/lib/sdkClient.spec.ts +++ b/packages/relay/tests/lib/sdkClient.spec.ts @@ -47,6 +47,7 @@ import pino from 'pino'; import { register, Registry } from 'prom-client'; import * as sinon from 'sinon'; +import { ConfigName } from '../../../config-service/src/services/configName'; import { formatTransactionId } from '../../src/formatters'; import { MirrorNodeClient, SDKClient } from '../../src/lib/clients'; import constants from '../../src/lib/constants'; @@ -102,7 +103,7 @@ describe('SdkClient', async function () { overrideEnvsInMochaDescribe({ GET_RECORD_DEFAULT_TO_CONSENSUS_NODE: true }); before(() => { - const hederaNetwork = ConfigService.get('HEDERA_NETWORK')!; + const hederaNetwork = ConfigService.get(ConfigName.HEDERA_NETWORK)! as string; if (hederaNetwork in constants.CHAIN_IDS) { client = Client.forName(hederaNetwork); } else { @@ -110,8 +111,8 @@ describe('SdkClient', async function () { } client = client.setOperator( - AccountId.fromString(ConfigService.get('OPERATOR_ID_MAIN')!), - Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN')!), + AccountId.fromString(ConfigService.get(ConfigName.OPERATOR_ID_MAIN)! as string), + Utils.createPrivateKeyBasedOnFormat(ConfigService.get(ConfigName.OPERATOR_KEY_MAIN)! as string), ); const duration = constants.HBAR_RATE_LIMIT_DURATION; eventEmitter = new EventEmitter(); @@ -148,7 +149,7 @@ describe('SdkClient', async function () { // mirror node client mirrorNodeClient = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL') || '', + (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) || '', logger.child({ name: `mirror-node` }), registry, new CacheService(logger.child({ name: `cache` }), registry), @@ -284,7 +285,7 @@ describe('SdkClient', async function () { }; this.beforeEach(() => { - if (ConfigService.get('OPERATOR_KEY_FORMAT') !== 'BAD_FORMAT') { + if (ConfigService.get(ConfigName.OPERATOR_KEY_FORMAT) !== 'BAD_FORMAT') { hapiService = new HAPIService(logger, registry, cacheService, eventEmitter, hbarLimitService); } }); @@ -335,8 +336,8 @@ describe('SdkClient', async function () { }); describe('HBAR Limiter', async () => { - const FILE_APPEND_CHUNK_SIZE = Number(ConfigService.get('FILE_APPEND_CHUNK_SIZE')) || 5120; - const MAX_CHUNKS = Number(ConfigService.get('FILE_APPEND_MAX_CHUNKS')) || 20; + const FILE_APPEND_CHUNK_SIZE = Number(ConfigService.get(ConfigName.FILE_APPEND_CHUNK_SIZE)) || 5120; + const MAX_CHUNKS = Number(ConfigService.get(ConfigName.FILE_APPEND_MAX_CHUNKS)) || 20; const transactionBuffer = new Uint8Array([ 2, 249, 250, 182, 130, 1, 42, 7, 1, 133, 209, 56, 92, 123, 240, 131, 228, 225, 192, 148, 61, 176, 51, 137, 34, 205, 229, 74, 102, 224, 197, 133, 1, 18, 73, 145, 93, 50, 210, 37, 134, 9, 24, 78, 114, 160, 0, 185, 250, 68, 130, @@ -2144,7 +2145,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileCreateFee / 10 ** 8) : fileCreateFee; transfers = [ { - accountId: ConfigService.get('OPERATOR_ID_MAIN'), + accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), amount: Hbar.fromTinybars(-1 * fileCreateFee), is_approval: false, }, @@ -2154,7 +2155,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileAppendFee / 10 ** 8) : fileAppendFee; transfers = [ { - accountId: ConfigService.get('OPERATOR_ID_MAIN'), + accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), amount: Hbar.fromTinybars(-1 * fileAppendFee), is_approval: false, }, @@ -2164,7 +2165,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileDeleteFee / 10 ** 8) : fileDeleteFee; transfers = [ { - accountId: ConfigService.get('OPERATOR_ID_MAIN'), + accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), amount: Hbar.fromTinybars(-1 * fileDeleteFee), is_approval: false, }, @@ -2179,12 +2180,12 @@ describe('SdkClient', async function () { is_approval: false, }, { - accountId: ConfigService.get('OPERATOR_ID_MAIN'), + accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), amount: Hbar.fromTinybars(-1 * defaultTransactionFee), is_approval: false, }, { - accountId: ConfigService.get('OPERATOR_ID_MAIN'), + accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), amount: Hbar.fromTinybars(defaultTransactionFee), is_approval: false, }, @@ -2650,7 +2651,7 @@ describe('SdkClient', async function () { is_approval: false, }, { - account: ConfigService.get('OPERATOR_ID_MAIN'), + account: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), amount: -1 * defaultTransactionFee, is_approval: false, }, @@ -2743,7 +2744,7 @@ describe('SdkClient', async function () { }); it('Should execute getTransferAmountSumForAccount() to calculate transactionFee by only transfers that are paid by the specify accountId', () => { - const accountId = ConfigService.get('OPERATOR_ID_MAIN') || ''; + const accountId = (ConfigService.get(ConfigName.OPERATOR_ID_MAIN) as string) || ''; const mockedTxRecord = getMockedTransactionRecord(EthereumTransaction.name, true); const transactionFee = sdkClient.getTransferAmountSumForAccount(mockedTxRecord, accountId); diff --git a/packages/relay/tests/lib/services/debugService/debug.spec.ts b/packages/relay/tests/lib/services/debugService/debug.spec.ts index 7b46dc9675..e4d6acf2c0 100644 --- a/packages/relay/tests/lib/services/debugService/debug.spec.ts +++ b/packages/relay/tests/lib/services/debugService/debug.spec.ts @@ -19,22 +19,24 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import MockAdapter from 'axios-mock-adapter'; import chai, { expect } from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import MockAdapter from 'axios-mock-adapter'; +import pino from 'pino'; import { Registry } from 'prom-client'; + +import { ConfigName } from '../../../../../config-service/src/services/configName'; +import { predefined } from '../../../../src'; +import { strip0x } from '../../../../src/formatters'; import { MirrorNodeClient } from '../../../../src/lib/clients'; -import pino from 'pino'; +import { IOpcodesResponse } from '../../../../src/lib/clients/models/IOpcodesResponse'; import { TracerType } from '../../../../src/lib/constants'; -import { DebugService } from '../../../../src/lib/services/debugService'; -import { getQueryParams, withOverriddenEnvsInMochaTest } from '../../../helpers'; -import RelayAssertions from '../../../assertions'; -import { predefined } from '../../../../src'; import { CacheService } from '../../../../src/lib/services/cacheService/cacheService'; +import { DebugService } from '../../../../src/lib/services/debugService'; import { CommonService } from '../../../../src/lib/services/ethService'; -import { IOpcodesResponse } from '../../../../src/lib/clients/models/IOpcodesResponse'; -import { strip0x } from '../../../../src/formatters'; import { RequestDetails } from '../../../../src/lib/types'; +import RelayAssertions from '../../../assertions'; +import { getQueryParams, withOverriddenEnvsInMochaTest } from '../../../helpers'; chai.use(chaiAsPromised); @@ -266,7 +268,7 @@ describe('Debug API Test Suite', async function () { cacheService = new CacheService(logger.child({ name: `cache` }), registry); // @ts-ignore mirrorNodeInstance = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL')!, + ConfigService.get(ConfigName.MIRROR_NODE_URL)! as string, logger.child({ name: `mirror-node` }), registry, cacheService, diff --git a/packages/relay/tests/lib/services/eth/filter.spec.ts b/packages/relay/tests/lib/services/eth/filter.spec.ts index 60b0c0217b..efc20594d6 100644 --- a/packages/relay/tests/lib/services/eth/filter.spec.ts +++ b/packages/relay/tests/lib/services/eth/filter.spec.ts @@ -19,13 +19,20 @@ */ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { ConfigName } from '@hashgraph/json-rpc-config-service/src/services/configName'; import MockAdapter from 'axios-mock-adapter'; import { expect } from 'chai'; +import pino from 'pino'; import { Registry } from 'prom-client'; +import { v4 as uuid } from 'uuid'; + +import { predefined } from '../../../../src'; import { MirrorNodeClient } from '../../../../src/lib/clients'; -import pino from 'pino'; import constants from '../../../../src/lib/constants'; +import { CacheService } from '../../../../src/lib/services/cacheService/cacheService'; import { CommonService, FilterService } from '../../../../src/lib/services/ethService'; +import { RequestDetails } from '../../../../src/lib/types'; +import RelayAssertions from '../../../assertions'; import { defaultBlock, defaultEvmAddress, @@ -34,11 +41,6 @@ import { toHex, withOverriddenEnvsInMochaTest, } from '../../../helpers'; -import RelayAssertions from '../../../assertions'; -import { predefined } from '../../../../src'; -import { CacheService } from '../../../../src/lib/services/cacheService/cacheService'; -import { RequestDetails } from '../../../../src/lib/types'; -import { v4 as uuid } from 'uuid'; const logger = pino(); const registry = new Registry(); @@ -82,7 +84,7 @@ describe('Filter API Test Suite', async function () { this.beforeAll(() => { cacheService = new CacheService(logger.child({ name: `cache` }), registry); mirrorNodeInstance = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL'), + ConfigService.get(ConfigName.MIRROR_NODE_URL) as string, logger.child({ name: `mirror-node` }), registry, cacheService, diff --git a/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts b/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts index 0b857e6297..d1466c6a90 100644 --- a/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts +++ b/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts @@ -1,8 +1,8 @@ -/* +/*- * * Hedera JSON RPC Relay * - * Copyright (C) 2022-2024 Hedera Hashgraph, LLC + * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ import { SubscriptionTier } from '../../../../src/lib/db/types/hbarLimiter/subsc import { CacheService } from '../../../../src/lib/services/cacheService/cacheService'; import { HbarLimitService } from '../../../../src/lib/services/hbarLimitService'; import { RequestDetails } from '../../../../src/lib/types'; +import { ConfigName } from '@hashgraph/json-rpc-config-service/src/services/configName'; chai.use(chaiAsPromised); @@ -61,7 +62,7 @@ describe('HBAR Rate Limit Service', function () { const mockPlanId = uuidV4(randomBytes(16)); const todayAtMidnight = new Date().setHours(0, 0, 0, 0); const operatorAddress = prepend0x( - AccountId.fromString(ConfigService.get('OPERATOR_ID_MAIN') as string).toSolidityAddress(), + AccountId.fromString(ConfigService.get(ConfigName.OPERATOR_ID_MAIN) as string).toSolidityAddress(), ); const requestDetails = new RequestDetails({ requestId: 'hbarLimitServiceTest', ipAddress: mockIpAddress }); diff --git a/packages/relay/tests/lib/services/metricService/metricService.spec.ts b/packages/relay/tests/lib/services/metricService/metricService.spec.ts index 3462192000..73207a5da5 100644 --- a/packages/relay/tests/lib/services/metricService/metricService.spec.ts +++ b/packages/relay/tests/lib/services/metricService/metricService.spec.ts @@ -28,6 +28,7 @@ import pino from 'pino'; import { register, Registry } from 'prom-client'; import * as sinon from 'sinon'; +import { ConfigName } from '../../../../../config-service/src/services/configName'; import { MirrorNodeClient, SDKClient } from '../../../../src/lib/clients'; import constants from '../../../../src/lib/constants'; import { EvmAddressHbarSpendingPlanRepository } from '../../../../src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository'; @@ -144,15 +145,15 @@ describe('Metric Service', function () { before(() => { // consensus node client - const hederaNetwork = ConfigService.get('HEDERA_NETWORK')! as string; + const hederaNetwork = ConfigService.get(ConfigName.HEDERA_NETWORK)! as string; if (hederaNetwork in constants.CHAIN_IDS) { client = Client.forName(hederaNetwork); } else { client = Client.forNetwork(JSON.parse(hederaNetwork)); } client = client.setOperator( - AccountId.fromString(ConfigService.get('OPERATOR_ID_MAIN')! as string), - Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN')! as string), + AccountId.fromString(ConfigService.get(ConfigName.OPERATOR_ID_MAIN)! as string), + Utils.createPrivateKeyBasedOnFormat(ConfigService.get(ConfigName.OPERATOR_KEY_MAIN)! as string), ); // mirror node client @@ -165,7 +166,7 @@ describe('Metric Service', function () { timeout: 20 * 1000, }); mirrorNodeClient = new MirrorNodeClient( - (ConfigService.get('MIRROR_NODE_URL') as string) || '', + (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) || '', logger.child({ name: `mirror-node` }), registry, new CacheService(logger.child({ name: `cache` }), registry), diff --git a/packages/relay/tests/lib/utils.spec.ts b/packages/relay/tests/lib/utils.spec.ts index a34fdea02f..fc5f6474b2 100644 --- a/packages/relay/tests/lib/utils.spec.ts +++ b/packages/relay/tests/lib/utils.spec.ts @@ -22,6 +22,7 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services' import { expect } from 'chai'; import createHash from 'keccak'; +import { ConfigName } from '../../../config-service/src/services/configName'; import { ASCIIToHex, prepend0x } from '../../src/formatters'; import constants from '../../src/lib/constants'; import { Utils } from '../../src/utils'; @@ -58,7 +59,7 @@ describe('Utils', () => { describe('estimateFileTransactionsFee', () => { const callDataSize = 6000; const mockedExchangeRateInCents: number = 12; - const fileChunkSize = Number(ConfigService.get('FILE_APPEND_CHUNK_SIZE')) || 5120; + const fileChunkSize = Number(ConfigService.get(ConfigName.FILE_APPEND_CHUNK_SIZE)) || 5120; it('Should execute estimateFileTransactionFee() to estimate total fee of file transactions', async () => { const result = Utils.estimateFileTransactionsFee(callDataSize, fileChunkSize, mockedExchangeRateInCents); const expectedResult = estimateFileTransactionsFee(callDataSize, fileChunkSize, mockedExchangeRateInCents); @@ -81,7 +82,7 @@ describe('Utils', () => { }); // @ts-ignore - JSON.parse(ConfigService.get('HEDERA_SPECIFIC_REVERT_STATUSES')).forEach((status) => { + JSON.parse(ConfigService.get(ConfigName.HEDERA_SPECIFIC_REVERT_STATUSES)).forEach((status) => { it(`should exclude transaction with result ${status}`, () => { expect(Utils.isRevertedDueToHederaSpecificValidation({ result: status, error_message: null })).to.be.true; }); diff --git a/packages/relay/tests/lib/web3.spec.ts b/packages/relay/tests/lib/web3.spec.ts index 30fda3912a..848e665a8c 100644 --- a/packages/relay/tests/lib/web3.spec.ts +++ b/packages/relay/tests/lib/web3.spec.ts @@ -20,8 +20,10 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { expect } from 'chai'; -import { Registry } from 'prom-client'; import pino from 'pino'; +import { Registry } from 'prom-client'; + +import { ConfigName } from '../../../config-service/src/services/configName'; import { RelayImpl } from '../../src'; import { withOverriddenEnvsInMochaTest } from '../helpers'; @@ -32,7 +34,7 @@ describe('Web3', function () { withOverriddenEnvsInMochaTest({ npm_package_version: '1.0.0' }, () => { it('should return "relay/1.0.0"', async function () { const clientVersion = Relay.web3().clientVersion(); - expect(clientVersion).to.be.equal('relay/' + ConfigService.get('npm_package_version')); + expect(clientVersion).to.be.equal('relay/' + ConfigService.get(ConfigName.npm_package_version)); }); }); diff --git a/packages/server/tests/acceptance/conformityTests.spec.ts b/packages/server/tests/acceptance/conformityTests.spec.ts index d758ebc949..20fae945bd 100644 --- a/packages/server/tests/acceptance/conformityTests.spec.ts +++ b/packages/server/tests/acceptance/conformityTests.spec.ts @@ -1,8 +1,8 @@ -/* +/*- * * Hedera JSON RPC Relay * - * Copyright (C) 2022-2024 Hedera Hashgraph, LLC + * Copyright (C) 2024 Hedera Hashgraph, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import LogsContract from '../contracts/Logs.json'; import CallerContract from '../contracts/Caller.json'; import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { parseOpenRPCDocument } from '@open-rpc/schema-utils-js'; +import { ConfigName } from '../../../config-service/src/services/configName'; const directoryPath = path.resolve(__dirname, '../../../../node_modules/execution-apis/tests'); @@ -68,7 +69,7 @@ addFormats(ajv); let execApisOpenRpcData; let relayOpenRpcData: any; -const chainId = Number(ConfigService.get('CHAIN_ID') || 0x12a); +const chainId = Number(ConfigService.get(ConfigName.CHAIN_ID) || 0x12a); let legacyTransaction = { chainId, diff --git a/packages/server/tests/acceptance/hbarLimiter.spec.ts b/packages/server/tests/acceptance/hbarLimiter.spec.ts index a805d066fc..f63ed96db3 100644 --- a/packages/server/tests/acceptance/hbarLimiter.spec.ts +++ b/packages/server/tests/acceptance/hbarLimiter.spec.ts @@ -39,6 +39,7 @@ import { resolve } from 'path'; import { Logger } from 'pino'; import { Registry } from 'prom-client'; +import { ConfigName } from '../../../config-service/src/services/configName'; import MetricsClient from '../clients/metricsClient'; import MirrorClient from '../clients/mirrorClient'; import RelayClient from '../clients/relayClient'; @@ -73,9 +74,9 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { metrics: MetricsClient; relayIsLocal: boolean; } = global; - const mockTTL = (ConfigService.get('HBAR_RATE_LIMIT_DURATION') as number) || 86400000; // 1 day - const operatorAccount = (ConfigService.get('OPERATOR_ID_MAIN') as string) || DOT_ENV.OPERATOR_ID_MAIN || ''; - const fileAppendChunkSize = Number(ConfigService.get('FILE_APPEND_CHUNK_SIZE')) || 5120; + const mockTTL = (ConfigService.get(ConfigName.HBAR_RATE_LIMIT_DURATION) as number) || 86400000; // 1 day + const operatorAccount = (ConfigService.get(ConfigName.OPERATOR_ID_MAIN) as string) || DOT_ENV.OPERATOR_ID_MAIN || ''; + const fileAppendChunkSize = Number(ConfigService.get(ConfigName.FILE_APPEND_CHUNK_SIZE)) || 5120; const requestId = 'hbarLimiterTest'; const requestDetails = new RequestDetails({ requestId: requestId, ipAddress: '0.0.0.0' }); const cacheService = new CacheService(logger.child({ name: 'cache-service' }), new Registry()); @@ -127,7 +128,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { return contract; }; - const transactionReecordCostTolerance = Number(ConfigService.get(`TEST_TRANSACTION_RECORD_COST_TOLERANCE`) || 0.02); + const transactionReecordCostTolerance = Number(ConfigService.get(ConfigName.TEST_TRANSACTION_RECORD_COST_TOLERANCE) || 0.02); const verifyRemainingLimit = (expectedCost: number, remainingHbarsBefore: number, remainingHbarsAfter: number) => { const delta = transactionReecordCostTolerance * expectedCost; @@ -220,7 +221,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { const accounts: AliasAccount[] = []; const defaultLondonTransactionData = { value: Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))), // 1 tinybar - chainId: Number(ConfigService.get('CHAIN_ID') || 0), + chainId: Number(ConfigService.get(ConfigName.CHAIN_ID) || 0), maxPriorityFeePerGas: Assertions.defaultGasPrice, maxFeePerGas: Assertions.defaultGasPrice, gasLimit: 3_000_000, @@ -231,7 +232,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { logger.info(`${requestDetails.formattedRequestId} Creating accounts`); logger.info( `${requestDetails.formattedRequestId} HBAR_RATE_LIMIT_TINYBAR: ${ConfigService.get( - 'HBAR_RATE_LIMIT_TINYBAR', + ConfigName.HBAR_RATE_LIMIT_TINYBAR, )}`, ); @@ -739,7 +740,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { }; describe('given a valid JSON file with pre-configured spending plans', async () => { - const SPENDING_PLANS_CONFIG_FILE = ConfigService.get('HBAR_SPENDING_PLANS_CONFIG') as string; + const SPENDING_PLANS_CONFIG_FILE = ConfigService.get(ConfigName.HBAR_SPENDING_PLANS_CONFIG) as string; const configPath = findConfig(SPENDING_PLANS_CONFIG_FILE); if (configPath) { @@ -899,7 +900,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { return { ...aliasAccount, hbarSpendingPlan: accountAliasPlan.hbarSpendingPlan }; }); - const totalHbarBudget = ConfigService.get(`HBAR_RATE_LIMIT_TINYBAR`) as number; + const totalHbarBudget = ConfigService.get(ConfigName.HBAR_RATE_LIMIT_TINYBAR) as number; let totalHbarSpent = totalHbarBudget - Number(await metrics.get(testConstants.METRICS.REMAINING_HBAR_LIMIT)); @@ -956,14 +957,14 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { before(async function () { logger.info( `${requestDetails.formattedRequestId} HBAR_RATE_LIMIT_TINYBAR: ${ConfigService.get( - 'HBAR_RATE_LIMIT_TINYBAR', + ConfigName.HBAR_RATE_LIMIT_TINYBAR, )}`, ); }); it('should eventually exhaust the hbar limit for a BASIC user after multiple deployments of large contracts, and not throw an error', async function () { // confirm that HBAR_RATE_LIMIT_TINYBAR is set to zero - expect(ConfigService.get('HBAR_RATE_LIMIT_TINYBAR')).to.eq(0); + expect(ConfigService.get(ConfigName.HBAR_RATE_LIMIT_TINYBAR)).to.eq(0); // This should set the remaining HBAR limit to zero const remainingHbarsBefore = Number(await metrics.get(testConstants.METRICS.REMAINING_HBAR_LIMIT)); expect(remainingHbarsBefore).to.eq(0); diff --git a/packages/server/tests/acceptance/index.spec.ts b/packages/server/tests/acceptance/index.spec.ts index 619c388225..7f390e1949 100644 --- a/packages/server/tests/acceptance/index.spec.ts +++ b/packages/server/tests/acceptance/index.spec.ts @@ -18,38 +18,34 @@ * */ // External resources +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { ConfigName } from '@hashgraph/json-rpc-config-service/src/services/configName'; +// Constants +import constants from '@hashgraph/json-rpc-relay/dist/lib/constants'; +import { app as wsApp } from '@hashgraph/json-rpc-ws-server/dist/webSocketServer'; +// Hashgraph SDK +import { AccountId, Hbar } from '@hashgraph/sdk'; import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; import dotenv from 'dotenv'; +// Other external resources +import fs from 'fs'; +import { Server } from 'http'; import path from 'path'; import pino from 'pino'; -import chaiAsPromised from 'chai-as-promised'; import { GCProfiler } from 'v8'; -// Other external resources -import fs from 'fs'; - -// Clients -import ServicesClient from '../clients/servicesClient'; -import MirrorClient from '../clients/mirrorClient'; -import RelayClient from '../clients/relayClient'; -import MetricsClient from '../clients/metricsClient'; - // Server related import app from '../../dist/server'; -import { app as wsApp } from '@hashgraph/json-rpc-ws-server/dist/webSocketServer'; - -// Hashgraph SDK -import { AccountId, Hbar } from '@hashgraph/sdk'; - -// Constants -import constants from '@hashgraph/json-rpc-relay/dist/lib/constants'; - +import { setServerTimeout } from '../../src/koaJsonRpc/lib/utils'; +import MetricsClient from '../clients/metricsClient'; +import MirrorClient from '../clients/mirrorClient'; +import RelayClient from '../clients/relayClient'; +// Clients +import ServicesClient from '../clients/servicesClient'; // Utils and types import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; -import { setServerTimeout } from '../../src/koaJsonRpc/lib/utils'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; -import { Server } from 'http'; chai.use(chaiAsPromised); dotenv.config({ path: path.resolve(__dirname, '../../../../.env') }); @@ -68,14 +64,14 @@ const testLogger = pino({ }); const logger = testLogger.child({ name: 'rpc-acceptance-test' }); -const NETWORK = ConfigService.get('HEDERA_NETWORK') || DOT_ENV.HEDERA_NETWORK || ''; -const OPERATOR_KEY = ConfigService.get('OPERATOR_KEY_MAIN') || DOT_ENV.OPERATOR_KEY_MAIN || ''; -const OPERATOR_ID = ConfigService.get('OPERATOR_ID_MAIN') || DOT_ENV.OPERATOR_ID_MAIN || ''; -const MIRROR_NODE_URL = ConfigService.get('MIRROR_NODE_URL') || DOT_ENV.MIRROR_NODE_URL || ''; +const NETWORK = ConfigService.get(ConfigName.HEDERA_NETWORK) || DOT_ENV.HEDERA_NETWORK || ''; +const OPERATOR_KEY = ConfigService.get(ConfigName.OPERATOR_KEY_MAIN) || DOT_ENV.OPERATOR_KEY_MAIN || ''; +const OPERATOR_ID = ConfigService.get(ConfigName.OPERATOR_ID_MAIN) || DOT_ENV.OPERATOR_ID_MAIN || ''; +const MIRROR_NODE_URL = ConfigService.get(ConfigName.MIRROR_NODE_URL) || DOT_ENV.MIRROR_NODE_URL || ''; const LOCAL_RELAY_URL = 'http://localhost:7546'; -const RELAY_URL = ConfigService.get('E2E_RELAY_HOST') || LOCAL_RELAY_URL; -const CHAIN_ID = ConfigService.get('CHAIN_ID') || '0x12a'; -const INITIAL_BALANCE = ConfigService.get('INITIAL_BALANCE') || '5000000000'; +const RELAY_URL = ConfigService.get(ConfigName.E2E_RELAY_HOST) || LOCAL_RELAY_URL; +const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; +const INITIAL_BALANCE = ConfigService.get(ConfigName.INITIAL_BALANCE) || '5000000000'; let startOperatorBalance: Hbar; global.relayIsLocal = RELAY_URL === LOCAL_RELAY_URL; @@ -104,19 +100,19 @@ describe('RPC Server Acceptance Tests', function () { }; // leak detection middleware - if (ConfigService.get('MEMWATCH_ENABLED')) { + if (ConfigService.get(ConfigName.MEMWATCH_ENABLED)) { Utils.captureMemoryLeaks(new GCProfiler()); } before(async () => { // configuration details logger.info('Acceptance Tests Configurations successfully loaded'); - logger.info(`LOCAL_NODE: ${ConfigService.get('LOCAL_NODE')}`); - logger.info(`CHAIN_ID: ${ConfigService.get('CHAIN_ID')}`); + logger.info(`LOCAL_NODE: ${ConfigService.get(ConfigName.LOCAL_NODE)}`); + logger.info(`CHAIN_ID: ${ConfigService.get(ConfigName.CHAIN_ID)}`); logger.info(`HEDERA_NETWORK: ${NETWORK}`); logger.info(`OPERATOR_ID_MAIN: ${OPERATOR_ID}`); logger.info(`MIRROR_NODE_URL: ${MIRROR_NODE_URL}`); - logger.info(`E2E_RELAY_HOST: ${ConfigService.get('E2E_RELAY_HOST')}`); + logger.info(`E2E_RELAY_HOST: ${ConfigService.get(ConfigName.E2E_RELAY_HOST)}`); if (global.relayIsLocal) { runLocalRelay(); @@ -128,7 +124,7 @@ describe('RPC Server Acceptance Tests', function () { RELAY_URL, CHAIN_ID, Utils.generateRequestId(), - Number(ConfigService.get('TEST_INITIAL_ACCOUNT_STARTING_BALANCE') || 2000), + Number(ConfigService.get(ConfigName.TEST_INITIAL_ACCOUNT_STARTING_BALANCE) || 2000), ); global.accounts = new Array(initialAccount); @@ -199,7 +195,7 @@ describe('RPC Server Acceptance Tests', function () { relayServer.close(); } - if (ConfigService.get('TEST_WS_SERVER') && global.socketServer !== undefined) { + if (ConfigService.get(ConfigName.TEST_WS_SERVER) && global.socketServer !== undefined) { global.socketServer.close(); } } @@ -213,7 +209,7 @@ describe('RPC Server Acceptance Tests', function () { global.relayServer = relayServer; setServerTimeout(relayServer); - if (ConfigService.get('TEST_WS_SERVER')) { + if (ConfigService.get(ConfigName.TEST_WS_SERVER)) { logger.info(`Start ws-server on port ${constants.WEB_SOCKET_PORT}`); global.socketServer = wsApp.listen({ port: constants.WEB_SOCKET_PORT }); } diff --git a/packages/server/tests/acceptance/rateLimiter.spec.ts b/packages/server/tests/acceptance/rateLimiter.spec.ts index 679536dc64..080b9a41d9 100644 --- a/packages/server/tests/acceptance/rateLimiter.spec.ts +++ b/packages/server/tests/acceptance/rateLimiter.spec.ts @@ -20,11 +20,13 @@ // Assertions and constants from local resources -import Assertions from '../helpers/assertions'; -import testConstants from '../../tests/helpers/constants'; -import relayConstants from '@hashgraph/json-rpc-relay/dist/lib/constants'; import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import relayConstants from '@hashgraph/json-rpc-relay/dist/lib/constants'; + +import { ConfigName } from '../../../config-service/src/services/configName'; +import testConstants from '../../tests/helpers/constants'; import RelayClient from '../clients/relayClient'; +import Assertions from '../helpers/assertions'; describe('@ratelimiter Rate Limiters Acceptance Tests', function () { this.timeout(480 * 1000); // 480 seconds @@ -36,9 +38,9 @@ describe('@ratelimiter Rate Limiters Acceptance Tests', function () { let requestId: string; const TIER_2_RATE_LIMIT = - (ConfigService.get('TIER_2_RATE_LIMIT') as unknown as number) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2; + (ConfigService.get(ConfigName.TIER_2_RATE_LIMIT) as unknown as number) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2; const LIMIT_DURATION = - (ConfigService.get('LIMIT_DURATION') as unknown as number) || relayConstants.DEFAULT_RATE_LIMIT.DURATION; + (ConfigService.get(ConfigName.LIMIT_DURATION) as unknown as number) || relayConstants.DEFAULT_RATE_LIMIT.DURATION; describe('RPC Rate Limiter Acceptance Tests', () => { const sendMultipleRequests = async (method: string, params: any[], threshold: number) => { diff --git a/packages/server/tests/acceptance/rpc_batch1.spec.ts b/packages/server/tests/acceptance/rpc_batch1.spec.ts index 0c41b43478..e62f95d886 100644 --- a/packages/server/tests/acceptance/rpc_batch1.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch1.spec.ts @@ -37,6 +37,7 @@ import { import { expect } from 'chai'; import { ethers } from 'ethers'; +import { ConfigName } from '../../../config-service/src/services/configName'; import { ConfigServiceTestHelper } from '../../../config-service/tests/configServiceTestHelper'; import basicContract from '../../tests/contracts/Basic.json'; import RelayCalls from '../../tests/helpers/constants'; @@ -72,7 +73,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () { let account2Address: string; let expectedGasPrice: string; - const CHAIN_ID = (ConfigService.get('CHAIN_ID') as string) || '0x12a'; + const CHAIN_ID = (ConfigService.get(ConfigName.CHAIN_ID) as string) || '0x12a'; const requestId = 'rpc_batch1Test'; const requestIdPrefix = Utils.formatRequestIdMessage(requestId); const requestDetails = JSON.stringify(new RequestDetails({ requestId: 'rpc_batch1Test', ipAddress: '0.0.0.0' })); @@ -83,9 +84,9 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () { const TEN_HBAR = Utils.add0xPrefix( (BigInt(new Hbar(10).toTinybars().toString()) * BigInt(Constants.TINYBAR_TO_WEIBAR_COEF)).toString(16), ); - const gasPriceDeviation = parseFloat((ConfigService.get('TEST_GAS_PRICE_DEVIATION') ?? '0.2') as string); + const gasPriceDeviation = parseFloat((ConfigService.get(ConfigName.TEST_GAS_PRICE_DEVIATION) ?? '0.2') as string); const sendRawTransaction = relay.sendRawTransaction; - const useAsyncTxProcessing = ConfigService.get('USE_ASYNC_TX_PROCESSING') as boolean; + const useAsyncTxProcessing = ConfigService.get(ConfigName.USE_ASYNC_TX_PROCESSING) as boolean; /** * resolves long zero addresses to EVM addresses by querying mirror node diff --git a/packages/server/tests/acceptance/rpc_batch2.spec.ts b/packages/server/tests/acceptance/rpc_batch2.spec.ts index b64b131399..17d8caae65 100644 --- a/packages/server/tests/acceptance/rpc_batch2.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch2.spec.ts @@ -20,6 +20,7 @@ // External resources import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { ConfigName } from '@hashgraph/json-rpc-config-service/src/services/configName'; import { predefined } from '@hashgraph/json-rpc-relay/dist'; import { numberTo0x } from '@hashgraph/json-rpc-relay/dist/formatters'; import { EthImpl } from '@hashgraph/json-rpc-relay/dist/lib/eth'; @@ -79,7 +80,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () { let createChildTx: ethers.ContractTransactionResponse; let accounts0StartBalance: bigint; - const CHAIN_ID = ConfigService.get('CHAIN_ID') || 0; + const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || 0; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); const ONE_WEIBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 18))); @@ -441,7 +442,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () { it('@release should call eth_gasPrice', async function () { const res = await relay.call(RelayCalls.ETH_ENDPOINTS.ETH_GAS_PRICE, [], requestId); expect(res).to.exist; - if (ConfigService.get('LOCAL_NODE')) { + if (ConfigService.get(ConfigName.LOCAL_NODE)) { expect(res).be.equal(expectedGasPrice); } else { expect(Number(res)).to.be.gt(0); @@ -1076,7 +1077,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () { }); // Only run the following tests against a local node since they only work with the genesis account - if (ConfigService.get('LOCAL_NODE')) { + if (ConfigService.get(ConfigName.LOCAL_NODE)) { describe('Gas Price related RPC endpoints', () => { let lastBlockBeforeUpdate; let lastBlockAfterUpdate; diff --git a/packages/server/tests/acceptance/rpc_batch3.spec.ts b/packages/server/tests/acceptance/rpc_batch3.spec.ts index 6528df9e08..d57ba0f60d 100644 --- a/packages/server/tests/acceptance/rpc_batch3.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch3.spec.ts @@ -56,6 +56,7 @@ import Assertions from '../helpers/assertions'; import RelayCalls from '../helpers/constants'; import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; +import { ConfigName } from '@hashgraph/json-rpc-config-service/src/services/configName'; chai.use(chaiExclude); @@ -74,7 +75,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () { let mirrorPrimaryAccount: ethers.Wallet; let mirrorSecondaryAccount: ethers.Wallet; - const CHAIN_ID = ConfigService.get('CHAIN_ID') || 0x12a; + const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || 0x12a; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); let reverterContract: ethers.Contract; @@ -547,7 +548,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () { }); // value is processed only when eth_call goes through the mirror node - if (!ConfigService.get('ETH_CALL_DEFAULT_TO_CONSENSUS_NODE')) { + if (!ConfigService.get(ConfigName.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE)) { it('010 Should call msgValue', async function () { const callData = { ...defaultCallData, @@ -611,7 +612,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () { }; // Since we want the http status code, we need to perform the call using a client http request instead of using the relay instance directly - const testClientPort = ConfigService.get('E2E_SERVER_PORT') || '7546'; + const testClientPort = ConfigService.get(ConfigName.E2E_SERVER_PORT) || '7546'; const testClient = Axios.create({ baseURL: 'http://localhost:' + testClientPort, responseType: 'json' as const, @@ -797,7 +798,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () { let initialEthCallSelectorsAlwaysToConsensus: any, hrc719Contract: ethers.Contract; before(async () => { - initialEthCallSelectorsAlwaysToConsensus = ConfigService.get('ETH_CALL_CONSENSUS_SELECTORS'); + initialEthCallSelectorsAlwaysToConsensus = ConfigService.get(ConfigName.ETH_CALL_CONSENSUS_SELECTORS); hrc719Contract = await Utils.deployContract( HRC719ContractJson.abi, @@ -814,7 +815,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () { }); it('should NOT allow eth_call to process IHRC719.isAssociated() method', async () => { - const selectorsList = ConfigService.get('ETH_CALL_CONSENSUS_SELECTORS'); + const selectorsList = ConfigService.get(ConfigName.ETH_CALL_CONSENSUS_SELECTORS); expect(selectorsList).to.be.undefined; // If the selector for `isAssociated` is not included in `ETH_CALL_CONSENSUS_SELECTORS`, the request will fail with a `CALL_EXCEPTION` error code. diff --git a/packages/server/tests/acceptance/serverConfig.spec.ts b/packages/server/tests/acceptance/serverConfig.spec.ts index a9c4086dc7..303b523a75 100644 --- a/packages/server/tests/acceptance/serverConfig.spec.ts +++ b/packages/server/tests/acceptance/serverConfig.spec.ts @@ -17,16 +17,18 @@ * limitations under the License. * */ +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { expect } from 'chai'; + +import { ConfigName } from '../../../config-service/src/services/configName'; import { Utils } from '../helpers/utils'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; describe('@server-config Server Configuration Options Coverage', function () { describe('Koa Server Timeout', () => { it('should timeout a request after the specified time', async () => { - const requestTimeoutMs: number = parseInt(ConfigService.get('SERVER_REQUEST_TIMEOUT_MS') || '3000'); + const requestTimeoutMs: number = parseInt(ConfigService.get(ConfigName.SERVER_REQUEST_TIMEOUT_MS) as string || '3000'); const host = ConfigService.get('SERVER_HOST') || 'localhost'; - const port = parseInt(ConfigService.get('SERVER_PORT') || '7546'); + const port = parseInt(ConfigService.get(ConfigName.SERVER_PORT) as string || '7546'); const method = 'eth_blockNumber'; const params: any[] = []; diff --git a/packages/server/tests/integration/server.spec.ts b/packages/server/tests/integration/server.spec.ts index 4b40136921..266ca96699 100644 --- a/packages/server/tests/integration/server.spec.ts +++ b/packages/server/tests/integration/server.spec.ts @@ -21,17 +21,16 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { ConfigServiceTestHelper } from '../../../config-service/tests/configServiceTestHelper'; ConfigServiceTestHelper.appendEnvsFromPath(__dirname + '/test.env'); +import { predefined, RelayImpl } from '@hashgraph/json-rpc-relay'; +import { MirrorNodeClient } from '@hashgraph/json-rpc-relay/dist/lib/clients'; import Axios, { AxiosInstance } from 'axios'; import { expect } from 'chai'; -import sinon from 'sinon'; import { Server } from 'http'; +import Koa from 'koa'; +import sinon from 'sinon'; import { GCProfiler } from 'v8'; -import Assertions from '../helpers/assertions'; -import { TracerType, Validator } from '../../src/validator'; -import RelayCalls from '../../tests/helpers/constants'; -import * as Constants from '../../src/validator/constants'; -import { Utils } from '../helpers/utils'; -import { predefined, RelayImpl } from '@hashgraph/json-rpc-relay'; + +import { ConfigName } from '../../../config-service/src/services/configName'; import { contractAddress1, contractAddress2, @@ -40,8 +39,11 @@ import { overrideEnvsInMochaDescribe, withOverriddenEnvsInMochaTest, } from '../../../relay/tests/helpers'; -import { MirrorNodeClient } from '@hashgraph/json-rpc-relay/dist/lib/clients'; -import Koa from 'koa'; +import { TracerType, Validator } from '../../src/validator'; +import * as Constants from '../../src/validator/constants'; +import RelayCalls from '../../tests/helpers/constants'; +import Assertions from '../helpers/assertions'; +import { Utils } from '../helpers/utils'; const MISSING_PARAM_ERROR = 'Missing value for required parameter'; @@ -54,11 +56,11 @@ describe('RPC Server', function () { before(function () { populatePreconfiguredSpendingPlansSpy = sinon.spy(RelayImpl.prototype, 'populatePreconfiguredSpendingPlans'); app = require('../../src/server').default; - testServer = app.listen(ConfigService.get('E2E_SERVER_PORT')); + testServer = app.listen(ConfigService.get(ConfigName.E2E_SERVER_PORT)); testClient = BaseTest.createTestClient(); // leak detection middleware - if (ConfigService.get('MEMWATCH_ENABLED')) { + if (ConfigService.get(ConfigName.MEMWATCH_ENABLED)) { Utils.captureMemoryLeaks(new GCProfiler()); } }); @@ -118,7 +120,7 @@ describe('RPC Server', function () { }); BaseTest.defaultResponseChecks(res); - expect(res.data.result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(res.data.result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); }); it('validates enforcement of request id', async function () { @@ -138,7 +140,7 @@ describe('RPC Server', function () { withOverriddenEnvsInMochaTest({ REQUEST_ID_IS_OPTIONAL: true }, async function () { xit('supports optionality of request id when configured', async function () { const app2 = require('../../src/server').default; - const port = `1${ConfigService.get('E2E_SERVER_PORT')}`; + const port = `1${ConfigService.get(ConfigName.E2E_SERVER_PORT)}`; const testServer2 = app2.listen(port); try { @@ -157,7 +159,7 @@ describe('RPC Server', function () { expect(response.data, "Default response: 'data' should have 'result' property").to.have.property('result'); expect(response.data.id, "Default response: 'data.id' should equal '2'").to.be.equal('2'); expect(response.data.jsonrpc, "Default response: 'data.jsonrpc' should equal '2.0'").to.be.equal('2.0'); - expect(response.data.result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(response.data.result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); } catch (error: any) { expect(true, `Unexpected error: ${error.message}`).to.eq(false); } finally { @@ -188,7 +190,7 @@ describe('RPC Server', function () { }); BaseTest.defaultResponseChecks(res); - expect(res.data.result).to.be.equal('relay/' + ConfigService.get('npm_package_version')); + expect(res.data.result).to.be.equal('relay/' + ConfigService.get(ConfigName.npm_package_version)); }); it('should execute "eth_getTransactionByHash with missing transaction"', async function () { @@ -541,7 +543,7 @@ describe('RPC Server', function () { // verify response for each request for (let i = 0; i < response.data.length; i++) { expect(response.data[i].id).to.be.equal((i + 2).toString()); - expect(response.data[i].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(response.data[i].result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); } }); @@ -558,14 +560,14 @@ describe('RPC Server', function () { // verify response for each result expect(response.data[0].id).to.be.equal('2'); - expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); // verify eth_accounts result expect(response.data[1].id).to.be.equal('3'); expect(response.data[1].result).to.be.an('Array'); expect(response.data[1].result.length).to.be.equal(0); // verify eth_chainId result expect(response.data[2].id).to.be.equal('4'); - expect(response.data[2].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(response.data[2].result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); }); it('should execute "eth_chainId" and "eth_accounts" in batch request with invalid request id', async function () { @@ -576,7 +578,7 @@ describe('RPC Server', function () { // verify response for each result expect(response.data[0].id).to.be.equal('2'); - expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); // verify eth_accounts result expect(response.data[1].id).to.be.equal(null); expect(response.data[1].error).to.be.an('Object'); @@ -596,7 +598,7 @@ describe('RPC Server', function () { // verify eth_chainId result on position 0 expect(response.data[0].id).to.be.equal('2'); - expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); // verify method not found error on position 1 expect(response.data[1].id).to.be.equal('3'); expect(response.data[1].error).to.be.an('Object'); @@ -604,7 +606,7 @@ describe('RPC Server', function () { expect(response.data[1].error.message).to.be.equal('Method non_existent_method not found'); // verify eth_chainId result on position 2 expect(response.data[2].id).to.be.equal('4'); - expect(response.data[2].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(response.data[2].result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); }); it('should execute "eth_chainId" and method not found and params error in batch request', async function () { @@ -624,7 +626,7 @@ describe('RPC Server', function () { // verify eth_chainId result on position 0 expect(response.data[0].id).to.be.equal('2'); - expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); // verify method not found error on position 1 expect(response.data[1].id).to.be.equal('3'); expect(response.data[1].error).to.be.an('Object'); @@ -2701,7 +2703,7 @@ describe('RPC Server', function () { }); class BaseTest { - static createTestClient(port = ConfigService.get('E2E_SERVER_PORT')) { + static createTestClient(port = ConfigService.get(ConfigName.E2E_SERVER_PORT)) { return Axios.create({ baseURL: 'http://localhost:' + port, responseType: 'json' as const, diff --git a/packages/ws-server/tests/acceptance/batchRequest.spec.ts b/packages/ws-server/tests/acceptance/batchRequest.spec.ts index 9295708856..6816d12ae9 100644 --- a/packages/ws-server/tests/acceptance/batchRequest.spec.ts +++ b/packages/ws-server/tests/acceptance/batchRequest.spec.ts @@ -19,11 +19,13 @@ */ // external resources +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { predefined } from '@hashgraph/json-rpc-relay/dist'; import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; + +import { ConfigName } from '../../../config-service/src/services/configName'; import { WsTestConstant, WsTestHelper } from '../helper'; -import { predefined } from '@hashgraph/json-rpc-relay/dist'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; describe('@web-socket-batch-request Batch Requests', async function () { const METHOD_NAME = 'batch_request'; @@ -103,7 +105,7 @@ describe('@web-socket-batch-request Batch Requests', async function () { const expectedError = predefined.BATCH_REQUESTS_AMOUNT_MAX_EXCEEDED( batchRequests.length, - Number(ConfigService.get('WS_BATCH_REQUESTS_MAX_SIZE')), + Number(ConfigService.get(ConfigName.WS_BATCH_REQUESTS_MAX_SIZE)), ); delete expectedError.data; diff --git a/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts b/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts index 4b1f4d0a9c..3ff79469f7 100644 --- a/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts @@ -19,21 +19,23 @@ */ // external resources -import { expect } from 'chai'; -import { ethers, WebSocketProvider } from 'ethers'; -import { WsTestConstant, WsTestHelper } from '../helper'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { numberTo0x } from '@hashgraph/json-rpc-relay/dist/formatters'; +import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; import { ONE_TINYBAR_IN_WEI_HEX } from '@hashgraph/json-rpc-relay/tests/lib/eth/eth-config'; -import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; -import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import MirrorClient from '@hashgraph/json-rpc-server/tests/clients/mirrorClient'; import RelayClient from '@hashgraph/json-rpc-server/tests/clients/relayClient'; -import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; +import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; +import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; +import { expect } from 'chai'; +import { ethers, WebSocketProvider } from 'ethers'; + +import { ConfigName } from '../../../config-service/src/services/configName'; +import { WsTestConstant, WsTestHelper } from '../helper'; describe('@web-socket-batch-2 eth_getTransactionByHash', async function () { const METHOD_NAME = 'eth_getTransactionByHash'; - const CHAIN_ID = ConfigService.get('CHAIN_ID') || '0x12a'; + const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; const INVALID_PARAMS = [ [], [''], diff --git a/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts b/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts index 278f6cf97f..048aacbdf0 100644 --- a/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts @@ -19,20 +19,22 @@ */ // external resources -import { expect } from 'chai'; -import { ethers, WebSocketProvider } from 'ethers'; -import { WsTestConstant, WsTestHelper } from '../helper'; -import { numberTo0x } from '@hashgraph/json-rpc-relay/dist/formatters'; -import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; -import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { numberTo0x } from '@hashgraph/json-rpc-relay/dist/formatters'; +import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; import MirrorClient from '@hashgraph/json-rpc-server/tests/clients/mirrorClient'; import RelayClient from '@hashgraph/json-rpc-server/tests/clients/relayClient'; -import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; +import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; +import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; +import { expect } from 'chai'; +import { ethers, WebSocketProvider } from 'ethers'; + +import { ConfigName } from '../../../config-service/src/services/configName'; +import { WsTestConstant, WsTestHelper } from '../helper'; describe('@release @web-socket-batch-2 eth_getTransactionCount', async function () { const METHOD_NAME = 'eth_getTransactionCount'; - const CHAIN_ID = ConfigService.get('CHAIN_ID') || '0x12a'; + const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); // @ts-ignore diff --git a/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts b/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts index be26f3061b..050cda646d 100644 --- a/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts @@ -19,21 +19,23 @@ */ // external resources -import { expect } from 'chai'; -import { ethers, WebSocketProvider } from 'ethers'; -import { WsTestConstant, WsTestHelper } from '../helper'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { numberTo0x } from '@hashgraph/json-rpc-relay/dist/formatters'; +import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; import { ONE_TINYBAR_IN_WEI_HEX } from '@hashgraph/json-rpc-relay/tests/lib/eth/eth-config'; -import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; -import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import MirrorClient from '@hashgraph/json-rpc-server/tests/clients/mirrorClient'; import RelayClient from '@hashgraph/json-rpc-server/tests/clients/relayClient'; -import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; +import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; +import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; +import { expect } from 'chai'; +import { ethers, WebSocketProvider } from 'ethers'; + +import { ConfigName } from '../../../config-service/src/services/configName'; +import { WsTestConstant, WsTestHelper } from '../helper'; describe('@web-socket-batch-2 eth_getTransactionReceipt', async function () { const METHOD_NAME = 'eth_getTransactionReceipt'; - const CHAIN_ID = ConfigService.get('CHAIN_ID') || '0x12a'; + const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; const INVALID_PARAMS = [ [], [''], diff --git a/packages/ws-server/tests/acceptance/index.spec.ts b/packages/ws-server/tests/acceptance/index.spec.ts index 6cb0202326..dec92e8006 100644 --- a/packages/ws-server/tests/acceptance/index.spec.ts +++ b/packages/ws-server/tests/acceptance/index.spec.ts @@ -17,25 +17,27 @@ * limitations under the License. * */ -import chai from 'chai'; -import path from 'path'; -import pino from 'pino'; -import dotenv from 'dotenv'; -import chaiAsPromised from 'chai-as-promised'; -import fs from 'fs'; -import { AccountId, Hbar } from '@hashgraph/sdk'; -import app from '@hashgraph/json-rpc-server/dist/server'; +import { Server } from 'node:http'; + +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { ConfigName } from '@hashgraph/json-rpc-config-service/src/services/configName'; import constants from '@hashgraph/json-rpc-relay/dist/lib/constants'; -import RelayClient from '@hashgraph/json-rpc-server/tests/clients/relayClient'; +import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; +import { setServerTimeout } from '@hashgraph/json-rpc-server/dist/koaJsonRpc/lib/utils'; +import app from '@hashgraph/json-rpc-server/dist/server'; import MirrorClient from '@hashgraph/json-rpc-server/tests/clients/mirrorClient'; -import { app as wsApp } from '@hashgraph/json-rpc-ws-server/dist/webSocketServer'; +import RelayClient from '@hashgraph/json-rpc-server/tests/clients/relayClient'; import ServicesClient from '@hashgraph/json-rpc-server/tests/clients/servicesClient'; import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; -import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; -import { Server } from 'node:http'; -import { setServerTimeout } from '@hashgraph/json-rpc-server/dist/koaJsonRpc/lib/utils'; +import { app as wsApp } from '@hashgraph/json-rpc-ws-server/dist/webSocketServer'; +import { AccountId, Hbar } from '@hashgraph/sdk'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +import dotenv from 'dotenv'; +import fs from 'fs'; +import path from 'path'; +import pino from 'pino'; chai.use(chaiAsPromised); @@ -44,7 +46,7 @@ const DOT_ENV = dotenv.parse(fs.readFileSync(path.resolve(__dirname, '../../../. const testLogger = pino({ name: 'hedera-json-rpc-relay', - level: ConfigService.get('LOG_LEVEL') || 'trace', + level: ConfigService.get(ConfigName.LOG_LEVEL) || 'trace', transport: { target: 'pino-pretty', options: { @@ -55,13 +57,13 @@ const testLogger = pino({ }); const logger = testLogger.child({ name: 'rpc-acceptance-test' }); -const NETWORK = ConfigService.get('HEDERA_NETWORK') || DOT_ENV.HEDERA_NETWORK || ''; -const OPERATOR_KEY = ConfigService.get('OPERATOR_KEY_MAIN') || DOT_ENV.OPERATOR_KEY_MAIN || ''; -const OPERATOR_ID = ConfigService.get('OPERATOR_ID_MAIN') || DOT_ENV.OPERATOR_ID_MAIN || ''; -const MIRROR_NODE_URL = ConfigService.get('MIRROR_NODE_URL') || DOT_ENV.MIRROR_NODE_URL || ''; +const NETWORK = ConfigService.get(ConfigName.HEDERA_NETWORK) || DOT_ENV.HEDERA_NETWORK || ''; +const OPERATOR_KEY = ConfigService.get(ConfigName.OPERATOR_KEY_MAIN) || DOT_ENV.OPERATOR_KEY_MAIN || ''; +const OPERATOR_ID = ConfigService.get(ConfigName.OPERATOR_ID_MAIN) || DOT_ENV.OPERATOR_ID_MAIN || ''; +const MIRROR_NODE_URL = ConfigService.get(ConfigName.MIRROR_NODE_URL) || DOT_ENV.MIRROR_NODE_URL || ''; const LOCAL_RELAY_URL = 'http://localhost:7546'; -const RELAY_URL = ConfigService.get('E2E_RELAY_HOST') || LOCAL_RELAY_URL; -const CHAIN_ID = ConfigService.get('CHAIN_ID') || '0x12a'; +const RELAY_URL = ConfigService.get(ConfigName.E2E_RELAY_HOST) || LOCAL_RELAY_URL; +const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; let startOperatorBalance: Hbar; global.relayIsLocal = RELAY_URL === LOCAL_RELAY_URL; @@ -82,12 +84,12 @@ describe('RPC Server Acceptance Tests', function () { before(async () => { // configuration details logger.info('Acceptance Tests Configurations successfully loaded'); - logger.info(`LOCAL_NODE: ${ConfigService.get('LOCAL_NODE')}`); - logger.info(`CHAIN_ID: ${ConfigService.get('CHAIN_ID')}`); + logger.info(`LOCAL_NODE: ${ConfigService.get(ConfigName.LOCAL_NODE)}`); + logger.info(`CHAIN_ID: ${ConfigService.get(ConfigName.CHAIN_ID)}`); logger.info(`HEDERA_NETWORK: ${NETWORK}`); logger.info(`OPERATOR_ID_MAIN: ${OPERATOR_ID}`); logger.info(`MIRROR_NODE_URL: ${MIRROR_NODE_URL}`); - logger.info(`E2E_RELAY_HOST: ${ConfigService.get('E2E_RELAY_HOST')}`); + logger.info(`E2E_RELAY_HOST: ${ConfigService.get(ConfigName.E2E_RELAY_HOST)}`); if (global.relayIsLocal) { runLocalRelay(); @@ -147,7 +149,7 @@ describe('RPC Server Acceptance Tests', function () { } const socketServer: Server = global.socketServer; - if (ConfigService.get('TEST_WS_SERVER') && socketServer !== undefined) { + if (ConfigService.get(ConfigName.TEST_WS_SERVER) && socketServer !== undefined) { socketServer.close(); } }); @@ -178,7 +180,7 @@ describe('RPC Server Acceptance Tests', function () { global.relayServer = relayServer; setServerTimeout(relayServer); - if (ConfigService.get('TEST_WS_SERVER')) { + if (ConfigService.get(ConfigName.TEST_WS_SERVER)) { logger.info(`Start ws-server on port ${constants.WEB_SOCKET_PORT}`); global.socketServer = wsApp.listen({ port: constants.WEB_SOCKET_PORT }); } diff --git a/packages/ws-server/tests/acceptance/rateLimiter.spec.ts b/packages/ws-server/tests/acceptance/rateLimiter.spec.ts index 1607c5fa4a..04d0c03cab 100644 --- a/packages/ws-server/tests/acceptance/rateLimiter.spec.ts +++ b/packages/ws-server/tests/acceptance/rateLimiter.spec.ts @@ -19,17 +19,19 @@ */ // external resources -import { expect } from 'chai'; -import { WsTestHelper } from '../helper'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import relayConstants from '@hashgraph/json-rpc-relay/dist/lib/constants'; -import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; import { IPRateLimitExceeded } from '@hashgraph/json-rpc-server/dist/koaJsonRpc/lib/RpcError'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; +import { expect } from 'chai'; + +import { ConfigName } from '../../../config-service/src/services/configName'; import { ConfigServiceTestHelper } from '../../../config-service/tests/configServiceTestHelper'; +import { WsTestHelper } from '../helper'; describe('@web-socket-ratelimiter Rate Limit Tests', async function () { - const rateLimitTier2 = Number(ConfigService.get('TIER_2_RATE_LIMIT') || relayConstants.DEFAULT_RATE_LIMIT.TIER_2); - const limitDuration = Number(ConfigService.get('LIMIT_DURATION')) || relayConstants.DEFAULT_RATE_LIMIT.DURATION; + const rateLimitTier2 = Number(ConfigService.get(ConfigName.TIER_2_RATE_LIMIT) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2); + const limitDuration = Number(ConfigService.get(ConfigName.LIMIT_DURATION)) || relayConstants.DEFAULT_RATE_LIMIT.DURATION; const batchRequests = [ { diff --git a/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts b/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts index bda0c5f2d4..04dd84cd94 100644 --- a/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts +++ b/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts @@ -19,23 +19,25 @@ */ // external resources -import { expect } from 'chai'; -import { ethers, WebSocketProvider } from 'ethers'; -import { WsTestConstant, WsTestHelper } from '../helper'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { predefined } from '@hashgraph/json-rpc-relay/dist'; -import constants from '@hashgraph/json-rpc-relay/dist/lib/constants'; import { numberTo0x } from '@hashgraph/json-rpc-relay/dist/formatters'; -import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; -import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; +import constants from '@hashgraph/json-rpc-relay/dist/lib/constants'; +import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; import { ONE_TINYBAR_IN_WEI_HEX } from '@hashgraph/json-rpc-relay/tests/lib/eth/eth-config'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import MirrorClient from '@hashgraph/json-rpc-server/tests/clients/mirrorClient'; import RelayClient from '@hashgraph/json-rpc-server/tests/clients/relayClient'; -import { RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/types'; +import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; +import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; +import { expect } from 'chai'; +import { ethers, WebSocketProvider } from 'ethers'; + +import { ConfigName } from '../../../config-service/src/services/configName'; +import { WsTestConstant, WsTestHelper } from '../helper'; describe('@web-socket-batch-2 eth_sendRawTransaction', async function () { const METHOD_NAME = 'eth_sendRawTransaction'; - const CHAIN_ID = ConfigService.get('CHAIN_ID') || '0x12a'; + const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; const INVALID_PARAMS = [ [], [''], diff --git a/packages/ws-server/tests/acceptance/subscribe.spec.ts b/packages/ws-server/tests/acceptance/subscribe.spec.ts index 479705e632..b42e168a75 100644 --- a/packages/ws-server/tests/acceptance/subscribe.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribe.spec.ts @@ -19,24 +19,26 @@ */ // external resources -import WebSocket from 'ws'; -import { ethers } from 'ethers'; -import chai, { expect } from 'chai'; -import { WsTestHelper } from '../helper'; -import { solidity } from 'ethereum-waffle'; -import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; -import Constants from '@hashgraph/json-rpc-server/tests/helpers/constants'; +import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import { predefined, WebSocketError } from '@hashgraph/json-rpc-relay/dist'; +import LogContractJson from '@hashgraph/json-rpc-server/tests/contracts/Logs.json'; +import IERC20Json from '@hashgraph/json-rpc-server/tests/contracts/openzeppelin/IERC20.json'; import Assertions from '@hashgraph/json-rpc-server/tests/helpers/assertions'; import assertions from '@hashgraph/json-rpc-server/tests/helpers/assertions'; -import LogContractJson from '@hashgraph/json-rpc-server/tests/contracts/Logs.json'; +import Constants from '@hashgraph/json-rpc-server/tests/helpers/constants'; +import { Utils } from '@hashgraph/json-rpc-server/tests/helpers/utils'; import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccount'; -import IERC20Json from '@hashgraph/json-rpc-server/tests/contracts/openzeppelin/IERC20.json'; -import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; +import chai, { expect } from 'chai'; +import { solidity } from 'ethereum-waffle'; +import { ethers } from 'ethers'; +import WebSocket from 'ws'; + +import { ConfigName } from '../../../config-service/src/services/configName'; +import { WsTestHelper } from '../helper'; chai.use(solidity); -const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL')}`; +const WS_RELAY_URL = `${ConfigService.get(ConfigName.WS_RELAY_URL)}`; const establishConnection = async () => { const provider = await new ethers.WebSocketProvider(WS_RELAY_URL); @@ -73,7 +75,7 @@ const createLogs = async (contract: ethers.Contract, requestId) => { describe('@web-socket-batch-3 eth_subscribe', async function () { this.timeout(240 * 1000); // 240 seconds - const CHAIN_ID = ConfigService.get('CHAIN_ID') || 0; + const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || 0; let server; // @ts-ignore const { servicesNode, relay, mirrorNode } = global; @@ -435,12 +437,12 @@ describe('@web-socket-batch-3 eth_subscribe', async function () { // We already have one connection expect(server._connections).to.equal(1); - for (let i = 1; i < parseInt(ConfigService.get('WS_CONNECTION_LIMIT')); i++) { + for (let i = 1; i < parseInt(ConfigService.get(ConfigName.WS_CONNECTION_LIMIT) as string); i++) { providers.push(await establishConnection()); } // Server is at max connections - expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT'))); + expect(server._connections).to.equal(parseInt(ConfigService.get(ConfigName.WS_CONNECTION_LIMIT) as string)); }); afterEach(async () => { @@ -499,7 +501,7 @@ describe('@web-socket-batch-3 eth_subscribe', async function () { expect(message.toString('utf8')).to.equal(WebSocketError.TTL_EXPIRED.message); }); - await new Promise((resolve) => setTimeout(resolve, parseInt(ConfigService.get('WS_MAX_INACTIVITY_TTL')) + 1000)); + await new Promise((resolve) => setTimeout(resolve, parseInt(ConfigService.get(ConfigName.WS_MAX_INACTIVITY_TTL) as string) + 1000)); expect(closeEventHandled2).to.eq(true); expect(closeEventHandled3).to.eq(true); @@ -896,7 +898,7 @@ describe('@web-socket-batch-3 eth_subscribe', async function () { // Creates the maximum allowed connections // @ts-ignore - for (let i = 1; i < parseInt(ConfigService.get('WS_CONNECTION_LIMIT_PER_IP')); i++) { + for (let i = 1; i < parseInt(ConfigService.get(ConfigName.WS_CONNECTION_LIMIT_PER_IP)); i++) { // @ts-ignore providers.push(await new ethers.WebSocketProvider(WS_RELAY_URL)); } @@ -906,7 +908,7 @@ describe('@web-socket-batch-3 eth_subscribe', async function () { // Repeat the following several times to make sure the internal counters are consistently correct for (let i = 0; i < 3; i++) { // @ts-ignore - expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT_PER_IP'))); + expect(server._connections).to.equal(parseInt(ConfigService.get(ConfigName.WS_CONNECTION_LIMIT_PER_IP))); // The next connection should be closed by the server const provider = await new ethers.WebSocketProvider(WS_RELAY_URL); @@ -921,7 +923,7 @@ describe('@web-socket-batch-3 eth_subscribe', async function () { await new Promise((resolve) => setTimeout(resolve, 1000)); // @ts-ignore - expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT_PER_IP'))); + expect(server._connections).to.equal(parseInt(ConfigService.get(ConfigName.WS_CONNECTION_LIMIT_PER_IP))); expect(closeEventHandled).to.eq(true); await new Promise((resolve) => setTimeout(resolve, 1000)); diff --git a/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts b/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts index 5c207aaa0d..53d579dd3f 100644 --- a/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts @@ -31,11 +31,12 @@ import { solidity } from 'ethereum-waffle'; import { ethers } from 'ethers'; import WebSocket from 'ws'; +import { ConfigName } from '../../../config-service/src/services/configName'; import { WsTestHelper } from '../helper'; chai.use(solidity); -const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL')}`; +const WS_RELAY_URL = `${ConfigService.get(ConfigName.WS_RELAY_URL)}`; const evmAddressRegex = /^0x[a-fA-F0-9]*$/; function verifyResponse(response: any, done: Mocha.Done, webSocket: any, includeTransactions: boolean) { @@ -99,7 +100,7 @@ function verifyResponse(response: any, done: Mocha.Done, webSocket: any, include describe('@web-socket-batch-3 eth_subscribe newHeads', async function () { this.timeout(240 * 1000); // 240 seconds const accounts: AliasAccount[] = []; - const CHAIN_ID = ConfigService.get('CHAIN_ID') || 0; + const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || 0; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); let mirrorNodeServer, requestId, rpcServer, wsServer; @@ -196,7 +197,7 @@ describe('@web-socket-batch-3 eth_subscribe newHeads', async function () { WsTestHelper.withOverriddenEnvsInMochaTest({ WS_NEW_HEADS_ENABLED: undefined }, () => { it('@release should subscribe to newHeads and receive a valid JSON RPC response', async (done) => { - expect(ConfigService.get('WS_NEW_HEADS_ENABLED')).to.be.undefined; + expect(ConfigService.get(ConfigName.WS_NEW_HEADS_ENABLED)).to.be.undefined; const webSocket = new WebSocket(WS_RELAY_URL); const subscriptionId = 1;