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

Add edge-case scenario handling in getLogLevel #209

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $ npm install -g lisk-migrator
$ lisk-migrator COMMAND
running command...
$ lisk-migrator (-v|--version|version)
lisk-migrator/2.0.0 darwin-arm64 node-v18.16.1
lisk-migrator/2.0.1 darwin-arm64 node-v18.16.1
$ lisk-migrator --help [COMMAND]
USAGE
$ lisk-migrator COMMAND
Expand All @@ -108,9 +108,9 @@ Lisk Migrator has an extensive set of unit tests. To run the tests, please insta
$ npm test
```

## Migrating from Lisk Core v3.1.0 to v4.0.0
## Migrating from Lisk Core v3.1.0 to v4.0.1

The [migration guide](./docs/migration.md) explains the transition process from Lisk Core v3.1.0 (or later) to Lisk Core v4.0.0 using Lisk Migrator v2.
The [migration guide](./docs/migration.md) explains the transition process from Lisk Core v3.1.0 (or later) to Lisk Core v4.0.1 using Lisk Migrator v2.

## Get Involved

Expand Down
4 changes: 2 additions & 2 deletions docs/migration.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Migration Guide

This section explains how to migrate a Lisk Core v3.1.0 node to Lisk Core v4.0.0 using the Lisk Migrator.
This section explains how to migrate a Lisk Core v3.1.0 node to Lisk Core v4.0.1 using the Lisk Migrator.

The Lisk Migrator CLI tool will generate a new genesis (snapshot) block for Lisk Core v4.0.0.
The Lisk Migrator CLI tool will generate a new genesis (snapshot) block for Lisk Core v4.0.1.
The new genesis block is created based on a snapshot of the existing blockchain (running on Lisk Core v3.1.0) at a pre-determined height.

Lisk Migrator automatically exports the node's Forging Status information to the file named `forgingStatus.json` under the output directory.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-migrator",
"version": "2.0.0",
"version": "2.0.1",
"description": "A command-line tool for migrating the blockchain state to the latest protocol after a hard fork",
"author": "Lisk Foundation <admin@lisk.io>, lightcurve GmbH <admin@lightcurve.io>",
"license": "Apache-2.0",
Expand Down
6 changes: 4 additions & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ export const getNetworkByNetworkID = (_networkID: string): string | Error => {

export const getLogLevel = (loggerConfig: LoggerConfig): string => {
const highestLogPriority = Math.max(
LOG_LEVEL_PRIORITY[String(loggerConfig.fileLogLevel).toUpperCase()],
LOG_LEVEL_PRIORITY[String(loggerConfig.consoleLogLevel).toUpperCase()],
LOG_LEVEL_PRIORITY[String(loggerConfig.fileLogLevel || '').toUpperCase()] ??
LOG_LEVEL_PRIORITY.INFO,
LOG_LEVEL_PRIORITY[String(loggerConfig.consoleLogLevel || '').toUpperCase()] ??
LOG_LEVEL_PRIORITY.INFO,
);

try {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from '../constants';
import { MigratorException } from './exception';

const INSTALL_LISK_CORE_COMMAND = 'npm i -g lisk-core@^4.0.0-rc.1';
const INSTALL_LISK_CORE_COMMAND = 'npm i -g lisk-core@^4.0.1';
const INSTALL_PM2_COMMAND = 'npm i -g pm2';
const PM2_FILE_NAME = 'pm2.migrator.config.json';

Expand Down Expand Up @@ -158,6 +158,9 @@ const resolveLiskCoreStartCommand = async (_this: Command, network: string, conf
let customStartCommand = baseStartCommand;

_this.log('Customizing Lisk Core start command');
_this.log(
`Kindly do not forget to include '--config ${configPath}' in your custom start command, if you still want to use this config.`,
);
let userInput = await cli.prompt(
"Please provide the Lisk Core start command flags (e.g. --api-ws), except the '--network (-n)' flag:",
);
Expand Down
38 changes: 37 additions & 1 deletion test/unit/utils/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ import { configV3, configV4 } from '../fixtures/config';
import { NETWORK_CONSTANT } from '../../../src/constants';
import {
getNetworkByNetworkID,
getLogLevel,
migrateUserConfig,
validateConfig,
writeConfig,
resolveConfigPathByNetworkID,
createBackup,
getConfig,
} from '../../../src/utils/config';
import { ApplicationConfigV3 } from '../../../src/types';
import { ApplicationConfigV3, LoggerConfig } from '../../../src/types';

const migratedConfigFilePath = join(__dirname, 'test/config');
const expectedBackupPath = join(__dirname, '../../..', 'backup');
Expand All @@ -38,6 +39,41 @@ const mockCommand = {
error,
};

describe('Test getLogLevel method', () => {
it('should return highest priority logLevel provided by user', async () => {
const loggerConfig = {
fileLogLevel: 'trace',
consoleLogLevel: 'error',
} as LoggerConfig;
const logLevel = getLogLevel(loggerConfig);
expect(logLevel).toBe('trace');
});

it('should return info when logger config is not available', async () => {
const loggerConfig = {} as LoggerConfig;
const logLevel = getLogLevel(loggerConfig);
expect(logLevel).toBe('info');
});

it('should return the highest priority log level when one of the specified logLevel is incorrect', async () => {
const loggerConfig = {
fileLogLevel: 'trace',
consoleLogLevel: 'err',
} as LoggerConfig;
const logLevel = getLogLevel(loggerConfig);
expect(logLevel).toBe('trace');
});

it('should return info if the specified valid log level is of lower priority than info and other is incorrect', async () => {
const loggerConfig = {
fileLogLevel: 'fatal',
consoleLogLevel: 'err',
} as LoggerConfig;
const logLevel = getLogLevel(loggerConfig);
expect(logLevel).toBe('info');
});
});

describe('Migrate user configuration', () => {
afterAll(() => {
fs.removeSync(migratedConfigFilePath);
Expand Down
Loading