Skip to content

Commit

Permalink
Merge pull request #59 from lidofinance/fix/limits-checker-integratio…
Browse files Browse the repository at this point in the history
…n-tests-motion-enactment

fix: motion can be enacted several times in one period
  • Loading branch information
rkolpakov authored Oct 20, 2023
2 parents 6ede292 + 71d2944 commit 2b93080
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,15 @@ def _top_up_allowed_recipient_by_motion(
top_up_allowed_recipients_evm_script_factory,
recipient_addresses,
top_up_amounts,
spent_amount=0
):
motion_creation_tx = create_top_up_allowed_recipients_motion(
top_up_allowed_recipients_evm_script_factory,
recipient_addresses,
top_up_amounts,
)

enact_top_up_allowed_recipient_motion_by_creation_tx(motion_creation_tx)
enact_top_up_allowed_recipient_motion_by_creation_tx(motion_creation_tx, spent_amount)

return _top_up_allowed_recipient_by_motion

Expand All @@ -430,7 +431,7 @@ def enact_top_up_allowed_recipient_motion_by_creation_tx(
enact_motion_by_creation_tx,
check_top_up_motion_enactment,
):
def _enact_top_up_allowed_recipient_motion_by_creation_tx(motion_creation_tx):
def _enact_top_up_allowed_recipient_motion_by_creation_tx(motion_creation_tx, spent_amount=0):
top_up_allowed_recipients_evm_script_factory = TopUpAllowedRecipients.at(
motion_creation_tx.events["MotionCreated"]["_evmScriptFactory"]
)
Expand Down Expand Up @@ -477,6 +478,7 @@ def _enact_top_up_allowed_recipient_motion_by_creation_tx(motion_creation_tx):
recipients_shares_balance_before=recipients_shares_balance_before,
top_up_recipients=recipients,
top_up_amounts=amounts,
spent_amount=spent_amount
)

return _enact_top_up_allowed_recipient_motion_by_creation_tx
Expand All @@ -497,22 +499,23 @@ def _check_top_up_motion_enactment(
recipients_shares_balance_before,
top_up_recipients,
top_up_amounts,
spent_amount,
):
allowed_recipients_registry = AllowedRecipientsRegistry.at(
top_up_allowed_recipients_evm_script_factory.allowedRecipientsRegistry()
)
limit, duration = allowed_recipients_registry.getLimitParameters()

spending = sum(top_up_amounts)
spendable = limit - spending
spendable = limit - (spending + spent_amount)

assert allowed_recipients_registry.isUnderSpendableBalance(spendable, 0)
assert allowed_recipients_registry.isUnderSpendableBalance(
limit, duration * MAX_SECONDS_IN_MONTH
)
assert (
allowed_recipients_registry.getPeriodState()["_alreadySpentAmount"]
== spending
== spending + spent_amount
)
assert (
allowed_recipients_registry.getPeriodState()["_spendableBalanceInPeriod"]
Expand Down Expand Up @@ -551,7 +554,7 @@ def _check_top_up_motion_enactment(
top_up_motion_enactment_tx.events["SpendableAmountChanged"][
"_alreadySpentAmount"
]
== spending
== spending + spent_amount
)
assert (
top_up_motion_enactment_tx.events["SpendableAmountChanged"][
Expand Down
54 changes: 54 additions & 0 deletions tests/integration/test_allowed_recipients_motions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,60 @@ def test_top_up_single_recipient(
)


def test_top_up_single_recipient_several_times_in_period(
recipients,
allowed_recipients_limit_params,
add_allowed_recipient_by_motion,
top_up_allowed_recipient_by_motion,
add_allowed_recipient_evm_script_factory,
top_up_allowed_recipients_evm_script_factory,
):
allowed_recipient = recipients[0]

add_allowed_recipient_by_motion(
add_allowed_recipient_evm_script_factory,
allowed_recipient.address,
allowed_recipient.title,
)

top_up_recipient_addresses = [allowed_recipient.address]
top_up_amounts = [int(allowed_recipients_limit_params.limit / 2)]

test_helpers.advance_chain_time_to_beginning_of_the_next_period(
allowed_recipients_limit_params.duration
)

top_up_allowed_recipient_by_motion(
top_up_allowed_recipients_evm_script_factory,
top_up_recipient_addresses,
top_up_amounts,
)

top_up_allowed_recipient_by_motion(
top_up_allowed_recipients_evm_script_factory,
top_up_recipient_addresses,
top_up_amounts,
sum(top_up_amounts)
)

with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"):
top_up_allowed_recipient_by_motion(
top_up_allowed_recipients_evm_script_factory,
top_up_recipient_addresses,
[1],
)

test_helpers.advance_chain_time_to_beginning_of_the_next_period(
allowed_recipients_limit_params.duration
)

top_up_allowed_recipient_by_motion(
top_up_allowed_recipients_evm_script_factory,
top_up_recipient_addresses,
[allowed_recipients_limit_params.limit]
)


def test_top_up_multiple_recipients(
recipients,
allowed_recipients_limit_params,
Expand Down

0 comments on commit 2b93080

Please sign in to comment.