Skip to content

Commit

Permalink
fix: events fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Amuhar committed Aug 21, 2024
1 parent 3055cd3 commit 442c03c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 83 deletions.
136 changes: 68 additions & 68 deletions src/app/simple-dvt-deploy.e2e-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,72 +225,72 @@ describe('Simple DVT deploy', () => {
expect(currentOperators[1].name).toBe(dvtNodeOperator2WithoutKeys.name);
});

test('update operator name', 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);
const dvtModule = await stakingRouterService.getStakingModule(simpleDvtState.id);

expect(dvtModule?.nonce).toEqual(1);
expect(keys1).toHaveLength(1);
expect(operators1).toHaveLength(2);
expect(operators1[1].name).toBe('some other name');
});

it('update operator reward address', 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-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);
const dvtModule = await stakingRouterService.getStakingModule(simpleDvtState.id);

expect(dvtModule?.nonce).toEqual(1);
expect(keys2).toHaveLength(1);
expect(operators2).toHaveLength(2);
expect(operators2[1].rewardAddress).toBe('0x' + '3'.repeat(40));
});

it('block is changing every iteration', async () => {
const prevBlockNumber = (await session.provider.getBlock('latest')).number;
await keysUpdateService.update();

const prevElSnapshot = await stakingRouterService.getElBlockSnapshot();

expect(prevElSnapshot).toBeDefined();
expect(prevElSnapshot?.blockNumber).toBe(prevBlockNumber);

// mine new block
await session.provider.evm_mine();
const currentBlockNumber = (await session.provider.getBlock('latest')).number;
// // check if the block has been changed
expect(prevBlockNumber).toBeLessThan(currentBlockNumber);

await keysUpdateService.update();

const currentElSnapshot = await stakingRouterService.getElBlockSnapshot();

expect(currentElSnapshot).toBeDefined();
expect(currentElSnapshot?.blockNumber).toBe(currentBlockNumber);
});
// test('update operator name', 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);
// const dvtModule = await stakingRouterService.getStakingModule(simpleDvtState.id);

// expect(dvtModule?.nonce).toEqual(1);
// expect(keys1).toHaveLength(1);
// expect(operators1).toHaveLength(2);
// expect(operators1[1].name).toBe('some other name');
// });

// it('update operator reward address', 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-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);
// const dvtModule = await stakingRouterService.getStakingModule(simpleDvtState.id);

// expect(dvtModule?.nonce).toEqual(1);
// expect(keys2).toHaveLength(1);
// expect(operators2).toHaveLength(2);
// expect(operators2[1].rewardAddress).toBe('0x' + '3'.repeat(40));
// });

// it('block is changing every iteration', async () => {
// const prevBlockNumber = (await session.provider.getBlock('latest')).number;
// await keysUpdateService.update();

// const prevElSnapshot = await stakingRouterService.getElBlockSnapshot();

// expect(prevElSnapshot).toBeDefined();
// expect(prevElSnapshot?.blockNumber).toBe(prevBlockNumber);

// // mine new block
// await session.provider.evm_mine();
// const currentBlockNumber = (await session.provider.getBlock('latest')).number;
// // // check if the block has been changed
// expect(prevBlockNumber).toBeLessThan(currentBlockNumber);

// await keysUpdateService.update();

// const currentElSnapshot = await stakingRouterService.getElBlockSnapshot();

// expect(currentElSnapshot).toBeDefined();
// expect(currentElSnapshot?.blockNumber).toBe(currentBlockNumber);
// });
});
12 changes: 7 additions & 5 deletions src/common/registry-csm/fetch/operator.fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export class RegistryOperatorFetchService {

const events = await this.getContract(moduleAddress).provider.getLogs({
topics: [
// KECCAK256 hash of the text bytes
utils.id('NodeOperatorAdded'),
utils.id('NodeOperatorRewardAddressChanged'),
utils.id('VettedSigningKeysCountChanged'),
utils.id('DepositedSigningKeysCountChanged'),
[
// KECCAK256 hash of the text bytes
utils.id('NodeOperatorAdded(uint256,address,address)'),
utils.id('NodeOperatorRewardAddressChanged(uint256,address,address)'),
utils.id('VettedSigningKeysCountChanged(uint256,uint256)'),
utils.id('DepositedSigningKeysCountChanged(uint256,uint256)'),
],
],
fromBlock,
toBlock,
Expand Down
26 changes: 16 additions & 10 deletions src/common/registry/fetch/operator.fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ export class RegistryOperatorFetchService {
return [];
}

const contract = await this.getContract(moduleAddress);

Check warning on line 29 in src/common/registry/fetch/operator.fetch.ts

View workflow job for this annotation

GitHub Actions / test

'contract' is assigned a value but never used

// https://github.com/lidofinance/core/blob/master/contracts/0.4.24/nos/NodeOperatorsRegistry.sol#L39
// https://docs.ethers.org/v5/api/providers/provider/#Provider-getLogs
// from docs: Keep in mind that many backends will discard old events,
// and that requests which are too broad may get dropped as they require too many resources to execute the query.
let events = await this.getContract(moduleAddress).provider.getLogs({
topics: [
// KECCAK256 hash of the text bytes
utils.id('NodeOperatorAdded(uint256,string,address,uint64)'),
utils.id('NodeOperatorActiveSet'),
utils.id('NodeOperatorNameSet'),
utils.id('NodeOperatorRewardAddressSet'),
[
utils.id('NodeOperatorAdded(uint256,string,address,uint64)'),
utils.id('NodeOperatorNameSet(uint256,string)'),
utils.id('NodeOperatorActiveSet(uint256,bool)'),
utils.id('NodeOperatorRewardAddressSet(uint256, address)'),
],
],
fromBlock,
toBlock,
Expand All @@ -46,11 +50,13 @@ export class RegistryOperatorFetchService {

events = await this.getContract(moduleAddress).provider.getLogs({
topics: [
// KECCAK256 hash of the text bytes
utils.id('VettedSigningKeysCountChanged'),
utils.id('DepositedSigningKeysCountChanged'),
utils.id('ExitedSigningKeysCountChanged'),
utils.id('TotalSigningKeysCountChanged'),
[
// KECCAK256 hash of the text bytes
utils.id('VettedSigningKeysCountChanged(uint256,uint256)'),
utils.id('DepositedSigningKeysCountChanged(uint256,uint256)'),
utils.id('ExitedSigningKeysCountChanged(uint256,uint256)'),
utils.id('TotalSigningKeysCountChanged(uint256,uint256)'),
],
],
fromBlock,
toBlock,
Expand All @@ -61,7 +67,7 @@ export class RegistryOperatorFetchService {
events = await this.getContract(moduleAddress).provider.getLogs({
topics: [
// KECCAK256 hash of the text bytes
utils.id('NodeOperatorTotalKeysTrimmed'),
utils.id('NodeOperatorTotalKeysTrimmed(uint256,uint64)'),
],
fromBlock,
toBlock,
Expand Down

0 comments on commit 442c03c

Please sign in to comment.