From c7e6a08ad1cf2488806636155d7e01f6149b77f4 Mon Sep 17 00:00:00 2001 From: belloibrahv Date: Fri, 27 Dec 2024 00:21:43 +0100 Subject: [PATCH] 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 97f22779e..52b2f07db 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 3fa97b316..40f3ad374 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 422c25b46..eb57a32c3 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 94ba27bf0..02c55549c 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 20fe81abc..8d7ddf255 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 895383df1..673f30f9e 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 8e772b060..f31c989f5 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 ebe89a07e..c7bc8137b 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 e47051e17..b0cccdbf3 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 38ac11f73..d7f4f0254 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 9a471117a..222768f86 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 62c796aca..a95794b00 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 9dde70930..1b36af1cf 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 c6f4d400c..fcd270d07 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 62a9a4cd2..250cebded 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 1ec4bd1c5..4ffd9cc1e 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 6b4e59262..7b0d8f62c 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 f9fe297e0..6a6d82298 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 ccf82f5a8..a41bf3aaf 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 752c4db2b..b8997a5ea 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 b0bcd6eaa..eadc77eae 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 8e4b3a334..784bc180a 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 580cfd9e8..4e9f3b8bc 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 6f271388d..ccd8cc681 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 150f2ebe7..2d97bb7ef 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 0da3a7884..61cf3b768 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 667caaf1b..c818ef2e3 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 ad1be2905..08eda1784 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 d021e7c9b..5252ede1a 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 700e15e22..53f9ee3df 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 802d42b5b..06c213df7 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 7092f1b93..d488a47f8 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 8ee8a1b0d..ecae0bfbd 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 50e42de35..9ec3266ca 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 d32f99398..c9750f0bb 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 18b4f02a3..dd5127817 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 03b235e43..820a6f43c 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 f8411adc9..931ec7ced 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 aa6943c64..fdfa32bed 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 139a1cb82..bcdb5e552 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 2abd4429c..7bef0648a 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;