Skip to content

Commit

Permalink
fix: Capture the npm_package_version (#3198)
Browse files Browse the repository at this point in the history
* fix: Capture the npm_package_version

Signed-off-by: ebadiere <[email protected]>

* 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 <[email protected]>

* chore: Updated package-lock.json

Signed-off-by: ebadiere <[email protected]>

---------

Signed-off-by: ebadiere <[email protected]>
  • Loading branch information
ebadiere authored Oct 31, 2024
1 parent dfcb7cf commit 74a4a03
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 32 deletions.
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions packages/config-service/src/services/globalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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',
Expand All @@ -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({});
Expand Down
3 changes: 0 additions & 3 deletions packages/server/tests/acceptance/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 74a4a03

Please sign in to comment.