Skip to content

Commit

Permalink
fix: e2e connects tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eddort committed Dec 21, 2023
1 parent 91ef826 commit 05d2553
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
23 changes: 19 additions & 4 deletions src/common/registry/fetch/operator.fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,27 @@ export class RegistryOperatorFetchService {
return false;
}

/** return blockTag for finalized block, it need for testing purposes */
public getFinalizedBlockTag() {
return 'finalized';
}

/** fetches number of operators */
public async count(moduleAddress: string, overrides: CallOverrides = {}): Promise<number> {
const bigNumber = await this.getContract(moduleAddress).getNodeOperatorsCount(overrides as any);
return bigNumber.toNumber();
}

/** fetches finalized operator */
public async getFinalizedNodeOperator(moduleAddress: string, operatorIndex: number) {
const fullInfo = true;
const contract = this.getContract(moduleAddress);
const finalizedOperator = await contract.getNodeOperator(operatorIndex, fullInfo, {
blockTag: this.getFinalizedBlockTag(),
});
return finalizedOperator;
}

/** fetches one operator */
public async fetchOne(
moduleAddress: string,
Expand All @@ -75,9 +90,6 @@ export class RegistryOperatorFetchService {
const contract = this.getContract(moduleAddress);

const operator = await contract.getNodeOperator(operatorIndex, fullInfo, overrides as any);
const finalizedOperator = await contract.getNodeOperator(operatorIndex, fullInfo, {
blockTag: 'finalized',
});

const {
name,
Expand All @@ -89,7 +101,10 @@ export class RegistryOperatorFetchService {
totalDepositedValidators,
} = operator;

const { totalDepositedValidators: finalizedUsedSigningKeys } = finalizedOperator;
const { totalDepositedValidators: finalizedUsedSigningKeys } = await this.getFinalizedNodeOperator(
moduleAddress,
operatorIndex,
);

return {
index: operatorIndex,
Expand Down
13 changes: 9 additions & 4 deletions src/common/registry/test/key-registry/connect.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Test } from '@nestjs/testing';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { nullTransport, LoggerModule } from '@lido-nestjs/logger';
import { BatchProviderModule, ExtendedJsonRpcBatchProvider } from '@lido-nestjs/execution';
import { KeyRegistryModule, KeyRegistryService, RegistryStorageService } from '../../';
import { KeyRegistryModule, KeyRegistryService, RegistryOperatorFetchService, RegistryStorageService } from '../../';
import { clearDb, compareTestOperators, mikroORMConfig } from '../testing.utils';
import { operators } from '../fixtures/connect.fixture';
import { MikroORM } from '@mikro-orm/core';
Expand All @@ -14,6 +14,7 @@ dotenv.config();
describe('Registry', () => {
let registryService: KeyRegistryService;
let storageService: RegistryStorageService;
let registryOperatorFetchService: RegistryOperatorFetchService;
let mikroOrm: MikroORM;
if (!process.env.CHAIN_ID) {
console.error("CHAIN_ID wasn't provides");
Expand All @@ -24,6 +25,8 @@ describe('Registry', () => {
return { ...key, moduleAddress: address };
});

const blockHash = '0x4ef0f15a8a04a97f60a9f76ba83d27bcf98dac9635685cd05fe1d78bd6e93418';

beforeEach(async () => {
const imports = [
MikroOrmModule.forRoot(mikroORMConfig),
Expand All @@ -46,7 +49,11 @@ describe('Registry', () => {
const moduleRef = await Test.createTestingModule({ imports }).compile();
registryService = moduleRef.get(KeyRegistryService);
storageService = moduleRef.get(RegistryStorageService);
registryOperatorFetchService = moduleRef.get(RegistryOperatorFetchService);
mikroOrm = moduleRef.get(MikroORM);

jest.spyOn(registryOperatorFetchService, 'getFinalizedBlockTag').mockImplementation(() => ({ blockHash } as any));

const generator = mikroOrm.getSchemaGenerator();
await generator.updateSchema();
});
Expand All @@ -56,9 +63,7 @@ describe('Registry', () => {
await storageService.onModuleDestroy();
});

test.skip('Update', async () => {
const blockHash = '0x4ef0f15a8a04a97f60a9f76ba83d27bcf98dac9635685cd05fe1d78bd6e93418';

test('Update', async () => {
await registryService.update(address, blockHash);

await compareTestOperators(address, registryService, {
Expand Down
19 changes: 14 additions & 5 deletions src/common/registry/test/validator-registry/connect.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { MikroOrmModule } from '@mikro-orm/nestjs';
import { nullTransport, LoggerModule } from '@lido-nestjs/logger';
import { BatchProviderModule, ExtendedJsonRpcBatchProvider } from '@lido-nestjs/execution';

import { ValidatorRegistryModule, ValidatorRegistryService, RegistryStorageService } from '../../';
import {
ValidatorRegistryModule,
ValidatorRegistryService,
RegistryStorageService,
RegistryOperatorFetchService,
} from '../../';

import { clearDb, compareTestOperators, mikroORMConfig } from '../testing.utils';
import { operators } from '../fixtures/connect.fixture';
Expand All @@ -15,6 +20,7 @@ dotenv.config();

describe('Registry', () => {
let registryService: ValidatorRegistryService;
let registryOperatorFetchService: RegistryOperatorFetchService;
let mikroOrm: MikroORM;

let storageService: RegistryStorageService;
Expand All @@ -28,6 +34,8 @@ describe('Registry', () => {
return { ...key, moduleAddress: address };
});

const blockHash = '0x4ef0f15a8a04a97f60a9f76ba83d27bcf98dac9635685cd05fe1d78bd6e93418';

beforeEach(async () => {
const imports = [
MikroOrmModule.forRoot(mikroORMConfig),
Expand All @@ -50,8 +58,11 @@ describe('Registry', () => {
const moduleRef = await Test.createTestingModule({ imports }).compile();
registryService = moduleRef.get(ValidatorRegistryService);
storageService = moduleRef.get(RegistryStorageService);

registryOperatorFetchService = moduleRef.get(RegistryOperatorFetchService);
mikroOrm = moduleRef.get(MikroORM);

jest.spyOn(registryOperatorFetchService, 'getFinalizedBlockTag').mockImplementation(() => ({ blockHash } as any));

const generator = mikroOrm.getSchemaGenerator();
await generator.updateSchema();
});
Expand All @@ -62,9 +73,7 @@ describe('Registry', () => {
await storageService.onModuleDestroy();
});

test.skip('Update', async () => {
const blockHash = '0x4ef0f15a8a04a97f60a9f76ba83d27bcf98dac9635685cd05fe1d78bd6e93418';

test('Update', async () => {
await registryService.update(address, blockHash);

await compareTestOperators(address, registryService, {
Expand Down

0 comments on commit 05d2553

Please sign in to comment.