Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
👌 Apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sameersubudhi committed Sep 29, 2023
1 parent 5e3f695 commit c836ba1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
19 changes: 5 additions & 14 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ import {
} from '../constants';
import { resolveAbsolutePath } from './fs';

export const NETWORKS = Object.freeze([
{
name: 'mainnet',
networkID: '4c09e6a781fc4c7bdb936ee815de8f94190f8a7519becd9de2081832be309a99',
},
{
name: 'testnet',
networkID: '15f0dacc1060e91818224a94286b13aa04279c640bd5d6f193182031d133df7c',
},
]);

const LOG_LEVEL_PRIORITY = Object.freeze({
FATAL: 0,
ERROR: 1,
Expand All @@ -52,8 +41,10 @@ const LOG_LEVEL_PRIORITY = Object.freeze({
}) as Record<string, number>;

export const getNetworkByNetworkID = (_networkID: string): string | Error => {
const networkInfo = NETWORKS.find(info => info.networkID === _networkID);
if (!networkInfo) throw new Error('Migrator running against unsupported network.');
const networkInfo = NETWORK_CONSTANT[_networkID];
if (!networkInfo) {
throw new Error('Migrator running against unidentified network. Cannot proceed.');
}
return networkInfo.name;
};

Expand All @@ -80,7 +71,7 @@ export const getConfig = async (
_networkID: string,
customConfigPath?: string,
): Promise<ApplicationConfigV3> => {
let network: String | Error = 'mainnet';
let network: string | Error = 'mainnet';
try {
network = getNetworkByNetworkID(_networkID);
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/genesis_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import { GenesisAssetEntry } from '../types';
import { execAsync } from './process';
import { copyFile } from './fs';

/* eslint-disable func-names, @typescript-eslint/no-explicit-any */
(BigInt.prototype as any).toJSON = function () {
return this.toString();
};
(Buffer.prototype as any).toJSON = function () {
return this.toString('hex');
};
/* eslint-enable func-names, @typescript-eslint/no-explicit-any */

export const createChecksum = async (filePath: string): Promise<string> => {
const fileStream = fs.createReadStream(filePath);
Expand Down
12 changes: 6 additions & 6 deletions test/unit/utils/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import * as fs from 'fs-extra';
import { resolve, join } from 'path';
import { ApplicationConfig } from 'lisk-framework';
import { configV3, configV4 } from '../fixtures/config';
import { NETWORK_CONSTANT } from '../../../src/constants';
import {
NETWORKS,
getNetworkByNetworkID,
migrateUserConfig,
validateConfig,
Expand Down Expand Up @@ -62,15 +62,15 @@ describe('Migrate user configuration', () => {

describe('Test networkIdentifier method', () => {
it('should determine network correctly by networkIdentifier', async () => {
NETWORKS.forEach(networkInfo => {
const network = getNetworkByNetworkID(networkInfo.networkID);
expect(network).toBe(networkInfo.name);
Object.keys(NETWORK_CONSTANT).forEach(networkID => {
const network = getNetworkByNetworkID(networkID);
expect(network).toBe(NETWORK_CONSTANT[networkID].name);
});
});

it('should throw error with unknown networkIdentifier', async () => {
expect(() => getNetworkByNetworkID('unknown network identifier')).toThrowError(
'Migrator running against unsupported network.',
expect(() => getNetworkByNetworkID('unknown network identifier')).toThrow(
'Migrator running against unidentified network. Cannot proceed.',
);
});
});
Expand Down

0 comments on commit c836ba1

Please sign in to comment.