From 15f86aefb56bc46719020e8b2ae251d6ba007505 Mon Sep 17 00:00:00 2001 From: Eric Badiere Date: Thu, 31 Oct 2024 13:26:26 -0600 Subject: [PATCH 1/2] fix: Capture the npm_package_version (#3198) * fix: Capture the npm_package_version Signed-off-by: ebadiere * fix: Adding npm_package_version at the root package.json file to allow test framework to load the value in the config service. Also some clean up. Signed-off-by: ebadiere * chore: Updated package-lock.json Signed-off-by: ebadiere --------- Signed-off-by: ebadiere --- package-lock.json | 2 ++ package.json | 3 ++- .../src/services/globalConfig.ts | 5 ++-- .../src/services/validationService.spec.ts | 26 +++++++++++++++++++ .../server/tests/acceptance/index.spec.ts | 3 --- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 844cc7959..d084e98e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,10 +1,12 @@ { "name": "root", + "version": "0.60.0-SNAPSHOT", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "root", + "version": "0.60.0-SNAPSHOT", "dependencies": { "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/trie": "^6.2.1", diff --git a/package.json b/package.json index f6d1eff7f..762141c36 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "root", + "version": "0.60.0-SNAPSHOT", "devDependencies": { "@hashgraph/hedera-local": "^2.31.0", "@open-rpc/schema-utils-js": "^1.16.1", @@ -45,7 +46,7 @@ "acceptancetest:api_batch1": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@api-batch-1' --exit", "acceptancetest:api_batch2": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@api-batch-2' --exit", "acceptancetest:api_batch3": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@api-batch-3' --exit", - "acceptancetest:erc20": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@erc20' --exit", + "acceptancetest:erc20": "npm_package_version=0.0.1 nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@erc20' --exit", "acceptancetest:ratelimiter": "nyc ts-mocha packages/ws-server/tests/acceptance/index.spec.ts -g '@web-socket-ratelimiter' --exit && ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@ratelimiter' --exit", "acceptancetest:hbarlimiter_batch1": "HBAR_RATE_LIMIT_BASIC=1000000000 HBAR_RATE_LIMIT_EXTENDED=1500000000 HBAR_RATE_LIMIT_PRIVILEGED=2000000000 nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@hbarlimiter-batch1' --exit", "acceptancetest:hbarlimiter_batch2": "HBAR_RATE_LIMIT_BASIC=1000000000 HBAR_RATE_LIMIT_EXTENDED=1500000000 HBAR_RATE_LIMIT_PRIVILEGED=2000000000 nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@hbarlimiter-batch2' --exit", diff --git a/packages/config-service/src/services/globalConfig.ts b/packages/config-service/src/services/globalConfig.ts index cd5dc1f4e..5f0f7c02c 100644 --- a/packages/config-service/src/services/globalConfig.ts +++ b/packages/config-service/src/services/globalConfig.ts @@ -495,10 +495,11 @@ export class GlobalConfig { required: false, defaultValue: null, }, - NPM_PACKAGE_VERSION: { + // the actual env var in the node process is npm_package_version + npm_package_version: { envName: 'npm_package_version', type: 'string', - required: false, + required: true, defaultValue: null, }, OPERATOR_ID_ETH_SENDRAWTRANSACTION: { diff --git a/packages/config-service/tests/src/services/validationService.spec.ts b/packages/config-service/tests/src/services/validationService.spec.ts index 8ea4fb79c..9fd5671ae 100644 --- a/packages/config-service/tests/src/services/validationService.spec.ts +++ b/packages/config-service/tests/src/services/validationService.spec.ts @@ -22,6 +22,7 @@ import chai, { expect } from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { GlobalConfig } from '../../../dist/services/globalConfig'; import { ValidationService } from '../../../dist/services/validationService'; +import { overrideEnvsInMochaDescribe } from '../../../../relay/tests/helpers'; chai.use(chaiAsPromised); @@ -31,6 +32,7 @@ describe('ValidationService tests', async function () { CHAIN_ID: '0x12a', HEDERA_NETWORK: '{"127.0.0.1:50211":"0.0.3"}', MIRROR_NODE_URL: 'http://127.0.0.1:5551', + npm_package_version: '1.0.0', OPERATOR_ID_MAIN: '0.0.1002', OPERATOR_KEY_MAIN: '302000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', @@ -55,6 +57,30 @@ describe('ValidationService tests', async function () { }); }); + describe('package-version', () => { + overrideEnvsInMochaDescribe({ + npm_package_version: undefined, + }); + + const mandatoryStartUpFields = { + CHAIN_ID: '0x12a', + HEDERA_NETWORK: '{"127.0.0.1:50211":"0.0.3"}', + MIRROR_NODE_URL: 'http://127.0.0.1:5551', + OPERATOR_ID_MAIN: '0.0.1002', + OPERATOR_KEY_MAIN: + '302000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + SERVER_PORT: '7546', + }; + + it('should fail fast if npm_package_version is not set', async () => { + expect(() => + ValidationService.startUp({ + ...mandatoryStartUpFields, + }), + ).to.throw('npm_package_version is a mandatory and the relay cannot operate without its value.'); + }); + }); + describe('typeCasting', () => { it('should be able to use default value for missing env if default value is set', async () => { const castedEnvs = ValidationService.typeCasting({}); diff --git a/packages/server/tests/acceptance/index.spec.ts b/packages/server/tests/acceptance/index.spec.ts index c8097bfe2..619c38822 100644 --- a/packages/server/tests/acceptance/index.spec.ts +++ b/packages/server/tests/acceptance/index.spec.ts @@ -82,9 +82,6 @@ global.relayIsLocal = RELAY_URL === LOCAL_RELAY_URL; describe('RPC Server Acceptance Tests', function () { this.timeout(240 * 1000); // 240 seconds - let relayServer; // Relay Server - let socketServer; - global.servicesNode = new ServicesClient( NETWORK, OPERATOR_ID, From 3f8a242f753174702afef83199eef8f4d16dd42d Mon Sep 17 00:00:00 2001 From: ebadiere Date: Thu, 31 Oct 2024 13:37:46 -0600 Subject: [PATCH 2/2] fix: Added the correct version to the root level package.json and rebuilt the package-lock.json. Signed-off-by: ebadiere --- package-lock.json | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index d084e98e8..6f3dadbbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "root", - "version": "0.60.0-SNAPSHOT", + "version": "0.59.0-rc2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "root", - "version": "0.60.0-SNAPSHOT", + "version": "0.59.0-rc2", "dependencies": { "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/trie": "^6.2.1", diff --git a/package.json b/package.json index 762141c36..f54027b5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "root", - "version": "0.60.0-SNAPSHOT", + "version": "0.59.0-rc2", "devDependencies": { "@hashgraph/hedera-local": "^2.31.0", "@open-rpc/schema-utils-js": "^1.16.1", @@ -46,7 +46,7 @@ "acceptancetest:api_batch1": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@api-batch-1' --exit", "acceptancetest:api_batch2": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@api-batch-2' --exit", "acceptancetest:api_batch3": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@api-batch-3' --exit", - "acceptancetest:erc20": "npm_package_version=0.0.1 nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@erc20' --exit", + "acceptancetest:erc20": "nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@erc20' --exit", "acceptancetest:ratelimiter": "nyc ts-mocha packages/ws-server/tests/acceptance/index.spec.ts -g '@web-socket-ratelimiter' --exit && ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@ratelimiter' --exit", "acceptancetest:hbarlimiter_batch1": "HBAR_RATE_LIMIT_BASIC=1000000000 HBAR_RATE_LIMIT_EXTENDED=1500000000 HBAR_RATE_LIMIT_PRIVILEGED=2000000000 nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@hbarlimiter-batch1' --exit", "acceptancetest:hbarlimiter_batch2": "HBAR_RATE_LIMIT_BASIC=1000000000 HBAR_RATE_LIMIT_EXTENDED=1500000000 HBAR_RATE_LIMIT_PRIVILEGED=2000000000 nyc ts-mocha packages/server/tests/acceptance/index.spec.ts -g '@hbarlimiter-batch2' --exit",