From 1ddc804889d1441cc66c1597d97eb6d53011ab62 Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Sat, 21 Dec 2024 03:20:53 +0100 Subject: [PATCH 01/11] 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 --- .../config-service/src/services/configName.ts | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 packages/config-service/src/services/configName.ts diff --git a/packages/config-service/src/services/configName.ts b/packages/config-service/src/services/configName.ts new file mode 100644 index 0000000000..983c178dc7 --- /dev/null +++ b/packages/config-service/src/services/configName.ts @@ -0,0 +1,141 @@ +/*- + * + * Hedera JSON RPC Relay + * + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +export enum ConfigName { + BATCH_REQUESTS_ENABLED = 'BATCH_REQUESTS_ENABLED', + BATCH_REQUESTS_MAX_SIZE = 'BATCH_REQUESTS_MAX_SIZE', + CACHE_MAX = 'CACHE_MAX', + CACHE_TTL = 'CACHE_TTL', + CHAIN_ID = 'CHAIN_ID', + CLIENT_TRANSPORT_SECURITY = 'CLIENT_TRANSPORT_SECURITY', + CONSENSUS_MAX_EXECUTION_TIME = 'CONSENSUS_MAX_EXECUTION_TIME', + CONTRACT_CALL_GAS_LIMIT = 'CONTRACT_CALL_GAS_LIMIT', + CONTRACT_QUERY_TIMEOUT_RETRIES = 'CONTRACT_QUERY_TIMEOUT_RETRIES', + DEBUG_API_ENABLED = 'DEBUG_API_ENABLED', + DEFAULT_RATE_LIMIT = 'DEFAULT_RATE_LIMIT', + DEV_MODE = 'DEV_MODE', + E2E_RELAY_HOST = 'E2E_RELAY_HOST', + E2E_SERVER_PORT = 'E2E_SERVER_PORT', + ESTIMATE_GAS_THROWS = 'ESTIMATE_GAS_THROWS', + ETH_BLOCK_NUMBER_CACHE_TTL_MS = 'ETH_BLOCK_NUMBER_CACHE_TTL_MS', + ETH_CALL_ACCEPTED_ERRORS = 'ETH_CALL_ACCEPTED_ERRORS', + ETH_CALL_CACHE_TTL = 'ETH_CALL_CACHE_TTL', + ETH_CALL_CONSENSUS_SELECTORS = 'ETH_CALL_CONSENSUS_SELECTORS', + ETH_CALL_DEFAULT_TO_CONSENSUS_NODE = 'ETH_CALL_DEFAULT_TO_CONSENSUS_NODE', + ETH_FEE_HISTORY_FIXED = 'ETH_FEE_HISTORY_FIXED', + ETH_GET_BALANCE_CACHE_TTL_MS = 'ETH_GET_BALANCE_CACHE_TTL_MS', + ETH_GET_GAS_PRICE_CACHE_TTL_MS = 'ETH_GET_GAS_PRICE_CACHE_TTL_MS', + ETH_GET_LOGS_BLOCK_RANGE_LIMIT = 'ETH_GET_LOGS_BLOCK_RANGE_LIMIT', + ETH_GET_TRANSACTION_COUNT_CACHE_TTL = 'ETH_GET_TRANSACTION_COUNT_CACHE_TTL', + ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE = 'ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE', + HEDERA_SPECIFIC_REVERT_STATUSES = 'HEDERA_SPECIFIC_REVERT_STATUSES', + FEE_HISTORY_MAX_RESULTS = 'FEE_HISTORY_MAX_RESULTS', + FILE_APPEND_CHUNK_SIZE = 'FILE_APPEND_CHUNK_SIZE', + FILE_APPEND_MAX_CHUNKS = 'FILE_APPEND_MAX_CHUNKS', + FILTER_API_ENABLED = 'FILTER_API_ENABLED', + FILTER_TTL = 'FILTER_TTL', + GAS_PRICE_PERCENTAGE_BUFFER = 'GAS_PRICE_PERCENTAGE_BUFFER', + GAS_PRICE_TINY_BAR_BUFFER = 'GAS_PRICE_TINY_BAR_BUFFER', + GET_RECORD_DEFAULT_TO_CONSENSUS_NODE = 'GET_RECORD_DEFAULT_TO_CONSENSUS_NODE', + GH_ACCESS_TOKEN = 'GH_ACCESS_TOKEN', + GITHUB_PR_NUMBER = 'GITHUB_PR_NUMBER', + GITHUB_REPOSITORY = 'GITHUB_REPOSITORY', + GITHUB_TOKEN = 'GITHUB_TOKEN', + HAPI_CLIENT_DURATION_RESET = 'HAPI_CLIENT_DURATION_RESET', + HAPI_CLIENT_ERROR_RESET = 'HAPI_CLIENT_ERROR_RESET', + HAPI_CLIENT_TRANSACTION_RESET = 'HAPI_CLIENT_TRANSACTION_RESET', + HBAR_RATE_LIMIT_BASIC = 'HBAR_RATE_LIMIT_BASIC', + HBAR_RATE_LIMIT_EXTENDED = 'HBAR_RATE_LIMIT_EXTENDED', + HBAR_RATE_LIMIT_PRIVILEGED = 'HBAR_RATE_LIMIT_PRIVILEGED', + HBAR_RATE_LIMIT_DURATION = 'HBAR_RATE_LIMIT_DURATION', + HBAR_RATE_LIMIT_TINYBAR = 'HBAR_RATE_LIMIT_TINYBAR', + HEDERA_NETWORK = 'HEDERA_NETWORK', + HBAR_SPENDING_PLANS_CONFIG = 'HBAR_SPENDING_PLANS_CONFIG', + INITIAL_BALANCE = 'INITIAL_BALANCE', + INPUT_SIZE_LIMIT = 'INPUT_SIZE_LIMIT', + LIMIT_DURATION = 'LIMIT_DURATION', + LOCAL_NODE = 'LOCAL_NODE', + LOG_LEVEL = 'LOG_LEVEL', + MAX_BLOCK_RANGE = 'MAX_BLOCK_RANGE', + MEMWATCH_ENABLED = 'MEMWATCH_ENABLED', + MIRROR_NODE_AGENT_CACHEABLE_DNS = 'MIRROR_NODE_AGENT_CACHEABLE_DNS', + MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX = 'MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX', + MIRROR_NODE_CONTRACT_RESULTS_PG_MAX = 'MIRROR_NODE_CONTRACT_RESULTS_PG_MAX', + MIRROR_NODE_HTTP_KEEP_ALIVE = 'MIRROR_NODE_HTTP_KEEP_ALIVE', + MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS = 'MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS', + MIRROR_NODE_HTTP_MAX_SOCKETS = 'MIRROR_NODE_HTTP_MAX_SOCKETS', + MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS = 'MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS', + MIRROR_NODE_HTTP_SOCKET_TIMEOUT = 'MIRROR_NODE_HTTP_SOCKET_TIMEOUT', + MIRROR_NODE_LIMIT_PARAM = 'MIRROR_NODE_LIMIT_PARAM', + MIRROR_NODE_MAX_REDIRECTS = 'MIRROR_NODE_MAX_REDIRECTS', + MIRROR_NODE_RETRIES = 'MIRROR_NODE_RETRIES', + MIRROR_NODE_RETRIES_DEVMODE = 'MIRROR_NODE_RETRIES_DEVMODE', + MIRROR_NODE_RETRY_CODES = 'MIRROR_NODE_RETRY_CODES', + MIRROR_NODE_RETRY_DELAY = 'MIRROR_NODE_RETRY_DELAY', + MIRROR_NODE_RETRY_DELAY_DEVMODE = 'MIRROR_NODE_RETRY_DELAY_DEVMODE', + MIRROR_NODE_REQUEST_RETRY_COUNT = 'MIRROR_NODE_REQUEST_RETRY_COUNT', + MIRROR_NODE_TIMEOUT = 'MIRROR_NODE_TIMEOUT', + MIRROR_NODE_URL = 'MIRROR_NODE_URL', + MIRROR_NODE_URL_HEADER_X_API_KEY = 'MIRROR_NODE_URL_HEADER_X_API_KEY', + MIRROR_NODE_URL_WEB3 = 'MIRROR_NODE_URL_WEB3', + MULTI_SET = 'MULTI_SET', + npm_package_version = 'npm_package_version', + OPERATOR_ID_ETH_SENDRAWTRANSACTION = 'OPERATOR_ID_ETH_SENDRAWTRANSACTION', + OPERATOR_ID_MAIN = 'OPERATOR_ID_MAIN', + OPERATOR_KEY_ETH_SENDRAWTRANSACTION = 'OPERATOR_KEY_ETH_SENDRAWTRANSACTION', + OPERATOR_KEY_FORMAT = 'OPERATOR_KEY_FORMAT', + OPERATOR_KEY_MAIN = 'OPERATOR_KEY_MAIN', + RATE_LIMIT_DISABLED = 'RATE_LIMIT_DISABLED', + REDIS_ENABLED = 'REDIS_ENABLED', + REDIS_RECONNECT_DELAY_MS = 'REDIS_RECONNECT_DELAY_MS', + REDIS_URL = 'REDIS_URL', + REQUEST_ID_IS_OPTIONAL = 'REQUEST_ID_IS_OPTIONAL', + SDK_REQUEST_TIMEOUT = 'SDK_REQUEST_TIMEOUT', + SEND_RAW_TRANSACTION_SIZE_LIMIT = 'SEND_RAW_TRANSACTION_SIZE_LIMIT', + SERVER_PORT = 'SERVER_PORT', + SERVER_REQUEST_TIMEOUT_MS = 'SERVER_REQUEST_TIMEOUT_MS', + SUBSCRIPTIONS_ENABLED = 'SUBSCRIPTIONS_ENABLED', + TEST = 'TEST', + TEST_GAS_PRICE_DEVIATION = 'TEST_GAS_PRICE_DEVIATION', + TEST_INITIAL_ACCOUNT_STARTING_BALANCE = 'TEST_INITIAL_ACCOUNT_STARTING_BALANCE', + TEST_TRANSACTION_RECORD_COST_TOLERANCE = 'TEST_TRANSACTION_RECORD_COST_TOLERANCE', + TEST_WS_SERVER = 'TEST_WS_SERVER', + TIER_1_RATE_LIMIT = 'TIER_1_RATE_LIMIT', + TIER_2_RATE_LIMIT = 'TIER_2_RATE_LIMIT', + TIER_3_RATE_LIMIT = 'TIER_3_RATE_LIMIT', + TX_DEFAULT_GAS = 'TX_DEFAULT_GAS', + USE_ASYNC_TX_PROCESSING = 'USE_ASYNC_TX_PROCESSING', + WEB_SOCKET_HTTP_PORT = 'WEB_SOCKET_HTTP_PORT', + WEB_SOCKET_PORT = 'WEB_SOCKET_PORT', + WRITE_SNAPSHOT_ON_MEMORY_LEAK = 'WRITE_SNAPSHOT_ON_MEMORY_LEAK', + WS_BATCH_REQUESTS_ENABLED = 'WS_BATCH_REQUESTS_ENABLED', + WS_BATCH_REQUESTS_MAX_SIZE = 'WS_BATCH_REQUESTS_MAX_SIZE', + WS_CACHE_TTL = 'WS_CACHE_TTL', + WS_CONNECTION_LIMIT = 'WS_CONNECTION_LIMIT', + WS_CONNECTION_LIMIT_PER_IP = 'WS_CONNECTION_LIMIT_PER_IP', + WS_MAX_INACTIVITY_TTL = 'WS_MAX_INACTIVITY_TTL', + WS_MULTIPLE_ADDRESSES_ENABLED = 'WS_MULTIPLE_ADDRESSES_ENABLED', + WS_NEW_HEADS_ENABLED = 'WS_NEW_HEADS_ENABLED', + WS_PING_INTERVAL = 'WS_PING_INTERVAL', + WS_POLLING_INTERVAL = 'WS_POLLING_INTERVAL', + WS_RELAY_URL = 'WS_RELAY_URL', + WS_SAME_SUB_FOR_SAME_EVENT = 'WS_SAME_SUB_FOR_SAME_EVENT', + WS_SUBSCRIPTION_LIMIT = 'WS_SUBSCRIPTION_LIMIT', +} From a3aabc7550ba0d9b07ab5a4ae4eb4729e04ad22b Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Sat, 21 Dec 2024 03:22:17 +0100 Subject: [PATCH 02/11] 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 | 5 +- 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 | 3 +- .../lib/eth/eth_sendRawTransaction.spec.ts | 5 +- .../relay/tests/lib/ethGetBlockBy.spec.ts | 3 +- packages/relay/tests/lib/hapiService.spec.ts | 1 + .../relay/tests/lib/mirrorNodeClient.spec.ts | 9 ++-- packages/relay/tests/lib/net.spec.ts | 5 +- packages/relay/tests/lib/openrpc.spec.ts | 3 +- 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 | 3 +- .../tests/lib/services/eth/filter.spec.ts | 3 +- .../metricService/metricService.spec.ts | 9 ++-- packages/relay/tests/lib/utils.spec.ts | 5 +- packages/relay/tests/lib/web3.spec.ts | 3 +- .../tests/acceptance/conformityTests.spec.ts | 7 +-- .../tests/acceptance/hbarLimiter.spec.ts | 17 ++++--- .../server/tests/acceptance/index.spec.ts | 18 +++---- .../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 | 16 ++++--- .../tests/acceptance/rateLimiter.spec.ts | 14 +++--- .../acceptance/sendRawTransaction.spec.ts | 20 ++++---- .../tests/acceptance/subscribe.spec.ts | 38 ++++++++------- .../acceptance/subscribeNewHeads.spec.ts | 7 +-- 39 files changed, 237 insertions(+), 179 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 9383d40ed9..761a71f531 100644 --- a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts +++ b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts @@ -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'; @@ -105,7 +106,7 @@ describe('HbarSpendingPlanConfigService', function () { }); after(async function () { - if (ConfigService.get('REDIS_ENABLED')) { + if (ConfigService.get(ConfigName.REDIS_ENABLED)) { await cacheService.disconnectRedisClient(); } }); @@ -385,7 +386,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 00bc072b34..94a8ffa152 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 ab05ce2036..fddeea6dae 100644 --- a/packages/relay/tests/lib/eth/eth_common.spec.ts +++ b/packages/relay/tests/lib/eth/eth_common.spec.ts @@ -24,6 +24,7 @@ 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'; @@ -43,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 1c8552fe4d..c033501901 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 105af5e97c..ed11ea3513 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 b9581784f7..8da5da6253 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'; diff --git a/packages/relay/tests/lib/mirrorNodeClient.spec.ts b/packages/relay/tests/lib/mirrorNodeClient.spec.ts index 481c81dfc5..3e51e44faf 100644 --- a/packages/relay/tests/lib/mirrorNodeClient.spec.ts +++ b/packages/relay/tests/lib/mirrorNodeClient.spec.ts @@ -26,6 +26,7 @@ import { expect } from 'chai'; import { ethers } from 'ethers'; import pino from 'pino'; import { Registry } from 'prom-client'; +import { ConfigName } from '../../../config-service/src/services/configName'; import { MirrorNodeClientError, predefined } from '../../src'; import { MirrorNodeClient } from '../../src/lib/clients'; @@ -58,7 +59,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, @@ -135,7 +136,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` }), @@ -162,14 +163,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 9299aed62e..9b6ba84922 100644 --- a/packages/relay/tests/lib/net.spec.ts +++ b/packages/relay/tests/lib/net.spec.ts @@ -26,6 +26,7 @@ import { Registry } from 'prom-client'; import constants from '../../src/lib/constants'; import { RelayImpl } from '../../src/lib/relay'; import { withOverriddenEnvsInMochaTest } from '../helpers'; +import { ConfigName } from '../../../config-service/src/services/configName'; const logger = pino({ level: 'silent' }); let Relay; @@ -41,8 +42,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 94293092ed..afc9fffa63 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'; @@ -122,7 +123,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 83fbf6cb26..b5696b3c69 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 0b159666bc..372158ca2f 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 e05e57bab7..ae78e5593d 100644 --- a/packages/relay/tests/lib/services/debugService/debug.spec.ts +++ b/packages/relay/tests/lib/services/debugService/debug.spec.ts @@ -25,6 +25,7 @@ import chaiAsPromised from 'chai-as-promised'; 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'; @@ -267,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 57afb197c9..2fc66c9a50 100644 --- a/packages/relay/tests/lib/services/eth/filter.spec.ts +++ b/packages/relay/tests/lib/services/eth/filter.spec.ts @@ -19,6 +19,7 @@ */ 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'; @@ -83,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/metricService/metricService.spec.ts b/packages/relay/tests/lib/services/metricService/metricService.spec.ts index 356ac89eb7..bbd757e43b 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 e1e40c495d..0f7733c3fb 100644 --- a/packages/relay/tests/lib/utils.spec.ts +++ b/packages/relay/tests/lib/utils.spec.ts @@ -25,6 +25,7 @@ import createHash from 'keccak'; import pino from 'pino'; import sinon from 'sinon'; +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'; @@ -61,7 +62,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); @@ -84,7 +85,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 056e722c90..1717e0eea8 100644 --- a/packages/relay/tests/lib/web3.spec.ts +++ b/packages/relay/tests/lib/web3.spec.ts @@ -23,6 +23,7 @@ import { expect } from 'chai'; 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'; @@ -33,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 42cad4c56f..9eee13cbc5 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'; @@ -126,7 +127,9 @@ 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; @@ -219,7 +222,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, @@ -230,7 +233,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, )}`, ); @@ -738,7 +741,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) { @@ -898,7 +901,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)); @@ -955,14 +958,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 db5a4739df..e7bd2929e6 100644 --- a/packages/server/tests/acceptance/index.spec.ts +++ b/packages/server/tests/acceptance/index.spec.ts @@ -23,8 +23,10 @@ import dotenv from 'dotenv'; import path from 'path'; dotenv.config({ path: path.resolve(__dirname, '../../../../.env') }); -// Constants +// 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 @@ -99,7 +101,7 @@ describe('RPC Server Acceptance Tests', function () { }; // leak detection middleware - if (ConfigService.get('MEMWATCH_ENABLED')) { + if (ConfigService.get(ConfigName.MEMWATCH_ENABLED)) { Utils.captureMemoryLeaks(new GCProfiler()); } @@ -108,12 +110,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(); @@ -125,7 +127,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); @@ -196,7 +198,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(); } } @@ -210,7 +212,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 ac244feb48..f0ba1940fe 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 60b91eb004..58afdac0cd 100644 --- a/packages/ws-server/tests/acceptance/index.spec.ts +++ b/packages/ws-server/tests/acceptance/index.spec.ts @@ -23,10 +23,12 @@ import dotenv from 'dotenv'; import path from 'path'; dotenv.config({ path: path.resolve(__dirname, '../../../../.env') }); -import { Server } from 'node:http'; - import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services'; import constants from '@hashgraph/json-rpc-relay/dist/lib/constants'; +import { Server } from 'node:http'; + +import { ConfigName } from '@hashgraph/json-rpc-config-service/src/services/configName'; +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'; @@ -83,12 +85,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(); @@ -148,7 +150,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(); } }); @@ -179,7 +181,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; From 70adae5e313d490a9e59fbc29bc1d7c090de990d Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Wed, 25 Dec 2024 08:54:43 +0100 Subject: [PATCH 03/11] Refactor GlobalConfig and revert header changes as per feedback Signed-off-by: belloibrahv --- .../config-service/src/services/configName.ts | 141 ------------------ .../src/services/globalConfig.ts | 12 +- .../tests/src/services/configService.spec.ts | 6 +- .../tests/src/services/loggerService.spec.ts | 6 +- .../hbarSpendingPlanConfigService.spec.ts | 6 +- packages/relay/tests/lib/eth/eth-config.ts | 4 +- packages/relay/tests/lib/eth/eth-helpers.ts | 4 +- .../relay/tests/lib/eth/eth_common.spec.ts | 4 +- .../lib/eth/eth_sendRawTransaction.spec.ts | 6 +- .../relay/tests/lib/ethGetBlockBy.spec.ts | 4 +- packages/relay/tests/lib/hapiService.spec.ts | 2 +- .../relay/tests/lib/mirrorNodeClient.spec.ts | 14 +- packages/relay/tests/lib/net.spec.ts | 6 +- packages/relay/tests/lib/openrpc.spec.ts | 3 +- packages/relay/tests/lib/poller.spec.ts | 4 +- packages/relay/tests/lib/precheck.spec.ts | 4 +- packages/relay/tests/lib/sdkClient.spec.ts | 30 ++-- .../lib/services/debugService/debug.spec.ts | 4 +- .../tests/lib/services/eth/filter.spec.ts | 4 +- .../metricService/metricService.spec.ts | 10 +- packages/relay/tests/lib/utils.spec.ts | 6 +- packages/relay/tests/lib/web3.spec.ts | 4 +- .../tests/acceptance/conformityTests.spec.ts | 4 +- .../tests/acceptance/hbarLimiter.spec.ts | 18 +-- .../server/tests/acceptance/index.spec.ts | 16 +- .../tests/acceptance/rateLimiter.spec.ts | 6 +- .../tests/acceptance/rpc_batch1.spec.ts | 8 +- .../tests/acceptance/rpc_batch2.spec.ts | 8 +- .../tests/acceptance/rpc_batch3.spec.ts | 12 +- .../tests/acceptance/serverConfig.spec.ts | 6 +- .../server/tests/integration/server.spec.ts | 30 ++-- .../tests/acceptance/batchRequest.spec.ts | 4 +- .../acceptance/getTransactionByHash.spec.ts | 4 +- .../acceptance/getTransactionCount.spec.ts | 4 +- .../acceptance/getTransactionReceipt.spec.ts | 4 +- .../ws-server/tests/acceptance/index.spec.ts | 11 +- .../tests/acceptance/rateLimiter.spec.ts | 6 +- .../acceptance/sendRawTransaction.spec.ts | 4 +- .../tests/acceptance/subscribe.spec.ts | 18 +-- .../acceptance/subscribeNewHeads.spec.ts | 8 +- 40 files changed, 156 insertions(+), 299 deletions(-) delete mode 100644 packages/config-service/src/services/configName.ts diff --git a/packages/config-service/src/services/configName.ts b/packages/config-service/src/services/configName.ts deleted file mode 100644 index 983c178dc7..0000000000 --- a/packages/config-service/src/services/configName.ts +++ /dev/null @@ -1,141 +0,0 @@ -/*- - * - * Hedera JSON RPC Relay - * - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -export enum ConfigName { - BATCH_REQUESTS_ENABLED = 'BATCH_REQUESTS_ENABLED', - BATCH_REQUESTS_MAX_SIZE = 'BATCH_REQUESTS_MAX_SIZE', - CACHE_MAX = 'CACHE_MAX', - CACHE_TTL = 'CACHE_TTL', - CHAIN_ID = 'CHAIN_ID', - CLIENT_TRANSPORT_SECURITY = 'CLIENT_TRANSPORT_SECURITY', - CONSENSUS_MAX_EXECUTION_TIME = 'CONSENSUS_MAX_EXECUTION_TIME', - CONTRACT_CALL_GAS_LIMIT = 'CONTRACT_CALL_GAS_LIMIT', - CONTRACT_QUERY_TIMEOUT_RETRIES = 'CONTRACT_QUERY_TIMEOUT_RETRIES', - DEBUG_API_ENABLED = 'DEBUG_API_ENABLED', - DEFAULT_RATE_LIMIT = 'DEFAULT_RATE_LIMIT', - DEV_MODE = 'DEV_MODE', - E2E_RELAY_HOST = 'E2E_RELAY_HOST', - E2E_SERVER_PORT = 'E2E_SERVER_PORT', - ESTIMATE_GAS_THROWS = 'ESTIMATE_GAS_THROWS', - ETH_BLOCK_NUMBER_CACHE_TTL_MS = 'ETH_BLOCK_NUMBER_CACHE_TTL_MS', - ETH_CALL_ACCEPTED_ERRORS = 'ETH_CALL_ACCEPTED_ERRORS', - ETH_CALL_CACHE_TTL = 'ETH_CALL_CACHE_TTL', - ETH_CALL_CONSENSUS_SELECTORS = 'ETH_CALL_CONSENSUS_SELECTORS', - ETH_CALL_DEFAULT_TO_CONSENSUS_NODE = 'ETH_CALL_DEFAULT_TO_CONSENSUS_NODE', - ETH_FEE_HISTORY_FIXED = 'ETH_FEE_HISTORY_FIXED', - ETH_GET_BALANCE_CACHE_TTL_MS = 'ETH_GET_BALANCE_CACHE_TTL_MS', - ETH_GET_GAS_PRICE_CACHE_TTL_MS = 'ETH_GET_GAS_PRICE_CACHE_TTL_MS', - ETH_GET_LOGS_BLOCK_RANGE_LIMIT = 'ETH_GET_LOGS_BLOCK_RANGE_LIMIT', - ETH_GET_TRANSACTION_COUNT_CACHE_TTL = 'ETH_GET_TRANSACTION_COUNT_CACHE_TTL', - ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE = 'ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE', - HEDERA_SPECIFIC_REVERT_STATUSES = 'HEDERA_SPECIFIC_REVERT_STATUSES', - FEE_HISTORY_MAX_RESULTS = 'FEE_HISTORY_MAX_RESULTS', - FILE_APPEND_CHUNK_SIZE = 'FILE_APPEND_CHUNK_SIZE', - FILE_APPEND_MAX_CHUNKS = 'FILE_APPEND_MAX_CHUNKS', - FILTER_API_ENABLED = 'FILTER_API_ENABLED', - FILTER_TTL = 'FILTER_TTL', - GAS_PRICE_PERCENTAGE_BUFFER = 'GAS_PRICE_PERCENTAGE_BUFFER', - GAS_PRICE_TINY_BAR_BUFFER = 'GAS_PRICE_TINY_BAR_BUFFER', - GET_RECORD_DEFAULT_TO_CONSENSUS_NODE = 'GET_RECORD_DEFAULT_TO_CONSENSUS_NODE', - GH_ACCESS_TOKEN = 'GH_ACCESS_TOKEN', - GITHUB_PR_NUMBER = 'GITHUB_PR_NUMBER', - GITHUB_REPOSITORY = 'GITHUB_REPOSITORY', - GITHUB_TOKEN = 'GITHUB_TOKEN', - HAPI_CLIENT_DURATION_RESET = 'HAPI_CLIENT_DURATION_RESET', - HAPI_CLIENT_ERROR_RESET = 'HAPI_CLIENT_ERROR_RESET', - HAPI_CLIENT_TRANSACTION_RESET = 'HAPI_CLIENT_TRANSACTION_RESET', - HBAR_RATE_LIMIT_BASIC = 'HBAR_RATE_LIMIT_BASIC', - HBAR_RATE_LIMIT_EXTENDED = 'HBAR_RATE_LIMIT_EXTENDED', - HBAR_RATE_LIMIT_PRIVILEGED = 'HBAR_RATE_LIMIT_PRIVILEGED', - HBAR_RATE_LIMIT_DURATION = 'HBAR_RATE_LIMIT_DURATION', - HBAR_RATE_LIMIT_TINYBAR = 'HBAR_RATE_LIMIT_TINYBAR', - HEDERA_NETWORK = 'HEDERA_NETWORK', - HBAR_SPENDING_PLANS_CONFIG = 'HBAR_SPENDING_PLANS_CONFIG', - INITIAL_BALANCE = 'INITIAL_BALANCE', - INPUT_SIZE_LIMIT = 'INPUT_SIZE_LIMIT', - LIMIT_DURATION = 'LIMIT_DURATION', - LOCAL_NODE = 'LOCAL_NODE', - LOG_LEVEL = 'LOG_LEVEL', - MAX_BLOCK_RANGE = 'MAX_BLOCK_RANGE', - MEMWATCH_ENABLED = 'MEMWATCH_ENABLED', - MIRROR_NODE_AGENT_CACHEABLE_DNS = 'MIRROR_NODE_AGENT_CACHEABLE_DNS', - MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX = 'MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX', - MIRROR_NODE_CONTRACT_RESULTS_PG_MAX = 'MIRROR_NODE_CONTRACT_RESULTS_PG_MAX', - MIRROR_NODE_HTTP_KEEP_ALIVE = 'MIRROR_NODE_HTTP_KEEP_ALIVE', - MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS = 'MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS', - MIRROR_NODE_HTTP_MAX_SOCKETS = 'MIRROR_NODE_HTTP_MAX_SOCKETS', - MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS = 'MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS', - MIRROR_NODE_HTTP_SOCKET_TIMEOUT = 'MIRROR_NODE_HTTP_SOCKET_TIMEOUT', - MIRROR_NODE_LIMIT_PARAM = 'MIRROR_NODE_LIMIT_PARAM', - MIRROR_NODE_MAX_REDIRECTS = 'MIRROR_NODE_MAX_REDIRECTS', - MIRROR_NODE_RETRIES = 'MIRROR_NODE_RETRIES', - MIRROR_NODE_RETRIES_DEVMODE = 'MIRROR_NODE_RETRIES_DEVMODE', - MIRROR_NODE_RETRY_CODES = 'MIRROR_NODE_RETRY_CODES', - MIRROR_NODE_RETRY_DELAY = 'MIRROR_NODE_RETRY_DELAY', - MIRROR_NODE_RETRY_DELAY_DEVMODE = 'MIRROR_NODE_RETRY_DELAY_DEVMODE', - MIRROR_NODE_REQUEST_RETRY_COUNT = 'MIRROR_NODE_REQUEST_RETRY_COUNT', - MIRROR_NODE_TIMEOUT = 'MIRROR_NODE_TIMEOUT', - MIRROR_NODE_URL = 'MIRROR_NODE_URL', - MIRROR_NODE_URL_HEADER_X_API_KEY = 'MIRROR_NODE_URL_HEADER_X_API_KEY', - MIRROR_NODE_URL_WEB3 = 'MIRROR_NODE_URL_WEB3', - MULTI_SET = 'MULTI_SET', - npm_package_version = 'npm_package_version', - OPERATOR_ID_ETH_SENDRAWTRANSACTION = 'OPERATOR_ID_ETH_SENDRAWTRANSACTION', - OPERATOR_ID_MAIN = 'OPERATOR_ID_MAIN', - OPERATOR_KEY_ETH_SENDRAWTRANSACTION = 'OPERATOR_KEY_ETH_SENDRAWTRANSACTION', - OPERATOR_KEY_FORMAT = 'OPERATOR_KEY_FORMAT', - OPERATOR_KEY_MAIN = 'OPERATOR_KEY_MAIN', - RATE_LIMIT_DISABLED = 'RATE_LIMIT_DISABLED', - REDIS_ENABLED = 'REDIS_ENABLED', - REDIS_RECONNECT_DELAY_MS = 'REDIS_RECONNECT_DELAY_MS', - REDIS_URL = 'REDIS_URL', - REQUEST_ID_IS_OPTIONAL = 'REQUEST_ID_IS_OPTIONAL', - SDK_REQUEST_TIMEOUT = 'SDK_REQUEST_TIMEOUT', - SEND_RAW_TRANSACTION_SIZE_LIMIT = 'SEND_RAW_TRANSACTION_SIZE_LIMIT', - SERVER_PORT = 'SERVER_PORT', - SERVER_REQUEST_TIMEOUT_MS = 'SERVER_REQUEST_TIMEOUT_MS', - SUBSCRIPTIONS_ENABLED = 'SUBSCRIPTIONS_ENABLED', - TEST = 'TEST', - TEST_GAS_PRICE_DEVIATION = 'TEST_GAS_PRICE_DEVIATION', - TEST_INITIAL_ACCOUNT_STARTING_BALANCE = 'TEST_INITIAL_ACCOUNT_STARTING_BALANCE', - TEST_TRANSACTION_RECORD_COST_TOLERANCE = 'TEST_TRANSACTION_RECORD_COST_TOLERANCE', - TEST_WS_SERVER = 'TEST_WS_SERVER', - TIER_1_RATE_LIMIT = 'TIER_1_RATE_LIMIT', - TIER_2_RATE_LIMIT = 'TIER_2_RATE_LIMIT', - TIER_3_RATE_LIMIT = 'TIER_3_RATE_LIMIT', - TX_DEFAULT_GAS = 'TX_DEFAULT_GAS', - USE_ASYNC_TX_PROCESSING = 'USE_ASYNC_TX_PROCESSING', - WEB_SOCKET_HTTP_PORT = 'WEB_SOCKET_HTTP_PORT', - WEB_SOCKET_PORT = 'WEB_SOCKET_PORT', - WRITE_SNAPSHOT_ON_MEMORY_LEAK = 'WRITE_SNAPSHOT_ON_MEMORY_LEAK', - WS_BATCH_REQUESTS_ENABLED = 'WS_BATCH_REQUESTS_ENABLED', - WS_BATCH_REQUESTS_MAX_SIZE = 'WS_BATCH_REQUESTS_MAX_SIZE', - WS_CACHE_TTL = 'WS_CACHE_TTL', - WS_CONNECTION_LIMIT = 'WS_CONNECTION_LIMIT', - WS_CONNECTION_LIMIT_PER_IP = 'WS_CONNECTION_LIMIT_PER_IP', - WS_MAX_INACTIVITY_TTL = 'WS_MAX_INACTIVITY_TTL', - WS_MULTIPLE_ADDRESSES_ENABLED = 'WS_MULTIPLE_ADDRESSES_ENABLED', - WS_NEW_HEADS_ENABLED = 'WS_NEW_HEADS_ENABLED', - WS_PING_INTERVAL = 'WS_PING_INTERVAL', - WS_POLLING_INTERVAL = 'WS_POLLING_INTERVAL', - WS_RELAY_URL = 'WS_RELAY_URL', - WS_SAME_SUB_FOR_SAME_EVENT = 'WS_SAME_SUB_FOR_SAME_EVENT', - WS_SUBSCRIPTION_LIMIT = 'WS_SUBSCRIPTION_LIMIT', -} diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index 9a28a7ce1d..4a37960006 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -18,8 +18,6 @@ * */ -import { ConfigName } from './configName'; - export interface ConfigProperty { envName: string; type: string; @@ -27,8 +25,7 @@ export interface ConfigProperty { defaultValue: string | number | boolean | null; } -export class GlobalConfig { - public static readonly ENTRIES: Record = { +const _CONFIG = { BATCH_REQUESTS_ENABLED: { envName: 'BATCH_REQUESTS_ENABLED', type: 'boolean', @@ -744,5 +741,10 @@ export class GlobalConfig { required: false, defaultValue: null, }, - }; +} satisfies { [key: string]: ConfigProperty }; + +export type ConfigKey = keyof typeof _CONFIG; + +export class GlobalConfig { + public static readonly ENTRIES: Record = _CONFIG; } diff --git a/packages/config-service/tests/src/services/configService.spec.ts b/packages/config-service/tests/src/services/configService.spec.ts index 023dd5f35c..01c34250e2 100644 --- a/packages/config-service/tests/src/services/configService.spec.ts +++ b/packages/config-service/tests/src/services/configService.spec.ts @@ -21,7 +21,7 @@ import chai, { expect } from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { ConfigService } from '../../../src/services'; -import { ConfigName } from '../../../src/services/configName'; +import { ConfigKey } from '../../../src/services/globalConfig'; chai.use(chaiAsPromised); @@ -50,13 +50,13 @@ describe('ConfigService tests', async function () { }); it('should be able to get existing env var', async () => { - const res = ConfigService.get(ConfigName.CHAIN_ID); + const res = ConfigService.get('CHAIN_ID' as ConfigKey); expect(res).to.equal('0x12a'); }); it('should return undefined for non-existing variable', async () => { - const res = ConfigService.get('NON_EXISTING_VAR'); + const res = ConfigService.get('NON_EXISTING_VAR' as ConfigKey); expect(res).to.equal(undefined); }); diff --git a/packages/config-service/tests/src/services/loggerService.spec.ts b/packages/config-service/tests/src/services/loggerService.spec.ts index 71ee309e98..2f862a84a9 100644 --- a/packages/config-service/tests/src/services/loggerService.spec.ts +++ b/packages/config-service/tests/src/services/loggerService.spec.ts @@ -24,7 +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'; +import { ConfigKey } from '../../../src/services/globalConfig'; chai.use(chaiAsPromised); @@ -48,8 +48,8 @@ describe('LoggerService tests', async function () { }); it('should be able to return plain information', async () => { - const envName = ConfigName.CHAIN_ID; - const res = ConfigService.get(envName) as string; + const envName = 'CHAIN_ID' as ConfigKey; + const res = ConfigService.get(envName) as string | undefined; 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 761a71f531..d8d7a3f3ff 100644 --- a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts +++ b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts @@ -27,7 +27,6 @@ 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'; @@ -48,6 +47,7 @@ import { verifyResult, withOverriddenEnvsInMochaTest, } from '../../helpers'; +import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; chai.use(chaiAsPromised); @@ -106,7 +106,7 @@ describe('HbarSpendingPlanConfigService', function () { }); after(async function () { - if (ConfigService.get(ConfigName.REDIS_ENABLED)) { + if (ConfigService.get('REDIS_ENABLED' as ConfigKey)) { await cacheService.disconnectRedisClient(); } }); @@ -386,7 +386,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(ConfigName.CACHE_TTL)))); + await new Promise((resolve) => setTimeout(resolve, Number(ConfigService.get('CACHE_TTL' as ConfigKey)))); await verifySpendingPlans(spendingPlansConfig); }); diff --git a/packages/relay/tests/lib/eth/eth-config.ts b/packages/relay/tests/lib/eth/eth-config.ts index 1e669dde2c..895383df13 100644 --- a/packages/relay/tests/lib/eth/eth-config.ts +++ b/packages/relay/tests/lib/eth/eth-config.ts @@ -20,7 +20,6 @@ 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 { @@ -33,6 +32,7 @@ import { mockData, toHex, } from '../../helpers'; +import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; export const BLOCK_TRANSACTION_COUNT = 77; export const GAS_USED_1 = 200000; @@ -121,7 +121,7 @@ export const CONTRACT_RESULT_MOCK = { }; export const CONTRACT_CALL_DATA = '0xef641f44'; -export const ETH_FEE_HISTORY_VALUE = ConfigService.get(ConfigName.ETH_FEE_HISTORY_FIXED) ?? true; +export const ETH_FEE_HISTORY_VALUE = ConfigService.get('ETH_FEE_HISTORY_FIXED' as ConfigKey) ?? 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 94a8ffa152..c9f339d4bf 100644 --- a/packages/relay/tests/lib/eth/eth-helpers.ts +++ b/packages/relay/tests/lib/eth/eth-helpers.ts @@ -24,7 +24,6 @@ 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'; @@ -35,6 +34,7 @@ import { EthImpl } from '../../../src/lib/eth'; import { CacheService } from '../../../src/lib/services/cacheService/cacheService'; import HAPIService from '../../../src/lib/services/hapiService/hapiService'; import { HbarLimitService } from '../../../src/lib/services/hbarLimitService'; +import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; export function contractResultsByNumberByIndexURL(number: number, index: number): string { return `contracts/results?block.number=${number}&transaction.index=${index}&limit=100&order=asc`; @@ -56,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(ConfigName.MIRROR_NODE_URL) as string || '', + ConfigService.get('MIRROR_NODE_URL' as ConfigKey) || '', 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 fddeea6dae..bae729764b 100644 --- a/packages/relay/tests/lib/eth/eth_common.spec.ts +++ b/packages/relay/tests/lib/eth/eth_common.spec.ts @@ -24,9 +24,9 @@ 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'; +import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; use(chaiAsPromised); @@ -44,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(ConfigName.CHAIN_ID)).toString(16)); + expect(chainId).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).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 c033501901..f0236e36f1 100644 --- a/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts +++ b/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts @@ -37,7 +37,6 @@ 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'; @@ -58,6 +57,7 @@ import { } from '../../helpers'; import { ACCOUNT_ADDRESS_1, DEFAULT_NETWORK_FEES, MAX_GAS_LIMIT_HEX, NO_TRANSACTIONS } from './eth-config'; import { generateEthTestEnv } from './eth-helpers'; +import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; use(chaiAsPromised); @@ -116,7 +116,7 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function () }, }; const transaction = { - chainId: Number(ConfigService.get(ConfigName.CHAIN_ID) || 0x12a), + chainId: Number(ConfigService.get('CHAIN_ID' as ConfigKey) || 0x12a), to: ACCOUNT_ADDRESS_1, from: accountAddress, value, @@ -136,7 +136,7 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function () }, receiver_sig_required: false, }; - const useAsyncTxProcessing = ConfigService.get(ConfigName.USE_ASYNC_TX_PROCESSING) as boolean; + const useAsyncTxProcessing = ConfigService.get('USE_ASYNC_TX_PROCESSING' as ConfigKey); beforeEach(() => { clock = useFakeTimers(); diff --git a/packages/relay/tests/lib/ethGetBlockBy.spec.ts b/packages/relay/tests/lib/ethGetBlockBy.spec.ts index ed11ea3513..6c5a913b0c 100644 --- a/packages/relay/tests/lib/ethGetBlockBy.spec.ts +++ b/packages/relay/tests/lib/ethGetBlockBy.spec.ts @@ -39,7 +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'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; use(chaiAsPromised); @@ -129,7 +129,7 @@ describe('eth_getBlockBy', async function () { // @ts-ignore mirrorNodeInstance = new MirrorNodeClient( - (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) ?? '', + (ConfigService.get('MIRROR_NODE_URL') as ConfigKey) ?? '', 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 8da5da6253..1fee16305f 100644 --- a/packages/relay/tests/lib/hapiService.spec.ts +++ b/packages/relay/tests/lib/hapiService.spec.ts @@ -25,7 +25,6 @@ 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'; @@ -36,6 +35,7 @@ import HAPIService from '../../src/lib/services/hapiService/hapiService'; import { HbarLimitService } from '../../src/lib/services/hbarLimitService'; import { RequestDetails } from '../../src/lib/types'; import { overrideEnvsInMochaDescribe, withOverriddenEnvsInMochaTest } from '../helpers'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const registry = new Registry(); const logger = pino({ level: 'silent' }); diff --git a/packages/relay/tests/lib/mirrorNodeClient.spec.ts b/packages/relay/tests/lib/mirrorNodeClient.spec.ts index 3e51e44faf..93c0454f27 100644 --- a/packages/relay/tests/lib/mirrorNodeClient.spec.ts +++ b/packages/relay/tests/lib/mirrorNodeClient.spec.ts @@ -22,11 +22,7 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services' import axios, { AxiosInstance } from 'axios'; import MockAdapter from 'axios-mock-adapter'; import { BigNumber } from 'bignumber.js'; -import { expect } from 'chai'; -import { ethers } from 'ethers'; -import pino from 'pino'; -import { Registry } from 'prom-client'; -import { ConfigName } from '../../../config-service/src/services/configName'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; import { MirrorNodeClientError, predefined } from '../../src'; import { MirrorNodeClient } from '../../src/lib/clients'; @@ -59,7 +55,7 @@ describe('MirrorNodeClient', async function () { cacheService = new CacheService(logger.child({ name: `cache` }), registry); mirrorNodeInstance = new MirrorNodeClient( // @ts-ignore - ConfigService.get(ConfigName.MIRROR_NODE_URL) || '', + ConfigService.get('MIRROR_NODE_URL' as ConfigKey) || '', logger.child({ name: `mirror-node` }), registry, cacheService, @@ -136,7 +132,7 @@ describe('MirrorNodeClient', async function () { it('`restUrl` is exposed and correct', async () => { // @ts-ignore - const domain = (ConfigService.get(ConfigName.MIRROR_NODE_URL) || '').replace(/^https?:\/\//, ''); + const domain = (ConfigService.get('MIRROR_NODE_URL' as ConfigKey) || '').replace(/^https?:\/\//, ''); const prodMirrorNodeInstance = new MirrorNodeClient( domain, logger.child({ name: `mirror-node` }), @@ -163,14 +159,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(ConfigName.MIRROR_NODE_URL) as string) || '', + ConfigService.get('MIRROR_NODE_URL' as ConfigKey) || '', 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(ConfigName.MIRROR_NODE_URL_HEADER_X_API_KEY)); + expect(axiosHeaders['x-api-key']).to.eq(ConfigService.get('MIRROR_NODE_URL_HEADER_X_API_KEY' as ConfigKey)); }); }); diff --git a/packages/relay/tests/lib/net.spec.ts b/packages/relay/tests/lib/net.spec.ts index 9b6ba84922..f35a8690e5 100644 --- a/packages/relay/tests/lib/net.spec.ts +++ b/packages/relay/tests/lib/net.spec.ts @@ -26,7 +26,7 @@ import { Registry } from 'prom-client'; import constants from '../../src/lib/constants'; import { RelayImpl } from '../../src/lib/relay'; import { withOverriddenEnvsInMochaTest } from '../helpers'; -import { ConfigName } from '../../../config-service/src/services/configName'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const logger = pino({ level: 'silent' }); let Relay; @@ -42,8 +42,8 @@ describe('Net', async function () { }); it('should execute "net_version"', function () { - const hederaNetwork: string = ((ConfigService.get(ConfigName.HEDERA_NETWORK) as string) || '{}').toLowerCase(); - let expectedNetVersion = ConfigService.get(ConfigName.CHAIN_ID) || constants.CHAIN_IDS[hederaNetwork] || '298'; + const hederaNetwork: string = ((ConfigService.get('HEDERA_NETWORK') as ConfigKey) || '{}').toLowerCase(); + let expectedNetVersion = ConfigService.get('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 afc9fffa63..fd3ff03dbc 100644 --- a/packages/relay/tests/lib/openrpc.spec.ts +++ b/packages/relay/tests/lib/openrpc.spec.ts @@ -33,7 +33,6 @@ 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'; @@ -123,7 +122,7 @@ describe('Open RPC Specification', function () { const cacheService = new CacheService(logger.child({ name: `cache` }), registry); // @ts-ignore mirrorNodeInstance = new MirrorNodeClient( - (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) || '', + ConfigService.get('MIRROR_NODE_URL' as ConfigKey) || '', 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 f94d04a1e8..62a9a4cd2e 100644 --- a/packages/relay/tests/lib/poller.spec.ts +++ b/packages/relay/tests/lib/poller.spec.ts @@ -24,9 +24,9 @@ import pino from 'pino'; 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'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const logger = pino({ level: 'trace' }); @@ -190,7 +190,7 @@ describe('Polling', async function () { ).to.equal(true); expect( loggerSpy.calledWith( - `Poller: Starting polling with interval=${ConfigService.get(ConfigName.WS_POLLING_INTERVAL)}`, + `Poller: Starting polling with interval=${ConfigService.get('WS_POLLING_INTERVAL' as ConfigKey)}`, ), ).to.equal(true); }); diff --git a/packages/relay/tests/lib/precheck.spec.ts b/packages/relay/tests/lib/precheck.spec.ts index b5696b3c69..72d2a080c2 100644 --- a/packages/relay/tests/lib/precheck.spec.ts +++ b/packages/relay/tests/lib/precheck.spec.ts @@ -27,7 +27,6 @@ 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'; @@ -45,6 +44,7 @@ import { ONE_TINYBAR_IN_WEI_HEX } from './eth/eth-config'; const registry = new Registry(); import { RequestDetails } from '../../src/lib/types'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const logger = pino({ level: 'silent' }); const limitOrderPostFix = '?order=desc&limit=1'; @@ -107,7 +107,7 @@ describe('Precheck', async function () { // @ts-ignore const mirrorNodeInstance = new MirrorNodeClient( - ConfigService.get(ConfigName.MIRROR_NODE_URL)! as string, + ConfigService.get('MIRROR_NODE_URL' as ConfigKey)!, 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 372158ca2f..1b2ee215c8 100644 --- a/packages/relay/tests/lib/sdkClient.spec.ts +++ b/packages/relay/tests/lib/sdkClient.spec.ts @@ -47,7 +47,6 @@ 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'; @@ -66,6 +65,7 @@ import { random20BytesAddress, withOverriddenEnvsInMochaTest, } from '../helpers'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const registry = new Registry(); const logger = pino({ level: 'silent' }); @@ -103,7 +103,7 @@ describe('SdkClient', async function () { overrideEnvsInMochaDescribe({ GET_RECORD_DEFAULT_TO_CONSENSUS_NODE: true }); before(() => { - const hederaNetwork = ConfigService.get(ConfigName.HEDERA_NETWORK)! as string; + const hederaNetwork = ConfigService.get('HEDERA_NETWORK' as ConfigKey)! as string; if (hederaNetwork in constants.CHAIN_IDS) { client = Client.forName(hederaNetwork); } else { @@ -111,8 +111,8 @@ describe('SdkClient', async function () { } client = client.setOperator( - AccountId.fromString(ConfigService.get(ConfigName.OPERATOR_ID_MAIN)! as string), - Utils.createPrivateKeyBasedOnFormat(ConfigService.get(ConfigName.OPERATOR_KEY_MAIN)! as string), + AccountId.fromString(ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey)! as string), + Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN' as ConfigKey)! as string), ); const duration = constants.HBAR_RATE_LIMIT_DURATION; eventEmitter = new EventEmitter(); @@ -149,7 +149,7 @@ describe('SdkClient', async function () { // mirror node client mirrorNodeClient = new MirrorNodeClient( - (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) || '', + (ConfigService.get('MIRROR_NODE_URL' as ConfigKey)) || '', logger.child({ name: `mirror-node` }), registry, new CacheService(logger.child({ name: `cache` }), registry), @@ -285,7 +285,7 @@ describe('SdkClient', async function () { }; this.beforeEach(() => { - if (ConfigService.get(ConfigName.OPERATOR_KEY_FORMAT) !== 'BAD_FORMAT') { + if (ConfigService.get('OPERATOR_KEY_FORMAT' as ConfigKey) !== 'BAD_FORMAT' as ConfigKey) { hapiService = new HAPIService(logger, registry, cacheService, eventEmitter, hbarLimitService); } }); @@ -336,8 +336,8 @@ describe('SdkClient', async function () { }); describe('HBAR Limiter', async () => { - 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 FILE_APPEND_CHUNK_SIZE = Number(ConfigService.get('FILE_APPEND_CHUNK_SIZE' as ConfigKey)) || 5120; + const MAX_CHUNKS = Number(ConfigService.get('FILE_APPEND_MAX_CHUNKS' as ConfigKey)) || 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, @@ -2145,7 +2145,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileCreateFee / 10 ** 8) : fileCreateFee; transfers = [ { - accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), + accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), amount: Hbar.fromTinybars(-1 * fileCreateFee), is_approval: false, }, @@ -2155,7 +2155,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileAppendFee / 10 ** 8) : fileAppendFee; transfers = [ { - accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), + accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), amount: Hbar.fromTinybars(-1 * fileAppendFee), is_approval: false, }, @@ -2165,7 +2165,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileDeleteFee / 10 ** 8) : fileDeleteFee; transfers = [ { - accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), + accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), amount: Hbar.fromTinybars(-1 * fileDeleteFee), is_approval: false, }, @@ -2180,12 +2180,12 @@ describe('SdkClient', async function () { is_approval: false, }, { - accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), + accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), amount: Hbar.fromTinybars(-1 * defaultTransactionFee), is_approval: false, }, { - accountId: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), + accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), amount: Hbar.fromTinybars(defaultTransactionFee), is_approval: false, }, @@ -2651,7 +2651,7 @@ describe('SdkClient', async function () { is_approval: false, }, { - account: ConfigService.get(ConfigName.OPERATOR_ID_MAIN), + account: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), amount: -1 * defaultTransactionFee, is_approval: false, }, @@ -2744,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(ConfigName.OPERATOR_ID_MAIN) as string) || ''; + const accountId = (ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey) 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 ae78e5593d..7d139acde3 100644 --- a/packages/relay/tests/lib/services/debugService/debug.spec.ts +++ b/packages/relay/tests/lib/services/debugService/debug.spec.ts @@ -25,7 +25,6 @@ import chaiAsPromised from 'chai-as-promised'; 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'; @@ -37,6 +36,7 @@ import { CommonService } from '../../../../src/lib/services/ethService'; import { RequestDetails } from '../../../../src/lib/types'; import RelayAssertions from '../../../assertions'; import { getQueryParams, withOverriddenEnvsInMochaTest } from '../../../helpers'; +import { ConfigKey } from '../../../../../config-service/src/services/globalConfig'; chai.use(chaiAsPromised); @@ -268,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(ConfigName.MIRROR_NODE_URL)! as string, + ConfigService.get('MIRROR_NODE_URL' as ConfigKey)!, 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 2fc66c9a50..3c0d006b82 100644 --- a/packages/relay/tests/lib/services/eth/filter.spec.ts +++ b/packages/relay/tests/lib/services/eth/filter.spec.ts @@ -19,7 +19,6 @@ */ 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'; @@ -41,6 +40,7 @@ import { toHex, withOverriddenEnvsInMochaTest, } from '../../../helpers'; +import { ConfigKey } from '../../../../../config-service/src/services/globalConfig'; const logger = pino({ level: 'silent' }); const registry = new Registry(); @@ -84,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(ConfigName.MIRROR_NODE_URL) as string, + ConfigService.get('MIRROR_NODE_URL' as ConfigKey), logger.child({ name: `mirror-node` }), registry, cacheService, diff --git a/packages/relay/tests/lib/services/metricService/metricService.spec.ts b/packages/relay/tests/lib/services/metricService/metricService.spec.ts index bbd757e43b..a3d8f2e132 100644 --- a/packages/relay/tests/lib/services/metricService/metricService.spec.ts +++ b/packages/relay/tests/lib/services/metricService/metricService.spec.ts @@ -28,7 +28,6 @@ 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'; @@ -44,6 +43,7 @@ import { overrideEnvsInMochaDescribe, withOverriddenEnvsInMochaTest, } from '../../../helpers'; +import { ConfigKey } from '../../../../../config-service/src/services/globalConfig'; const registry = new Registry(); const logger = pino({ level: 'silent' }); @@ -145,15 +145,15 @@ describe('Metric Service', function () { before(() => { // consensus node client - const hederaNetwork = ConfigService.get(ConfigName.HEDERA_NETWORK)! as string; + const hederaNetwork = ConfigService.get('HEDERA_NETWORK' as ConfigKey)!; if (hederaNetwork in constants.CHAIN_IDS) { client = Client.forName(hederaNetwork); } else { client = Client.forNetwork(JSON.parse(hederaNetwork)); } client = client.setOperator( - AccountId.fromString(ConfigService.get(ConfigName.OPERATOR_ID_MAIN)! as string), - Utils.createPrivateKeyBasedOnFormat(ConfigService.get(ConfigName.OPERATOR_KEY_MAIN)! as string), + AccountId.fromString(ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey)!), + Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN' as ConfigKey)!), ); // mirror node client @@ -166,7 +166,7 @@ describe('Metric Service', function () { timeout: 20 * 1000, }); mirrorNodeClient = new MirrorNodeClient( - (ConfigService.get(ConfigName.MIRROR_NODE_URL) as string) || '', + (ConfigService.get('MIRROR_NODE_URL' as ConfigKey)) || '', 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 0f7733c3fb..c24cbefa11 100644 --- a/packages/relay/tests/lib/utils.spec.ts +++ b/packages/relay/tests/lib/utils.spec.ts @@ -25,7 +25,7 @@ import createHash from 'keccak'; import pino from 'pino'; import sinon from 'sinon'; -import { ConfigName } from '../../../config-service/src/services/configName'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; import { ASCIIToHex, prepend0x } from '../../src/formatters'; import constants from '../../src/lib/constants'; import { Utils } from '../../src/utils'; @@ -62,7 +62,7 @@ describe('Utils', () => { describe('estimateFileTransactionsFee', () => { const callDataSize = 6000; const mockedExchangeRateInCents: number = 12; - const fileChunkSize = Number(ConfigService.get(ConfigName.FILE_APPEND_CHUNK_SIZE)) || 5120; + const fileChunkSize = Number(ConfigService.get('FILE_APPEND_CHUNK_SIZE' as ConfigKey)) || 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); @@ -85,7 +85,7 @@ describe('Utils', () => { }); // @ts-ignore - JSON.parse(ConfigService.get(ConfigName.HEDERA_SPECIFIC_REVERT_STATUSES)).forEach((status) => { + JSON.parse(ConfigService.get('HEDERA_SPECIFIC_REVERT_STATUSES' as ConfigKey)).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 1717e0eea8..41d8668121 100644 --- a/packages/relay/tests/lib/web3.spec.ts +++ b/packages/relay/tests/lib/web3.spec.ts @@ -23,7 +23,7 @@ import { expect } from 'chai'; import pino from 'pino'; import { Registry } from 'prom-client'; -import { ConfigName } from '../../../config-service/src/services/configName'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; import { RelayImpl } from '../../src'; import { withOverriddenEnvsInMochaTest } from '../helpers'; @@ -34,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(ConfigName.npm_package_version)); + expect(clientVersion).to.be.equal('relay/' + ConfigService.get('npm_package_version' as ConfigKey)); }); }); diff --git a/packages/server/tests/acceptance/conformityTests.spec.ts b/packages/server/tests/acceptance/conformityTests.spec.ts index 20fae945bd..d6cedd0b7e 100644 --- a/packages/server/tests/acceptance/conformityTests.spec.ts +++ b/packages/server/tests/acceptance/conformityTests.spec.ts @@ -32,7 +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'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const directoryPath = path.resolve(__dirname, '../../../../node_modules/execution-apis/tests'); @@ -69,7 +69,7 @@ addFormats(ajv); let execApisOpenRpcData; let relayOpenRpcData: any; -const chainId = Number(ConfigService.get(ConfigName.CHAIN_ID) || 0x12a); +const chainId = Number(ConfigService.get('CHAIN_ID' as ConfigKey) || 0x12a); let legacyTransaction = { chainId, diff --git a/packages/server/tests/acceptance/hbarLimiter.spec.ts b/packages/server/tests/acceptance/hbarLimiter.spec.ts index 9eee13cbc5..96c5c4c76f 100644 --- a/packages/server/tests/acceptance/hbarLimiter.spec.ts +++ b/packages/server/tests/acceptance/hbarLimiter.spec.ts @@ -31,7 +31,7 @@ import { ITransfer, RequestDetails } from '@hashgraph/json-rpc-relay/dist/lib/ty import { SpendingPlanConfig } from '@hashgraph/json-rpc-relay/src/lib/types/spendingPlanConfig'; import { estimateFileTransactionsFee, overrideEnvsInMochaDescribe } from '@hashgraph/json-rpc-relay/tests/helpers'; import { expect } from 'chai'; -import dotenv, { config } from 'dotenv'; +import { config } from 'dotenv'; import { BaseContract, ethers } from 'ethers'; import findConfig from 'find-config'; import fs from 'fs'; @@ -39,7 +39,6 @@ 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'; @@ -53,6 +52,7 @@ import testConstants from '../helpers/constants'; // Local resources import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; config({ path: resolve(__dirname, '../localAcceptance.env') }); @@ -128,7 +128,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { return contract; }; const transactionReecordCostTolerance = Number( - ConfigService.get(ConfigName.TEST_TRANSACTION_RECORD_COST_TOLERANCE) || 0.02, + ConfigService.get('TEST_TRANSACTION_RECORD_COST_TOLERANCE' as ConfigKey) || 0.02, ); const verifyRemainingLimit = (expectedCost: number, remainingHbarsBefore: number, remainingHbarsAfter: number) => { @@ -222,7 +222,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(ConfigName.CHAIN_ID) || 0), + chainId: Number(ConfigService.get('CHAIN_ID' as ConfigKey) || 0), maxPriorityFeePerGas: Assertions.defaultGasPrice, maxFeePerGas: Assertions.defaultGasPrice, gasLimit: 3_000_000, @@ -233,7 +233,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { logger.info(`${requestDetails.formattedRequestId} Creating accounts`); logger.info( `${requestDetails.formattedRequestId} HBAR_RATE_LIMIT_TINYBAR: ${ConfigService.get( - ConfigName.HBAR_RATE_LIMIT_TINYBAR, + 'HBAR_RATE_LIMIT_TINYBAR' as ConfigKey, )}`, ); @@ -741,7 +741,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(ConfigName.HBAR_SPENDING_PLANS_CONFIG) as string; + const SPENDING_PLANS_CONFIG_FILE = ConfigService.get('HBAR_SPENDING_PLANS_CONFIG' as ConfigKey); const configPath = findConfig(SPENDING_PLANS_CONFIG_FILE); if (configPath) { @@ -901,7 +901,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { return { ...aliasAccount, hbarSpendingPlan: accountAliasPlan.hbarSpendingPlan }; }); - const totalHbarBudget = ConfigService.get(ConfigName.HBAR_RATE_LIMIT_TINYBAR) as number; + const totalHbarBudget = ConfigService.get('HBAR_RATE_LIMIT_TINYBAR' as ConfigKey); let totalHbarSpent = totalHbarBudget - Number(await metrics.get(testConstants.METRICS.REMAINING_HBAR_LIMIT)); @@ -958,14 +958,14 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { before(async function () { logger.info( `${requestDetails.formattedRequestId} HBAR_RATE_LIMIT_TINYBAR: ${ConfigService.get( - ConfigName.HBAR_RATE_LIMIT_TINYBAR, + 'HBAR_RATE_LIMIT_TINYBAR' as ConfigKey, )}`, ); }); 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(ConfigName.HBAR_RATE_LIMIT_TINYBAR)).to.eq(0); + expect(ConfigService.get('HBAR_RATE_LIMIT_TINYBAR' as ConfigKey)).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 e7bd2929e6..e12fb9130c 100644 --- a/packages/server/tests/acceptance/index.spec.ts +++ b/packages/server/tests/acceptance/index.spec.ts @@ -25,7 +25,6 @@ dotenv.config({ path: path.resolve(__dirname, '../../../../.env') }); // 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'; @@ -50,6 +49,7 @@ import ServicesClient from '../clients/servicesClient'; // Utils and types import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(chaiAsPromised); @@ -101,7 +101,7 @@ describe('RPC Server Acceptance Tests', function () { }; // leak detection middleware - if (ConfigService.get(ConfigName.MEMWATCH_ENABLED)) { + if (ConfigService.get('MEMWATCH_ENABLED' as ConfigKey)) { Utils.captureMemoryLeaks(new GCProfiler()); } @@ -110,12 +110,12 @@ describe('RPC Server Acceptance Tests', function () { before(async () => { // configuration details logger.info('Acceptance Tests Configurations successfully loaded'); - logger.info(`LOCAL_NODE: ${ConfigService.get(ConfigName.LOCAL_NODE)}`); - logger.info(`CHAIN_ID: ${ConfigService.get(ConfigName.CHAIN_ID)}`); + logger.info(`LOCAL_NODE: ${ConfigService.get('LOCAL_NODE' as ConfigKey)}`); + logger.info(`CHAIN_ID: ${ConfigService.get('CHAIN_ID' as ConfigKey)}`); 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(ConfigName.E2E_RELAY_HOST)}`); + logger.info(`E2E_RELAY_HOST: ${ConfigService.get('E2E_RELAY_HOST' as ConfigKey)}`); if (global.relayIsLocal) { runLocalRelay(); @@ -127,7 +127,7 @@ describe('RPC Server Acceptance Tests', function () { RELAY_URL, CHAIN_ID, Utils.generateRequestId(), - Number(ConfigService.get(ConfigName.TEST_INITIAL_ACCOUNT_STARTING_BALANCE) || 2000), + Number(ConfigService.get('TEST_INITIAL_ACCOUNT_STARTING_BALANCE' as ConfigKey) || 2000), ); global.accounts = new Array(initialAccount); @@ -198,7 +198,7 @@ describe('RPC Server Acceptance Tests', function () { relayServer.close(); } - if (ConfigService.get(ConfigName.TEST_WS_SERVER) && global.socketServer !== undefined) { + if (ConfigService.get('TEST_WS_SERVER' as ConfigKey) && global.socketServer !== undefined) { global.socketServer.close(); } } @@ -212,7 +212,7 @@ describe('RPC Server Acceptance Tests', function () { global.relayServer = relayServer; setServerTimeout(relayServer); - if (ConfigService.get(ConfigName.TEST_WS_SERVER)) { + if (ConfigService.get('TEST_WS_SERVER' as ConfigKey)) { 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 080b9a41d9..667caaf1b1 100644 --- a/packages/server/tests/acceptance/rateLimiter.spec.ts +++ b/packages/server/tests/acceptance/rateLimiter.spec.ts @@ -23,10 +23,10 @@ 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'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@ratelimiter Rate Limiters Acceptance Tests', function () { this.timeout(480 * 1000); // 480 seconds @@ -38,9 +38,9 @@ describe('@ratelimiter Rate Limiters Acceptance Tests', function () { let requestId: string; const TIER_2_RATE_LIMIT = - (ConfigService.get(ConfigName.TIER_2_RATE_LIMIT) as unknown as number) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2; + (ConfigService.get('TIER_2_RATE_LIMIT' as ConfigKey)) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2; const LIMIT_DURATION = - (ConfigService.get(ConfigName.LIMIT_DURATION) as unknown as number) || relayConstants.DEFAULT_RATE_LIMIT.DURATION; + (ConfigService.get('LIMIT_DURATION' as ConfigKey)) || 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 f0ba1940fe..8cee93df04 100644 --- a/packages/server/tests/acceptance/rpc_batch1.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch1.spec.ts @@ -37,7 +37,6 @@ 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'; @@ -51,6 +50,7 @@ import parentContractJson from '../contracts/Parent.json'; import Assertions from '../helpers/assertions'; import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const Address = RelayCalls; @@ -73,7 +73,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () { let account2Address: string; let expectedGasPrice: string; - const CHAIN_ID = (ConfigService.get(ConfigName.CHAIN_ID) as string) || '0x12a'; + const CHAIN_ID = (ConfigService.get('CHAIN_ID' as ConfigKey)) || '0x12a'; const requestId = 'rpc_batch1Test'; const requestIdPrefix = Utils.formatRequestIdMessage(requestId); const requestDetails = JSON.stringify(new RequestDetails({ requestId: 'rpc_batch1Test', ipAddress: '0.0.0.0' })); @@ -84,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(ConfigName.TEST_GAS_PRICE_DEVIATION) ?? '0.2') as string); + const gasPriceDeviation = parseFloat((ConfigService.get('TEST_GAS_PRICE_DEVIATION' as ConfigKey) ?? '0.2') as string); const sendRawTransaction = relay.sendRawTransaction; - const useAsyncTxProcessing = ConfigService.get(ConfigName.USE_ASYNC_TX_PROCESSING) as boolean; + const useAsyncTxProcessing = ConfigService.get('USE_ASYNC_TX_PROCESSING' as ConfigKey); /** * 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 17d8caae65..d021e7c9bd 100644 --- a/packages/server/tests/acceptance/rpc_batch2.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch2.spec.ts @@ -20,7 +20,6 @@ // 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'; @@ -47,6 +46,7 @@ import TokenCreateJson from '../contracts/TokenCreateContract.json'; import Assertions from '../helpers/assertions'; import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@api-batch-2 RPC Server Acceptance Tests', function () { this.timeout(240 * 1000); // 240 seconds @@ -80,7 +80,7 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () { let createChildTx: ethers.ContractTransactionResponse; let accounts0StartBalance: bigint; - const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || 0; + const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || 0; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); const ONE_WEIBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 18))); @@ -442,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(ConfigName.LOCAL_NODE)) { + if (ConfigService.get('LOCAL_NODE' as ConfigKey)) { expect(res).be.equal(expectedGasPrice); } else { expect(Number(res)).to.be.gt(0); @@ -1077,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(ConfigName.LOCAL_NODE)) { + if (ConfigService.get('LOCAL_NODE' as ConfigKey)) { 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 d57ba0f60d..700e15e227 100644 --- a/packages/server/tests/acceptance/rpc_batch3.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch3.spec.ts @@ -56,7 +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'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(chaiExclude); @@ -75,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(ConfigName.CHAIN_ID) || 0x12a; + const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || 0x12a; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); let reverterContract: ethers.Contract; @@ -548,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(ConfigName.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE)) { + if (!ConfigService.get('ETH_CALL_DEFAULT_TO_CONSENSUS_NODE' as ConfigKey)) { it('010 Should call msgValue', async function () { const callData = { ...defaultCallData, @@ -612,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(ConfigName.E2E_SERVER_PORT) || '7546'; + const testClientPort = ConfigService.get('E2E_SERVER_PORT' as ConfigKey) || '7546'; const testClient = Axios.create({ baseURL: 'http://localhost:' + testClientPort, responseType: 'json' as const, @@ -798,7 +798,7 @@ describe('@api-batch-3 RPC Server Acceptance Tests', function () { let initialEthCallSelectorsAlwaysToConsensus: any, hrc719Contract: ethers.Contract; before(async () => { - initialEthCallSelectorsAlwaysToConsensus = ConfigService.get(ConfigName.ETH_CALL_CONSENSUS_SELECTORS); + initialEthCallSelectorsAlwaysToConsensus = ConfigService.get('ETH_CALL_CONSENSUS_SELECTORS' as ConfigKey); hrc719Contract = await Utils.deployContract( HRC719ContractJson.abi, @@ -815,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(ConfigName.ETH_CALL_CONSENSUS_SELECTORS); + const selectorsList = ConfigService.get('ETH_CALL_CONSENSUS_SELECTORS' as ConfigKey); 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 303b523a75..802d42b5b8 100644 --- a/packages/server/tests/acceptance/serverConfig.spec.ts +++ b/packages/server/tests/acceptance/serverConfig.spec.ts @@ -20,15 +20,15 @@ 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 { ConfigKey } from '../../../config-service/src/services/globalConfig'; 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(ConfigName.SERVER_REQUEST_TIMEOUT_MS) as string || '3000'); + const requestTimeoutMs: number = parseInt(ConfigService.get('SERVER_REQUEST_TIMEOUT_MS' as ConfigKey) || '3000'); const host = ConfigService.get('SERVER_HOST') || 'localhost'; - const port = parseInt(ConfigService.get(ConfigName.SERVER_PORT) as string || '7546'); + const port = parseInt(ConfigService.get('SERVER_PORT' as ConfigKey) || '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 266ca96699..7092f1b931 100644 --- a/packages/server/tests/integration/server.spec.ts +++ b/packages/server/tests/integration/server.spec.ts @@ -30,7 +30,6 @@ import Koa from 'koa'; import sinon from 'sinon'; import { GCProfiler } from 'v8'; -import { ConfigName } from '../../../config-service/src/services/configName'; import { contractAddress1, contractAddress2, @@ -44,6 +43,7 @@ import * as Constants from '../../src/validator/constants'; import RelayCalls from '../../tests/helpers/constants'; import Assertions from '../helpers/assertions'; import { Utils } from '../helpers/utils'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const MISSING_PARAM_ERROR = 'Missing value for required parameter'; @@ -56,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(ConfigName.E2E_SERVER_PORT)); + testServer = app.listen(ConfigService.get('E2E_SERVER_PORT' as ConfigKey)); testClient = BaseTest.createTestClient(); // leak detection middleware - if (ConfigService.get(ConfigName.MEMWATCH_ENABLED)) { + if (ConfigService.get('MEMWATCH_ENABLED' as ConfigKey)) { Utils.captureMemoryLeaks(new GCProfiler()); } }); @@ -120,7 +120,7 @@ describe('RPC Server', function () { }); BaseTest.defaultResponseChecks(res); - expect(res.data.result).to.be.equal('0x' + Number(ConfigService.get(ConfigName.CHAIN_ID)).toString(16)); + expect(res.data.result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).toString(16)); }); it('validates enforcement of request id', async function () { @@ -140,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(ConfigName.E2E_SERVER_PORT)}`; + const port = `1${ConfigService.get('E2E_SERVER_PORT' as ConfigKey)}`; const testServer2 = app2.listen(port); try { @@ -159,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(ConfigName.CHAIN_ID)).toString(16)); + expect(response.data.result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).toString(16)); } catch (error: any) { expect(true, `Unexpected error: ${error.message}`).to.eq(false); } finally { @@ -190,7 +190,7 @@ describe('RPC Server', function () { }); BaseTest.defaultResponseChecks(res); - expect(res.data.result).to.be.equal('relay/' + ConfigService.get(ConfigName.npm_package_version)); + expect(res.data.result).to.be.equal('relay/' + ConfigService.get('npm_package_version' as ConfigKey)); }); it('should execute "eth_getTransactionByHash with missing transaction"', async function () { @@ -543,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(ConfigName.CHAIN_ID)).toString(16)); + expect(response.data[i].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).toString(16)); } }); @@ -560,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(ConfigName.CHAIN_ID)).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).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(ConfigName.CHAIN_ID)).toString(16)); + expect(response.data[2].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).toString(16)); }); it('should execute "eth_chainId" and "eth_accounts" in batch request with invalid request id', async function () { @@ -578,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(ConfigName.CHAIN_ID)).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).toString(16)); // verify eth_accounts result expect(response.data[1].id).to.be.equal(null); expect(response.data[1].error).to.be.an('Object'); @@ -598,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(ConfigName.CHAIN_ID)).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).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'); @@ -606,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(ConfigName.CHAIN_ID)).toString(16)); + expect(response.data[2].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).toString(16)); }); it('should execute "eth_chainId" and method not found and params error in batch request', async function () { @@ -626,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(ConfigName.CHAIN_ID)).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).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'); @@ -2703,7 +2703,7 @@ describe('RPC Server', function () { }); class BaseTest { - static createTestClient(port = ConfigService.get(ConfigName.E2E_SERVER_PORT)) { + static createTestClient(port = ConfigService.get('E2E_SERVER_PORT' as ConfigKey)) { 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 6816d12ae9..8ee8a1b0da 100644 --- a/packages/ws-server/tests/acceptance/batchRequest.spec.ts +++ b/packages/ws-server/tests/acceptance/batchRequest.spec.ts @@ -24,8 +24,8 @@ 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 { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-request Batch Requests', async function () { const METHOD_NAME = 'batch_request'; @@ -105,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(ConfigName.WS_BATCH_REQUESTS_MAX_SIZE)), + Number(ConfigService.get('WS_BATCH_REQUESTS_MAX_SIZE' as ConfigKey)), ); delete expectedError.data; diff --git a/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts b/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts index 3ff79469f7..50e42de354 100644 --- a/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts @@ -30,12 +30,12 @@ import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccoun import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; -import { ConfigName } from '../../../config-service/src/services/configName'; import { WsTestConstant, WsTestHelper } from '../helper'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_getTransactionByHash', async function () { const METHOD_NAME = 'eth_getTransactionByHash'; - const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; + const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || '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 048aacbdf0..d32f993985 100644 --- a/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts @@ -29,12 +29,12 @@ import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccoun import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; -import { ConfigName } from '../../../config-service/src/services/configName'; import { WsTestConstant, WsTestHelper } from '../helper'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@release @web-socket-batch-2 eth_getTransactionCount', async function () { const METHOD_NAME = 'eth_getTransactionCount'; - const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; + const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || '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 050cda646d..18b4f02a33 100644 --- a/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts @@ -30,12 +30,12 @@ import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccoun import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; -import { ConfigName } from '../../../config-service/src/services/configName'; import { WsTestConstant, WsTestHelper } from '../helper'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_getTransactionReceipt', async function () { const METHOD_NAME = 'eth_getTransactionReceipt'; - const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; + const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || '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 58afdac0cd..68e09b60a2 100644 --- a/packages/ws-server/tests/acceptance/index.spec.ts +++ b/packages/ws-server/tests/acceptance/index.spec.ts @@ -42,6 +42,7 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import fs from 'fs'; import pino from 'pino'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(chaiAsPromised); @@ -85,12 +86,12 @@ describe('RPC Server Acceptance Tests', function () { before(async () => { // configuration details logger.info('Acceptance Tests Configurations successfully loaded'); - logger.info(`LOCAL_NODE: ${ConfigService.get(ConfigName.LOCAL_NODE)}`); - logger.info(`CHAIN_ID: ${ConfigService.get(ConfigName.CHAIN_ID)}`); + logger.info(`LOCAL_NODE: ${ConfigService.get('LOCAL_NODE' as ConfigKey)}`); + logger.info(`CHAIN_ID: ${ConfigService.get('CHAIN_ID' as ConfigKey)}`); 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(ConfigName.E2E_RELAY_HOST)}`); + logger.info(`E2E_RELAY_HOST: ${ConfigService.get('E2E_RELAY_HOST' as ConfigKey)}`); if (global.relayIsLocal) { runLocalRelay(); @@ -150,7 +151,7 @@ describe('RPC Server Acceptance Tests', function () { } const socketServer: Server = global.socketServer; - if (ConfigService.get(ConfigName.TEST_WS_SERVER) && socketServer !== undefined) { + if (ConfigService.get('TEST_WS_SERVER' as ConfigKey) && socketServer !== undefined) { socketServer.close(); } }); @@ -181,7 +182,7 @@ describe('RPC Server Acceptance Tests', function () { global.relayServer = relayServer; setServerTimeout(relayServer); - if (ConfigService.get(ConfigName.TEST_WS_SERVER)) { + if (ConfigService.get('TEST_WS_SERVER' as ConfigKey)) { 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 04d0c03cab..f8411adc9a 100644 --- a/packages/ws-server/tests/acceptance/rateLimiter.spec.ts +++ b/packages/ws-server/tests/acceptance/rateLimiter.spec.ts @@ -25,13 +25,13 @@ import { IPRateLimitExceeded } from '@hashgraph/json-rpc-server/dist/koaJsonRpc/ 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'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-ratelimiter Rate Limit Tests', async function () { - 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 rateLimitTier2 = Number(ConfigService.get('TIER_2_RATE_LIMIT' as ConfigKey) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2); + const limitDuration = Number(ConfigService.get('LIMIT_DURATION' as ConfigKey)) || 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 04dd84cd94..aa6943c645 100644 --- a/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts +++ b/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts @@ -32,12 +32,12 @@ import { AliasAccount } from '@hashgraph/json-rpc-server/tests/types/AliasAccoun import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; -import { ConfigName } from '../../../config-service/src/services/configName'; import { WsTestConstant, WsTestHelper } from '../helper'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_sendRawTransaction', async function () { const METHOD_NAME = 'eth_sendRawTransaction'; - const CHAIN_ID = ConfigService.get(ConfigName.CHAIN_ID) || '0x12a'; + const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || '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 b42e168a75..139a1cb821 100644 --- a/packages/ws-server/tests/acceptance/subscribe.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribe.spec.ts @@ -33,12 +33,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'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(solidity); -const WS_RELAY_URL = `${ConfigService.get(ConfigName.WS_RELAY_URL)}`; +const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL' as ConfigKey)}`; const establishConnection = async () => { const provider = await new ethers.WebSocketProvider(WS_RELAY_URL); @@ -75,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(ConfigName.CHAIN_ID) || 0; + const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || 0; let server; // @ts-ignore const { servicesNode, relay, mirrorNode } = global; @@ -437,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(ConfigName.WS_CONNECTION_LIMIT) as string); i++) { + for (let i = 1; i < parseInt(ConfigService.get('WS_CONNECTION_LIMIT' as ConfigKey)); i++) { providers.push(await establishConnection()); } // Server is at max connections - expect(server._connections).to.equal(parseInt(ConfigService.get(ConfigName.WS_CONNECTION_LIMIT) as string)); + expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT' as ConfigKey))); }); afterEach(async () => { @@ -501,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(ConfigName.WS_MAX_INACTIVITY_TTL) as string) + 1000)); + await new Promise((resolve) => setTimeout(resolve, parseInt(ConfigService.get('WS_MAX_INACTIVITY_TTL' as ConfigKey)) + 1000)); expect(closeEventHandled2).to.eq(true); expect(closeEventHandled3).to.eq(true); @@ -898,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(ConfigName.WS_CONNECTION_LIMIT_PER_IP)); i++) { + for (let i = 1; i < parseInt(ConfigService.get('WS_CONNECTION_LIMIT_PER_IP' as ConfigKey)); i++) { // @ts-ignore providers.push(await new ethers.WebSocketProvider(WS_RELAY_URL)); } @@ -908,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(ConfigName.WS_CONNECTION_LIMIT_PER_IP))); + expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT_PER_IP' as ConfigKey))); // The next connection should be closed by the server const provider = await new ethers.WebSocketProvider(WS_RELAY_URL); @@ -923,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(ConfigName.WS_CONNECTION_LIMIT_PER_IP))); + expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT_PER_IP' as ConfigKey))); 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 53d579dd3f..2abd4429c9 100644 --- a/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts @@ -31,12 +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'; +import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(solidity); -const WS_RELAY_URL = `${ConfigService.get(ConfigName.WS_RELAY_URL)}`; +const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL' as ConfigKey)}`; const evmAddressRegex = /^0x[a-fA-F0-9]*$/; function verifyResponse(response: any, done: Mocha.Done, webSocket: any, includeTransactions: boolean) { @@ -100,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(ConfigName.CHAIN_ID) || 0; + const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || 0; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); let mirrorNodeServer, requestId, rpcServer, wsServer; @@ -197,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(ConfigName.WS_NEW_HEADS_ENABLED)).to.be.undefined; + expect(ConfigService.get('WS_NEW_HEADS_ENABLED' as ConfigKey)).to.be.undefined; const webSocket = new WebSocket(WS_RELAY_URL); const subscriptionId = 1; From afea6baaca93fa3330adc70e56ce5682590246df Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Wed, 25 Dec 2024 08:55:42 +0100 Subject: [PATCH 04/11] Reverting License Header Changes Signed-off-by: belloibrahv --- packages/config-service/src/commands/printEnvs.ts | 2 +- packages/config-service/src/services/globalConfig.ts | 2 +- packages/config-service/src/services/index.ts | 2 +- packages/config-service/src/services/loggerService.ts | 2 +- packages/config-service/src/services/validationService.ts | 2 +- packages/config-service/tests/configServiceTestHelper.ts | 2 +- .../config-service/tests/src/services/configService.spec.ts | 2 +- .../config-service/tests/src/services/loggerService.spec.ts | 2 +- .../config-service/tests/src/services/validationService.spec.ts | 2 +- packages/relay/src/lib/types/ITracerConfig.ts | 2 +- packages/relay/src/lib/types/ITracerConfigWrapper.ts | 2 +- packages/relay/src/lib/types/ITransactionReceipt.ts | 2 +- packages/relay/src/lib/types/RequestDetails.ts | 2 +- packages/relay/src/lib/types/index.ts | 2 +- packages/relay/src/logsBloomUtils.ts | 2 +- packages/relay/src/receiptsRootUtils.ts | 2 +- packages/relay/src/utils.ts | 2 +- .../tests/lib/config/hbarSpendingPlanConfigService.spec.ts | 2 +- packages/relay/tests/lib/logsBloomUtils.spec.ts | 2 +- packages/relay/tests/lib/receiptsRootUtils.spec.ts | 2 +- .../lib/services/hbarLimitService/hbarLimitService.spec.ts | 2 +- packages/relay/tests/lib/utils.spec.ts | 2 +- packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts | 2 +- packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts | 2 +- packages/server/tests/acceptance/conformityTests.spec.ts | 2 +- packages/server/tests/acceptance/hbarLimiter.spec.ts | 2 +- packages/server/tests/clients/githubClient.ts | 2 +- packages/server/tests/types/GitHubContext.ts | 2 +- packages/server/tests/types/HeapDifferenceStatistics.ts | 2 +- tools/brownie-example/LICENSE | 2 +- tools/waffle-example/test/samplecontract.test.mjs | 2 +- tools/wagmi-example/src/App.tsx | 2 +- tools/wagmi-example/src/components/Contract.tsx | 2 +- tools/wagmi-example/src/components/Profile.tsx | 2 +- tools/wagmi-example/src/hooks/use-balance.ts | 2 +- tools/wagmi-example/src/hooks/use-deploy.ts | 2 +- tools/wagmi-example/src/main.tsx | 2 +- tools/wagmi-example/src/wagmi.ts | 2 +- 38 files changed, 38 insertions(+), 38 deletions(-) diff --git a/packages/config-service/src/commands/printEnvs.ts b/packages/config-service/src/commands/printEnvs.ts index cfde9dd5f0..2764b21f70 100644 --- a/packages/config-service/src/commands/printEnvs.ts +++ b/packages/config-service/src/commands/printEnvs.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index 4a37960006..97f22779e3 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/config-service/src/services/index.ts b/packages/config-service/src/services/index.ts index 1ed30abaef..1d9b0a58b0 100644 --- a/packages/config-service/src/services/index.ts +++ b/packages/config-service/src/services/index.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/config-service/src/services/loggerService.ts b/packages/config-service/src/services/loggerService.ts index 5f5a5e346d..027fe7f447 100644 --- a/packages/config-service/src/services/loggerService.ts +++ b/packages/config-service/src/services/loggerService.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/config-service/src/services/validationService.ts b/packages/config-service/src/services/validationService.ts index 738fc36391..0419763830 100644 --- a/packages/config-service/src/services/validationService.ts +++ b/packages/config-service/src/services/validationService.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/config-service/tests/configServiceTestHelper.ts b/packages/config-service/tests/configServiceTestHelper.ts index 1344cb30f0..288734f101 100644 --- a/packages/config-service/tests/configServiceTestHelper.ts +++ b/packages/config-service/tests/configServiceTestHelper.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/config-service/tests/src/services/configService.spec.ts b/packages/config-service/tests/src/services/configService.spec.ts index 01c34250e2..422c25b466 100644 --- a/packages/config-service/tests/src/services/configService.spec.ts +++ b/packages/config-service/tests/src/services/configService.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/config-service/tests/src/services/loggerService.spec.ts b/packages/config-service/tests/src/services/loggerService.spec.ts index 2f862a84a9..94ba27bf0d 100644 --- a/packages/config-service/tests/src/services/loggerService.spec.ts +++ b/packages/config-service/tests/src/services/loggerService.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/config-service/tests/src/services/validationService.spec.ts b/packages/config-service/tests/src/services/validationService.spec.ts index 9fd5671ae0..b5c8ca4763 100644 --- a/packages/config-service/tests/src/services/validationService.spec.ts +++ b/packages/config-service/tests/src/services/validationService.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/src/lib/types/ITracerConfig.ts b/packages/relay/src/lib/types/ITracerConfig.ts index 6f92ccbbb2..7cec49efd9 100644 --- a/packages/relay/src/lib/types/ITracerConfig.ts +++ b/packages/relay/src/lib/types/ITracerConfig.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/src/lib/types/ITracerConfigWrapper.ts b/packages/relay/src/lib/types/ITracerConfigWrapper.ts index 3499c2f913..dc444fd38d 100644 --- a/packages/relay/src/lib/types/ITracerConfigWrapper.ts +++ b/packages/relay/src/lib/types/ITracerConfigWrapper.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/src/lib/types/ITransactionReceipt.ts b/packages/relay/src/lib/types/ITransactionReceipt.ts index c42b7cf56d..a208da06f4 100644 --- a/packages/relay/src/lib/types/ITransactionReceipt.ts +++ b/packages/relay/src/lib/types/ITransactionReceipt.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/src/lib/types/RequestDetails.ts b/packages/relay/src/lib/types/RequestDetails.ts index 5d557d2151..206d325b98 100644 --- a/packages/relay/src/lib/types/RequestDetails.ts +++ b/packages/relay/src/lib/types/RequestDetails.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/src/lib/types/index.ts b/packages/relay/src/lib/types/index.ts index 2ca506dbf4..dc048c8dca 100644 --- a/packages/relay/src/lib/types/index.ts +++ b/packages/relay/src/lib/types/index.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/src/logsBloomUtils.ts b/packages/relay/src/logsBloomUtils.ts index f0e6cd29f2..e7e94cab3b 100644 --- a/packages/relay/src/logsBloomUtils.ts +++ b/packages/relay/src/logsBloomUtils.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/src/receiptsRootUtils.ts b/packages/relay/src/receiptsRootUtils.ts index 3f3415dac2..80731477a7 100644 --- a/packages/relay/src/receiptsRootUtils.ts +++ b/packages/relay/src/receiptsRootUtils.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/src/utils.ts b/packages/relay/src/utils.ts index f7b5c13bc9..2704297fbd 100644 --- a/packages/relay/src/utils.ts +++ b/packages/relay/src/utils.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts index d8d7a3f3ff..4ce82f3634 100644 --- a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts +++ b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/tests/lib/logsBloomUtils.spec.ts b/packages/relay/tests/lib/logsBloomUtils.spec.ts index 4046d07097..4ec141c1e1 100644 --- a/packages/relay/tests/lib/logsBloomUtils.spec.ts +++ b/packages/relay/tests/lib/logsBloomUtils.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/tests/lib/receiptsRootUtils.spec.ts b/packages/relay/tests/lib/receiptsRootUtils.spec.ts index 36e6f26acd..4bd417b291 100644 --- a/packages/relay/tests/lib/receiptsRootUtils.spec.ts +++ b/packages/relay/tests/lib/receiptsRootUtils.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts b/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts index 5a97deeecb..fe05b346a7 100644 --- a/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts +++ b/packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/relay/tests/lib/utils.spec.ts b/packages/relay/tests/lib/utils.spec.ts index c24cbefa11..3c52cc9cbd 100644 --- a/packages/relay/tests/lib/utils.spec.ts +++ b/packages/relay/tests/lib/utils.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts b/packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts index 7f78ec1b91..91e7a85649 100644 --- a/packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts +++ b/packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts b/packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts index ba14478890..debce1547a 100644 --- a/packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts +++ b/packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/server/tests/acceptance/conformityTests.spec.ts b/packages/server/tests/acceptance/conformityTests.spec.ts index d6cedd0b7e..6f271388d6 100644 --- a/packages/server/tests/acceptance/conformityTests.spec.ts +++ b/packages/server/tests/acceptance/conformityTests.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/server/tests/acceptance/hbarLimiter.spec.ts b/packages/server/tests/acceptance/hbarLimiter.spec.ts index 96c5c4c76f..7d8fa3cad5 100644 --- a/packages/server/tests/acceptance/hbarLimiter.spec.ts +++ b/packages/server/tests/acceptance/hbarLimiter.spec.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + *Copyright (C) 2022-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. diff --git a/packages/server/tests/clients/githubClient.ts b/packages/server/tests/clients/githubClient.ts index b08d287713..932ef7ca17 100644 --- a/packages/server/tests/clients/githubClient.ts +++ b/packages/server/tests/clients/githubClient.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/server/tests/types/GitHubContext.ts b/packages/server/tests/types/GitHubContext.ts index 355bbcefe4..22c949939d 100644 --- a/packages/server/tests/types/GitHubContext.ts +++ b/packages/server/tests/types/GitHubContext.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/packages/server/tests/types/HeapDifferenceStatistics.ts b/packages/server/tests/types/HeapDifferenceStatistics.ts index db67e82b62..ce96510525 100644 --- a/packages/server/tests/types/HeapDifferenceStatistics.ts +++ b/packages/server/tests/types/HeapDifferenceStatistics.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/tools/brownie-example/LICENSE b/tools/brownie-example/LICENSE index b902617e1b..26837975df 100644 --- a/tools/brownie-example/LICENSE +++ b/tools/brownie-example/LICENSE @@ -1,6 +1,6 @@ Hedera Brownie Example -Copyright (C) 2024 Hedera Hashgraph, LLC +Copyright (C) 2022-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. diff --git a/tools/waffle-example/test/samplecontract.test.mjs b/tools/waffle-example/test/samplecontract.test.mjs index 7609cfa1b1..76401a2b1b 100644 --- a/tools/waffle-example/test/samplecontract.test.mjs +++ b/tools/waffle-example/test/samplecontract.test.mjs @@ -2,7 +2,7 @@ * * Hedera Waffle Project * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/tools/wagmi-example/src/App.tsx b/tools/wagmi-example/src/App.tsx index 63a0f15360..27d7efb8a8 100644 --- a/tools/wagmi-example/src/App.tsx +++ b/tools/wagmi-example/src/App.tsx @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/tools/wagmi-example/src/components/Contract.tsx b/tools/wagmi-example/src/components/Contract.tsx index 4f9cea022c..e6b8c015bf 100644 --- a/tools/wagmi-example/src/components/Contract.tsx +++ b/tools/wagmi-example/src/components/Contract.tsx @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/tools/wagmi-example/src/components/Profile.tsx b/tools/wagmi-example/src/components/Profile.tsx index 41389a77a5..be417b05b9 100644 --- a/tools/wagmi-example/src/components/Profile.tsx +++ b/tools/wagmi-example/src/components/Profile.tsx @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/tools/wagmi-example/src/hooks/use-balance.ts b/tools/wagmi-example/src/hooks/use-balance.ts index 78b7c546ff..f37e00e00d 100644 --- a/tools/wagmi-example/src/hooks/use-balance.ts +++ b/tools/wagmi-example/src/hooks/use-balance.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/tools/wagmi-example/src/hooks/use-deploy.ts b/tools/wagmi-example/src/hooks/use-deploy.ts index 27c249e859..15f47e3a69 100644 --- a/tools/wagmi-example/src/hooks/use-deploy.ts +++ b/tools/wagmi-example/src/hooks/use-deploy.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/tools/wagmi-example/src/main.tsx b/tools/wagmi-example/src/main.tsx index cda3a08d7e..6b10f73ae7 100644 --- a/tools/wagmi-example/src/main.tsx +++ b/tools/wagmi-example/src/main.tsx @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. diff --git a/tools/wagmi-example/src/wagmi.ts b/tools/wagmi-example/src/wagmi.ts index 21a4f2d3df..687a33605f 100644 --- a/tools/wagmi-example/src/wagmi.ts +++ b/tools/wagmi-example/src/wagmi.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * Copyright (C) 2024 Hedera Hashgraph, LLC + * Copyright (C) 2022-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. From 1a937afb1db7fd1da836cfddf78e97d05d39a4bc Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Fri, 27 Dec 2024 00:21:43 +0100 Subject: [PATCH 05/11] Refinment of ConfigService.get() (to conform to newly suggested changes) Signed-off-by: belloibrahv --- .../src/services/globalConfig.ts | 6 ++++ packages/config-service/src/services/index.ts | 3 +- .../tests/src/services/configService.spec.ts | 4 +-- .../tests/src/services/loggerService.spec.ts | 2 +- .../hbarSpendingPlanConfigService.spec.ts | 4 +-- packages/relay/tests/lib/eth/eth-config.ts | 2 +- packages/relay/tests/lib/eth/eth-helpers.ts | 2 +- .../relay/tests/lib/eth/eth_common.spec.ts | 2 +- .../lib/eth/eth_sendRawTransaction.spec.ts | 4 +-- .../relay/tests/lib/ethGetBlockBy.spec.ts | 2 +- .../relay/tests/lib/mirrorNodeClient.spec.ts | 9 ++++-- packages/relay/tests/lib/net.spec.ts | 2 +- packages/relay/tests/lib/poller.spec.ts | 2 +- packages/relay/tests/lib/precheck.spec.ts | 2 +- packages/relay/tests/lib/sdkClient.spec.ts | 28 +++++++++---------- .../lib/services/debugService/debug.spec.ts | 2 +- .../tests/lib/services/eth/filter.spec.ts | 2 +- .../metricService/metricService.spec.ts | 8 +++--- packages/relay/tests/lib/utils.spec.ts | 4 +-- packages/relay/tests/lib/web3.spec.ts | 2 +- .../tests/acceptance/conformityTests.spec.ts | 2 +- .../tests/acceptance/hbarLimiter.spec.ts | 12 ++++---- .../server/tests/acceptance/index.spec.ts | 14 +++++----- .../tests/acceptance/rateLimiter.spec.ts | 4 +-- .../tests/acceptance/rpc_batch1.spec.ts | 6 ++-- .../tests/acceptance/rpc_batch2.spec.ts | 6 ++-- .../tests/acceptance/rpc_batch3.spec.ts | 10 +++---- .../tests/acceptance/serverConfig.spec.ts | 4 +-- .../server/tests/integration/server.spec.ts | 28 +++++++++---------- .../tests/acceptance/batchRequest.spec.ts | 2 +- .../acceptance/getTransactionByHash.spec.ts | 2 +- .../acceptance/getTransactionCount.spec.ts | 2 +- .../acceptance/getTransactionReceipt.spec.ts | 2 +- .../ws-server/tests/acceptance/index.spec.ts | 10 +++---- .../tests/acceptance/rateLimiter.spec.ts | 4 +-- .../acceptance/sendRawTransaction.spec.ts | 2 +- .../tests/acceptance/subscribe.spec.ts | 16 +++++------ .../acceptance/subscribeNewHeads.spec.ts | 6 ++-- 38 files changed, 117 insertions(+), 107 deletions(-) diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index 97f22779e3..52b2f07dbb 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -567,6 +567,12 @@ const _CONFIG = { required: false, defaultValue: null, }, + SERVER_HOST: { + envName: 'SERVER_HOST', + type: 'string', + required: false, + defaultValue: null, + }, SERVER_PORT: { envName: 'SERVER_PORT', type: 'number', diff --git a/packages/config-service/src/services/index.ts b/packages/config-service/src/services/index.ts index 1d9b0a58b0..87ff70b670 100644 --- a/packages/config-service/src/services/index.ts +++ b/packages/config-service/src/services/index.ts @@ -24,6 +24,7 @@ import pino from 'pino'; import { LoggerService } from './loggerService'; import { ValidationService } from './validationService'; +import { ConfigKey } from './globalConfig'; const mainLogger = pino({ name: 'hedera-json-rpc-relay', @@ -97,7 +98,7 @@ export class ConfigService { * @param name string * @returns string | undefined */ - public static get(name: string): string | number | boolean | null | undefined { + public static get(name: ConfigKey): string | number | boolean | null | undefined { return this.getInstance().envs[name]; } } diff --git a/packages/config-service/tests/src/services/configService.spec.ts b/packages/config-service/tests/src/services/configService.spec.ts index 422c25b466..eb57a32c38 100644 --- a/packages/config-service/tests/src/services/configService.spec.ts +++ b/packages/config-service/tests/src/services/configService.spec.ts @@ -21,7 +21,7 @@ import chai, { expect } from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { ConfigService } from '../../../src/services'; -import { ConfigKey } from '../../../src/services/globalConfig'; +import type { ConfigKey } from '../../../src/services/globalConfig'; chai.use(chaiAsPromised); @@ -50,7 +50,7 @@ describe('ConfigService tests', async function () { }); it('should be able to get existing env var', async () => { - const res = ConfigService.get('CHAIN_ID' as ConfigKey); + const res = ConfigService.get('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 94ba27bf0d..02c55549c5 100644 --- a/packages/config-service/tests/src/services/loggerService.spec.ts +++ b/packages/config-service/tests/src/services/loggerService.spec.ts @@ -48,7 +48,7 @@ describe('LoggerService tests', async function () { }); it('should be able to return plain information', async () => { - const envName = 'CHAIN_ID' as ConfigKey; + const envName = 'CHAIN_ID'; const res = ConfigService.get(envName) as string | undefined; 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 4ce82f3634..a50414f182 100644 --- a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts +++ b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts @@ -106,7 +106,7 @@ describe('HbarSpendingPlanConfigService', function () { }); after(async function () { - if (ConfigService.get('REDIS_ENABLED' as ConfigKey)) { + if (ConfigService.get('REDIS_ENABLED')) { await cacheService.disconnectRedisClient(); } }); @@ -386,7 +386,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' as ConfigKey)))); + await new Promise((resolve) => setTimeout(resolve, Number(ConfigService.get('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 895383df13..673f30f9e5 100644 --- a/packages/relay/tests/lib/eth/eth-config.ts +++ b/packages/relay/tests/lib/eth/eth-config.ts @@ -121,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' as ConfigKey) ?? true; +export const ETH_FEE_HISTORY_VALUE = ConfigService.get('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 c9f339d4bf..d7736e7937 100644 --- a/packages/relay/tests/lib/eth/eth-helpers.ts +++ b/packages/relay/tests/lib/eth/eth-helpers.ts @@ -56,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' as ConfigKey) || '', + ConfigService.get('MIRROR_NODE_URL') || '', 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 bae729764b..e771df0ec8 100644 --- a/packages/relay/tests/lib/eth/eth_common.spec.ts +++ b/packages/relay/tests/lib/eth/eth_common.spec.ts @@ -44,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' as ConfigKey)).toString(16)); + expect(chainId).to.be.equal('0x' + Number(ConfigService.get('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 f0236e36f1..abf6593020 100644 --- a/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts +++ b/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts @@ -116,7 +116,7 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function () }, }; const transaction = { - chainId: Number(ConfigService.get('CHAIN_ID' as ConfigKey) || 0x12a), + chainId: Number(ConfigService.get('CHAIN_ID') || 0x12a), to: ACCOUNT_ADDRESS_1, from: accountAddress, value, @@ -136,7 +136,7 @@ describe('@ethSendRawTransaction eth_sendRawTransaction spec', async function () }, receiver_sig_required: false, }; - const useAsyncTxProcessing = ConfigService.get('USE_ASYNC_TX_PROCESSING' as ConfigKey); + const useAsyncTxProcessing = ConfigService.get('USE_ASYNC_TX_PROCESSING'); beforeEach(() => { clock = useFakeTimers(); diff --git a/packages/relay/tests/lib/ethGetBlockBy.spec.ts b/packages/relay/tests/lib/ethGetBlockBy.spec.ts index 6c5a913b0c..605ce74e88 100644 --- a/packages/relay/tests/lib/ethGetBlockBy.spec.ts +++ b/packages/relay/tests/lib/ethGetBlockBy.spec.ts @@ -129,7 +129,7 @@ describe('eth_getBlockBy', async function () { // @ts-ignore mirrorNodeInstance = new MirrorNodeClient( - (ConfigService.get('MIRROR_NODE_URL') as ConfigKey) ?? '', + (ConfigService.get('MIRROR_NODE_URL')) ?? '', logger.child({ name: `mirror-node` }), registry, cacheService, diff --git a/packages/relay/tests/lib/mirrorNodeClient.spec.ts b/packages/relay/tests/lib/mirrorNodeClient.spec.ts index 93c0454f27..9aff1f8ebd 100644 --- a/packages/relay/tests/lib/mirrorNodeClient.spec.ts +++ b/packages/relay/tests/lib/mirrorNodeClient.spec.ts @@ -31,6 +31,9 @@ import { SDKClientError } from '../../src/lib/errors/SDKClientError'; import { CacheService } from '../../src/lib/services/cacheService/cacheService'; import { MirrorNodeTransactionRecord, RequestDetails } from '../../src/lib/types'; import { mockData, random20BytesAddress, withOverriddenEnvsInMochaTest } from '../helpers'; +import { expect } from 'chai'; +import { Registry } from 'prom-client'; +import pino from 'pino'; describe('MirrorNodeClient', async function () { this.timeout(20000); @@ -55,7 +58,7 @@ describe('MirrorNodeClient', async function () { cacheService = new CacheService(logger.child({ name: `cache` }), registry); mirrorNodeInstance = new MirrorNodeClient( // @ts-ignore - ConfigService.get('MIRROR_NODE_URL' as ConfigKey) || '', + ConfigService.get('MIRROR_NODE_URL') || '', logger.child({ name: `mirror-node` }), registry, cacheService, @@ -132,7 +135,7 @@ describe('MirrorNodeClient', async function () { it('`restUrl` is exposed and correct', async () => { // @ts-ignore - const domain = (ConfigService.get('MIRROR_NODE_URL' as ConfigKey) || '').replace(/^https?:\/\//, ''); + const domain = (ConfigService.get('MIRROR_NODE_URL') || '').replace(/^https?:\/\//, ''); const prodMirrorNodeInstance = new MirrorNodeClient( domain, logger.child({ name: `mirror-node` }), @@ -166,7 +169,7 @@ describe('MirrorNodeClient', async function () { ); 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' as ConfigKey)); + expect(axiosHeaders['x-api-key']).to.eq(ConfigService.get('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 f35a8690e5..2bf051a5d7 100644 --- a/packages/relay/tests/lib/net.spec.ts +++ b/packages/relay/tests/lib/net.spec.ts @@ -42,7 +42,7 @@ describe('Net', async function () { }); it('should execute "net_version"', function () { - const hederaNetwork: string = ((ConfigService.get('HEDERA_NETWORK') as ConfigKey) || '{}').toLowerCase(); + const hederaNetwork: string = ((ConfigService.get('HEDERA_NETWORK')) || '{}').toLowerCase(); let expectedNetVersion = ConfigService.get('CHAIN_ID') || constants.CHAIN_IDS[hederaNetwork] || '298'; if (expectedNetVersion.startsWith('0x')) expectedNetVersion = parseInt(expectedNetVersion, 16).toString(); diff --git a/packages/relay/tests/lib/poller.spec.ts b/packages/relay/tests/lib/poller.spec.ts index 62a9a4cd2e..250cebdede 100644 --- a/packages/relay/tests/lib/poller.spec.ts +++ b/packages/relay/tests/lib/poller.spec.ts @@ -190,7 +190,7 @@ describe('Polling', async function () { ).to.equal(true); expect( loggerSpy.calledWith( - `Poller: Starting polling with interval=${ConfigService.get('WS_POLLING_INTERVAL' as ConfigKey)}`, + `Poller: Starting polling with interval=${ConfigService.get('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 72d2a080c2..a71c241b1e 100644 --- a/packages/relay/tests/lib/precheck.spec.ts +++ b/packages/relay/tests/lib/precheck.spec.ts @@ -107,7 +107,7 @@ describe('Precheck', async function () { // @ts-ignore const mirrorNodeInstance = new MirrorNodeClient( - ConfigService.get('MIRROR_NODE_URL' as ConfigKey)!, + ConfigService.get('MIRROR_NODE_URL')!, 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 1b2ee215c8..3bac376a89 100644 --- a/packages/relay/tests/lib/sdkClient.spec.ts +++ b/packages/relay/tests/lib/sdkClient.spec.ts @@ -103,7 +103,7 @@ describe('SdkClient', async function () { overrideEnvsInMochaDescribe({ GET_RECORD_DEFAULT_TO_CONSENSUS_NODE: true }); before(() => { - const hederaNetwork = ConfigService.get('HEDERA_NETWORK' as ConfigKey)! as string; + const hederaNetwork = ConfigService.get('HEDERA_NETWORK')! as string; if (hederaNetwork in constants.CHAIN_IDS) { client = Client.forName(hederaNetwork); } else { @@ -111,8 +111,8 @@ describe('SdkClient', async function () { } client = client.setOperator( - AccountId.fromString(ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey)! as string), - Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN' as ConfigKey)! as string), + AccountId.fromString(ConfigService.get('OPERATOR_ID_MAIN')! as string), + Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN')! as string), ); const duration = constants.HBAR_RATE_LIMIT_DURATION; eventEmitter = new EventEmitter(); @@ -149,7 +149,7 @@ describe('SdkClient', async function () { // mirror node client mirrorNodeClient = new MirrorNodeClient( - (ConfigService.get('MIRROR_NODE_URL' as ConfigKey)) || '', + (ConfigService.get('MIRROR_NODE_URL')) || '', logger.child({ name: `mirror-node` }), registry, new CacheService(logger.child({ name: `cache` }), registry), @@ -285,7 +285,7 @@ describe('SdkClient', async function () { }; this.beforeEach(() => { - if (ConfigService.get('OPERATOR_KEY_FORMAT' as ConfigKey) !== 'BAD_FORMAT' as ConfigKey) { + if (ConfigService.get('OPERATOR_KEY_FORMAT') !== 'BAD_FORMAT') { hapiService = new HAPIService(logger, registry, cacheService, eventEmitter, hbarLimitService); } }); @@ -336,8 +336,8 @@ describe('SdkClient', async function () { }); describe('HBAR Limiter', async () => { - const FILE_APPEND_CHUNK_SIZE = Number(ConfigService.get('FILE_APPEND_CHUNK_SIZE' as ConfigKey)) || 5120; - const MAX_CHUNKS = Number(ConfigService.get('FILE_APPEND_MAX_CHUNKS' as ConfigKey)) || 20; + 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 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, @@ -2145,7 +2145,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileCreateFee / 10 ** 8) : fileCreateFee; transfers = [ { - accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), + accountId: ConfigService.get('OPERATOR_ID_MAIN'), amount: Hbar.fromTinybars(-1 * fileCreateFee), is_approval: false, }, @@ -2155,7 +2155,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileAppendFee / 10 ** 8) : fileAppendFee; transfers = [ { - accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), + accountId: ConfigService.get('OPERATOR_ID_MAIN'), amount: Hbar.fromTinybars(-1 * fileAppendFee), is_approval: false, }, @@ -2165,7 +2165,7 @@ describe('SdkClient', async function () { transactionFee = toHbar ? new Hbar(fileDeleteFee / 10 ** 8) : fileDeleteFee; transfers = [ { - accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), + accountId: ConfigService.get('OPERATOR_ID_MAIN'), amount: Hbar.fromTinybars(-1 * fileDeleteFee), is_approval: false, }, @@ -2180,12 +2180,12 @@ describe('SdkClient', async function () { is_approval: false, }, { - accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), + accountId: ConfigService.get('OPERATOR_ID_MAIN'), amount: Hbar.fromTinybars(-1 * defaultTransactionFee), is_approval: false, }, { - accountId: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), + accountId: ConfigService.get('OPERATOR_ID_MAIN'), amount: Hbar.fromTinybars(defaultTransactionFee), is_approval: false, }, @@ -2651,7 +2651,7 @@ describe('SdkClient', async function () { is_approval: false, }, { - account: ConfigService.get('OPERATOR_ID_MAIN' as ConfigKey), + account: ConfigService.get('OPERATOR_ID_MAIN'), amount: -1 * defaultTransactionFee, is_approval: false, }, @@ -2744,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' as ConfigKey) as string) || ''; + const accountId = (ConfigService.get('OPERATOR_ID_MAIN')) || ''; 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 7d139acde3..9b3bd3b7d0 100644 --- a/packages/relay/tests/lib/services/debugService/debug.spec.ts +++ b/packages/relay/tests/lib/services/debugService/debug.spec.ts @@ -268,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' as ConfigKey)!, + ConfigService.get('MIRROR_NODE_URL')!, 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 3c0d006b82..d2f5b2530a 100644 --- a/packages/relay/tests/lib/services/eth/filter.spec.ts +++ b/packages/relay/tests/lib/services/eth/filter.spec.ts @@ -84,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' as ConfigKey), + ConfigService.get('MIRROR_NODE_URL'), logger.child({ name: `mirror-node` }), registry, cacheService, diff --git a/packages/relay/tests/lib/services/metricService/metricService.spec.ts b/packages/relay/tests/lib/services/metricService/metricService.spec.ts index a3d8f2e132..68a54d5a3d 100644 --- a/packages/relay/tests/lib/services/metricService/metricService.spec.ts +++ b/packages/relay/tests/lib/services/metricService/metricService.spec.ts @@ -145,15 +145,15 @@ describe('Metric Service', function () { before(() => { // consensus node client - const hederaNetwork = ConfigService.get('HEDERA_NETWORK' as ConfigKey)!; + const hederaNetwork = ConfigService.get('HEDERA_NETWORK')!; 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 ConfigKey)!), - Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN' as ConfigKey)!), + AccountId.fromString(ConfigService.get('OPERATOR_ID_MAIN')!), + Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN')!), ); // mirror node client @@ -166,7 +166,7 @@ describe('Metric Service', function () { timeout: 20 * 1000, }); mirrorNodeClient = new MirrorNodeClient( - (ConfigService.get('MIRROR_NODE_URL' as ConfigKey)) || '', + (ConfigService.get('MIRROR_NODE_URL')) || '', 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 3c52cc9cbd..6ba90f5c3d 100644 --- a/packages/relay/tests/lib/utils.spec.ts +++ b/packages/relay/tests/lib/utils.spec.ts @@ -62,7 +62,7 @@ describe('Utils', () => { describe('estimateFileTransactionsFee', () => { const callDataSize = 6000; const mockedExchangeRateInCents: number = 12; - const fileChunkSize = Number(ConfigService.get('FILE_APPEND_CHUNK_SIZE' as ConfigKey)) || 5120; + const fileChunkSize = Number(ConfigService.get('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); @@ -85,7 +85,7 @@ describe('Utils', () => { }); // @ts-ignore - JSON.parse(ConfigService.get('HEDERA_SPECIFIC_REVERT_STATUSES' as ConfigKey)).forEach((status) => { + JSON.parse(ConfigService.get('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 41d8668121..a59b5d9fa1 100644 --- a/packages/relay/tests/lib/web3.spec.ts +++ b/packages/relay/tests/lib/web3.spec.ts @@ -34,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' as ConfigKey)); + expect(clientVersion).to.be.equal('relay/' + ConfigService.get('npm_package_version')); }); }); diff --git a/packages/server/tests/acceptance/conformityTests.spec.ts b/packages/server/tests/acceptance/conformityTests.spec.ts index 6f271388d6..ccd8cc6818 100644 --- a/packages/server/tests/acceptance/conformityTests.spec.ts +++ b/packages/server/tests/acceptance/conformityTests.spec.ts @@ -69,7 +69,7 @@ addFormats(ajv); let execApisOpenRpcData; let relayOpenRpcData: any; -const chainId = Number(ConfigService.get('CHAIN_ID' as ConfigKey) || 0x12a); +const chainId = Number(ConfigService.get('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 7d8fa3cad5..466e79e6b0 100644 --- a/packages/server/tests/acceptance/hbarLimiter.spec.ts +++ b/packages/server/tests/acceptance/hbarLimiter.spec.ts @@ -222,7 +222,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' as ConfigKey) || 0), + chainId: Number(ConfigService.get('CHAIN_ID') || 0), maxPriorityFeePerGas: Assertions.defaultGasPrice, maxFeePerGas: Assertions.defaultGasPrice, gasLimit: 3_000_000, @@ -233,7 +233,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' as ConfigKey, + 'HBAR_RATE_LIMIT_TINYBAR', )}`, ); @@ -741,7 +741,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 ConfigKey); + const SPENDING_PLANS_CONFIG_FILE = ConfigService.get('HBAR_SPENDING_PLANS_CONFIG'); const configPath = findConfig(SPENDING_PLANS_CONFIG_FILE); if (configPath) { @@ -901,7 +901,7 @@ describe('@hbarlimiter HBAR Limiter Acceptance Tests', function () { return { ...aliasAccount, hbarSpendingPlan: accountAliasPlan.hbarSpendingPlan }; }); - const totalHbarBudget = ConfigService.get('HBAR_RATE_LIMIT_TINYBAR' as ConfigKey); + const totalHbarBudget = ConfigService.get('HBAR_RATE_LIMIT_TINYBAR'); let totalHbarSpent = totalHbarBudget - Number(await metrics.get(testConstants.METRICS.REMAINING_HBAR_LIMIT)); @@ -958,14 +958,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' as ConfigKey, + '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' as ConfigKey)).to.eq(0); + expect(ConfigService.get('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 e12fb9130c..b60682d8a6 100644 --- a/packages/server/tests/acceptance/index.spec.ts +++ b/packages/server/tests/acceptance/index.spec.ts @@ -101,7 +101,7 @@ describe('RPC Server Acceptance Tests', function () { }; // leak detection middleware - if (ConfigService.get('MEMWATCH_ENABLED' as ConfigKey)) { + if (ConfigService.get('MEMWATCH_ENABLED')) { Utils.captureMemoryLeaks(new GCProfiler()); } @@ -110,12 +110,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' as ConfigKey)}`); - logger.info(`CHAIN_ID: ${ConfigService.get('CHAIN_ID' as ConfigKey)}`); + logger.info(`LOCAL_NODE: ${ConfigService.get('LOCAL_NODE')}`); + logger.info(`CHAIN_ID: ${ConfigService.get('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' as ConfigKey)}`); + logger.info(`E2E_RELAY_HOST: ${ConfigService.get('E2E_RELAY_HOST')}`); if (global.relayIsLocal) { runLocalRelay(); @@ -127,7 +127,7 @@ describe('RPC Server Acceptance Tests', function () { RELAY_URL, CHAIN_ID, Utils.generateRequestId(), - Number(ConfigService.get('TEST_INITIAL_ACCOUNT_STARTING_BALANCE' as ConfigKey) || 2000), + Number(ConfigService.get('TEST_INITIAL_ACCOUNT_STARTING_BALANCE') || 2000), ); global.accounts = new Array(initialAccount); @@ -198,7 +198,7 @@ describe('RPC Server Acceptance Tests', function () { relayServer.close(); } - if (ConfigService.get('TEST_WS_SERVER' as ConfigKey) && global.socketServer !== undefined) { + if (ConfigService.get('TEST_WS_SERVER') && global.socketServer !== undefined) { global.socketServer.close(); } } @@ -212,7 +212,7 @@ describe('RPC Server Acceptance Tests', function () { global.relayServer = relayServer; setServerTimeout(relayServer); - if (ConfigService.get('TEST_WS_SERVER' as ConfigKey)) { + if (ConfigService.get('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 667caaf1b1..c818ef2e32 100644 --- a/packages/server/tests/acceptance/rateLimiter.spec.ts +++ b/packages/server/tests/acceptance/rateLimiter.spec.ts @@ -38,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 ConfigKey)) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2; + (ConfigService.get('TIER_2_RATE_LIMIT')) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2; const LIMIT_DURATION = - (ConfigService.get('LIMIT_DURATION' as ConfigKey)) || relayConstants.DEFAULT_RATE_LIMIT.DURATION; + (ConfigService.get('LIMIT_DURATION')) || 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 8cee93df04..dd1f0a6643 100644 --- a/packages/server/tests/acceptance/rpc_batch1.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch1.spec.ts @@ -73,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 ConfigKey)) || '0x12a'; + const CHAIN_ID = (ConfigService.get('CHAIN_ID')) || '0x12a'; const requestId = 'rpc_batch1Test'; const requestIdPrefix = Utils.formatRequestIdMessage(requestId); const requestDetails = JSON.stringify(new RequestDetails({ requestId: 'rpc_batch1Test', ipAddress: '0.0.0.0' })); @@ -84,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' as ConfigKey) ?? '0.2') as string); + const gasPriceDeviation = parseFloat((ConfigService.get('TEST_GAS_PRICE_DEVIATION') ?? '0.2') as string); const sendRawTransaction = relay.sendRawTransaction; - const useAsyncTxProcessing = ConfigService.get('USE_ASYNC_TX_PROCESSING' as ConfigKey); + const useAsyncTxProcessing = ConfigService.get('USE_ASYNC_TX_PROCESSING'); /** * 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 d021e7c9bd..5252ede1ad 100644 --- a/packages/server/tests/acceptance/rpc_batch2.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch2.spec.ts @@ -80,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' as ConfigKey) || 0; + const CHAIN_ID = ConfigService.get('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))); @@ -442,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' as ConfigKey)) { + if (ConfigService.get('LOCAL_NODE')) { expect(res).be.equal(expectedGasPrice); } else { expect(Number(res)).to.be.gt(0); @@ -1077,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' as ConfigKey)) { + if (ConfigService.get('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 700e15e227..53f9ee3df7 100644 --- a/packages/server/tests/acceptance/rpc_batch3.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch3.spec.ts @@ -75,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' as ConfigKey) || 0x12a; + const CHAIN_ID = ConfigService.get('CHAIN_ID') || 0x12a; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); let reverterContract: ethers.Contract; @@ -548,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' as ConfigKey)) { + if (!ConfigService.get('ETH_CALL_DEFAULT_TO_CONSENSUS_NODE')) { it('010 Should call msgValue', async function () { const callData = { ...defaultCallData, @@ -612,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' as ConfigKey) || '7546'; + const testClientPort = ConfigService.get('E2E_SERVER_PORT') || '7546'; const testClient = Axios.create({ baseURL: 'http://localhost:' + testClientPort, responseType: 'json' as const, @@ -798,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' as ConfigKey); + initialEthCallSelectorsAlwaysToConsensus = ConfigService.get('ETH_CALL_CONSENSUS_SELECTORS'); hrc719Contract = await Utils.deployContract( HRC719ContractJson.abi, @@ -815,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' as ConfigKey); + const selectorsList = ConfigService.get('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 802d42b5b8..06c213df7b 100644 --- a/packages/server/tests/acceptance/serverConfig.spec.ts +++ b/packages/server/tests/acceptance/serverConfig.spec.ts @@ -26,9 +26,9 @@ import { ConfigKey } from '../../../config-service/src/services/globalConfig'; 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' as ConfigKey) || '3000'); + const requestTimeoutMs: number = parseInt(ConfigService.get('SERVER_REQUEST_TIMEOUT_MS') || '3000'); const host = ConfigService.get('SERVER_HOST') || 'localhost'; - const port = parseInt(ConfigService.get('SERVER_PORT' as ConfigKey) || '7546'); + const port = parseInt(ConfigService.get('SERVER_PORT') || '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 7092f1b931..d488a47f86 100644 --- a/packages/server/tests/integration/server.spec.ts +++ b/packages/server/tests/integration/server.spec.ts @@ -56,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' as ConfigKey)); + testServer = app.listen(ConfigService.get('E2E_SERVER_PORT')); testClient = BaseTest.createTestClient(); // leak detection middleware - if (ConfigService.get('MEMWATCH_ENABLED' as ConfigKey)) { + if (ConfigService.get('MEMWATCH_ENABLED')) { Utils.captureMemoryLeaks(new GCProfiler()); } }); @@ -120,7 +120,7 @@ describe('RPC Server', function () { }); BaseTest.defaultResponseChecks(res); - expect(res.data.result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID' as ConfigKey)).toString(16)); + expect(res.data.result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); }); it('validates enforcement of request id', async function () { @@ -140,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' as ConfigKey)}`; + const port = `1${ConfigService.get('E2E_SERVER_PORT')}`; const testServer2 = app2.listen(port); try { @@ -159,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' as ConfigKey)).toString(16)); + expect(response.data.result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); } catch (error: any) { expect(true, `Unexpected error: ${error.message}`).to.eq(false); } finally { @@ -190,7 +190,7 @@ describe('RPC Server', function () { }); BaseTest.defaultResponseChecks(res); - expect(res.data.result).to.be.equal('relay/' + ConfigService.get('npm_package_version' as ConfigKey)); + expect(res.data.result).to.be.equal('relay/' + ConfigService.get('npm_package_version')); }); it('should execute "eth_getTransactionByHash with missing transaction"', async function () { @@ -543,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' as ConfigKey)).toString(16)); + expect(response.data[i].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); } }); @@ -560,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' as ConfigKey)).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('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' as ConfigKey)).toString(16)); + expect(response.data[2].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); }); it('should execute "eth_chainId" and "eth_accounts" in batch request with invalid request id', async function () { @@ -578,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' as ConfigKey)).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('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'); @@ -598,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' as ConfigKey)).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('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'); @@ -606,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' as ConfigKey)).toString(16)); + expect(response.data[2].result).to.be.equal('0x' + Number(ConfigService.get('CHAIN_ID')).toString(16)); }); it('should execute "eth_chainId" and method not found and params error in batch request', async function () { @@ -626,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' as ConfigKey)).toString(16)); + expect(response.data[0].result).to.be.equal('0x' + Number(ConfigService.get('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'); @@ -2703,7 +2703,7 @@ describe('RPC Server', function () { }); class BaseTest { - static createTestClient(port = ConfigService.get('E2E_SERVER_PORT' as ConfigKey)) { + static createTestClient(port = ConfigService.get('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 8ee8a1b0da..ecae0bfbd3 100644 --- a/packages/ws-server/tests/acceptance/batchRequest.spec.ts +++ b/packages/ws-server/tests/acceptance/batchRequest.spec.ts @@ -105,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' as ConfigKey)), + Number(ConfigService.get('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 50e42de354..9ec3266ca1 100644 --- a/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts @@ -35,7 +35,7 @@ import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_getTransactionByHash', async function () { const METHOD_NAME = 'eth_getTransactionByHash'; - const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || '0x12a'; + const CHAIN_ID = ConfigService.get('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 d32f993985..c9750f0bb8 100644 --- a/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts @@ -34,7 +34,7 @@ import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@release @web-socket-batch-2 eth_getTransactionCount', async function () { const METHOD_NAME = 'eth_getTransactionCount'; - const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || '0x12a'; + const CHAIN_ID = ConfigService.get('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 18b4f02a33..dd51278179 100644 --- a/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts @@ -35,7 +35,7 @@ import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_getTransactionReceipt', async function () { const METHOD_NAME = 'eth_getTransactionReceipt'; - const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || '0x12a'; + const CHAIN_ID = ConfigService.get('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 68e09b60a2..91c6da93dc 100644 --- a/packages/ws-server/tests/acceptance/index.spec.ts +++ b/packages/ws-server/tests/acceptance/index.spec.ts @@ -86,12 +86,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' as ConfigKey)}`); - logger.info(`CHAIN_ID: ${ConfigService.get('CHAIN_ID' as ConfigKey)}`); + logger.info(`LOCAL_NODE: ${ConfigService.get('LOCAL_NODE')}`); + logger.info(`CHAIN_ID: ${ConfigService.get('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' as ConfigKey)}`); + logger.info(`E2E_RELAY_HOST: ${ConfigService.get('E2E_RELAY_HOST')}`); if (global.relayIsLocal) { runLocalRelay(); @@ -151,7 +151,7 @@ describe('RPC Server Acceptance Tests', function () { } const socketServer: Server = global.socketServer; - if (ConfigService.get('TEST_WS_SERVER' as ConfigKey) && socketServer !== undefined) { + if (ConfigService.get('TEST_WS_SERVER') && socketServer !== undefined) { socketServer.close(); } }); @@ -182,7 +182,7 @@ describe('RPC Server Acceptance Tests', function () { global.relayServer = relayServer; setServerTimeout(relayServer); - if (ConfigService.get('TEST_WS_SERVER' as ConfigKey)) { + if (ConfigService.get('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 f8411adc9a..931ec7ced2 100644 --- a/packages/ws-server/tests/acceptance/rateLimiter.spec.ts +++ b/packages/ws-server/tests/acceptance/rateLimiter.spec.ts @@ -30,8 +30,8 @@ import { WsTestHelper } from '../helper'; import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-ratelimiter Rate Limit Tests', async function () { - const rateLimitTier2 = Number(ConfigService.get('TIER_2_RATE_LIMIT' as ConfigKey) || relayConstants.DEFAULT_RATE_LIMIT.TIER_2); - const limitDuration = Number(ConfigService.get('LIMIT_DURATION' as ConfigKey)) || relayConstants.DEFAULT_RATE_LIMIT.DURATION; + 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 batchRequests = [ { diff --git a/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts b/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts index aa6943c645..fdfa32bed4 100644 --- a/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts +++ b/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts @@ -37,7 +37,7 @@ import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_sendRawTransaction', async function () { const METHOD_NAME = 'eth_sendRawTransaction'; - const CHAIN_ID = ConfigService.get('CHAIN_ID' as ConfigKey) || '0x12a'; + const CHAIN_ID = ConfigService.get('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 139a1cb821..bcdb5e552d 100644 --- a/packages/ws-server/tests/acceptance/subscribe.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribe.spec.ts @@ -38,7 +38,7 @@ import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(solidity); -const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL' as ConfigKey)}`; +const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL')}`; const establishConnection = async () => { const provider = await new ethers.WebSocketProvider(WS_RELAY_URL); @@ -75,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' as ConfigKey) || 0; + const CHAIN_ID = ConfigService.get('CHAIN_ID') || 0; let server; // @ts-ignore const { servicesNode, relay, mirrorNode } = global; @@ -437,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' as ConfigKey)); i++) { + for (let i = 1; i < parseInt(ConfigService.get('WS_CONNECTION_LIMIT')); i++) { providers.push(await establishConnection()); } // Server is at max connections - expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT' as ConfigKey))); + expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT'))); }); afterEach(async () => { @@ -501,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' as ConfigKey)) + 1000)); + await new Promise((resolve) => setTimeout(resolve, parseInt(ConfigService.get('WS_MAX_INACTIVITY_TTL')) + 1000)); expect(closeEventHandled2).to.eq(true); expect(closeEventHandled3).to.eq(true); @@ -898,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' as ConfigKey)); i++) { + for (let i = 1; i < parseInt(ConfigService.get('WS_CONNECTION_LIMIT_PER_IP')); i++) { // @ts-ignore providers.push(await new ethers.WebSocketProvider(WS_RELAY_URL)); } @@ -908,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' as ConfigKey))); + expect(server._connections).to.equal(parseInt(ConfigService.get('WS_CONNECTION_LIMIT_PER_IP'))); // The next connection should be closed by the server const provider = await new ethers.WebSocketProvider(WS_RELAY_URL); @@ -923,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' as ConfigKey))); + expect(server._connections).to.equal(parseInt(ConfigService.get('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 2abd4429c9..7bef0648a6 100644 --- a/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts @@ -36,7 +36,7 @@ import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(solidity); -const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL' as ConfigKey)}`; +const WS_RELAY_URL = `${ConfigService.get('WS_RELAY_URL')}`; const evmAddressRegex = /^0x[a-fA-F0-9]*$/; function verifyResponse(response: any, done: Mocha.Done, webSocket: any, includeTransactions: boolean) { @@ -100,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' as ConfigKey) || 0; + const CHAIN_ID = ConfigService.get('CHAIN_ID') || 0; const ONE_TINYBAR = Utils.add0xPrefix(Utils.toHex(ethers.parseUnits('1', 10))); let mirrorNodeServer, requestId, rpcServer, wsServer; @@ -197,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' as ConfigKey)).to.be.undefined; + expect(ConfigService.get('WS_NEW_HEADS_ENABLED')).to.be.undefined; const webSocket = new WebSocket(WS_RELAY_URL); const subscriptionId = 1; From 423b25da1ab620dcc70b860b155a3fbcbbc627d0 Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Wed, 8 Jan 2025 12:46:22 +0100 Subject: [PATCH 06/11] Refactor ConfigService.get to enhance type safety and remove manual casting Signed-off-by: belloibrahv --- .../config-service/src/commands/printEnvs.ts | 2 +- .../src/services/globalConfig.ts | 52 ++++++++++++++++++- packages/config-service/src/services/index.ts | 4 +- .../src/services/validationService.ts | 2 +- .../tests/configServiceTestHelper.ts | 2 +- .../tests/src/services/configService.spec.ts | 2 +- .../tests/src/services/loggerService.spec.ts | 3 +- .../src/services/validationService.spec.ts | 2 +- .../hbarSpendingPlanConfigService.spec.ts | 1 - packages/relay/tests/lib/eth/eth-config.ts | 1 - packages/relay/tests/lib/eth/eth-helpers.ts | 1 - .../relay/tests/lib/eth/eth_common.spec.ts | 1 - .../lib/eth/eth_sendRawTransaction.spec.ts | 1 - .../relay/tests/lib/ethGetBlockBy.spec.ts | 3 +- packages/relay/tests/lib/hapiService.spec.ts | 1 - .../relay/tests/lib/mirrorNodeClient.spec.ts | 1 - packages/relay/tests/lib/net.spec.ts | 1 - packages/relay/tests/lib/poller.spec.ts | 1 - packages/relay/tests/lib/precheck.spec.ts | 1 - packages/relay/tests/lib/sdkClient.spec.ts | 1 - .../lib/services/debugService/debug.spec.ts | 1 - .../tests/lib/services/eth/filter.spec.ts | 1 - .../metricService/metricService.spec.ts | 1 - packages/relay/tests/lib/utils.spec.ts | 1 - packages/relay/tests/lib/web3.spec.ts | 1 - .../tests/acceptance/conformityTests.spec.ts | 1 - .../tests/acceptance/hbarLimiter.spec.ts | 1 - .../server/tests/acceptance/index.spec.ts | 1 - .../tests/acceptance/rateLimiter.spec.ts | 1 - .../tests/acceptance/rpc_batch1.spec.ts | 1 - .../tests/acceptance/rpc_batch2.spec.ts | 1 - .../tests/acceptance/rpc_batch3.spec.ts | 1 - .../tests/acceptance/serverConfig.spec.ts | 1 - .../server/tests/integration/server.spec.ts | 1 - .../tests/acceptance/batchRequest.spec.ts | 1 - .../acceptance/getTransactionByHash.spec.ts | 1 - .../acceptance/getTransactionCount.spec.ts | 1 - .../acceptance/getTransactionReceipt.spec.ts | 1 - .../ws-server/tests/acceptance/index.spec.ts | 1 - .../tests/acceptance/rateLimiter.spec.ts | 1 - .../acceptance/sendRawTransaction.spec.ts | 1 - .../tests/acceptance/subscribe.spec.ts | 1 - .../acceptance/subscribeNewHeads.spec.ts | 1 - tools/brownie-example/LICENSE | 3 +- 44 files changed, 61 insertions(+), 48 deletions(-) diff --git a/packages/config-service/src/commands/printEnvs.ts b/packages/config-service/src/commands/printEnvs.ts index 2764b21f70..fb392098fd 100644 --- a/packages/config-service/src/commands/printEnvs.ts +++ b/packages/config-service/src/commands/printEnvs.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index 52b2f07dbb..a15955482f 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -2,7 +2,7 @@ * * 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. @@ -18,6 +18,22 @@ * */ +type TypeStrToType = Tstr extends 'string' + ? string + : Tstr extends 'boolean' + ? boolean + : Tstr extends 'number' + ? number + : Tstr extends 'array' + ? unknown[] + : never; + +type GetTypeStrOfKey = K extends keyof typeof _CONFIG + ? typeof _CONFIG[K]['type'] + : never; + +export type TypeOfKey = TypeStrToType>; + export interface ConfigProperty { envName: string; type: string; @@ -751,6 +767,40 @@ const _CONFIG = { export type ConfigKey = keyof typeof _CONFIG; +export class ConfigService { + private static config: typeof _CONFIG = _CONFIG; + + public static get(name: K): TypeOfKey | undefined { + const configItem = this.config[name]; + if (!configItem) { + return undefined; + } + + const value = process.env[configItem.envName]; + + if (value === undefined) { + return configItem.defaultValue as TypeOfKey; + } + + switch (configItem.type) { + case 'boolean': + return (value.toLowerCase() === 'true') as TypeOfKey; + case 'number': + return Number(value) as TypeOfKey; + case 'string': + return value as TypeOfKey; + case 'array': + try { + return JSON.parse(value) as TypeOfKey; + } catch { + return undefined; + } + default: + return undefined; + } + } +} + export class GlobalConfig { public static readonly ENTRIES: Record = _CONFIG; } diff --git a/packages/config-service/src/services/index.ts b/packages/config-service/src/services/index.ts index 87ff70b670..39b62e9a7f 100644 --- a/packages/config-service/src/services/index.ts +++ b/packages/config-service/src/services/index.ts @@ -2,7 +2,7 @@ * * 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. @@ -24,7 +24,7 @@ import pino from 'pino'; import { LoggerService } from './loggerService'; import { ValidationService } from './validationService'; -import { ConfigKey } from './globalConfig'; +import type { ConfigKey } from './globalConfig'; const mainLogger = pino({ name: 'hedera-json-rpc-relay', diff --git a/packages/config-service/src/services/validationService.ts b/packages/config-service/src/services/validationService.ts index 0419763830..738fc36391 100644 --- a/packages/config-service/src/services/validationService.ts +++ b/packages/config-service/src/services/validationService.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/config-service/tests/configServiceTestHelper.ts b/packages/config-service/tests/configServiceTestHelper.ts index 288734f101..1344cb30f0 100644 --- a/packages/config-service/tests/configServiceTestHelper.ts +++ b/packages/config-service/tests/configServiceTestHelper.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/config-service/tests/src/services/configService.spec.ts b/packages/config-service/tests/src/services/configService.spec.ts index eb57a32c38..48d4fb0ed3 100644 --- a/packages/config-service/tests/src/services/configService.spec.ts +++ b/packages/config-service/tests/src/services/configService.spec.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/config-service/tests/src/services/loggerService.spec.ts b/packages/config-service/tests/src/services/loggerService.spec.ts index 02c55549c5..428e75979d 100644 --- a/packages/config-service/tests/src/services/loggerService.spec.ts +++ b/packages/config-service/tests/src/services/loggerService.spec.ts @@ -2,7 +2,7 @@ * * 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. @@ -24,7 +24,6 @@ import crypto from 'crypto'; import { ConfigService } from '../../../src/services'; import { LoggerService } from '../../../src/services/loggerService'; import { GlobalConfig } from '../../../dist/services/globalConfig'; -import { ConfigKey } from '../../../src/services/globalConfig'; chai.use(chaiAsPromised); diff --git a/packages/config-service/tests/src/services/validationService.spec.ts b/packages/config-service/tests/src/services/validationService.spec.ts index b5c8ca4763..9fd5671ae0 100644 --- a/packages/config-service/tests/src/services/validationService.spec.ts +++ b/packages/config-service/tests/src/services/validationService.spec.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts index a50414f182..ddc1c57785 100644 --- a/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts +++ b/packages/relay/tests/lib/config/hbarSpendingPlanConfigService.spec.ts @@ -47,7 +47,6 @@ import { verifyResult, withOverriddenEnvsInMochaTest, } from '../../helpers'; -import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; chai.use(chaiAsPromised); diff --git a/packages/relay/tests/lib/eth/eth-config.ts b/packages/relay/tests/lib/eth/eth-config.ts index 673f30f9e5..647e304c7b 100644 --- a/packages/relay/tests/lib/eth/eth-config.ts +++ b/packages/relay/tests/lib/eth/eth-config.ts @@ -32,7 +32,6 @@ import { mockData, toHex, } from '../../helpers'; -import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; export const BLOCK_TRANSACTION_COUNT = 77; export const GAS_USED_1 = 200000; diff --git a/packages/relay/tests/lib/eth/eth-helpers.ts b/packages/relay/tests/lib/eth/eth-helpers.ts index d7736e7937..00bc072b34 100644 --- a/packages/relay/tests/lib/eth/eth-helpers.ts +++ b/packages/relay/tests/lib/eth/eth-helpers.ts @@ -34,7 +34,6 @@ import { EthImpl } from '../../../src/lib/eth'; import { CacheService } from '../../../src/lib/services/cacheService/cacheService'; import HAPIService from '../../../src/lib/services/hapiService/hapiService'; import { HbarLimitService } from '../../../src/lib/services/hbarLimitService'; -import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; export function contractResultsByNumberByIndexURL(number: number, index: number): string { return `contracts/results?block.number=${number}&transaction.index=${index}&limit=100&order=asc`; diff --git a/packages/relay/tests/lib/eth/eth_common.spec.ts b/packages/relay/tests/lib/eth/eth_common.spec.ts index e771df0ec8..ab05ce2036 100644 --- a/packages/relay/tests/lib/eth/eth_common.spec.ts +++ b/packages/relay/tests/lib/eth/eth_common.spec.ts @@ -26,7 +26,6 @@ import { Registry } from 'prom-client'; import { RelayImpl } from '../../../src'; import { RequestDetails } from '../../../src/lib/types'; -import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; use(chaiAsPromised); diff --git a/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts b/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts index abf6593020..46f75dbe88 100644 --- a/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts +++ b/packages/relay/tests/lib/eth/eth_sendRawTransaction.spec.ts @@ -57,7 +57,6 @@ import { } from '../../helpers'; import { ACCOUNT_ADDRESS_1, DEFAULT_NETWORK_FEES, MAX_GAS_LIMIT_HEX, NO_TRANSACTIONS } from './eth-config'; import { generateEthTestEnv } from './eth-helpers'; -import { ConfigKey } from '../../../../config-service/src/services/globalConfig'; use(chaiAsPromised); diff --git a/packages/relay/tests/lib/ethGetBlockBy.spec.ts b/packages/relay/tests/lib/ethGetBlockBy.spec.ts index 605ce74e88..105af5e97c 100644 --- a/packages/relay/tests/lib/ethGetBlockBy.spec.ts +++ b/packages/relay/tests/lib/ethGetBlockBy.spec.ts @@ -39,7 +39,6 @@ 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 { ConfigKey } from '../../../config-service/src/services/globalConfig'; use(chaiAsPromised); @@ -129,7 +128,7 @@ describe('eth_getBlockBy', async function () { // @ts-ignore mirrorNodeInstance = new MirrorNodeClient( - (ConfigService.get('MIRROR_NODE_URL')) ?? '', + ConfigService.get('MIRROR_NODE_URL') ?? '', 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 1fee16305f..b9581784f7 100644 --- a/packages/relay/tests/lib/hapiService.spec.ts +++ b/packages/relay/tests/lib/hapiService.spec.ts @@ -35,7 +35,6 @@ import HAPIService from '../../src/lib/services/hapiService/hapiService'; import { HbarLimitService } from '../../src/lib/services/hbarLimitService'; import { RequestDetails } from '../../src/lib/types'; import { overrideEnvsInMochaDescribe, withOverriddenEnvsInMochaTest } from '../helpers'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const registry = new Registry(); const logger = pino({ level: 'silent' }); diff --git a/packages/relay/tests/lib/mirrorNodeClient.spec.ts b/packages/relay/tests/lib/mirrorNodeClient.spec.ts index 9aff1f8ebd..48b9c263fa 100644 --- a/packages/relay/tests/lib/mirrorNodeClient.spec.ts +++ b/packages/relay/tests/lib/mirrorNodeClient.spec.ts @@ -22,7 +22,6 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services' import axios, { AxiosInstance } from 'axios'; import MockAdapter from 'axios-mock-adapter'; import { BigNumber } from 'bignumber.js'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; import { MirrorNodeClientError, predefined } from '../../src'; import { MirrorNodeClient } from '../../src/lib/clients'; diff --git a/packages/relay/tests/lib/net.spec.ts b/packages/relay/tests/lib/net.spec.ts index 2bf051a5d7..056ca44c3f 100644 --- a/packages/relay/tests/lib/net.spec.ts +++ b/packages/relay/tests/lib/net.spec.ts @@ -26,7 +26,6 @@ import { Registry } from 'prom-client'; import constants from '../../src/lib/constants'; import { RelayImpl } from '../../src/lib/relay'; import { withOverriddenEnvsInMochaTest } from '../helpers'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const logger = pino({ level: 'silent' }); let Relay; diff --git a/packages/relay/tests/lib/poller.spec.ts b/packages/relay/tests/lib/poller.spec.ts index 250cebdede..75333a38f8 100644 --- a/packages/relay/tests/lib/poller.spec.ts +++ b/packages/relay/tests/lib/poller.spec.ts @@ -26,7 +26,6 @@ import sinon from 'sinon'; import { EthImpl } from '../../src/lib/eth'; import { Poller } from '../../src/lib/poller'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const logger = pino({ level: 'trace' }); diff --git a/packages/relay/tests/lib/precheck.spec.ts b/packages/relay/tests/lib/precheck.spec.ts index a71c241b1e..83fbf6cb26 100644 --- a/packages/relay/tests/lib/precheck.spec.ts +++ b/packages/relay/tests/lib/precheck.spec.ts @@ -44,7 +44,6 @@ import { ONE_TINYBAR_IN_WEI_HEX } from './eth/eth-config'; const registry = new Registry(); import { RequestDetails } from '../../src/lib/types'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const logger = pino({ level: 'silent' }); const limitOrderPostFix = '?order=desc&limit=1'; diff --git a/packages/relay/tests/lib/sdkClient.spec.ts b/packages/relay/tests/lib/sdkClient.spec.ts index 3bac376a89..6e1f932c81 100644 --- a/packages/relay/tests/lib/sdkClient.spec.ts +++ b/packages/relay/tests/lib/sdkClient.spec.ts @@ -65,7 +65,6 @@ import { random20BytesAddress, withOverriddenEnvsInMochaTest, } from '../helpers'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const registry = new Registry(); const logger = pino({ level: 'silent' }); diff --git a/packages/relay/tests/lib/services/debugService/debug.spec.ts b/packages/relay/tests/lib/services/debugService/debug.spec.ts index 9b3bd3b7d0..e05e57bab7 100644 --- a/packages/relay/tests/lib/services/debugService/debug.spec.ts +++ b/packages/relay/tests/lib/services/debugService/debug.spec.ts @@ -36,7 +36,6 @@ import { CommonService } from '../../../../src/lib/services/ethService'; import { RequestDetails } from '../../../../src/lib/types'; import RelayAssertions from '../../../assertions'; import { getQueryParams, withOverriddenEnvsInMochaTest } from '../../../helpers'; -import { ConfigKey } from '../../../../../config-service/src/services/globalConfig'; chai.use(chaiAsPromised); diff --git a/packages/relay/tests/lib/services/eth/filter.spec.ts b/packages/relay/tests/lib/services/eth/filter.spec.ts index d2f5b2530a..57afb197c9 100644 --- a/packages/relay/tests/lib/services/eth/filter.spec.ts +++ b/packages/relay/tests/lib/services/eth/filter.spec.ts @@ -40,7 +40,6 @@ import { toHex, withOverriddenEnvsInMochaTest, } from '../../../helpers'; -import { ConfigKey } from '../../../../../config-service/src/services/globalConfig'; const logger = pino({ level: 'silent' }); const registry = new Registry(); diff --git a/packages/relay/tests/lib/services/metricService/metricService.spec.ts b/packages/relay/tests/lib/services/metricService/metricService.spec.ts index 68a54d5a3d..84074ae315 100644 --- a/packages/relay/tests/lib/services/metricService/metricService.spec.ts +++ b/packages/relay/tests/lib/services/metricService/metricService.spec.ts @@ -43,7 +43,6 @@ import { overrideEnvsInMochaDescribe, withOverriddenEnvsInMochaTest, } from '../../../helpers'; -import { ConfigKey } from '../../../../../config-service/src/services/globalConfig'; const registry = new Registry(); const logger = pino({ level: 'silent' }); diff --git a/packages/relay/tests/lib/utils.spec.ts b/packages/relay/tests/lib/utils.spec.ts index 6ba90f5c3d..6c3121b65b 100644 --- a/packages/relay/tests/lib/utils.spec.ts +++ b/packages/relay/tests/lib/utils.spec.ts @@ -25,7 +25,6 @@ import createHash from 'keccak'; import pino from 'pino'; import sinon from 'sinon'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; import { ASCIIToHex, prepend0x } from '../../src/formatters'; import constants from '../../src/lib/constants'; import { Utils } from '../../src/utils'; diff --git a/packages/relay/tests/lib/web3.spec.ts b/packages/relay/tests/lib/web3.spec.ts index a59b5d9fa1..056e722c90 100644 --- a/packages/relay/tests/lib/web3.spec.ts +++ b/packages/relay/tests/lib/web3.spec.ts @@ -23,7 +23,6 @@ import { expect } from 'chai'; import pino from 'pino'; import { Registry } from 'prom-client'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; import { RelayImpl } from '../../src'; import { withOverriddenEnvsInMochaTest } from '../helpers'; diff --git a/packages/server/tests/acceptance/conformityTests.spec.ts b/packages/server/tests/acceptance/conformityTests.spec.ts index ccd8cc6818..46bb0d4976 100644 --- a/packages/server/tests/acceptance/conformityTests.spec.ts +++ b/packages/server/tests/acceptance/conformityTests.spec.ts @@ -32,7 +32,6 @@ 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 { ConfigKey } from '../../../config-service/src/services/globalConfig'; const directoryPath = path.resolve(__dirname, '../../../../node_modules/execution-apis/tests'); diff --git a/packages/server/tests/acceptance/hbarLimiter.spec.ts b/packages/server/tests/acceptance/hbarLimiter.spec.ts index 466e79e6b0..7d3ba8970e 100644 --- a/packages/server/tests/acceptance/hbarLimiter.spec.ts +++ b/packages/server/tests/acceptance/hbarLimiter.spec.ts @@ -52,7 +52,6 @@ import testConstants from '../helpers/constants'; // Local resources import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; config({ path: resolve(__dirname, '../localAcceptance.env') }); diff --git a/packages/server/tests/acceptance/index.spec.ts b/packages/server/tests/acceptance/index.spec.ts index b60682d8a6..2ea9538378 100644 --- a/packages/server/tests/acceptance/index.spec.ts +++ b/packages/server/tests/acceptance/index.spec.ts @@ -49,7 +49,6 @@ import ServicesClient from '../clients/servicesClient'; // Utils and types import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(chaiAsPromised); diff --git a/packages/server/tests/acceptance/rateLimiter.spec.ts b/packages/server/tests/acceptance/rateLimiter.spec.ts index c818ef2e32..a1154e927b 100644 --- a/packages/server/tests/acceptance/rateLimiter.spec.ts +++ b/packages/server/tests/acceptance/rateLimiter.spec.ts @@ -26,7 +26,6 @@ import relayConstants from '@hashgraph/json-rpc-relay/dist/lib/constants'; import testConstants from '../../tests/helpers/constants'; import RelayClient from '../clients/relayClient'; import Assertions from '../helpers/assertions'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@ratelimiter Rate Limiters Acceptance Tests', function () { this.timeout(480 * 1000); // 480 seconds diff --git a/packages/server/tests/acceptance/rpc_batch1.spec.ts b/packages/server/tests/acceptance/rpc_batch1.spec.ts index dd1f0a6643..3ca08c04b6 100644 --- a/packages/server/tests/acceptance/rpc_batch1.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch1.spec.ts @@ -50,7 +50,6 @@ import parentContractJson from '../contracts/Parent.json'; import Assertions from '../helpers/assertions'; import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const Address = RelayCalls; diff --git a/packages/server/tests/acceptance/rpc_batch2.spec.ts b/packages/server/tests/acceptance/rpc_batch2.spec.ts index 5252ede1ad..b64b131399 100644 --- a/packages/server/tests/acceptance/rpc_batch2.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch2.spec.ts @@ -46,7 +46,6 @@ import TokenCreateJson from '../contracts/TokenCreateContract.json'; import Assertions from '../helpers/assertions'; import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@api-batch-2 RPC Server Acceptance Tests', function () { this.timeout(240 * 1000); // 240 seconds diff --git a/packages/server/tests/acceptance/rpc_batch3.spec.ts b/packages/server/tests/acceptance/rpc_batch3.spec.ts index 53f9ee3df7..6528df9e08 100644 --- a/packages/server/tests/acceptance/rpc_batch3.spec.ts +++ b/packages/server/tests/acceptance/rpc_batch3.spec.ts @@ -56,7 +56,6 @@ import Assertions from '../helpers/assertions'; import RelayCalls from '../helpers/constants'; import { Utils } from '../helpers/utils'; import { AliasAccount } from '../types/AliasAccount'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(chaiExclude); diff --git a/packages/server/tests/acceptance/serverConfig.spec.ts b/packages/server/tests/acceptance/serverConfig.spec.ts index 06c213df7b..d80a755850 100644 --- a/packages/server/tests/acceptance/serverConfig.spec.ts +++ b/packages/server/tests/acceptance/serverConfig.spec.ts @@ -21,7 +21,6 @@ import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services' import { expect } from 'chai'; import { Utils } from '../helpers/utils'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@server-config Server Configuration Options Coverage', function () { describe('Koa Server Timeout', () => { diff --git a/packages/server/tests/integration/server.spec.ts b/packages/server/tests/integration/server.spec.ts index d488a47f86..47577126ab 100644 --- a/packages/server/tests/integration/server.spec.ts +++ b/packages/server/tests/integration/server.spec.ts @@ -43,7 +43,6 @@ import * as Constants from '../../src/validator/constants'; import RelayCalls from '../../tests/helpers/constants'; import Assertions from '../helpers/assertions'; import { Utils } from '../helpers/utils'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; const MISSING_PARAM_ERROR = 'Missing value for required parameter'; diff --git a/packages/ws-server/tests/acceptance/batchRequest.spec.ts b/packages/ws-server/tests/acceptance/batchRequest.spec.ts index ecae0bfbd3..0a55083ae7 100644 --- a/packages/ws-server/tests/acceptance/batchRequest.spec.ts +++ b/packages/ws-server/tests/acceptance/batchRequest.spec.ts @@ -25,7 +25,6 @@ import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; import { WsTestConstant, WsTestHelper } from '../helper'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-request Batch Requests', async function () { const METHOD_NAME = 'batch_request'; diff --git a/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts b/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts index 9ec3266ca1..c787afbe1b 100644 --- a/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionByHash.spec.ts @@ -31,7 +31,6 @@ import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; import { WsTestConstant, WsTestHelper } from '../helper'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_getTransactionByHash', async function () { const METHOD_NAME = 'eth_getTransactionByHash'; diff --git a/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts b/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts index c9750f0bb8..8407572064 100644 --- a/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionCount.spec.ts @@ -30,7 +30,6 @@ import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; import { WsTestConstant, WsTestHelper } from '../helper'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@release @web-socket-batch-2 eth_getTransactionCount', async function () { const METHOD_NAME = 'eth_getTransactionCount'; diff --git a/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts b/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts index dd51278179..edae3d0664 100644 --- a/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts +++ b/packages/ws-server/tests/acceptance/getTransactionReceipt.spec.ts @@ -31,7 +31,6 @@ import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; import { WsTestConstant, WsTestHelper } from '../helper'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_getTransactionReceipt', async function () { const METHOD_NAME = 'eth_getTransactionReceipt'; diff --git a/packages/ws-server/tests/acceptance/index.spec.ts b/packages/ws-server/tests/acceptance/index.spec.ts index 91c6da93dc..c2af1689f3 100644 --- a/packages/ws-server/tests/acceptance/index.spec.ts +++ b/packages/ws-server/tests/acceptance/index.spec.ts @@ -42,7 +42,6 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import fs from 'fs'; import pino from 'pino'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(chaiAsPromised); diff --git a/packages/ws-server/tests/acceptance/rateLimiter.spec.ts b/packages/ws-server/tests/acceptance/rateLimiter.spec.ts index 931ec7ced2..0c2cd11e3d 100644 --- a/packages/ws-server/tests/acceptance/rateLimiter.spec.ts +++ b/packages/ws-server/tests/acceptance/rateLimiter.spec.ts @@ -27,7 +27,6 @@ import { expect } from 'chai'; import { ConfigServiceTestHelper } from '../../../config-service/tests/configServiceTestHelper'; import { WsTestHelper } from '../helper'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-ratelimiter Rate Limit Tests', async function () { const rateLimitTier2 = Number(ConfigService.get('TIER_2_RATE_LIMIT') || relayConstants.DEFAULT_RATE_LIMIT.TIER_2); diff --git a/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts b/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts index fdfa32bed4..85a107c16e 100644 --- a/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts +++ b/packages/ws-server/tests/acceptance/sendRawTransaction.spec.ts @@ -33,7 +33,6 @@ import { expect } from 'chai'; import { ethers, WebSocketProvider } from 'ethers'; import { WsTestConstant, WsTestHelper } from '../helper'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; describe('@web-socket-batch-2 eth_sendRawTransaction', async function () { const METHOD_NAME = 'eth_sendRawTransaction'; diff --git a/packages/ws-server/tests/acceptance/subscribe.spec.ts b/packages/ws-server/tests/acceptance/subscribe.spec.ts index bcdb5e552d..4395a06af1 100644 --- a/packages/ws-server/tests/acceptance/subscribe.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribe.spec.ts @@ -34,7 +34,6 @@ import { ethers } from 'ethers'; import WebSocket from 'ws'; import { WsTestHelper } from '../helper'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(solidity); diff --git a/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts b/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts index 7bef0648a6..5c207aaa0d 100644 --- a/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts +++ b/packages/ws-server/tests/acceptance/subscribeNewHeads.spec.ts @@ -32,7 +32,6 @@ import { ethers } from 'ethers'; import WebSocket from 'ws'; import { WsTestHelper } from '../helper'; -import { ConfigKey } from '../../../config-service/src/services/globalConfig'; chai.use(solidity); diff --git a/tools/brownie-example/LICENSE b/tools/brownie-example/LICENSE index 26837975df..56eb59cd28 100644 --- a/tools/brownie-example/LICENSE +++ b/tools/brownie-example/LICENSE @@ -1,7 +1,6 @@ Hedera Brownie Example -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. You may obtain a copy of the License at From 8c8264fb61779450044f3a660d1b74f4c19ffd35 Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Sat, 18 Jan 2025 01:25:40 +0100 Subject: [PATCH 07/11] fix bugs in workflow Signed-off-by: belloibrahv --- .../config-service/src/commands/printEnvs.ts | 2 +- .../src/services/globalConfig.ts | 38 +------------------ packages/config-service/src/services/index.ts | 6 +-- .../src/services/loggerService.ts | 2 +- packages/relay/src/lib/types/ITracerConfig.ts | 2 +- .../src/lib/types/ITracerConfigWrapper.ts | 2 +- .../src/lib/types/ITransactionReceipt.ts | 2 +- .../relay/src/lib/types/RequestDetails.ts | 2 +- packages/relay/src/lib/types/index.ts | 2 +- packages/relay/src/logsBloomUtils.ts | 2 +- packages/relay/src/receiptsRootUtils.ts | 2 +- packages/relay/src/utils.ts | 2 +- .../relay/tests/lib/logsBloomUtils.spec.ts | 2 +- .../relay/tests/lib/receiptsRootUtils.spec.ts | 2 +- packages/relay/tests/lib/utils.spec.ts | 2 +- .../src/koaJsonRpc/lib/IJsonRpcRequest.ts | 2 +- .../src/koaJsonRpc/lib/IJsonRpcResponse.ts | 2 +- .../tests/acceptance/hbarLimiter.spec.ts | 2 +- packages/server/tests/clients/githubClient.ts | 2 +- packages/server/tests/types/GitHubContext.ts | 2 +- .../tests/types/HeapDifferenceStatistics.ts | 2 +- .../test/samplecontract.test.mjs | 2 +- tools/wagmi-example/src/App.tsx | 2 +- .../wagmi-example/src/components/Contract.tsx | 2 +- .../wagmi-example/src/components/Profile.tsx | 2 +- tools/wagmi-example/src/hooks/use-balance.ts | 2 +- tools/wagmi-example/src/hooks/use-deploy.ts | 2 +- tools/wagmi-example/src/main.tsx | 2 +- tools/wagmi-example/src/wagmi.ts | 2 +- 29 files changed, 32 insertions(+), 66 deletions(-) diff --git a/packages/config-service/src/commands/printEnvs.ts b/packages/config-service/src/commands/printEnvs.ts index fb392098fd..cfde9dd5f0 100644 --- a/packages/config-service/src/commands/printEnvs.ts +++ b/packages/config-service/src/commands/printEnvs.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 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. diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index a15955482f..8df62aa2e6 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay * - * Copyright (C) 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. @@ -29,7 +29,7 @@ type TypeStrToType = Tstr extends 'string' : never; type GetTypeStrOfKey = K extends keyof typeof _CONFIG - ? typeof _CONFIG[K]['type'] + ? typeof _CONFIG[K]['type'] : never; export type TypeOfKey = TypeStrToType>; @@ -767,40 +767,6 @@ const _CONFIG = { export type ConfigKey = keyof typeof _CONFIG; -export class ConfigService { - private static config: typeof _CONFIG = _CONFIG; - - public static get(name: K): TypeOfKey | undefined { - const configItem = this.config[name]; - if (!configItem) { - return undefined; - } - - const value = process.env[configItem.envName]; - - if (value === undefined) { - return configItem.defaultValue as TypeOfKey; - } - - switch (configItem.type) { - case 'boolean': - return (value.toLowerCase() === 'true') as TypeOfKey; - case 'number': - return Number(value) as TypeOfKey; - case 'string': - return value as TypeOfKey; - case 'array': - try { - return JSON.parse(value) as TypeOfKey; - } catch { - return undefined; - } - default: - return undefined; - } - } -} - export class GlobalConfig { public static readonly ENTRIES: Record = _CONFIG; } diff --git a/packages/config-service/src/services/index.ts b/packages/config-service/src/services/index.ts index 39b62e9a7f..aa595c102c 100644 --- a/packages/config-service/src/services/index.ts +++ b/packages/config-service/src/services/index.ts @@ -22,9 +22,9 @@ import dotenv from 'dotenv'; import findConfig from 'find-config'; import pino from 'pino'; +import type { ConfigKey, TypeOfKey } from './globalConfig'; import { LoggerService } from './loggerService'; import { ValidationService } from './validationService'; -import type { ConfigKey } from './globalConfig'; const mainLogger = pino({ name: 'hedera-json-rpc-relay', @@ -98,7 +98,7 @@ export class ConfigService { * @param name string * @returns string | undefined */ - public static get(name: ConfigKey): string | number | boolean | null | undefined { - return this.getInstance().envs[name]; + public static get(name: K): TypeOfKey | undefined { + return this.getInstance().envs[name] as TypeOfKey | undefined; } } diff --git a/packages/config-service/src/services/loggerService.ts b/packages/config-service/src/services/loggerService.ts index 027fe7f447..5f5a5e346d 100644 --- a/packages/config-service/src/services/loggerService.ts +++ b/packages/config-service/src/services/loggerService.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/src/lib/types/ITracerConfig.ts b/packages/relay/src/lib/types/ITracerConfig.ts index 7cec49efd9..6f92ccbbb2 100644 --- a/packages/relay/src/lib/types/ITracerConfig.ts +++ b/packages/relay/src/lib/types/ITracerConfig.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/src/lib/types/ITracerConfigWrapper.ts b/packages/relay/src/lib/types/ITracerConfigWrapper.ts index dc444fd38d..3499c2f913 100644 --- a/packages/relay/src/lib/types/ITracerConfigWrapper.ts +++ b/packages/relay/src/lib/types/ITracerConfigWrapper.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/src/lib/types/ITransactionReceipt.ts b/packages/relay/src/lib/types/ITransactionReceipt.ts index a208da06f4..c42b7cf56d 100644 --- a/packages/relay/src/lib/types/ITransactionReceipt.ts +++ b/packages/relay/src/lib/types/ITransactionReceipt.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/src/lib/types/RequestDetails.ts b/packages/relay/src/lib/types/RequestDetails.ts index 206d325b98..5d557d2151 100644 --- a/packages/relay/src/lib/types/RequestDetails.ts +++ b/packages/relay/src/lib/types/RequestDetails.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/src/lib/types/index.ts b/packages/relay/src/lib/types/index.ts index dc048c8dca..2ca506dbf4 100644 --- a/packages/relay/src/lib/types/index.ts +++ b/packages/relay/src/lib/types/index.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/src/logsBloomUtils.ts b/packages/relay/src/logsBloomUtils.ts index e7e94cab3b..f0e6cd29f2 100644 --- a/packages/relay/src/logsBloomUtils.ts +++ b/packages/relay/src/logsBloomUtils.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/src/receiptsRootUtils.ts b/packages/relay/src/receiptsRootUtils.ts index 80731477a7..3f3415dac2 100644 --- a/packages/relay/src/receiptsRootUtils.ts +++ b/packages/relay/src/receiptsRootUtils.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/src/utils.ts b/packages/relay/src/utils.ts index 2704297fbd..f7b5c13bc9 100644 --- a/packages/relay/src/utils.ts +++ b/packages/relay/src/utils.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/tests/lib/logsBloomUtils.spec.ts b/packages/relay/tests/lib/logsBloomUtils.spec.ts index 4ec141c1e1..4046d07097 100644 --- a/packages/relay/tests/lib/logsBloomUtils.spec.ts +++ b/packages/relay/tests/lib/logsBloomUtils.spec.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/tests/lib/receiptsRootUtils.spec.ts b/packages/relay/tests/lib/receiptsRootUtils.spec.ts index 4bd417b291..36e6f26acd 100644 --- a/packages/relay/tests/lib/receiptsRootUtils.spec.ts +++ b/packages/relay/tests/lib/receiptsRootUtils.spec.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/relay/tests/lib/utils.spec.ts b/packages/relay/tests/lib/utils.spec.ts index 6c3121b65b..e1e40c495d 100644 --- a/packages/relay/tests/lib/utils.spec.ts +++ b/packages/relay/tests/lib/utils.spec.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts b/packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts index 91e7a85649..7f78ec1b91 100644 --- a/packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts +++ b/packages/server/src/koaJsonRpc/lib/IJsonRpcRequest.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts b/packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts index debce1547a..ba14478890 100644 --- a/packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts +++ b/packages/server/src/koaJsonRpc/lib/IJsonRpcResponse.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/server/tests/acceptance/hbarLimiter.spec.ts b/packages/server/tests/acceptance/hbarLimiter.spec.ts index 7d3ba8970e..e6d185068c 100644 --- a/packages/server/tests/acceptance/hbarLimiter.spec.ts +++ b/packages/server/tests/acceptance/hbarLimiter.spec.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/server/tests/clients/githubClient.ts b/packages/server/tests/clients/githubClient.ts index 932ef7ca17..b08d287713 100644 --- a/packages/server/tests/clients/githubClient.ts +++ b/packages/server/tests/clients/githubClient.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/server/tests/types/GitHubContext.ts b/packages/server/tests/types/GitHubContext.ts index 22c949939d..355bbcefe4 100644 --- a/packages/server/tests/types/GitHubContext.ts +++ b/packages/server/tests/types/GitHubContext.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/packages/server/tests/types/HeapDifferenceStatistics.ts b/packages/server/tests/types/HeapDifferenceStatistics.ts index ce96510525..db67e82b62 100644 --- a/packages/server/tests/types/HeapDifferenceStatistics.ts +++ b/packages/server/tests/types/HeapDifferenceStatistics.ts @@ -2,7 +2,7 @@ * * 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. diff --git a/tools/waffle-example/test/samplecontract.test.mjs b/tools/waffle-example/test/samplecontract.test.mjs index 76401a2b1b..7609cfa1b1 100644 --- a/tools/waffle-example/test/samplecontract.test.mjs +++ b/tools/waffle-example/test/samplecontract.test.mjs @@ -2,7 +2,7 @@ * * Hedera Waffle Project * - * 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. diff --git a/tools/wagmi-example/src/App.tsx b/tools/wagmi-example/src/App.tsx index 27d7efb8a8..63a0f15360 100644 --- a/tools/wagmi-example/src/App.tsx +++ b/tools/wagmi-example/src/App.tsx @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * 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. diff --git a/tools/wagmi-example/src/components/Contract.tsx b/tools/wagmi-example/src/components/Contract.tsx index e6b8c015bf..4f9cea022c 100644 --- a/tools/wagmi-example/src/components/Contract.tsx +++ b/tools/wagmi-example/src/components/Contract.tsx @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * 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. diff --git a/tools/wagmi-example/src/components/Profile.tsx b/tools/wagmi-example/src/components/Profile.tsx index be417b05b9..41389a77a5 100644 --- a/tools/wagmi-example/src/components/Profile.tsx +++ b/tools/wagmi-example/src/components/Profile.tsx @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * 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. diff --git a/tools/wagmi-example/src/hooks/use-balance.ts b/tools/wagmi-example/src/hooks/use-balance.ts index f37e00e00d..78b7c546ff 100644 --- a/tools/wagmi-example/src/hooks/use-balance.ts +++ b/tools/wagmi-example/src/hooks/use-balance.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * 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. diff --git a/tools/wagmi-example/src/hooks/use-deploy.ts b/tools/wagmi-example/src/hooks/use-deploy.ts index 15f47e3a69..27c249e859 100644 --- a/tools/wagmi-example/src/hooks/use-deploy.ts +++ b/tools/wagmi-example/src/hooks/use-deploy.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * 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. diff --git a/tools/wagmi-example/src/main.tsx b/tools/wagmi-example/src/main.tsx index 6b10f73ae7..cda3a08d7e 100644 --- a/tools/wagmi-example/src/main.tsx +++ b/tools/wagmi-example/src/main.tsx @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * 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. diff --git a/tools/wagmi-example/src/wagmi.ts b/tools/wagmi-example/src/wagmi.ts index 687a33605f..21a4f2d3df 100644 --- a/tools/wagmi-example/src/wagmi.ts +++ b/tools/wagmi-example/src/wagmi.ts @@ -2,7 +2,7 @@ * * Hedera JSON RPC Relay - Wagmi Example * - * 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. From 59dfbf4888ea1501e4f8d51fba4e4f0abe65671a Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Tue, 21 Jan 2025 23:32:33 +0100 Subject: [PATCH 08/11] Remove assesrtion Signed-off-by: belloibrahv --- packages/relay/tests/lib/sdkClient.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/relay/tests/lib/sdkClient.spec.ts b/packages/relay/tests/lib/sdkClient.spec.ts index 6e1f932c81..d30f46e507 100644 --- a/packages/relay/tests/lib/sdkClient.spec.ts +++ b/packages/relay/tests/lib/sdkClient.spec.ts @@ -102,7 +102,7 @@ describe('SdkClient', async function () { overrideEnvsInMochaDescribe({ GET_RECORD_DEFAULT_TO_CONSENSUS_NODE: true }); before(() => { - const hederaNetwork = ConfigService.get('HEDERA_NETWORK')! as string; + const hederaNetwork = ConfigService.get('HEDERA_NETWORK')!; if (hederaNetwork in constants.CHAIN_IDS) { client = Client.forName(hederaNetwork); } else { @@ -110,8 +110,8 @@ describe('SdkClient', async function () { } 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('OPERATOR_ID_MAIN')!), + Utils.createPrivateKeyBasedOnFormat(ConfigService.get('OPERATOR_KEY_MAIN')!), ); const duration = constants.HBAR_RATE_LIMIT_DURATION; eventEmitter = new EventEmitter(); From 67bc0370dff5ea949819fb0684d1e5815fab7205 Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Wed, 22 Jan 2025 09:09:03 +0100 Subject: [PATCH 09/11] Remove assesrtion Signed-off-by: belloibrahv --- .../config-service/tests/src/services/loggerService.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/config-service/tests/src/services/loggerService.spec.ts b/packages/config-service/tests/src/services/loggerService.spec.ts index 428e75979d..dc311f687c 100644 --- a/packages/config-service/tests/src/services/loggerService.spec.ts +++ b/packages/config-service/tests/src/services/loggerService.spec.ts @@ -48,7 +48,7 @@ describe('LoggerService tests', async function () { it('should be able to return plain information', async () => { const envName = 'CHAIN_ID'; - const res = ConfigService.get(envName) as string | undefined; + const res = ConfigService.get(envName); expect(LoggerService.maskUpEnv(envName, res)).to.equal(`${envName} = ${res}`); }); From b65aff51a5ba949f1817091d36ac4f551b75988f Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Thu, 23 Jan 2025 14:06:34 +0100 Subject: [PATCH 10/11] Add assertion to _CONFIG (in the globalConfig.ts file) Signed-off-by: belloibrahv --- packages/config-service/src/services/globalConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index 8df62aa2e6..7d01f1e55b 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -763,7 +763,7 @@ const _CONFIG = { required: false, defaultValue: null, }, -} satisfies { [key: string]: ConfigProperty }; +} as const satisfies { [key: string]: ConfigProperty }; export type ConfigKey = keyof typeof _CONFIG; From b1723374001c4d779249f55af80f180833200849 Mon Sep 17 00:00:00 2001 From: Logan Nguyen Date: Wed, 29 Jan 2025 18:42:40 -0600 Subject: [PATCH 11/11] chore: renamed types and added explanation Signed-off-by: Logan Nguyen --- .../src/services/globalConfig.ts | 1494 +++++++++-------- packages/config-service/src/services/index.ts | 6 +- 2 files changed, 764 insertions(+), 736 deletions(-) diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index 7d01f1e55b..c34b1dc594 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -18,22 +18,46 @@ * */ -type TypeStrToType = Tstr extends 'string' +// Type mapping utility that converts string representations of types +// (e.g., 'string', 'boolean', 'number', 'array') to their corresponding +// TypeScript types. This allows for dynamic type resolution based on +// configuration definitions. +// Example: +// - 'string' -> string +// - 'boolean' -> boolean +// - 'number' -> number +// - 'array' -> unknown[] +type StringTypeToActualType = Tstr extends 'string' ? string : Tstr extends 'boolean' - ? boolean - : Tstr extends 'number' - ? number - : Tstr extends 'array' - ? unknown[] - : never; - -type GetTypeStrOfKey = K extends keyof typeof _CONFIG - ? typeof _CONFIG[K]['type'] + ? boolean + : Tstr extends 'number' + ? number + : Tstr extends 'array' + ? unknown[] : never; -export type TypeOfKey = TypeStrToType>; +// This type extracts the type string associated with a specific key +// in the _CONFIG object. It checks if the provided key K is a valid +// key in _CONFIG. If it is, it retrieves the 'type' property of the +// corresponding configuration object; otherwise, it resolves to 'never'. +// Example: +// - For key 'CHAIN_ID', it returns 'string' if defined in _CONFIG. +// - For an invalid key 'INVALID_KEY', it returns never. +type ExtractTypeStringFromKey = K extends keyof typeof _CONFIG ? (typeof _CONFIG)[K]['type'] : never; + +// This type maps a configuration key K to its corresponding TypeScript type. +// It first uses ExtractTypeStringFromKey to get the type string and then +// converts that string to the actual TypeScript type using StringTypeToActualType. +// Example: +// - GetTypeOfConfigKey<'CHAIN_ID'> would resolve to string. +// - GetTypeOfConfigKey<'BATCH_REQUESTS_ENABLED'> would resolve to boolean. +export type GetTypeOfConfigKey = StringTypeToActualType>; +// Interface defining the structure of a configuration property. +// Each property includes the environment variable name, its type, +// whether it is required, and its default value. +// Example of a ConfigProperty: export interface ConfigProperty { envName: string; type: string; @@ -41,729 +65,733 @@ export interface ConfigProperty { defaultValue: string | number | boolean | null; } +// Configuration object defining various properties and their metadata. +// Each property is an object that contains information about the environment variable, +// its type, whether it is required, and its default value. +// Example of a configuration entry: const _CONFIG = { - BATCH_REQUESTS_ENABLED: { - envName: 'BATCH_REQUESTS_ENABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - BATCH_REQUESTS_MAX_SIZE: { - envName: 'BATCH_REQUESTS_MAX_SIZE', - type: 'number', - required: false, - defaultValue: null, - }, - CACHE_MAX: { - envName: 'CACHE_MAX', - type: 'number', - required: false, - defaultValue: null, - }, - CACHE_TTL: { - envName: 'CACHE_TTL', - type: 'number', - required: false, - defaultValue: null, - }, - CHAIN_ID: { - envName: 'CHAIN_ID', - type: 'string', - required: true, - defaultValue: null, - }, - CLIENT_TRANSPORT_SECURITY: { - envName: 'CLIENT_TRANSPORT_SECURITY', - type: 'boolean', - required: false, - defaultValue: null, - }, - CONSENSUS_MAX_EXECUTION_TIME: { - envName: 'CONSENSUS_MAX_EXECUTION_TIME', - type: 'number', - required: false, - defaultValue: null, - }, - CONTRACT_CALL_GAS_LIMIT: { - envName: 'CONTRACT_CALL_GAS_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - CONTRACT_QUERY_TIMEOUT_RETRIES: { - envName: 'CONTRACT_QUERY_TIMEOUT_RETRIES', - type: 'number', - required: false, - defaultValue: null, - }, - DEBUG_API_ENABLED: { - envName: 'DEBUG_API_ENABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - DEFAULT_RATE_LIMIT: { - envName: 'DEFAULT_RATE_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - DEV_MODE: { - envName: 'DEV_MODE', - type: 'boolean', - required: false, - defaultValue: null, - }, - E2E_RELAY_HOST: { - envName: 'E2E_RELAY_HOST', - type: 'string', - required: false, - defaultValue: 'http://localhost:7546', - }, - E2E_SERVER_PORT: { - envName: 'E2E_SERVER_PORT', - type: 'number', - required: false, - defaultValue: null, - }, - ESTIMATE_GAS_THROWS: { - envName: 'ESTIMATE_GAS_THROWS', - type: 'boolean', - required: false, - defaultValue: null, - }, - ETH_BLOCK_NUMBER_CACHE_TTL_MS: { - envName: 'ETH_BLOCK_NUMBER_CACHE_TTL_MS', - type: 'number', - required: false, - defaultValue: null, - }, - ETH_CALL_ACCEPTED_ERRORS: { - envName: 'ETH_CALL_ACCEPTED_ERRORS', - type: 'array', - required: false, - defaultValue: null, - }, - ETH_CALL_CACHE_TTL: { - envName: 'ETH_CALL_CACHE_TTL', - type: 'number', - required: false, - defaultValue: null, - }, - ETH_CALL_CONSENSUS_SELECTORS: { - envName: 'ETH_CALL_CONSENSUS_SELECTORS', - type: 'array', - required: false, - defaultValue: null, - }, - ETH_CALL_DEFAULT_TO_CONSENSUS_NODE: { - envName: 'ETH_CALL_DEFAULT_TO_CONSENSUS_NODE', - type: 'boolean', - required: false, - defaultValue: null, - }, - ETH_FEE_HISTORY_FIXED: { - envName: 'ETH_FEE_HISTORY_FIXED', - type: 'boolean', - required: false, - defaultValue: null, - }, - ETH_GET_BALANCE_CACHE_TTL_MS: { - envName: 'ETH_GET_BALANCE_CACHE_TTL_MS', - type: 'number', - required: false, - defaultValue: null, - }, - ETH_GET_GAS_PRICE_CACHE_TTL_MS: { - envName: 'ETH_GET_GAS_PRICE_CACHE_TTL_MS', - type: 'number', - required: false, - defaultValue: null, - }, - ETH_GET_LOGS_BLOCK_RANGE_LIMIT: { - envName: 'ETH_GET_LOGS_BLOCK_RANGE_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - ETH_GET_TRANSACTION_COUNT_CACHE_TTL: { - envName: 'ETH_GET_TRANSACTION_COUNT_CACHE_TTL', - type: 'number', - required: false, - defaultValue: null, - }, - ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE: { - envName: 'ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE', - type: 'number', - required: false, - defaultValue: null, - }, - HEDERA_SPECIFIC_REVERT_STATUSES: { - envName: 'HEDERA_SPECIFIC_REVERT_STATUSES', - type: 'string', - required: false, - defaultValue: '["WRONG_NONCE", "INVALID_ACCOUNT_ID"]', - }, - FEE_HISTORY_MAX_RESULTS: { - envName: 'FEE_HISTORY_MAX_RESULTS', - type: 'number', - required: false, - defaultValue: null, - }, - FILE_APPEND_CHUNK_SIZE: { - envName: 'FILE_APPEND_CHUNK_SIZE', - type: 'number', - required: false, - defaultValue: null, - }, - FILE_APPEND_MAX_CHUNKS: { - envName: 'FILE_APPEND_MAX_CHUNKS', - type: 'number', - required: false, - defaultValue: null, - }, - FILTER_API_ENABLED: { - envName: 'FILTER_API_ENABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - FILTER_TTL: { - envName: 'FILTER_TTL', - type: 'number', - required: false, - defaultValue: null, - }, - GAS_PRICE_PERCENTAGE_BUFFER: { - envName: 'GAS_PRICE_PERCENTAGE_BUFFER', - type: 'number', - required: false, - defaultValue: null, - }, - GAS_PRICE_TINY_BAR_BUFFER: { - envName: 'GAS_PRICE_TINY_BAR_BUFFER', - type: 'number', - required: false, - defaultValue: null, - }, - GET_RECORD_DEFAULT_TO_CONSENSUS_NODE: { - envName: 'GET_RECORD_DEFAULT_TO_CONSENSUS_NODE', - type: 'boolean', - required: false, - defaultValue: null, - }, - GH_ACCESS_TOKEN: { - envName: 'GH_ACCESS_TOKEN', - type: 'string', - required: false, - defaultValue: null, - }, - GITHUB_PR_NUMBER: { - envName: 'GITHUB_PR_NUMBER', - type: 'string', - required: false, - defaultValue: null, - }, - GITHUB_REPOSITORY: { - envName: 'GITHUB_REPOSITORY', - type: 'string', - required: false, - defaultValue: null, - }, - GITHUB_TOKEN: { - envName: 'GITHUB_TOKEN', - type: 'string', - required: false, - defaultValue: null, - }, - HAPI_CLIENT_DURATION_RESET: { - envName: 'HAPI_CLIENT_DURATION_RESET', - type: 'number', - required: false, - defaultValue: null, - }, - HAPI_CLIENT_ERROR_RESET: { - envName: 'HAPI_CLIENT_ERROR_RESET', - type: 'array', - required: false, - defaultValue: null, - }, - HAPI_CLIENT_TRANSACTION_RESET: { - envName: 'HAPI_CLIENT_TRANSACTION_RESET', - type: 'number', - required: false, - defaultValue: null, - }, - HBAR_RATE_LIMIT_BASIC: { - envName: 'HBAR_RATE_LIMIT_BASIC', - type: 'number', - required: false, - defaultValue: 1_120_000_000, // 11.2 hbar - }, - HBAR_RATE_LIMIT_EXTENDED: { - envName: 'HBAR_RATE_LIMIT_EXTENDED', - type: 'number', - required: false, - defaultValue: 3_200_000_000, // 32 hbar - }, - HBAR_RATE_LIMIT_PRIVILEGED: { - envName: 'HBAR_RATE_LIMIT_PRIVILEGED', - type: 'number', - required: false, - defaultValue: 8_000_000_000, // 80 hbar - }, - HBAR_RATE_LIMIT_DURATION: { - envName: 'HBAR_RATE_LIMIT_DURATION', - type: 'number', - required: false, - defaultValue: 86_400_000, // 24 hours - }, - HBAR_RATE_LIMIT_TINYBAR: { - envName: 'HBAR_RATE_LIMIT_TINYBAR', - type: 'number', - required: false, - defaultValue: 800_000_000_000, // 8000 hbar - }, - HEDERA_NETWORK: { - envName: 'HEDERA_NETWORK', - type: 'string', - required: true, - defaultValue: null, - }, - HBAR_SPENDING_PLANS_CONFIG: { - envName: 'HBAR_SPENDING_PLANS_CONFIG', - type: 'string', - required: false, - defaultValue: 'spendingPlansConfig.json', - }, - INITIAL_BALANCE: { - envName: 'INITIAL_BALANCE', - type: 'number', - required: false, - defaultValue: null, - }, - INPUT_SIZE_LIMIT: { - envName: 'INPUT_SIZE_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - LIMIT_DURATION: { - envName: 'LIMIT_DURATION', - type: 'number', - required: false, - defaultValue: null, - }, - LOCAL_NODE: { - envName: 'LOCAL_NODE', - type: 'boolean', - required: false, - defaultValue: null, - }, - LOG_LEVEL: { - envName: 'LOG_LEVEL', - type: 'string', - required: false, - defaultValue: null, - }, - MAX_BLOCK_RANGE: { - envName: 'MAX_BLOCK_RANGE', - type: 'number', - required: false, - defaultValue: null, - }, - MEMWATCH_ENABLED: { - envName: 'MEMWATCH_ENABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - MIRROR_NODE_AGENT_CACHEABLE_DNS: { - envName: 'MIRROR_NODE_AGENT_CACHEABLE_DNS', - type: 'boolean', - required: false, - defaultValue: null, - }, - MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX: { - envName: 'MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_CONTRACT_RESULTS_PG_MAX: { - envName: 'MIRROR_NODE_CONTRACT_RESULTS_PG_MAX', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_HTTP_KEEP_ALIVE: { - envName: 'MIRROR_NODE_HTTP_KEEP_ALIVE', - type: 'boolean', - required: false, - defaultValue: null, - }, - MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS: { - envName: 'MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_HTTP_MAX_SOCKETS: { - envName: 'MIRROR_NODE_HTTP_MAX_SOCKETS', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS: { - envName: 'MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_HTTP_SOCKET_TIMEOUT: { - envName: 'MIRROR_NODE_HTTP_SOCKET_TIMEOUT', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_LIMIT_PARAM: { - envName: 'MIRROR_NODE_LIMIT_PARAM', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_MAX_REDIRECTS: { - envName: 'MIRROR_NODE_MAX_REDIRECTS', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_RETRIES: { - envName: 'MIRROR_NODE_RETRIES', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_RETRIES_DEVMODE: { - envName: 'MIRROR_NODE_RETRIES_DEVMODE', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_RETRY_CODES: { - envName: 'MIRROR_NODE_RETRY_CODES', - type: 'array', - required: false, - defaultValue: null, - }, - MIRROR_NODE_RETRY_DELAY: { - envName: 'MIRROR_NODE_RETRY_DELAY', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_RETRY_DELAY_DEVMODE: { - envName: 'MIRROR_NODE_RETRY_DELAY_DEVMODE', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_REQUEST_RETRY_COUNT: { - envName: 'MIRROR_NODE_REQUEST_RETRY_COUNT', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_TIMEOUT: { - envName: 'MIRROR_NODE_TIMEOUT', - type: 'number', - required: false, - defaultValue: null, - }, - MIRROR_NODE_URL: { - envName: 'MIRROR_NODE_URL', - type: 'string', - required: true, - defaultValue: null, - }, - MIRROR_NODE_URL_HEADER_X_API_KEY: { - envName: 'MIRROR_NODE_URL_HEADER_X_API_KEY', - type: 'array', - required: false, - defaultValue: null, - }, - MIRROR_NODE_URL_WEB3: { - envName: 'MIRROR_NODE_URL_WEB3', - type: 'string', - required: false, - defaultValue: null, - }, - MULTI_SET: { - envName: 'MULTI_SET', - type: 'boolean', - required: false, - defaultValue: null, - }, - // the actual env var in the node process is npm_package_version - npm_package_version: { - envName: 'npm_package_version', - type: 'string', - required: true, - defaultValue: null, - }, - OPERATOR_ID_ETH_SENDRAWTRANSACTION: { - envName: 'OPERATOR_ID_ETH_SENDRAWTRANSACTION', - type: 'string', - required: false, - defaultValue: null, - }, - OPERATOR_ID_MAIN: { - envName: 'OPERATOR_ID_MAIN', - type: 'string', - required: true, - defaultValue: null, - }, - OPERATOR_KEY_ETH_SENDRAWTRANSACTION: { - envName: 'OPERATOR_KEY_ETH_SENDRAWTRANSACTION', - type: 'string', - required: false, - defaultValue: null, - }, - OPERATOR_KEY_FORMAT: { - envName: 'OPERATOR_KEY_FORMAT', - type: 'string', - required: false, - defaultValue: null, - }, - OPERATOR_KEY_MAIN: { - envName: 'OPERATOR_KEY_MAIN', - type: 'string', - required: true, - defaultValue: null, - }, - RATE_LIMIT_DISABLED: { - envName: 'RATE_LIMIT_DISABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - REDIS_ENABLED: { - envName: 'REDIS_ENABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - REDIS_RECONNECT_DELAY_MS: { - envName: 'REDIS_RECONNECT_DELAY_MS', - type: 'number', - required: false, - defaultValue: null, - }, - REDIS_URL: { - envName: 'REDIS_URL', - type: 'string', - required: false, - defaultValue: 'redis://127.0.0.1:6379', - }, - REQUEST_ID_IS_OPTIONAL: { - envName: 'REQUEST_ID_IS_OPTIONAL', - type: 'boolean', - required: false, - defaultValue: null, - }, - SDK_REQUEST_TIMEOUT: { - envName: 'SDK_REQUEST_TIMEOUT', - type: 'number', - required: false, - defaultValue: null, - }, - SEND_RAW_TRANSACTION_SIZE_LIMIT: { - envName: 'SEND_RAW_TRANSACTION_SIZE_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - SERVER_HOST: { - envName: 'SERVER_HOST', - type: 'string', - required: false, - defaultValue: null, - }, - SERVER_PORT: { - envName: 'SERVER_PORT', - type: 'number', - required: false, - defaultValue: 7546, - }, - SERVER_REQUEST_TIMEOUT_MS: { - envName: 'SERVER_REQUEST_TIMEOUT_MS', - type: 'number', - required: false, - defaultValue: null, - }, - SUBSCRIPTIONS_ENABLED: { - envName: 'SUBSCRIPTIONS_ENABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - TEST: { - envName: 'TEST', - type: 'boolean', - required: false, - defaultValue: null, - }, - TEST_GAS_PRICE_DEVIATION: { - envName: 'TEST_GAS_PRICE_DEVIATION', - type: 'number', - required: false, - defaultValue: null, - }, - TEST_INITIAL_ACCOUNT_STARTING_BALANCE: { - envName: 'TEST_INITIAL_ACCOUNT_STARTING_BALANCE', - type: 'number', - required: false, - defaultValue: null, - }, - TEST_TRANSACTION_RECORD_COST_TOLERANCE: { - envName: 'TEST_TRANSACTION_RECORD_COST_TOLERANCE', - type: 'number', - required: false, - defaultValue: null, - }, - TEST_WS_SERVER: { - envName: 'TEST_WS_SERVER', - type: 'boolean', - required: false, - defaultValue: null, - }, - TIER_1_RATE_LIMIT: { - envName: 'TIER_1_RATE_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - TIER_2_RATE_LIMIT: { - envName: 'TIER_2_RATE_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - TIER_3_RATE_LIMIT: { - envName: 'TIER_3_RATE_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - TX_DEFAULT_GAS: { - envName: 'TX_DEFAULT_GAS', - type: 'number', - required: false, - defaultValue: null, - }, - USE_ASYNC_TX_PROCESSING: { - envName: 'USE_ASYNC_TX_PROCESSING', - type: 'boolean', - required: false, - defaultValue: false, - }, - WEB_SOCKET_HTTP_PORT: { - envName: 'WEB_SOCKET_HTTP_PORT', - type: 'number', - required: false, - defaultValue: 8547, - }, - WEB_SOCKET_PORT: { - envName: 'WEB_SOCKET_PORT', - type: 'number', - required: false, - defaultValue: 8546, - }, - WRITE_SNAPSHOT_ON_MEMORY_LEAK: { - envName: 'WRITE_SNAPSHOT_ON_MEMORY_LEAK', - type: 'boolean', - required: false, - defaultValue: null, - }, - WS_BATCH_REQUESTS_ENABLED: { - envName: 'WS_BATCH_REQUESTS_ENABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - WS_BATCH_REQUESTS_MAX_SIZE: { - envName: 'WS_BATCH_REQUESTS_MAX_SIZE', - type: 'number', - required: false, - defaultValue: null, - }, - WS_CACHE_TTL: { - envName: 'WS_CACHE_TTL', - type: 'number', - required: false, - defaultValue: null, - }, - WS_CONNECTION_LIMIT: { - envName: 'WS_CONNECTION_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, - WS_CONNECTION_LIMIT_PER_IP: { - envName: 'WS_CONNECTION_LIMIT_PER_IP', - type: 'number', - required: false, - defaultValue: null, - }, - WS_MAX_INACTIVITY_TTL: { - envName: 'WS_MAX_INACTIVITY_TTL', - type: 'number', - required: false, - defaultValue: null, - }, - WS_MULTIPLE_ADDRESSES_ENABLED: { - envName: 'WS_MULTIPLE_ADDRESSES_ENABLED', - type: 'boolean', - required: false, - defaultValue: null, - }, - WS_NEW_HEADS_ENABLED: { - envName: 'WS_NEW_HEADS_ENABLED', - type: 'boolean', - required: false, - defaultValue: true, - }, - WS_PING_INTERVAL: { - envName: 'WS_PING_INTERVAL', - type: 'number', - required: false, - defaultValue: null, - }, - WS_POLLING_INTERVAL: { - envName: 'WS_POLLING_INTERVAL', - type: 'number', - required: false, - defaultValue: null, - }, - WS_RELAY_URL: { - envName: 'WS_RELAY_URL', - type: 'string', - required: false, - defaultValue: 'ws://127.0.0.1:8546', - }, - WS_SAME_SUB_FOR_SAME_EVENT: { - envName: 'WS_SAME_SUB_FOR_SAME_EVENT', - type: 'boolean', - required: false, - defaultValue: null, - }, - WS_SUBSCRIPTION_LIMIT: { - envName: 'WS_SUBSCRIPTION_LIMIT', - type: 'number', - required: false, - defaultValue: null, - }, -} as const satisfies { [key: string]: ConfigProperty }; + BATCH_REQUESTS_ENABLED: { + envName: 'BATCH_REQUESTS_ENABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + BATCH_REQUESTS_MAX_SIZE: { + envName: 'BATCH_REQUESTS_MAX_SIZE', + type: 'number', + required: false, + defaultValue: null, + }, + CACHE_MAX: { + envName: 'CACHE_MAX', + type: 'number', + required: false, + defaultValue: null, + }, + CACHE_TTL: { + envName: 'CACHE_TTL', + type: 'number', + required: false, + defaultValue: null, + }, + CHAIN_ID: { + envName: 'CHAIN_ID', + type: 'string', + required: true, + defaultValue: null, + }, + CLIENT_TRANSPORT_SECURITY: { + envName: 'CLIENT_TRANSPORT_SECURITY', + type: 'boolean', + required: false, + defaultValue: null, + }, + CONSENSUS_MAX_EXECUTION_TIME: { + envName: 'CONSENSUS_MAX_EXECUTION_TIME', + type: 'number', + required: false, + defaultValue: null, + }, + CONTRACT_CALL_GAS_LIMIT: { + envName: 'CONTRACT_CALL_GAS_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + CONTRACT_QUERY_TIMEOUT_RETRIES: { + envName: 'CONTRACT_QUERY_TIMEOUT_RETRIES', + type: 'number', + required: false, + defaultValue: null, + }, + DEBUG_API_ENABLED: { + envName: 'DEBUG_API_ENABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + DEFAULT_RATE_LIMIT: { + envName: 'DEFAULT_RATE_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + DEV_MODE: { + envName: 'DEV_MODE', + type: 'boolean', + required: false, + defaultValue: null, + }, + E2E_RELAY_HOST: { + envName: 'E2E_RELAY_HOST', + type: 'string', + required: false, + defaultValue: 'http://localhost:7546', + }, + E2E_SERVER_PORT: { + envName: 'E2E_SERVER_PORT', + type: 'number', + required: false, + defaultValue: null, + }, + ESTIMATE_GAS_THROWS: { + envName: 'ESTIMATE_GAS_THROWS', + type: 'boolean', + required: false, + defaultValue: null, + }, + ETH_BLOCK_NUMBER_CACHE_TTL_MS: { + envName: 'ETH_BLOCK_NUMBER_CACHE_TTL_MS', + type: 'number', + required: false, + defaultValue: null, + }, + ETH_CALL_ACCEPTED_ERRORS: { + envName: 'ETH_CALL_ACCEPTED_ERRORS', + type: 'array', + required: false, + defaultValue: null, + }, + ETH_CALL_CACHE_TTL: { + envName: 'ETH_CALL_CACHE_TTL', + type: 'number', + required: false, + defaultValue: null, + }, + ETH_CALL_CONSENSUS_SELECTORS: { + envName: 'ETH_CALL_CONSENSUS_SELECTORS', + type: 'array', + required: false, + defaultValue: null, + }, + ETH_CALL_DEFAULT_TO_CONSENSUS_NODE: { + envName: 'ETH_CALL_DEFAULT_TO_CONSENSUS_NODE', + type: 'boolean', + required: false, + defaultValue: null, + }, + ETH_FEE_HISTORY_FIXED: { + envName: 'ETH_FEE_HISTORY_FIXED', + type: 'boolean', + required: false, + defaultValue: null, + }, + ETH_GET_BALANCE_CACHE_TTL_MS: { + envName: 'ETH_GET_BALANCE_CACHE_TTL_MS', + type: 'number', + required: false, + defaultValue: null, + }, + ETH_GET_GAS_PRICE_CACHE_TTL_MS: { + envName: 'ETH_GET_GAS_PRICE_CACHE_TTL_MS', + type: 'number', + required: false, + defaultValue: null, + }, + ETH_GET_LOGS_BLOCK_RANGE_LIMIT: { + envName: 'ETH_GET_LOGS_BLOCK_RANGE_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + ETH_GET_TRANSACTION_COUNT_CACHE_TTL: { + envName: 'ETH_GET_TRANSACTION_COUNT_CACHE_TTL', + type: 'number', + required: false, + defaultValue: null, + }, + ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE: { + envName: 'ETH_GET_TRANSACTION_COUNT_MAX_BLOCK_RANGE', + type: 'number', + required: false, + defaultValue: null, + }, + HEDERA_SPECIFIC_REVERT_STATUSES: { + envName: 'HEDERA_SPECIFIC_REVERT_STATUSES', + type: 'string', + required: false, + defaultValue: '["WRONG_NONCE", "INVALID_ACCOUNT_ID"]', + }, + FEE_HISTORY_MAX_RESULTS: { + envName: 'FEE_HISTORY_MAX_RESULTS', + type: 'number', + required: false, + defaultValue: null, + }, + FILE_APPEND_CHUNK_SIZE: { + envName: 'FILE_APPEND_CHUNK_SIZE', + type: 'number', + required: false, + defaultValue: null, + }, + FILE_APPEND_MAX_CHUNKS: { + envName: 'FILE_APPEND_MAX_CHUNKS', + type: 'number', + required: false, + defaultValue: null, + }, + FILTER_API_ENABLED: { + envName: 'FILTER_API_ENABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + FILTER_TTL: { + envName: 'FILTER_TTL', + type: 'number', + required: false, + defaultValue: null, + }, + GAS_PRICE_PERCENTAGE_BUFFER: { + envName: 'GAS_PRICE_PERCENTAGE_BUFFER', + type: 'number', + required: false, + defaultValue: null, + }, + GAS_PRICE_TINY_BAR_BUFFER: { + envName: 'GAS_PRICE_TINY_BAR_BUFFER', + type: 'number', + required: false, + defaultValue: null, + }, + GET_RECORD_DEFAULT_TO_CONSENSUS_NODE: { + envName: 'GET_RECORD_DEFAULT_TO_CONSENSUS_NODE', + type: 'boolean', + required: false, + defaultValue: null, + }, + GH_ACCESS_TOKEN: { + envName: 'GH_ACCESS_TOKEN', + type: 'string', + required: false, + defaultValue: null, + }, + GITHUB_PR_NUMBER: { + envName: 'GITHUB_PR_NUMBER', + type: 'string', + required: false, + defaultValue: null, + }, + GITHUB_REPOSITORY: { + envName: 'GITHUB_REPOSITORY', + type: 'string', + required: false, + defaultValue: null, + }, + GITHUB_TOKEN: { + envName: 'GITHUB_TOKEN', + type: 'string', + required: false, + defaultValue: null, + }, + HAPI_CLIENT_DURATION_RESET: { + envName: 'HAPI_CLIENT_DURATION_RESET', + type: 'number', + required: false, + defaultValue: null, + }, + HAPI_CLIENT_ERROR_RESET: { + envName: 'HAPI_CLIENT_ERROR_RESET', + type: 'array', + required: false, + defaultValue: null, + }, + HAPI_CLIENT_TRANSACTION_RESET: { + envName: 'HAPI_CLIENT_TRANSACTION_RESET', + type: 'number', + required: false, + defaultValue: null, + }, + HBAR_RATE_LIMIT_BASIC: { + envName: 'HBAR_RATE_LIMIT_BASIC', + type: 'number', + required: false, + defaultValue: 1_120_000_000, // 11.2 hbar + }, + HBAR_RATE_LIMIT_EXTENDED: { + envName: 'HBAR_RATE_LIMIT_EXTENDED', + type: 'number', + required: false, + defaultValue: 3_200_000_000, // 32 hbar + }, + HBAR_RATE_LIMIT_PRIVILEGED: { + envName: 'HBAR_RATE_LIMIT_PRIVILEGED', + type: 'number', + required: false, + defaultValue: 8_000_000_000, // 80 hbar + }, + HBAR_RATE_LIMIT_DURATION: { + envName: 'HBAR_RATE_LIMIT_DURATION', + type: 'number', + required: false, + defaultValue: 86_400_000, // 24 hours + }, + HBAR_RATE_LIMIT_TINYBAR: { + envName: 'HBAR_RATE_LIMIT_TINYBAR', + type: 'number', + required: false, + defaultValue: 800_000_000_000, // 8000 hbar + }, + HEDERA_NETWORK: { + envName: 'HEDERA_NETWORK', + type: 'string', + required: true, + defaultValue: null, + }, + HBAR_SPENDING_PLANS_CONFIG: { + envName: 'HBAR_SPENDING_PLANS_CONFIG', + type: 'string', + required: false, + defaultValue: 'spendingPlansConfig.json', + }, + INITIAL_BALANCE: { + envName: 'INITIAL_BALANCE', + type: 'number', + required: false, + defaultValue: null, + }, + INPUT_SIZE_LIMIT: { + envName: 'INPUT_SIZE_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + LIMIT_DURATION: { + envName: 'LIMIT_DURATION', + type: 'number', + required: false, + defaultValue: null, + }, + LOCAL_NODE: { + envName: 'LOCAL_NODE', + type: 'boolean', + required: false, + defaultValue: null, + }, + LOG_LEVEL: { + envName: 'LOG_LEVEL', + type: 'string', + required: false, + defaultValue: null, + }, + MAX_BLOCK_RANGE: { + envName: 'MAX_BLOCK_RANGE', + type: 'number', + required: false, + defaultValue: null, + }, + MEMWATCH_ENABLED: { + envName: 'MEMWATCH_ENABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + MIRROR_NODE_AGENT_CACHEABLE_DNS: { + envName: 'MIRROR_NODE_AGENT_CACHEABLE_DNS', + type: 'boolean', + required: false, + defaultValue: null, + }, + MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX: { + envName: 'MIRROR_NODE_CONTRACT_RESULTS_LOGS_PG_MAX', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_CONTRACT_RESULTS_PG_MAX: { + envName: 'MIRROR_NODE_CONTRACT_RESULTS_PG_MAX', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_HTTP_KEEP_ALIVE: { + envName: 'MIRROR_NODE_HTTP_KEEP_ALIVE', + type: 'boolean', + required: false, + defaultValue: null, + }, + MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS: { + envName: 'MIRROR_NODE_HTTP_KEEP_ALIVE_MSECS', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_HTTP_MAX_SOCKETS: { + envName: 'MIRROR_NODE_HTTP_MAX_SOCKETS', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS: { + envName: 'MIRROR_NODE_HTTP_MAX_TOTAL_SOCKETS', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_HTTP_SOCKET_TIMEOUT: { + envName: 'MIRROR_NODE_HTTP_SOCKET_TIMEOUT', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_LIMIT_PARAM: { + envName: 'MIRROR_NODE_LIMIT_PARAM', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_MAX_REDIRECTS: { + envName: 'MIRROR_NODE_MAX_REDIRECTS', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_RETRIES: { + envName: 'MIRROR_NODE_RETRIES', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_RETRIES_DEVMODE: { + envName: 'MIRROR_NODE_RETRIES_DEVMODE', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_RETRY_CODES: { + envName: 'MIRROR_NODE_RETRY_CODES', + type: 'array', + required: false, + defaultValue: null, + }, + MIRROR_NODE_RETRY_DELAY: { + envName: 'MIRROR_NODE_RETRY_DELAY', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_RETRY_DELAY_DEVMODE: { + envName: 'MIRROR_NODE_RETRY_DELAY_DEVMODE', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_REQUEST_RETRY_COUNT: { + envName: 'MIRROR_NODE_REQUEST_RETRY_COUNT', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_TIMEOUT: { + envName: 'MIRROR_NODE_TIMEOUT', + type: 'number', + required: false, + defaultValue: null, + }, + MIRROR_NODE_URL: { + envName: 'MIRROR_NODE_URL', + type: 'string', + required: true, + defaultValue: null, + }, + MIRROR_NODE_URL_HEADER_X_API_KEY: { + envName: 'MIRROR_NODE_URL_HEADER_X_API_KEY', + type: 'array', + required: false, + defaultValue: null, + }, + MIRROR_NODE_URL_WEB3: { + envName: 'MIRROR_NODE_URL_WEB3', + type: 'string', + required: false, + defaultValue: null, + }, + MULTI_SET: { + envName: 'MULTI_SET', + type: 'boolean', + required: false, + defaultValue: null, + }, + // the actual env var in the node process is npm_package_version + npm_package_version: { + envName: 'npm_package_version', + type: 'string', + required: true, + defaultValue: null, + }, + OPERATOR_ID_ETH_SENDRAWTRANSACTION: { + envName: 'OPERATOR_ID_ETH_SENDRAWTRANSACTION', + type: 'string', + required: false, + defaultValue: null, + }, + OPERATOR_ID_MAIN: { + envName: 'OPERATOR_ID_MAIN', + type: 'string', + required: true, + defaultValue: null, + }, + OPERATOR_KEY_ETH_SENDRAWTRANSACTION: { + envName: 'OPERATOR_KEY_ETH_SENDRAWTRANSACTION', + type: 'string', + required: false, + defaultValue: null, + }, + OPERATOR_KEY_FORMAT: { + envName: 'OPERATOR_KEY_FORMAT', + type: 'string', + required: false, + defaultValue: null, + }, + OPERATOR_KEY_MAIN: { + envName: 'OPERATOR_KEY_MAIN', + type: 'string', + required: true, + defaultValue: null, + }, + RATE_LIMIT_DISABLED: { + envName: 'RATE_LIMIT_DISABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + REDIS_ENABLED: { + envName: 'REDIS_ENABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + REDIS_RECONNECT_DELAY_MS: { + envName: 'REDIS_RECONNECT_DELAY_MS', + type: 'number', + required: false, + defaultValue: null, + }, + REDIS_URL: { + envName: 'REDIS_URL', + type: 'string', + required: false, + defaultValue: 'redis://127.0.0.1:6379', + }, + REQUEST_ID_IS_OPTIONAL: { + envName: 'REQUEST_ID_IS_OPTIONAL', + type: 'boolean', + required: false, + defaultValue: null, + }, + SDK_REQUEST_TIMEOUT: { + envName: 'SDK_REQUEST_TIMEOUT', + type: 'number', + required: false, + defaultValue: null, + }, + SEND_RAW_TRANSACTION_SIZE_LIMIT: { + envName: 'SEND_RAW_TRANSACTION_SIZE_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + SERVER_HOST: { + envName: 'SERVER_HOST', + type: 'string', + required: false, + defaultValue: null, + }, + SERVER_PORT: { + envName: 'SERVER_PORT', + type: 'number', + required: false, + defaultValue: 7546, + }, + SERVER_REQUEST_TIMEOUT_MS: { + envName: 'SERVER_REQUEST_TIMEOUT_MS', + type: 'number', + required: false, + defaultValue: null, + }, + SUBSCRIPTIONS_ENABLED: { + envName: 'SUBSCRIPTIONS_ENABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + TEST: { + envName: 'TEST', + type: 'boolean', + required: false, + defaultValue: null, + }, + TEST_GAS_PRICE_DEVIATION: { + envName: 'TEST_GAS_PRICE_DEVIATION', + type: 'number', + required: false, + defaultValue: null, + }, + TEST_INITIAL_ACCOUNT_STARTING_BALANCE: { + envName: 'TEST_INITIAL_ACCOUNT_STARTING_BALANCE', + type: 'number', + required: false, + defaultValue: null, + }, + TEST_TRANSACTION_RECORD_COST_TOLERANCE: { + envName: 'TEST_TRANSACTION_RECORD_COST_TOLERANCE', + type: 'number', + required: false, + defaultValue: null, + }, + TEST_WS_SERVER: { + envName: 'TEST_WS_SERVER', + type: 'boolean', + required: false, + defaultValue: null, + }, + TIER_1_RATE_LIMIT: { + envName: 'TIER_1_RATE_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + TIER_2_RATE_LIMIT: { + envName: 'TIER_2_RATE_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + TIER_3_RATE_LIMIT: { + envName: 'TIER_3_RATE_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + TX_DEFAULT_GAS: { + envName: 'TX_DEFAULT_GAS', + type: 'number', + required: false, + defaultValue: null, + }, + USE_ASYNC_TX_PROCESSING: { + envName: 'USE_ASYNC_TX_PROCESSING', + type: 'boolean', + required: false, + defaultValue: false, + }, + WEB_SOCKET_HTTP_PORT: { + envName: 'WEB_SOCKET_HTTP_PORT', + type: 'number', + required: false, + defaultValue: 8547, + }, + WEB_SOCKET_PORT: { + envName: 'WEB_SOCKET_PORT', + type: 'number', + required: false, + defaultValue: 8546, + }, + WRITE_SNAPSHOT_ON_MEMORY_LEAK: { + envName: 'WRITE_SNAPSHOT_ON_MEMORY_LEAK', + type: 'boolean', + required: false, + defaultValue: null, + }, + WS_BATCH_REQUESTS_ENABLED: { + envName: 'WS_BATCH_REQUESTS_ENABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + WS_BATCH_REQUESTS_MAX_SIZE: { + envName: 'WS_BATCH_REQUESTS_MAX_SIZE', + type: 'number', + required: false, + defaultValue: null, + }, + WS_CACHE_TTL: { + envName: 'WS_CACHE_TTL', + type: 'number', + required: false, + defaultValue: null, + }, + WS_CONNECTION_LIMIT: { + envName: 'WS_CONNECTION_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, + WS_CONNECTION_LIMIT_PER_IP: { + envName: 'WS_CONNECTION_LIMIT_PER_IP', + type: 'number', + required: false, + defaultValue: null, + }, + WS_MAX_INACTIVITY_TTL: { + envName: 'WS_MAX_INACTIVITY_TTL', + type: 'number', + required: false, + defaultValue: null, + }, + WS_MULTIPLE_ADDRESSES_ENABLED: { + envName: 'WS_MULTIPLE_ADDRESSES_ENABLED', + type: 'boolean', + required: false, + defaultValue: null, + }, + WS_NEW_HEADS_ENABLED: { + envName: 'WS_NEW_HEADS_ENABLED', + type: 'boolean', + required: false, + defaultValue: true, + }, + WS_PING_INTERVAL: { + envName: 'WS_PING_INTERVAL', + type: 'number', + required: false, + defaultValue: null, + }, + WS_POLLING_INTERVAL: { + envName: 'WS_POLLING_INTERVAL', + type: 'number', + required: false, + defaultValue: null, + }, + WS_RELAY_URL: { + envName: 'WS_RELAY_URL', + type: 'string', + required: false, + defaultValue: 'ws://127.0.0.1:8546', + }, + WS_SAME_SUB_FOR_SAME_EVENT: { + envName: 'WS_SAME_SUB_FOR_SAME_EVENT', + type: 'boolean', + required: false, + defaultValue: null, + }, + WS_SUBSCRIPTION_LIMIT: { + envName: 'WS_SUBSCRIPTION_LIMIT', + type: 'number', + required: false, + defaultValue: null, + }, +} as const satisfies { [key: string]: ConfigProperty }; // Ensures _CONFIG is read-only and conforms to the ConfigProperty structure export type ConfigKey = keyof typeof _CONFIG; diff --git a/packages/config-service/src/services/index.ts b/packages/config-service/src/services/index.ts index aa595c102c..48688ad880 100644 --- a/packages/config-service/src/services/index.ts +++ b/packages/config-service/src/services/index.ts @@ -22,7 +22,7 @@ import dotenv from 'dotenv'; import findConfig from 'find-config'; import pino from 'pino'; -import type { ConfigKey, TypeOfKey } from './globalConfig'; +import type { ConfigKey, GetTypeOfConfigKey } from './globalConfig'; import { LoggerService } from './loggerService'; import { ValidationService } from './validationService'; @@ -98,7 +98,7 @@ export class ConfigService { * @param name string * @returns string | undefined */ - public static get(name: K): TypeOfKey | undefined { - return this.getInstance().envs[name] as TypeOfKey | undefined; + public static get(name: K): GetTypeOfConfigKey | undefined { + return this.getInstance().envs[name] as GetTypeOfConfigKey | undefined; } }