Skip to content

Commit

Permalink
fix: add keys test and fix check nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
eddort committed Sep 21, 2023
1 parent 3f8fbdd commit 0153260
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/app/simple-dvt-deploy.e2e-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('Simple DVT deploy', () => {
expect(operators).toHaveLength(0);
});

test('add simple-dvt node operator', async () => {
test('add simple-dvt node operator with key', async () => {
const simpleDvtState = deployState.stakingRouterData.stakingModules[1];

sdvtNodeOperator1 = await session.story('simple-dvt/add-node-operator', {
Expand All @@ -156,13 +156,21 @@ describe('Simple DVT deploy', () => {
rewardAddress: '0x' + '5'.repeat(40),
});

await session.story('simple-dvt/add-node-operator-keys', {
norAddress: simpleDvtState.stakingModuleAddress,
keysCount: 1,
keys: '0x' + '5'.repeat(96),
signatures: '0x' + '5'.repeat(192),
noId: sdvtNodeOperator1.nodeOperatorId,
});

await keysUpdateService.update();

const moduleInstance = stakingRouterService.getStakingRouterModuleImpl(simpleDvtState.type);
const keys = await moduleInstance.getKeys(simpleDvtState.stakingModuleAddress, {});
const operators = await moduleInstance.getOperators(simpleDvtState.stakingModuleAddress);

expect(keys).toHaveLength(0);
expect(keys).toHaveLength(1);
expect(operators).toHaveLength(1);
expect(operators[0].name).toBe(sdvtNodeOperator1.name);
});
Expand Down
3 changes: 2 additions & 1 deletion src/jobs/keys-update/keys-update.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ export class KeysUpdateService {
const moduleInstance = this.stakingRouterService.getStakingRouterModuleImpl(module.type);
const currNonce = await moduleInstance.getCurrentNonce(module.stakingModuleAddress, currElMeta.hash);
const moduleInStorage = await this.srModulesStorage.findOneById(module.id);
const oldNonce = moduleInStorage?.nonce;
// update staking module information
await this.srModulesStorage.upsert(module, currNonce);

// now updating decision should be here moduleInstance.update
// TODO: operators list also the same ?
if (moduleInStorage && moduleInStorage.nonce === currNonce) {
if (moduleInStorage && oldNonce === currNonce) {
// nothing changed, don't need to update
this.logger.log(
`Nonce was not changed for staking module ${moduleInStorage.id}. Don't need to update keys and operators in database`,
Expand Down

0 comments on commit 0153260

Please sign in to comment.