diff --git a/package-lock.json b/package-lock.json index 4242952b..148dfd82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@hashgraph/hedera-local", - "version": "2.25.3", + "version": "2.26.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@hashgraph/hedera-local", - "version": "2.25.3", + "version": "2.26.0", "license": "Apache-2.0", "dependencies": { "@hashgraph/sdk": "^2.43.0", @@ -9069,4 +9069,4 @@ } } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 02c4748a..d9a632ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hashgraph/hedera-local", - "version": "2.25.3", + "version": "2.26.0", "description": "Developer tooling for running Local Hedera Network (Consensus + Mirror Nodes).", "main": "index.ts", "scripts": { diff --git a/src/configuration/local.json b/src/configuration/local.json index 2b4ad927..f40afea3 100644 --- a/src/configuration/local.json +++ b/src/configuration/local.json @@ -1,9 +1,9 @@ { "imageTagConfiguration": [ - {"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.50.0"}, - {"key": "HAVEGED_IMAGE_TAG", "value": "0.50.0"}, - {"key": "MIRROR_IMAGE_TAG", "value": "0.104.0"}, - {"key": "RELAY_IMAGE_TAG", "value": "0.47.0"}, + {"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.51.0-alpha.3"}, + {"key": "HAVEGED_IMAGE_TAG", "value": "0.51.0-alpha.3"}, + {"key": "MIRROR_IMAGE_TAG", "value": "0.106.1"}, + {"key": "RELAY_IMAGE_TAG", "value": "0.48.1"}, {"key": "MIRROR_NODE_EXPLORER_IMAGE_TAG", "value": "24.4.0"} ], "envConfiguration": [ diff --git a/src/configuration/mainnet.json b/src/configuration/mainnet.json index 61b9fb4b..63041d90 100644 --- a/src/configuration/mainnet.json +++ b/src/configuration/mainnet.json @@ -2,8 +2,8 @@ "imageTagConfiguration": [ {"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.49.7"}, {"key": "HAVEGED_IMAGE_TAG", "value": "0.49.7"}, - {"key": "MIRROR_IMAGE_TAG", "value": "0.104.0"}, - {"key": "RELAY_IMAGE_TAG", "value": "0.47.0"}, + {"key": "MIRROR_IMAGE_TAG", "value": "0.105.0"}, + {"key": "RELAY_IMAGE_TAG", "value": "0.48.1"}, {"key": "MIRROR_NODE_EXPLORER_IMAGE_TAG", "value": "24.4.0"} ], "nodeConfiguration": { diff --git a/src/configuration/previewnet.json b/src/configuration/previewnet.json index ad1a2ff0..5aa42aba 100644 --- a/src/configuration/previewnet.json +++ b/src/configuration/previewnet.json @@ -1,9 +1,9 @@ { "imageTagConfiguration": [ - {"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.50.0-alpha.1"}, - {"key": "HAVEGED_IMAGE_TAG", "value": "0.50.0-alpha.1"}, - {"key": "MIRROR_IMAGE_TAG", "value": "0.105.0-rc2"}, - {"key": "RELAY_IMAGE_TAG", "value": "0.48.0-rc2"}, + {"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.51.0-alpha.3"}, + {"key": "HAVEGED_IMAGE_TAG", "value": "0.51.0-alpha.3"}, + {"key": "MIRROR_IMAGE_TAG", "value": "0.106.1"}, + {"key": "RELAY_IMAGE_TAG", "value": "0.48.1"}, {"key": "MIRROR_NODE_EXPLORER_IMAGE_TAG", "value": "24.4.0"} ], "nodeConfiguration": { diff --git a/src/configuration/testnet.json b/src/configuration/testnet.json index cad1a844..b1f39cba 100644 --- a/src/configuration/testnet.json +++ b/src/configuration/testnet.json @@ -2,8 +2,8 @@ "imageTagConfiguration": [ {"key": "NETWORK_NODE_IMAGE_TAG", "value": "0.49.7"}, {"key": "HAVEGED_IMAGE_TAG", "value": "0.49.7"}, - {"key": "MIRROR_IMAGE_TAG", "value": "0.104.0"}, - {"key": "RELAY_IMAGE_TAG", "value": "0.48.0-rc2"}, + {"key": "MIRROR_IMAGE_TAG", "value": "0.106.1"}, + {"key": "RELAY_IMAGE_TAG", "value": "0.48.0"}, {"key": "MIRROR_NODE_EXPLORER_IMAGE_TAG", "value": "24.4.0"} ], "nodeConfiguration": { diff --git a/src/constants.ts b/src/constants.ts index a3ae8c49..172a6171 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -71,61 +71,70 @@ export const DEBUG_COLOR = '\x1b[36m' // white export const TRACE_COLOR = '\x1b[37m' +// check success +export const CHECK_SUCCESS = `${INFO_COLOR}[✔︎]${COLOR_RESET}` +// check warn +export const CHEKC_WARN = `${WARNING_COLOR}[!]${COLOR_RESET}` +// check fail +export const CHECK_FAIL = `${ERROR_COLOR}[✘]${COLOR_RESET}` +// waiting +export const LOADING = `⏳`; + // Start State -export const START_STATE_INIT_MESSAGE = 'Start State Initialized!'; -export const START_STATE_STARTING_MESSAGE = 'Starting Hedera Local Node...'; -export const START_STATE_ON_START_MESSAGE = 'Initiating start procedure. Trying to start docker containers...'; -export const START_STATE_STARTED_DETECTING = 'Detecting network...'; -export const START_STATE_STARTED_MESSAGE = 'Hedera Local Node successfully started!'; +export const START_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Start State Initialized!`; +export const START_STATE_STARTING_MESSAGE = `${LOADING} Starting Hedera Local Node...`; +export const START_STATE_ON_START_MESSAGE = `${LOADING} Initiating start procedure. Trying to start docker containers...`; +export const START_STATE_STARTED_DETECTING = `${LOADING} Detecting network...`; +export const START_STATE_STARTED_MESSAGE = `${CHECK_SUCCESS} Hedera Local Node successfully started!`; // Stop State -export const STOP_STATE_INIT_MESSAGE = 'Stop State Initialized!'; -export const STOP_STATE_ON_START_MESSAGE = 'Initiating stop procedure. Trying to stop docker containers and clean up volumes...'; -export const STOP_STATE_STOPPING_MESSAGE = 'Stopping the network...'; -export const STOP_STATE_STOPPED_MESSAGE = 'Hedera Local Node was stopped successfully.'; +export const STOP_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Stop State Initialized!`; +export const STOP_STATE_ON_START_MESSAGE = `${LOADING} Initiating stop procedure. Trying to stop docker containers and clean up volumes...`; +export const STOP_STATE_STOPPING_MESSAGE = `${LOADING} Stopping the network...`; +export const STOP_STATE_STOPPED_MESSAGE = `${CHECK_SUCCESS} Hedera Local Node was stopped successfully.`; // Docker commands -export const DOCKER_STOPPING_CONTAINERS_MESSAGE = 'Stopping the docker containers...'; -export const DOCKER_CLEANING_VALUMES_MESSAGE = 'Cleaning the volumes and temp files...'; +export const DOCKER_STOPPING_CONTAINERS_MESSAGE = `${LOADING} Stopping the docker containers...`; +export const DOCKER_CLEANING_VALUMES_MESSAGE = `${LOADING} Cleaning the volumes and temp files...`; // Recovery state -export const RECOVERY_STATE_INIT_MESSAGE = 'Recovery State Initialized!'; -export const RECOVERY_STATE_STARTING_MESSAGE = "Starting Recovery State..."; +export const RECOVERY_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Recovery State Initialized!`; +export const RECOVERY_STATE_STARTING_MESSAGE = `${LOADING} Starting Recovery State...`; // Network Prep State -export const NETWORK_PREP_STATE_INIT_MESSAGE = 'Network Preparation State Initialized!' -export const NETWORK_PREP_STATE_STARTING_MESSAGE = 'Starting Network Preparation State...'; -export const NETWORK_PREP_STATE_IMPORT_FEES_START = 'Starting Fees import...'; -export const NETWORK_PREP_STATE_IMPORT_FEES_END = 'Imported fees successfully'; -export const NETWORK_PREP_STATE_WAITING_TOPIC_CREATION = 'Waiting for topic creation...'; -export const NETWORK_PREP_STATE_TOPIC_CREATED = 'Topic was created!'; +export const NETWORK_PREP_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Network Preparation State Initialized!`; +export const NETWORK_PREP_STATE_STARTING_MESSAGE = `${LOADING} Starting Network Preparation State...`; +export const NETWORK_PREP_STATE_IMPORT_FEES_START = `${LOADING} Starting Fees import...`; +export const NETWORK_PREP_STATE_IMPORT_FEES_END = `${CHECK_SUCCESS} Imported fees successfully!`; +export const NETWORK_PREP_STATE_WAITING_TOPIC_CREATION = `${LOADING} Waiting for topic creation...`; +export const NETWORK_PREP_STATE_TOPIC_CREATED = `${CHECK_SUCCESS} Topic was created!`; // Init state -export const INIT_STATE_INIT_MESSAGE = 'Initialization State Initialized!'; -export const INIT_STATE_STARTING_MESSAGE = 'Initialization State Starting...'; -export const INIT_STATE_START_DOCKER_CHECK = "Making sure that Docker is started and it's correct version..."; -export const INIT_STATE_CONFIGURING_ENV_VARIABLES_FINISH = 'Needed environment variables were set for this configuration.'; -export const INIT_STATE_RELAY_LIMITS_DISABLED = 'Hedera JSON-RPC Relay rate limits were disabled.'; -export const INIT_STATE_BOOTSTRAPPED_PROP_SET = 'Needed bootsrap properties were set for this configuration.'; -export const INIT_STATE_MIRROR_PROP_SET = 'Needed mirror node properties were set for this configuration.'; -export const INIT_STATE_NO_NODE_CONF_NEEDED = 'No additional node configuration needed.'; -export const INIT_STATE_NO_ENV_VAR_CONFIGURED = 'No new environment variables were configured.'; +export const INIT_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Initialization State Initialized!`; +export const INIT_STATE_STARTING_MESSAGE = `${CHECK_SUCCESS} Initialization State Starting...`; +export const INIT_STATE_START_DOCKER_CHECK = `${LOADING} Making sure that Docker is started and it is correct version...`; +export const INIT_STATE_CONFIGURING_ENV_VARIABLES_FINISH = `${CHECK_SUCCESS} Needed environment variables were set for this configuration.`; +export const INIT_STATE_RELAY_LIMITS_DISABLED = `${CHECK_SUCCESS} Hedera JSON-RPC Relay rate limits were disabled.`; +export const INIT_STATE_BOOTSTRAPPED_PROP_SET = `${CHECK_SUCCESS} Needed bootsrap properties were set for this configuration.`; +export const INIT_STATE_MIRROR_PROP_SET = `${CHECK_SUCCESS} Needed mirror node properties were set for this configuration.`; +export const INIT_STATE_NO_NODE_CONF_NEEDED = `${CHECK_SUCCESS} No additional node configuration needed.`; +export const INIT_STATE_NO_ENV_VAR_CONFIGURED = `${CHECK_SUCCESS} No new environment variables were configured.`; // Debug state -export const DEBUG_STATE_INIT_MESSAGE = 'Debug State Initialized!'; -export const DEBUG_STATE_STARTING_MESSAGE = 'Debug State Starting...'; -// StateController -export const STATE_CONTROLLER_MISSING_STATE_CONFIG_ERROR = 'Something is wrong with state configuration!'; +export const DEBUG_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Debug State Initialized!`; +export const DEBUG_STATE_STARTING_MESSAGE = `${LOADING} Debug State Starting...`; +// StateController +export const STATE_CONTROLLER_MISSING_STATE_CONFIG_ERROR = `${CHECK_FAIL} Something is wrong with state configuration!`; // Account Creation State - -export const ACCOUNT_CREATION_STATE_INIT_MESSAGE = 'Account Creation State Initialized!'; -export const ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE = 'Starting Account Creation state in synchronous mode '; -export const ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE ='Starting Account Creation state in asynchronous mode '; -export const ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_BLOCKLIST_MESSAGE = 'Starting Account Creation state in asynchronous mode with 1 blocklisted accounts'; +export const ACCOUNT_CREATION_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Account Creation State Initialized!`; +export const ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE = `${LOADING} Starting Account Creation state in synchronous mode...`; +export const ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE = `${LOADING} Starting Account Creation state in asynchronous mode...`; +export const ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_BLOCKLIST_MESSAGE = `${LOADING} Starting Account Creation state in asynchronous mode with 1 blocklisted accounts...`; +export const ACCOUNT_CREATION_FINISHED = `${CHECK_SUCCESS} Accounts created succefully!`; // Resource Creation State -export const RESOURCE_CREATION_STATE_INIT_MESSAGE = 'Resource Creation State Initialized!'; -export const RESOURCE_CREATION_STARTING_SYNCHRONOUS_MESSAGE = 'Starting Resource Creation state in synchronous mode'; -export const RESOURCE_CREATION_STARTING_ASYNCHRONOUS_MESSAGE ='Starting Resource Creation state in asynchronous mode'; +export const RESOURCE_CREATION_STATE_INIT_MESSAGE = `${CHECK_SUCCESS} Resource Creation State Initialized!`; +export const RESOURCE_CREATION_STARTING_SYNCHRONOUS_MESSAGE = `${LOADING} Starting Resource Creation state in synchronous mode...`; +export const RESOURCE_CREATION_STARTING_ASYNCHRONOUS_MESSAGE = `${LOADING} Starting Resource Creation state in asynchronous mode...`; diff --git a/src/controller/StateController.ts b/src/controller/StateController.ts index bb7d92ce..c338a055 100644 --- a/src/controller/StateController.ts +++ b/src/controller/StateController.ts @@ -18,6 +18,7 @@ * */ +import { CHECK_FAIL, CHECK_SUCCESS } from '../constants'; import { StateData } from '../data/StateData'; import { LoggerService } from '../services/LoggerService'; import { ServiceLocator } from '../services/ServiceLocator'; @@ -73,8 +74,8 @@ export class StateController implements IOBserver{ this.stateConfiguration = new StateData().getSelectedStateConfiguration(stateName); this.currStateNum = 0; this.maxStateNum = 0; - this.logger.trace('State Controller Initialized!', this.controllerName); - this.logger.info(`Starting ${stateName} procedure!`, this.controllerName); + this.logger.trace(`${CHECK_SUCCESS} State Controller Initialized!`, this.controllerName); + this.logger.info(`${CHECK_SUCCESS} Starting ${stateName} procedure!`, this.controllerName); } /** @@ -84,7 +85,7 @@ export class StateController implements IOBserver{ */ public async startStateMachine() { if (!this.stateConfiguration) { - this.logger.error('Something is wrong with state configuration!', this.controllerName); + this.logger.error(`${CHECK_FAIL} Something is wrong with state configuration!`, this.controllerName); // TODO: handle error process.exit(1); } else { diff --git a/src/services/DockerService.ts b/src/services/DockerService.ts index aa2e9944..5fb1b6b8 100644 --- a/src/services/DockerService.ts +++ b/src/services/DockerService.ts @@ -24,7 +24,10 @@ import semver from'semver'; import fs from 'fs'; import { IS_WINDOWS, NECESSARY_PORTS, UNKNOWN_VERSION, OPTIONAL_PORTS, MIN_CPUS, MIN_MEMORY_MULTI_MODE, MIN_MEMORY_SINGLE_MODE, - RECOMMENDED_CPUS, RECOMMENDED_MEMORY_SINGLE_MODE } from '../constants'; + RECOMMENDED_CPUS, RECOMMENDED_MEMORY_SINGLE_MODE, + CHECK_SUCCESS, + CHECK_FAIL, + LOADING} from '../constants'; import { IService } from './IService'; import { LoggerService } from './LoggerService'; import { ServiceLocator } from './ServiceLocator'; @@ -66,7 +69,7 @@ export class DockerService implements IService{ constructor() { this.serviceName = DockerService.name; this.logger = ServiceLocator.Current.get(LoggerService.name); - this.logger.trace('Docker Service Initialized!', this.serviceName); + this.logger.trace(`${CHECK_SUCCESS} Docker Service Initialized!`, this.serviceName); const defaultSocketPath = IS_WINDOWS ? '//./pipe/docker_engine' @@ -109,11 +112,11 @@ export class DockerService implements IService{ await docker .info() .then(() => { - this.logger.trace('Docker is running.', this.serviceName); + this.logger.trace(`${CHECK_SUCCESS} Docker is running.`, this.serviceName); isRunning = true; }) .catch(() => { - this.logger.error('Docker is not running.', this.serviceName); + this.logger.error(`${CHECK_FAIL} Docker is not running.`, this.serviceName); isRunning = false; }); return isRunning; @@ -140,16 +143,16 @@ export class DockerService implements IService{ resolvedPromises.forEach((result, index) => { const port = portsToCheck[index]; if (result && OPTIONAL_PORTS.includes(port)) { - this.logger.info(`Port ${port} is in use.`, this.serviceName); + this.logger.warn(`Port ${port} is in use.`, this.serviceName); } else if (result && NECESSARY_PORTS.includes(port)) { - this.logger.error(`Port ${port} is in use.`, this.serviceName); + this.logger.error(`${CHECK_FAIL} Port ${port} is in use.`, this.serviceName); } }); const resolvedPromisesNecessaryPortsOnly = resolvedPromises.slice(0, NECESSARY_PORTS.length); if(!(resolvedPromisesNecessaryPortsOnly.every(value => value === false))) { - this.logger.error('Node cannot start properly because necessary ports are in use', this.serviceName); + this.logger.error(`${CHECK_FAIL} Node cannot start properly because necessary ports are in use!`, this.serviceName); process.exit(1); } } @@ -161,7 +164,7 @@ export class DockerService implements IService{ * @returns {Promise} - A promise that resolves to a boolean indicating whether the Docker Compose version is correct. */ public async isCorrectDockerComposeVersion (): Promise { - this.logger.info('Checking docker compose version...', this.serviceName); + this.logger.info(`${LOADING} Checking docker compose version...`, this.serviceName); // We are executing both commands because in Linux we may have docker-compose v2, so we need to check both const resultFirstCommand = await shell.exec( 'docker compose version --short', @@ -174,13 +177,13 @@ export class DockerService implements IService{ // Exit code is 127 when no docker installation is found if (resultFirstCommand.code === 127 && resultSecondCommand.code === 127) { - this.logger.error('Please install docker compose V2.', this.serviceName); + this.logger.error(`Please install docker compose V2.`, this.serviceName); } else if ( resultFirstCommand.code === 127 && resultSecondCommand.code === 0 ) { this.logger.error( - 'Looks like you have docker-compose V1, but you need docker compose V2', + `Looks like you have docker-compose V1, but you need docker compose V2!`, this.serviceName ); } else { @@ -200,7 +203,7 @@ export class DockerService implements IService{ } public async checkDockerResources(isMultiNodeMode: boolean) { - this.logger.info('Checking docker resources...', this.serviceName); + this.logger.info(`${LOADING} Checking docker resources...`, this.serviceName); const resultDockerInfoCommand = await shell.exec( "docker system info --format='{{json .}}'", { silent: true } @@ -389,6 +392,6 @@ export class DockerService implements IService{ this.logger.trace('Cleaning the volumes and temp files...', stateName); shell.exec(`rm -rf network-logs/* >${nullOutput} 2>&1`); shell.exec(`docker network prune -f 2>${nullOutput}`); - this.logger.info('Trying to startup again...', stateName); + this.logger.info(`${LOADING} Trying to startup again...`, stateName); } } diff --git a/src/services/LoggerService.ts b/src/services/LoggerService.ts index 281cae2d..65f3b5b9 100644 --- a/src/services/LoggerService.ts +++ b/src/services/LoggerService.ts @@ -21,6 +21,8 @@ import { log, screen, Widgets } from 'blessed'; import terminal from 'blessed-terminal'; import { + CHECK_FAIL, + CHEKC_WARN, COLOR_DIM, COLOR_RESET, CONSENSUS_NODE_LABEL, @@ -231,7 +233,7 @@ export class LoggerService implements IService{ if (this.verboseLevel < VerboseLevel.WARNING) { return; } - const msgToLog = LoggerService.messageCompute(msg, module, VerboseLevel.WARNING); + const msgToLog = LoggerService.messageCompute(`${CHEKC_WARN} ${msg}`, module, VerboseLevel.WARNING); this.writeToLog(msgToLog, module); } @@ -245,7 +247,7 @@ export class LoggerService implements IService{ if (this.verboseLevel < VerboseLevel.ERROR) { return; } - const msgToLog = LoggerService.messageCompute(msg, module, VerboseLevel.ERROR); + const msgToLog = LoggerService.messageCompute(`${CHECK_FAIL} ${msg}`, module, VerboseLevel.ERROR); this.writeToLog(msgToLog, module); } diff --git a/src/state/AccountCreationState.ts b/src/state/AccountCreationState.ts index 001c0c98..43925f4f 100644 --- a/src/state/AccountCreationState.ts +++ b/src/state/AccountCreationState.ts @@ -35,7 +35,7 @@ import { privateKeysECDSA, privateKeysED25519 } from '../configuration/accountConfiguration.json'; -import { EVM_ADDRESSES_BLOCKLIST_FILE_RELATIVE_PATH } from '../constants'; +import { ACCOUNT_CREATION_STATE_INIT_MESSAGE, CHECK_SUCCESS, EVM_ADDRESSES_BLOCKLIST_FILE_RELATIVE_PATH, LOADING } from '../constants'; import local from '../configuration/local.json'; import { AccountUtils } from '../utils/AccountUtils'; @@ -85,7 +85,7 @@ export class AccountCreationState implements IState { this.cliService = ServiceLocator.Current.get(CLIService.name); this.clientService = ServiceLocator.Current.get(ClientService.name); this.nodeStartup = true; - this.logger.trace('Account Creation State Initialized!', this.stateName); + this.logger.trace(ACCOUNT_CREATION_STATE_INIT_MESSAGE, this.stateName); } /** @@ -119,13 +119,14 @@ export class AccountCreationState implements IState { const mode = async ? 'asynchronous' : 'synchronous'; const blockListedMessage = blocklisting ? `with ${blocklistedAccountsCount} blocklisted accounts` : ''; this.logger.info( - `Starting Account Creation state in ${mode} mode ${blockListedMessage}`, this.stateName + `${LOADING} Starting Account Creation state in ${mode} mode ${blockListedMessage}...`, this.stateName ); const promise = this.generateAccounts(balance, accounts); if (!async) { await promise; } + this.logger.info(`${CHECK_SUCCESS} Accounts created succefully!`, this.stateName); this.observer!.update(EventType.Finish); } diff --git a/src/state/CleanUpState.ts b/src/state/CleanUpState.ts index 3f3b42f5..52617d9e 100644 --- a/src/state/CleanUpState.ts +++ b/src/state/CleanUpState.ts @@ -29,6 +29,7 @@ import { IState } from './IState'; import { CLIService } from '../services/CLIService'; import { CLIOptions } from '../types/CLIOptions'; import { EventType } from '../types/EventType'; +import { CHECK_SUCCESS, LOADING } from '../constants'; /** * The `CleanUpState` class is responsible for cleaning up and reverting unneeded changes to files. @@ -86,7 +87,7 @@ export class CleanUpState implements IState{ * @returns {Promise} */ public async onStart(): Promise { - this.logger.info('Initiating clean up procedure. Trying to revert unneeded changes to files...', this.stateName); + this.logger.info(`${LOADING} Initiating clean up procedure. Trying to revert unneeded changes to files...`, this.stateName); this.revertNodeProperties(); this.revertMirrorNodeProperties(); if (this.observer) { @@ -114,7 +115,7 @@ export class CleanUpState implements IState{ application.hedera.mirror.monitor.nodes = originalNodeConfiguration.fullNodeProperties; writeFileSync(propertiesFilePath, yaml.dump(application, { lineWidth: 256 })); - this.logger.info('Clean up of mirror node properties finished.', this.stateName); + this.logger.info(`${CHECK_SUCCESS} Clean up of mirror node properties finished.`, this.stateName); } /** @@ -138,6 +139,6 @@ export class CleanUpState implements IState{ writeFileSync(propertiesFilePath, originalProperties, { flag: 'w' }); - this.logger.info('Clean up of consensus node properties finished.', this.stateName); + this.logger.info(`${CHECK_SUCCESS} Clean up of consensus node properties finished.`, this.stateName); } } diff --git a/src/state/DebugState.ts b/src/state/DebugState.ts index 1e788d15..f6cb834f 100644 --- a/src/state/DebugState.ts +++ b/src/state/DebugState.ts @@ -27,7 +27,7 @@ import { ServiceLocator } from '../services/ServiceLocator'; import { IState } from './IState'; import { CLIService } from '../services/CLIService'; import { Errors } from '../Errors/LocalNodeErrors'; -import { RELATIVE_RECORDS_DIR_PATH, RELATIVE_TMP_DIR_PATH } from '../constants'; +import { DEBUG_STATE_INIT_MESSAGE, DEBUG_STATE_STARTING_MESSAGE, RELATIVE_RECORDS_DIR_PATH, RELATIVE_TMP_DIR_PATH } from '../constants'; /** * Represents the debug state of the Hedera Local Node. @@ -48,7 +48,7 @@ export class DebugState implements IState{ constructor() { this.stateName = DebugState.name; this.logger = ServiceLocator.Current.get(LoggerService.name); - this.logger.trace('Debug State Initialized!', this.stateName); + this.logger.trace(DEBUG_STATE_INIT_MESSAGE, this.stateName); } public subscribe(observer: IOBserver): void { @@ -72,7 +72,7 @@ export class DebugState implements IState{ try { const { timestamp, workDir } = ServiceLocator.Current.get(CLIService.name).getCurrentArgv(); // DebugState.checkForDebugMode(); - this.logger.trace('Debug State Starting...', this.stateName); + this.logger.trace(DEBUG_STATE_STARTING_MESSAGE, this.stateName); const jsTimestampNum = DebugState.getAndValidateTimestamp(timestamp); const tempDir = resolve(workDir, RELATIVE_TMP_DIR_PATH); diff --git a/src/state/InitState.ts b/src/state/InitState.ts index 570548cc..8de4823d 100644 --- a/src/state/InitState.ts +++ b/src/state/InitState.ts @@ -36,6 +36,7 @@ import originalNodeConfiguration from '../configuration/originalNodeConfiguratio import { DockerService } from '../services/DockerService'; import { APPLICATION_YML_RELATIVE_PATH, + CHECK_SUCCESS, INIT_STATE_BOOTSTRAPPED_PROP_SET, INIT_STATE_CONFIGURING_ENV_VARIABLES_FINISH, INIT_STATE_INIT_MESSAGE, @@ -45,6 +46,7 @@ import { INIT_STATE_RELAY_LIMITS_DISABLED, INIT_STATE_START_DOCKER_CHECK, INIT_STATE_STARTING_MESSAGE, + LOADING, NECESSARY_PORTS, NETWORK_NODE_CONFIG_DIR_PATH, OPTIONAL_PORTS, @@ -125,7 +127,7 @@ export class InitState implements IState{ await this.dockerService.isPortInUse(NECESSARY_PORTS.concat(OPTIONAL_PORTS)); - this.logger.info(`Setting configuration for ${this.cliOptions.network} network with latest images on host ${this.cliOptions.host} with dev mode turned ${this.cliOptions.devMode ? 'on' : 'off'} using ${this.cliOptions.fullMode? 'full': 'turbo'} mode in ${this.cliOptions.multiNode? 'multi' : 'single'} node configuration...`, this.stateName); + this.logger.info(`${LOADING} Setting configuration for ${this.cliOptions.network} network with latest images on host ${this.cliOptions.host} with dev mode turned ${this.cliOptions.devMode ? 'on' : 'off'} using ${this.cliOptions.fullMode? 'full': 'turbo'} mode in ${this.cliOptions.multiNode? 'multi' : 'single'} node configuration...`, this.stateName); this.prepareWorkDirectory(); const workDirConfiguration = [ @@ -153,7 +155,7 @@ export class InitState implements IState{ * @returns {void} */ private prepareWorkDirectory() { - this.logger.info(`Local Node Working directory set to ${this.cliOptions.workDir}`, this.stateName); + this.logger.info(`${CHECK_SUCCESS} Local Node Working directory set to ${this.cliOptions.workDir}.`, this.stateName); FileSystemUtils.createEphemeralDirectories(this.cliOptions.workDir); const configDirSource = join(__dirname, `../../${NETWORK_NODE_CONFIG_DIR_PATH}`); const configPathMirrorNodeSource = join(__dirname, `../../${APPLICATION_YML_RELATIVE_PATH}`); diff --git a/src/state/ResourceCreationState.ts b/src/state/ResourceCreationState.ts index 7e30e5db..b40aec63 100644 --- a/src/state/ResourceCreationState.ts +++ b/src/state/ResourceCreationState.ts @@ -31,6 +31,7 @@ import { TokenUtils } from '../utils/TokenUtils'; import { ITokenProps } from '../configuration/types/ITokenProps'; import { IAccountProps } from '../configuration/types/IAccountProps'; import { AccountUtils } from '../utils/AccountUtils'; +import { LOADING, RESOURCE_CREATION_STATE_INIT_MESSAGE } from '../constants'; /** * Represents the state of resource creation. @@ -76,7 +77,7 @@ export class ResourceCreationState implements IState { this.logger = ServiceLocator.Current.get(LoggerService.name); this.cliService = ServiceLocator.Current.get(CLIService.name); this.clientService = ServiceLocator.Current.get(ClientService.name); - this.logger.trace('Resource Creation State Initialized!', this.stateName); + this.logger.trace(RESOURCE_CREATION_STATE_INIT_MESSAGE, this.stateName); } /** @@ -102,7 +103,7 @@ export class ResourceCreationState implements IState { const mode = async ? 'asynchronous' : 'synchronous'; this.logger.info( - `Starting Resource Creation state in ${mode} mode`, this.stateName); + `${LOADING} Starting Resource Creation state in ${mode} mode...`, this.stateName); const promise = this.createResources(); if (!async) { diff --git a/test/unit/states/AccountCreationState.spec.ts b/test/unit/states/AccountCreationState.spec.ts index b2d375b3..4d5c35e9 100644 --- a/test/unit/states/AccountCreationState.spec.ts +++ b/test/unit/states/AccountCreationState.spec.ts @@ -28,8 +28,6 @@ import { getTestBed } from '../testBed'; import { SinonSandbox, SinonSpy, SinonStub, SinonStubbedInstance } from 'sinon'; import { ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_BLOCKLIST_MESSAGE, - ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE, - ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE, ACCOUNT_CREATION_STATE_INIT_MESSAGE } from '../../../src/constants'; import { IOBserver } from '../../../src/controller/IObserver'; @@ -101,7 +99,7 @@ describe('AccountCreationState', () => { await accountCreationState.subscribe(observer); await accountCreationState.onStart(); - testSandbox.assert.calledWith(loggerService.info, ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE, 'AccountCreationState'); + testSandbox.assert.calledTwice(loggerService.info); testSandbox.assert.calledOnce(generateECDSAStub); testSandbox.assert.calledOnce(generateAliasECDSAStub); testSandbox.assert.calledOnce(generateED25519Stub); @@ -120,7 +118,7 @@ describe('AccountCreationState', () => { await accountCreationState.subscribe(observer); await accountCreationState.onStart(); - testSandbox.assert.calledWith(loggerService.info, ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE, 'AccountCreationState'); + testSandbox.assert.callCount(loggerService.info, 4); testSandbox.assert.calledOnce(generateECDSAStub); testSandbox.assert.calledOnce(generateAliasECDSAStub); testSandbox.assert.calledOnce(generateED25519Stub); @@ -228,7 +226,7 @@ describe('AccountCreationState', () => { await accountCreationState.subscribe(observer); await accountCreationState.onStart(); - testSandbox.assert.calledWith(loggerService.info, ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE, 'AccountCreationState'); + testSandbox.assert.callCount(loggerService.info, 8); testSandbox.assert.called(generateECDSA); testSandbox.assert.called(generateAliasECDSA); testSandbox.assert.called(generateED25519); @@ -253,7 +251,7 @@ describe('AccountCreationState', () => { await accountCreationState.subscribe(observer); await accountCreationState.onStart(); - testSandbox.assert.calledWith(loggerService.info, ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE, 'AccountCreationState'); + testSandbox.assert.callCount(loggerService.info, 10); testSandbox.assert.called(generateECDSA); testSandbox.assert.called(generateAliasECDSA); testSandbox.assert.called(generateED25519); @@ -287,6 +285,7 @@ describe('AccountCreationState', () => { generateED25519.restore(); generateAliasECDSA.restore(); privateKeySpy.restore(); + loggerService.info.resetHistory() }) it('should generate AliasECDSA accounts synchronously and log the title and divider', async () => { @@ -301,7 +300,7 @@ describe('AccountCreationState', () => { await accountCreationState.subscribe(observer); await accountCreationState.onStart(); - testSandbox.assert.calledWith(loggerService.info, ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE, 'AccountCreationState'); + testSandbox.assert.callCount(loggerService.info, 12); testSandbox.assert.called(generateAliasECDSA); testSandbox.assert.called(generateECDSA); testSandbox.assert.called(generateED25519); @@ -326,7 +325,7 @@ describe('AccountCreationState', () => { await accountCreationState.subscribe(observer); await accountCreationState.onStart(); - testSandbox.assert.calledWith(loggerService.info, ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE, 'AccountCreationState'); + testSandbox.assert.callCount(loggerService.info, 2); testSandbox.assert.called(generateAliasECDSA); testSandbox.assert.called(generateECDSA); testSandbox.assert.called(generateED25519); @@ -360,6 +359,7 @@ describe('AccountCreationState', () => { generateECDSA.restore(); generateED25519.restore(); privateKeySpy.restore(); + loggerService.info.resetHistory(); }) it('should generate ED25519 accounts synchronously and log the title and divider', async () => { @@ -374,7 +374,7 @@ describe('AccountCreationState', () => { await accountCreationState.subscribe(observer); await accountCreationState.onStart(); - testSandbox.assert.calledWith(loggerService.info, ACCOUNT_CREATION_STARTING_SYNCHRONOUS_MESSAGE, 'AccountCreationState'); + testSandbox.assert.callCount(loggerService.info, 2); testSandbox.assert.called(generateAliasECDSA); testSandbox.assert.called(generateECDSA); testSandbox.assert.called(generateED25519); @@ -399,7 +399,7 @@ describe('AccountCreationState', () => { await accountCreationState.subscribe(observer); await accountCreationState.onStart(); - testSandbox.assert.calledWith(loggerService.info, ACCOUNT_CREATION_STARTING_ASYNCHRONOUS_MESSAGE, 'AccountCreationState'); + testSandbox.assert.callCount(loggerService.info, 2); testSandbox.assert.called(generateAliasECDSA); testSandbox.assert.called(generateECDSA); testSandbox.assert.called(generateED25519); diff --git a/test/unit/states/CleanUpState.spec.ts b/test/unit/states/CleanUpState.spec.ts index 256c858b..9112ce9f 100644 --- a/test/unit/states/CleanUpState.spec.ts +++ b/test/unit/states/CleanUpState.spec.ts @@ -27,6 +27,7 @@ import fs from 'fs'; import path from 'path'; import { SinonSandbox, SinonStub, SinonStubbedInstance } from 'sinon'; import { getTestBed } from '../testBed'; +import { LOADING } from '../../../src/constants'; describe('CleanUpState', () => { let cleanUpState: CleanUpState; @@ -87,7 +88,7 @@ describe('CleanUpState', () => { // Verify that revertNodeProperties and revertMirrorNodeProperties are called expect(revertNodePropertiesStub.calledOnce).to.be.true; expect(revertMirrorNodePropertiesStub.calledOnce).to.be.true; - testSandbox.assert.calledOnceWithExactly(loggerService.info, 'Initiating clean up procedure. Trying to revert unneeded changes to files...', 'CleanUpState'); + testSandbox.assert.calledOnceWithExactly(loggerService.info, `${LOADING} Initiating clean up procedure. Trying to revert unneeded changes to files...`, 'CleanUpState'); }); it('should call observer.update with EventType.Finish', async () => { diff --git a/test/unit/states/DebugState.spec.ts b/test/unit/states/DebugState.spec.ts index ee448e47..9a81e1dd 100644 --- a/test/unit/states/DebugState.spec.ts +++ b/test/unit/states/DebugState.spec.ts @@ -65,6 +65,7 @@ describe('DebugState tests', () => { after(() => { testSandbox.resetHistory(); + loggerService.trace.resetHistory(); }); it('should initialize the Debug State', async () => { @@ -102,6 +103,7 @@ describe('DebugState tests', () => { testSandbox.assert.calledWith(shellExecStub, shellCommand); testSandbox.assert.calledTwice(loggerService.trace) + testSandbox.assert.calledWith(loggerService.trace, DEBUG_STATE_INIT_MESSAGE, DebugState.name); testSandbox.assert.calledWith(loggerService.trace, DEBUG_STATE_STARTING_MESSAGE, DebugState.name); getAndValidateTimestampSub.restore(); diff --git a/test/unit/states/InitState.spec.ts b/test/unit/states/InitState.spec.ts index 89b87deb..863eb418 100644 --- a/test/unit/states/InitState.spec.ts +++ b/test/unit/states/InitState.spec.ts @@ -25,6 +25,7 @@ import { join } from 'path'; import { SinonSandbox, SinonSpy, SinonStub, SinonStubbedInstance } from 'sinon'; import { APPLICATION_YML_RELATIVE_PATH, + CHECK_SUCCESS, INIT_STATE_BOOTSTRAPPED_PROP_SET, INIT_STATE_CONFIGURING_ENV_VARIABLES_FINISH, INIT_STATE_INIT_MESSAGE, @@ -247,7 +248,7 @@ describe('InitState tests', () => { onStartStub = testSandbox.stub(initState, 'onStart') .callsFake(() => (initState as any).prepareWorkDirectory()) await initState.onStart(); - testSandbox.assert.calledWithExactly(loggerService.info, "Local Node Working directory set to testDir", InitState.name); + testSandbox.assert.calledWithExactly(loggerService.info, `${CHECK_SUCCESS} Local Node Working directory set to testDir.`, InitState.name); testSandbox.assert.calledOnceWithExactly(createEphemeralDirectoriesStub, "testDir"); testSandbox.assert.calledOnceWithExactly(copyPathsStub, configFiles);