diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index b1721e24..e5373140 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -398,6 +398,7 @@ 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, @@ -405,7 +406,7 @@ def _top_up_allowed_recipient_by_motion( 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 @@ -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"] ) @@ -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 @@ -497,6 +499,7 @@ 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() @@ -504,7 +507,7 @@ def _check_top_up_motion_enactment( 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( @@ -512,7 +515,7 @@ def _check_top_up_motion_enactment( ) assert ( allowed_recipients_registry.getPeriodState()["_alreadySpentAmount"] - == spending + == spending + spent_amount ) assert ( allowed_recipients_registry.getPeriodState()["_spendableBalanceInPeriod"] @@ -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"][ diff --git a/tests/integration/test_allowed_recipients_motions.py b/tests/integration/test_allowed_recipients_motions.py index ba2d3f92..4cd886ff 100644 --- a/tests/integration/test_allowed_recipients_motions.py +++ b/tests/integration/test_allowed_recipients_motions.py @@ -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,