Skip to content

Commit

Permalink
fix: update the negative rebase test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDZhon committed Nov 15, 2024
1 parent 89b19f8 commit 7c2b44c
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions tests/regression/test_neg_rebase_sanity_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
INACTIVITY_PENALTIES_AMOUNT_PWEI = 101
ONE_PWEI = ETH(0.001)


@pytest.fixture(scope="module")
def oracle_report_sanity_checker() -> Contract:
return contracts.oracle_report_sanity_checker
Expand All @@ -28,31 +29,39 @@ def test_negative_rebase_correct_exited_validators_count_pos_rebase(oracle_repor
reported_validators = exited_validators_count()

reported_validators_values = [value + 2 for value in reported_validators.values()]
oracle_report(cl_diff=ETH(300), stakingModuleIdsWithNewlyExitedValidators=list(reported_validators.keys()),
numExitedValidatorsByStakingModule=reported_validators_values)
oracle_report(
cl_diff=ETH(300),
stakingModuleIdsWithNewlyExitedValidators=list(reported_validators.keys()),
numExitedValidatorsByStakingModule=reported_validators_values,
)

count = oracle_report_sanity_checker.getReportDataCount()
assert count > 0
(_, stored_exited_validators, _) = oracle_report_sanity_checker.reportData(count - 1)

assert stored_exited_validators == sum(reported_validators_values)


def test_negative_rebase_correct_exited_validators_count_neg_rebase(oracle_report_sanity_checker):
locator = contracts.lido_locator
assert oracle_report_sanity_checker.address == locator.oracleReportSanityChecker()

reported_validators = exited_validators_count()

reported_validators_values = [value + 3 for value in reported_validators.values()]
oracle_report(cl_diff=-ETH(40000), stakingModuleIdsWithNewlyExitedValidators=list(reported_validators.keys()),
numExitedValidatorsByStakingModule=reported_validators_values)
oracle_report(
cl_diff=-ETH(40000),
stakingModuleIdsWithNewlyExitedValidators=list(reported_validators.keys()),
numExitedValidatorsByStakingModule=reported_validators_values,
)

count = oracle_report_sanity_checker.getReportDataCount()
assert count > 0
(_, stored_exited_validators, _) = oracle_report_sanity_checker.reportData(count - 1)

assert stored_exited_validators == sum(reported_validators_values)


def test_negative_rebase_correct_balance_neg_rebase(oracle_report_sanity_checker):
locator = contracts.lido_locator
assert oracle_report_sanity_checker.address == locator.oracleReportSanityChecker()
Expand All @@ -78,12 +87,32 @@ def test_blocked_huge_negative_rebase(oracle_report_sanity_checker):
locator = contracts.lido_locator
assert oracle_report_sanity_checker.address == locator.oracleReportSanityChecker()

# Advance the chain 60 days more without accounting oracle reports
# The idea is to simplify the calculation of the exited validators for 18 and 54 days ago
chain.sleep(60 * 24 * 60 * 60)
chain.mine(1)

(_, cl_validators, cl_balance) = contracts.lido.getBeaconStat()
count = oracle_report_sanity_checker.getReportDataCount()
assert count > 0
(_, stored_exited_validators, _) = oracle_report_sanity_checker.reportData(count - 1)

max_cl_balance = (INITIAL_SLASHING_AMOUNT_PWEI + INACTIVITY_PENALTIES_AMOUNT_PWEI) * ONE_PWEI * cl_validators
error_cl_decrease = cl_balance // 10 # 10% of current balance will lead to error
max_cl_balance = (
(INITIAL_SLASHING_AMOUNT_PWEI + INACTIVITY_PENALTIES_AMOUNT_PWEI)
* ONE_PWEI
* (cl_validators - stored_exited_validators)
)
error_cl_decrease = cl_balance // 10 # 10% of current balance will lead to error

print(encode_error("IncorrectCLBalanceDecrease(uint256, uint256)", [error_cl_decrease, max_cl_balance]))
with reverts(encode_error("IncorrectCLBalanceDecrease(uint256, uint256)", [error_cl_decrease, max_cl_balance])):
oracle_report(cl_diff=-error_cl_decrease, exclude_vaults_balances=True, silent=True)
oracle_report(
cl_diff=-error_cl_decrease,
exclude_vaults_balances=True,
simulation_block_identifier=chain.height,
silent=True,
)


def test_negative_rebase_more_than_54_reports(oracle_report_sanity_checker):
locator = contracts.lido_locator
Expand All @@ -92,8 +121,11 @@ def test_negative_rebase_more_than_54_reports(oracle_report_sanity_checker):
reported_validators_values = exited_validators_count().values()
for _ in range(58):
reported_validators_values = [value + 3 for value in reported_validators_values]
oracle_report(cl_diff=-ETH(400), stakingModuleIdsWithNewlyExitedValidators=exited_validators_count().keys(),
numExitedValidatorsByStakingModule=reported_validators_values)
oracle_report(
cl_diff=-ETH(400),
stakingModuleIdsWithNewlyExitedValidators=exited_validators_count().keys(),
numExitedValidatorsByStakingModule=reported_validators_values,
)

count = oracle_report_sanity_checker.getReportDataCount()
assert count > 0
Expand Down

0 comments on commit 7c2b44c

Please sign in to comment.