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

Commit

Permalink
Update generator status default values to snapshot height
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Nov 8, 2023
1 parent 23d7bef commit 209ea1b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: ${
Expand All @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { NetworkConfigLocal } from '../types';

export const getCommandsToExecPostMigration = async (
networkConstant: NetworkConfigLocal,
snapshotHeight: number,
outputDir: string,
) => {
const commandsToExecute = [];
Expand All @@ -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',
);
Expand All @@ -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,
);

Expand Down
9 changes: 8 additions & 1 deletion test/unit/utils/commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down

0 comments on commit 209ea1b

Please sign in to comment.