Skip to content

Commit

Permalink
fix: add fixes, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Amuhar committed Sep 26, 2023
1 parent 6bdb491 commit 9a22c4d
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.4.7",
"prettier": "^2.5.1",
"simple-dvt-v1": "^0.0.5",
"simple-dvt-v1": "^0.0.7",
"supertest": "^6.2.1",
"ts-jest": "^27.1.3",
"ts-loader": "^9.2.6",
Expand Down
41 changes: 39 additions & 2 deletions src/app/simple-dvt-deploy.e2e-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Simple DVT deploy', () => {
let deployState: chronix.StoryResult<'simple-dvt/deploy'>;
let reduceNOState: chronix.StoryResult<'simple-dvt/reduce-no'>;
let sdvtNodeOperator1: chronix.StoryResult<'simple-dvt/add-node-operator'>;
let dvtNodeOperator2WithoutKeys: chronix.StoryResult<'simple-dvt/set-node-operator-name'>;

let moduleRef: TestingModule;

Expand Down Expand Up @@ -203,7 +204,7 @@ describe('Simple DVT deploy', () => {
const simpleDvtState = deployState.stakingRouterData.stakingModules[1];
const srModuleAddress = convertAddressToLowerCase(simpleDvtState.stakingModuleAddress);
const moduleInstance = stakingRouterService.getStakingRouterModuleImpl(simpleDvtState.type);
const newOperator = await session.story('simple-dvt/add-node-operator', {
dvtNodeOperator2WithoutKeys = await session.story('simple-dvt/add-node-operator', {
norAddress: simpleDvtState.stakingModuleAddress,
name: 'new simple dvt operator ',
rewardAddress: '0x' + '6'.repeat(40),
Expand All @@ -215,6 +216,42 @@ describe('Simple DVT deploy', () => {

expect(currentKeys).toHaveLength(1);
expect(currentOperators).toHaveLength(2);
expect(currentOperators[1].name).toBe(newOperator.name);
expect(currentOperators[1].name).toBe(dvtNodeOperator2WithoutKeys.name);
});

test('update operator', async () => {
const simpleDvtState = deployState.stakingRouterData.stakingModules[1];
const srModuleAddress = convertAddressToLowerCase(simpleDvtState.stakingModuleAddress);
const moduleInstance = stakingRouterService.getStakingRouterModuleImpl(simpleDvtState.type);

await session.story('simple-dvt/set-node-operator-name', {
norAddress: simpleDvtState.stakingModuleAddress,
nodeOperatorId: dvtNodeOperator2WithoutKeys.nodeOperatorId,
name: 'some other name',
});

await keysUpdateService.update();

const keys1 = await moduleInstance.getKeys(srModuleAddress, {});
const operators1 = await moduleInstance.getOperators(srModuleAddress);

expect(keys1).toHaveLength(1);
expect(operators1).toHaveLength(2);
expect(operators1[1].name).toBe('some other name');

await session.story('simple-dvt/set-node-operator-reward-address', {
norAddress: simpleDvtState.stakingModuleAddress,
nodeOperatorId: dvtNodeOperator2WithoutKeys.nodeOperatorId,
rewardAddress: '0x' + '3'.repeat(40),
});

await keysUpdateService.update();

const keys2 = await moduleInstance.getKeys(srModuleAddress, {});
const operators2 = await moduleInstance.getOperators(srModuleAddress);

expect(keys2).toHaveLength(1);
expect(operators2).toHaveLength(2);
expect(operators2[1].rewardAddress).toBe('0x' + '3'.repeat(40));
});
});
2 changes: 1 addition & 1 deletion src/common/registry/fetch/operator.fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class RegistryOperatorFetchService {
return this.contract.attach(moduleAddress);
}

public async operatorsWereUpdated(
public async operatorsWereChanged(
moduleAddress: string,
fromBlockNumber: number,
toBlockNumber: number,
Expand Down
8 changes: 3 additions & 5 deletions src/common/registry/main/abstract-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ export abstract class AbstractRegistryService {
/**
*
* @param moduleAddress contract address
* @param prevBlockHash previous block number for that operators were updated
* @param currBlockHash current block number
* @returns were operators updated or not
* @returns Check if operators have been changed
*/
public async operatorsWereUpdated(
public async operatorsWereChanged(
moduleAddress: string,
fromBlockNumber: number,
toBlockNumber: number,
): Promise<boolean> {
return await this.operatorFetch.operatorsWereUpdated(moduleAddress, fromBlockNumber, toBlockNumber);
return await this.operatorFetch.operatorsWereChanged(moduleAddress, fromBlockNumber, toBlockNumber);
}

/** returns operators from the contract */
Expand Down
5 changes: 3 additions & 2 deletions src/jobs/keys-update/keys-update.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ export class KeysUpdateService {

if (prevNonce === currNonce) {
// case when prevELMeta is undefined but prevNonce === currNonce looks like invalid
// use here prevElMeta.blockNumber + 1 because operators were updated in database for prevElMeta.blockNumber block
if (
prevElMeta &&
prevElMeta.blockNumber + 1 <= currElMeta.number &&
(await moduleInstance.operatorsWereUpdated(
prevElMeta.blockNumber < currElMeta.number &&
(await moduleInstance.operatorsWereChanged(
contractModule.stakingModuleAddress,
prevElMeta.blockNumber + 1,
currElMeta.number,
Expand Down
4 changes: 2 additions & 2 deletions src/staking-router-modules/curated-module.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export class CuratedModuleService implements StakingModuleInterface {
await this.keyRegistryService.update(moduleAddress, blockHash);
}

public async operatorsWereUpdated(
public async operatorsWereChanged(
moduleAddress: string,
fromBlockNumber: number,
toBlockNumber: number,
): Promise<boolean> {
return await this.keyRegistryService.operatorsWereUpdated(moduleAddress, fromBlockNumber, toBlockNumber);
return await this.keyRegistryService.operatorsWereChanged(moduleAddress, fromBlockNumber, toBlockNumber);
}

public async updateOperators(moduleAddress: string, blockHash: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface StakingModule {
export interface StakingModuleInterface {
update(moduleAddress: string, blockHash: string): Promise<void>;

operatorsWereUpdated(moduleAddress: string, fromBlockNumber: number, toBlockNumber: number): Promise<boolean>;
operatorsWereChanged(moduleAddress: string, fromBlockNumber: number, toBlockNumber: number): Promise<boolean>;

updateOperators(moduleAddress: string, blockHash: string): Promise<void>;

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"@aragon/apps-vault" "^4.0.0"
"@aragon/os" "4.2.0"

"@aragon/apps-lido@lidofinance/aragon-apps#master":
"@aragon/apps-lido@github:lidofinance/aragon-apps#master":
version "1.0.0"
resolved "https://codeload.github.com/lidofinance/aragon-apps/tar.gz/b09834d29c0db211ddd50f50905cbeff257fc8e0"

Expand Down Expand Up @@ -11058,10 +11058,10 @@ simple-concat@^1.0.0:
resolved "https://registry.yarnpkg.com/simple-concat/-/simple-concat-1.0.1.tgz#f46976082ba35c2263f1c8ab5edfe26c41c9552f"
integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==

simple-dvt-v1@^0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/simple-dvt-v1/-/simple-dvt-v1-0.0.5.tgz#6c221ab3757931c62736117388a3db4da340589c"
integrity sha512-NEtatJ7KZFWjSyKzDD03V1wxbHXvi2oi65SVZ+LVHQNKIUO/tYIOtTRa01y6AH20wEl3hL/W68GS3+/wOLOH6g==
simple-dvt-v1@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/simple-dvt-v1/-/simple-dvt-v1-0.0.7.tgz#fb366f03a3b2aa90352c59361e0da9ef69ce0705"
integrity sha512-hEzxC7SUgJylLkUP+dtCvRGJ0N7BUULeOwR34GTdNM4HsYVHRBuonsyHgwhcQ5wof1mzTXO6l4jv3ZOSEVUbHQ==
dependencies:
"@aragon/apps-agent" "^2.1.0"
"@aragon/apps-finance" "^3.0.0"
Expand Down

0 comments on commit 9a22c4d

Please sign in to comment.