From e5b379c7a5b4b412f2e651380bf499bdc8601b14 Mon Sep 17 00:00:00 2001 From: Roman Kolpakov Date: Fri, 20 Oct 2023 17:02:40 +0400 Subject: [PATCH 1/2] fix: motion can be enacted several times in one period --- tests/integration/conftest.py | 13 ++++--- .../test_allowed_recipients_motions.py | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) 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..400b1355 100644 --- a/tests/integration/test_allowed_recipients_motions.py +++ b/tests/integration/test_allowed_recipients_motions.py @@ -237,6 +237,43 @@ 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 = [2 * 10 ** 18] + + 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) + ) + + def test_top_up_multiple_recipients( recipients, allowed_recipients_limit_params, From 71d29446e4ac742995ab182c1ad7563f4fbe627a Mon Sep 17 00:00:00 2001 From: Roman Kolpakov Date: Fri, 20 Oct 2023 17:21:27 +0400 Subject: [PATCH 2/2] feat: improve test creating top up motions several times --- .../test_allowed_recipients_motions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_allowed_recipients_motions.py b/tests/integration/test_allowed_recipients_motions.py index 400b1355..4cd886ff 100644 --- a/tests/integration/test_allowed_recipients_motions.py +++ b/tests/integration/test_allowed_recipients_motions.py @@ -254,7 +254,7 @@ def test_top_up_single_recipient_several_times_in_period( ) top_up_recipient_addresses = [allowed_recipient.address] - top_up_amounts = [2 * 10 ** 18] + 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 @@ -273,6 +273,23 @@ def test_top_up_single_recipient_several_times_in_period( 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,