Skip to content

Commit

Permalink
Merge pull request #561 from lidofinance/feat/csm/tests-on-mainnet-fork
Browse files Browse the repository at this point in the history
feat: add test for modules on network fork
  • Loading branch information
F4ever authored Jan 23, 2025
2 parents 3711651 + 039ab2b commit d984b2a
Show file tree
Hide file tree
Showing 14 changed files with 671 additions and 9 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/mainnet_fork_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Mainnet Fork Tests

on:
pull_request:
types:
- opened
- synchronize
- reopened
- edited
- closed
branches:
- main
- develop
paths:
- "src/**"

permissions:
contents: read
security-events: write

jobs:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Setup poetry
run: >
curl -sSL https://install.python-poetry.org | python - &&
echo "$POETRY_HOME/bin" >> "$GITHUB_PATH"
env:
POETRY_HOME: "/opt/poetry"
POETRY_VERSION: 1.3.2

- name: Install Python dependencies
run: |
poetry install --no-interaction --with=dev
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Mainnet Fork Tests
run: poetry run pytest -m 'fork' -n auto tests
env:
EXECUTION_CLIENT_URI: ${{ secrets.EXECUTION_CLIENT_URI }}
CONSENSUS_CLIENT_URI: ${{ secrets.CONSENSUS_CLIENT_URI }}
KEYS_API_URI: ${{ secrets.KEYS_API_URI }}
LIDO_LOCATOR_ADDRESS: "0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb"
CSM_MODULE_ADDRESS: "0xdA7dE2ECdDfccC6c3AF10108Db212ACBBf9EA83F"

2 changes: 1 addition & 1 deletion assets/HashConsensus.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ markers = [
"integration: tests with using providers",
"possible_integration: tests with using providers, but can be run using mocks",
"e2e: complex tests with using providers and real Ethereum network",
"fork: tests with using forked Ethereum network",
]
addopts = "-s -vv --pdbcls pudb.debugger:Debugger"

Expand Down
3 changes: 2 additions & 1 deletion src/modules/accounting/accounting.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ def _get_slots_elapsed_from_last_report(self, blockstamp: ReferenceBlockStamp):
if last_ref_slot:
slots_elapsed = blockstamp.ref_slot - last_ref_slot
else:
slots_elapsed = blockstamp.ref_slot - frame_config.initial_epoch * chain_conf.slots_per_epoch
# https://github.com/lidofinance/core/blob/master/contracts/0.8.9/oracle/HashConsensus.sol#L667
slots_elapsed = blockstamp.ref_slot - (frame_config.initial_epoch * chain_conf.slots_per_epoch - 1)

return slots_elapsed

Expand Down
4 changes: 1 addition & 3 deletions src/modules/csm/csm.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,7 @@ def converter(self, blockstamp: BlockStamp) -> Web3Converter:
return Web3Converter(self.get_chain_config(blockstamp), self.get_frame_config(blockstamp))

def _get_module_id(self) -> StakingModuleId:
modules: list[StakingModule] = self.w3.lido_contracts.staking_router.get_staking_modules(
self._receive_last_finalized_slot().block_hash
)
modules: list[StakingModule] = self.w3.lido_contracts.staking_router.get_staking_modules()

for mod in modules:
if mod.staking_module_address == self.w3.csm.module.address:
Expand Down
4 changes: 2 additions & 2 deletions src/modules/csm/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from src.types import EpochNumber, ValidatorIndex
from src.utils.range import sequence
from src.variables import CACHE_PATH
from src import variables

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -81,7 +81,7 @@ def commit(self) -> None:

@classmethod
def file(cls) -> Path:
return CACHE_PATH / Path("cache").with_suffix(cls.EXTENSION)
return variables.CACHE_PATH / Path("cache").with_suffix(cls.EXTENSION)

@property
def buffer(self) -> Path:
Expand Down
3 changes: 2 additions & 1 deletion src/utils/slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _get_non_missed_slot_header(
# Exception case can be when all slots are missed in range [slot, last_finalized_slot_number] it will mean that
# block response of CL node contradicts itself, because few moments ago we got existed `last_finalized_slot_number`
if slot > last_finalized_slot_number:
raise ValueError('`slot` should be less or equal `last_finalized_slot_number`')
raise ValueError(f'{slot=} should be less or equal {last_finalized_slot_number=}')

slot_is_missing = False
existing_header = None
Expand Down Expand Up @@ -106,6 +106,7 @@ def get_prev_non_missed_slot(
):
raise InconsistentData(
"Parent root next to `slot` existing header doesn't match the expected slot.\n"
f'Expected {slot=}, Got {parent_header.data.header.message.slot=}'
'Probably, a problem with the consensus node.'
)

Expand Down
Empty file added tests/fork/__init__.py
Empty file.
Loading

0 comments on commit d984b2a

Please sign in to comment.