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