Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test for modules on network fork #561

Merged
merged 27 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e9e9b80
feat: add test for csm on mainnet fork
vgorkavenko Nov 6, 2024
15672af
fix: make it network-agnostic
vgorkavenko Nov 8, 2024
9d9be46
fix: run_cycle
vgorkavenko Nov 26, 2024
074aa88
feat: add ejector and accounting fork tests
vgorkavenko Dec 17, 2024
a7577e4
feat: workflow
vgorkavenko Dec 17, 2024
ba92c90
fix: linter
vgorkavenko Dec 18, 2024
9ce45b1
fix: tests
vgorkavenko Dec 18, 2024
4b40325
fix: `_get_module_id` in CSM module should be on `latest`
vgorkavenko Dec 18, 2024
bb19dec
fix: `_get_slots_elapsed_from_last_report` in accounting Oracle
vgorkavenko Dec 18, 2024
1f1afbb
fix: add csm module address
vgorkavenko Dec 18, 2024
90b0211
fix: epochs_per_frame and initial_epoch
vgorkavenko Dec 18, 2024
992183c
fix: subprocess logs
vgorkavenko Dec 19, 2024
327816d
fix: linter
vgorkavenko Dec 19, 2024
e0cb446
fix: log in `_get_non_missed_slot_header`
vgorkavenko Dec 20, 2024
442ec86
fix: add `clean_global_cache_after_test` fixture
vgorkavenko Jan 9, 2025
c4e7dd2
Update src/modules/accounting/accounting.py
F4ever Jan 22, 2025
9afe6fb
chore: rename workflow
vgorkavenko Jan 23, 2025
19437a0
fix: run with "fork" mark
vgorkavenko Jan 23, 2025
f74b891
chore: parallel run in CI
vgorkavenko Jan 23, 2025
dbd3d25
fix: test
vgorkavenko Jan 23, 2025
b495084
revert: package-mode
vgorkavenko Jan 23, 2025
a0c74c2
fix: black
vgorkavenko Jan 23, 2025
3a56723
fix: `SUBMIT_DATA_DELAY_IN_SLOTS` and `CYCLE_SLEEP_IN_SECONDS` should…
vgorkavenko Jan 23, 2025
e676ca2
revert: edited
vgorkavenko Jan 23, 2025
687cbe7
fix: create uniq path per test
vgorkavenko Jan 23, 2025
eaf3a9a
fix: linter
vgorkavenko Jan 23, 2025
039ab2b
fix: user worker_id
vgorkavenko Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -298,7 +298,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 @@ -397,9 +397,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
Loading