diff --git a/src/index.ts b/src/index.ts index 32867721..d22553bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -526,7 +526,13 @@ class LiskMigrator extends Command { commandsToExecute.push('\n', '-----------------------------------------------------', '\n'); } - await writeCommandsToExec(this, networkConstant, outputDir, commandsToExecute); + await writeCommandsToExec( + this, + networkConstant, + snapshotHeight, + outputDir, + commandsToExecute, + ); this.error( `Migrator could not finish execution successfully due to: ${ @@ -535,7 +541,7 @@ class LiskMigrator extends Command { ); } - await writeCommandsToExec(this, networkConstant, outputDir); + await writeCommandsToExec(this, networkConstant, snapshotHeight, outputDir); this.log('Successfully finished migration. Exiting!!!'); process.exit(0); diff --git a/src/utils/commands.ts b/src/utils/commands.ts index 146497ce..1877a564 100644 --- a/src/utils/commands.ts +++ b/src/utils/commands.ts @@ -21,6 +21,7 @@ import { NetworkConfigLocal } from '../types'; export const getCommandsToExecPostMigration = async ( networkConstant: NetworkConfigLocal, + snapshotHeight: number, outputDir: string, ) => { const commandsToExecute = []; @@ -44,7 +45,11 @@ export const getCommandsToExecPostMigration = async ( `lisk-core keys:create --chainid ${chainID} --output ${keysFilepath} --add-legacy`, `lisk-core keys:import --file-path ${keysFilepath}`, `lisk-core endpoint:invoke random_setHashOnion '{ "address":"${forgingStatus.lskAddress}"}'`, - `lisk-core endpoint:invoke generator_setStatus '{ "address":"${forgingStatus.lskAddress}", "height": ${forgingStatus.height}, "maxHeightGenerated": ${forgingStatus.maxHeightPreviouslyForged}, "maxHeightPrevoted": ${forgingStatus.maxHeightPrevoted} }' --pretty`, + `lisk-core endpoint:invoke generator_setStatus '{ "address":"${ + forgingStatus.lskAddress + }", "height": ${forgingStatus.height ?? snapshotHeight}, "maxHeightGenerated": ${ + forgingStatus.maxHeightPreviouslyForged ?? snapshotHeight + }, "maxHeightPrevoted": ${forgingStatus.maxHeightPrevoted ?? snapshotHeight} }' --pretty`, `lisk-core generator:enable ${forgingStatus.lskAddress} --use-status-value`, 'lisk-core transaction:create legacy registerKeys 400000 --key-derivation-path=legacy --send', ); @@ -59,12 +64,14 @@ export const getCommandsToExecPostMigration = async ( export const writeCommandsToExec = async ( _this: Command, networkConstant: NetworkConfigLocal, + snapshotHeight: number, outputDir: string, preCompletionCommands?: string[], ) => { const commandsToExecPreCompletion = preCompletionCommands ?? []; const commandsToExecPostMigration = await getCommandsToExecPostMigration( networkConstant, + snapshotHeight, outputDir, ); diff --git a/src/utils/node.ts b/src/utils/node.ts index 6d3a3fdd..abf81c9a 100644 --- a/src/utils/node.ts +++ b/src/utils/node.ts @@ -142,14 +142,14 @@ export const validateStartCommandFlags = async ( }; const resolveLiskCoreStartCommand = async (_this: Command, network: string, configPath: string) => { + const baseStartCommand = `lisk-core start --network ${network}`; + const defaultStartCommand = `${baseStartCommand} --config ${configPath}`; + const isUserConfirmed = await cli.confirm( - 'Would you like to customize the Lisk Core v4 start command? [yes/no]', + `Default start command: ${defaultStartCommand}\nWould you like to customize the Lisk Core v4 start command? [yes/no]`, ); - const baseStartCommand = `lisk-core start --network ${network}`; - if (!isUserConfirmed) { - const defaultStartCommand = `${baseStartCommand} --config ${configPath}`; liskCoreStartCommand = defaultStartCommand; return defaultStartCommand; } diff --git a/test/unit/utils/commands.spec.ts b/test/unit/utils/commands.spec.ts index fc2b0f17..073d4b96 100644 --- a/test/unit/utils/commands.spec.ts +++ b/test/unit/utils/commands.spec.ts @@ -30,14 +30,21 @@ const mockCommand = { }; describe('Test getCommandsToExecPostMigration method', () => { + const snapshotHeight = 10815; + it('should create commandsToExecute text file', async () => { const networkConstant = NETWORK_CONSTANT['4c09e6a781fc4c7bdb936ee815de8f94190f8a7519becd9de2081832be309a99']; - const commandsToExecute = await getCommandsToExecPostMigration(networkConstant, outputDir); + const commandsToExecute = await getCommandsToExecPostMigration( + networkConstant, + snapshotHeight, + outputDir, + ); await writeCommandsToExec( mockCommand as Command, networkConstant, + snapshotHeight, outputDir, commandsToExecute, );