From 98ddef85ff38277c76ca58abc3fb4af599f2cf56 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Tue, 5 Mar 2024 17:24:58 +0100 Subject: [PATCH 1/5] Proto/AI/test: add label to add_account_with_funds argument to disambiguate funder account from new account --- .../lib_protocol/test/helpers/scenario_op.ml | 6 +++--- .../test/integration/test_scenario_autostaking.ml | 6 +++--- .../test/integration/test_scenario_base.ml | 2 +- .../test/integration/test_scenario_rewards.ml | 6 +++--- .../test/integration/test_scenario_slashing.ml | 2 +- .../test/integration/test_scenario_stake.ml | 13 ++++++++----- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml index bedba04f7bba..f4f94fa52172 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml @@ -452,6 +452,6 @@ let make_denunciations_ ?(filter = fun {State.denounced; _} -> not denounced) until the operations are included in a block (by default the next block) *) let make_denunciations ?filter () = exec_op (make_denunciations_ ?filter) -(** Create an account and give an initial balance funded by [source] *) -let add_account_with_funds name source amount = - add_account name --> transfer source name amount --> reveal name +(** Create an account and give an initial balance funded by [funder] *) +let add_account_with_funds name ~funder amount = + add_account name --> transfer funder name amount --> reveal name diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_autostaking.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_autostaking.ml index 4b9a5e8e1cb7..bb2c4a3005ab 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_autostaking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_autostaking.ml @@ -60,11 +60,11 @@ let setup ~activate_ai = --> begin_test [delegate] --> add_account_with_funds delegator1 - "__bootstrap__" + ~funder:"__bootstrap__" (Amount (Tez.of_mutez 2_000_000_000L)) --> add_account_with_funds delegator2 - "__bootstrap__" + ~funder:"__bootstrap__" (Amount (Tez.of_mutez 2_000_000_000L)) --> next_cycle --> snapshot_balances "before delegation" [delegate] @@ -150,7 +150,7 @@ let test_overdelegation = --> begin_test ["delegate"; "faucet1"; "faucet2"; "faucet3"] --> add_account_with_funds "delegator_to_fund" - "delegate" + ~funder:"delegate" (Amount (Tez.of_mutez 3_600_000_000_000L)) (* Delegate has 200k staked and 200k liquid *) --> set_delegate "delegator_to_fund" (Some "delegate") diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml index 37353d93f31e..77b9619e6018 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml @@ -55,7 +55,7 @@ let init_scenario ?(force_ai = true) ?reward_per_block () = --> begin_test ~activate_ai:true ~self_stake:false --> add_account_with_funds "staker" - "delegate" + ~funder:"delegate" (Amount (Tez.of_mutez 2_000_000_000_000L)) --> set_delegate "staker" (Some "delegate")) --> wait_delegate_parameters_activation --> next_cycle diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_rewards.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_rewards.ml index 160069056bd7..ef3b2db6790f 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_rewards.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_rewards.ml @@ -39,15 +39,15 @@ let test_wait_with_rewards = |+ Tag "edge = 1" --> set_edge 1.) --> add_account_with_funds "staker1" - "faucet" + ~funder:"faucet" (Amount (Tez.of_mutez 2_000_000_000L)) --> add_account_with_funds "staker2" - "faucet" + ~funder:"faucet" (Amount (Tez.of_mutez 2_000_000_000L)) --> add_account_with_funds "staker3" - "faucet" + ~funder:"faucet" (Amount (Tez.of_mutez 2_000_000_000L)) --> set_delegate "staker1" (Some "delegate") --> set_delegate "staker2" (Some "delegate") diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml index ed20f9b38e0d..343684318623 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_slashing.ml @@ -256,7 +256,7 @@ let init_scenario_with_delegators delegate_name faucet_name delegators_list = | (delegator, amount) :: t -> add_account_with_funds delegator - faucet_name + ~funder:faucet_name (Amount (Tez.of_mutez amount)) --> set_delegate delegator (Some delegate_name) --> init_delegators t diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml index 0b7694da9b7d..c807850dcc58 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml @@ -145,7 +145,10 @@ let scenario_forbidden_operations = --> unstake "staker" Nothing let full_balance_in_finalizable = - add_account_with_funds "dummy" "staker" (Amount (Tez.of_mutez 10_000_000L)) + add_account_with_funds + "dummy" + ~funder:"staker" + (Amount (Tez.of_mutez 10_000_000L)) --> stake "staker" All_but_one --> next_cycle --> unstake "staker" All --> wait_n_cycles_f (unstake_wait ++ 2) (* At this point, almost all the balance (but one mutez) of the stake is in finalizable *) @@ -175,7 +178,7 @@ let change_delegate = --> set_delegate_params "delegate2" init_params --> add_account_with_funds "staker" - "delegate1" + ~funder:"delegate1" (Amount (Tez.of_mutez 2_000_000_000_000L)) --> set_delegate "staker" (Some "delegate1") --> wait_delegate_parameters_activation --> next_cycle --> stake "staker" Half @@ -196,11 +199,11 @@ let unset_delegate = --> set_delegate_params "delegate" init_params --> add_account_with_funds "staker" - "delegate" + ~funder:"delegate" (Amount (Tez.of_mutez 2_000_000_000_000L)) --> add_account_with_funds "dummy" - "delegate" + ~funder:"delegate" (Amount (Tez.of_mutez 2_000_000L)) --> set_delegate "staker" (Some "delegate") --> wait_delegate_parameters_activation --> next_cycle --> stake "staker" Half @@ -234,7 +237,7 @@ let forbid_costaking = --> set_delegate_params "delegate" init_params --> add_account_with_funds "staker" - "delegate" + ~funder:"delegate" (Amount (Tez.of_mutez 2_000_000_000_000L)) --> set_delegate "staker" (Some "delegate") --> wait_cycle_until (`And (`AI_activation, `delegate_parameters_activation)) -- GitLab From 23572f4f5f1d1e5026c0f84316c00f24eeb9572e Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Tue, 5 Mar 2024 15:54:38 +0100 Subject: [PATCH 2/5] Proto/AI/test: remove unused force_ai and reward_per_block arguments --- .../test/integration/test_scenario_base.ml | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml index 77b9619e6018..5043a1e5237e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml @@ -29,44 +29,33 @@ let test_expected_error = [Inconsistent_number_of_bootstrap_accounts]) (exec (fun _ -> failwith ""))) -(** Initialization of scenarios with 3 cases: +(** Initialization of scenarios with 2 cases: - AI activated, staker = delegate - AI activated, staker != delegate - - AI not activated (and staker = delegate) - Any scenario that begins with this will be triplicated. - *) -let init_scenario ?(force_ai = true) ?reward_per_block () = + Any scenario that begins with this will be duplicated. *) +let init_scenario () = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - let begin_test ~activate_ai ~self_stake = + let begin_test ~self_stake = let name = if self_stake then "staker" else "delegate" in - init_constants ?reward_per_block () + init_constants () --> set S.Adaptive_issuance.autostaking_enable false - --> Scenario_begin.activate_ai (if activate_ai then `Force else `No) + --> Scenario_begin.activate_ai `Force --> begin_test [name] --> set_delegate_params name init_params --> set_baker "__bootstrap__" in - let ai_activated = - Tag "AI activated" - --> (Tag "self stake" --> begin_test ~activate_ai:true ~self_stake:true - |+ Tag "external stake" - --> begin_test ~activate_ai:true ~self_stake:false - --> add_account_with_funds - "staker" - ~funder:"delegate" - (Amount (Tez.of_mutez 2_000_000_000_000L)) - --> set_delegate "staker" (Some "delegate")) - --> wait_delegate_parameters_activation --> next_cycle - in - - let ai_deactivated = - Tag "AI deactivated, self stake" - --> begin_test ~activate_ai:false ~self_stake:true - in - (if force_ai then ai_activated else ai_activated |+ ai_deactivated) - --> next_block + Tag "AI activated" + --> (Tag "self stake" --> begin_test ~self_stake:true + |+ Tag "external stake" + --> begin_test ~self_stake:false + --> add_account_with_funds + "staker" + ~funder:"delegate" + (Amount (Tez.of_mutez 2_000_000_000_000L)) + --> set_delegate "staker" (Some "delegate")) + --> wait_delegate_parameters_activation --> next_cycle let tests = tests_of_scenarios -- GitLab From 39d398313e0770171dbf9a3db4a25610ebd43f09 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Fri, 8 Mar 2024 16:57:33 +0100 Subject: [PATCH 3/5] Proto/AI/test: rename init_scenario to init_staker_delegate_or_external and move it to test_scenario_stake and move its calls to the test bodies --- .../test/integration/test_scenario_base.ml | 36 +------- .../test/integration/test_scenario_stake.ml | 82 +++++++++++++------ 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml index 5043a1e5237e..9a14737b3144 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_base.ml @@ -13,9 +13,6 @@ Subject: Test basic functionality of the scenario framework. *) -open Adaptive_issuance_helpers -open State_account -open Tez_helpers.Ez_tez open Scenario let test_expected_error = @@ -29,39 +26,8 @@ let test_expected_error = [Inconsistent_number_of_bootstrap_accounts]) (exec (fun _ -> failwith ""))) -(** Initialization of scenarios with 2 cases: - - AI activated, staker = delegate - - AI activated, staker != delegate - Any scenario that begins with this will be duplicated. *) -let init_scenario () = - let init_params = - {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} - in - let begin_test ~self_stake = - let name = if self_stake then "staker" else "delegate" in - init_constants () - --> set S.Adaptive_issuance.autostaking_enable false - --> Scenario_begin.activate_ai `Force - --> begin_test [name] - --> set_delegate_params name init_params - --> set_baker "__bootstrap__" - in - Tag "AI activated" - --> (Tag "self stake" --> begin_test ~self_stake:true - |+ Tag "external stake" - --> begin_test ~self_stake:false - --> add_account_with_funds - "staker" - ~funder:"delegate" - (Amount (Tez.of_mutez 2_000_000_000_000L)) - --> set_delegate "staker" (Some "delegate")) - --> wait_delegate_parameters_activation --> next_cycle - let tests = tests_of_scenarios - @@ [ - ("Test expected error in assert failure", test_expected_error); - ("Test init", init_scenario () --> Action (fun _ -> return_unit)); - ] + @@ [("Test expected error in assert failure", test_expected_error)] let () = register_tests ~__FILE__ ~tags:["protocol"; "scenario"; "base"] tests diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml index c807850dcc58..9b4ca2a377fc 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml @@ -17,10 +17,40 @@ open Adaptive_issuance_helpers open State_account open Tez_helpers.Ez_tez open Scenario -open Test_scenario_base let fs = Format.asprintf +(** Initializes of scenarios with 2 cases: + - staker = delegate + - staker != delegate + Any scenario that begins with this will be duplicated. + + Also, ensures that AI is activated (sets EMA threshold to zero, + enables activation vote, and waits for AI activation). *) +let init_staker_delegate_or_external = + let init_params = + {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} + in + let begin_test ~self_stake = + let name = if self_stake then "staker" else "delegate" in + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false + --> Scenario_begin.activate_ai `Force + --> begin_test [name] + --> set_delegate_params name init_params + --> set_baker "__bootstrap__" + in + Tag "AI activated" + --> (Tag "self stake" --> begin_test ~self_stake:true + |+ Tag "external stake" + --> begin_test ~self_stake:false + --> add_account_with_funds + "staker" + ~funder:"delegate" + (Amount (Tez.of_mutez 2_000_000_000_000L)) + --> set_delegate "staker" (Some "delegate")) + --> wait_delegate_parameters_activation --> next_cycle + let stake_init = stake "staker" Half --> (Tag "no wait after stake" --> Empty @@ -49,14 +79,14 @@ let finalize staker = --> check_balance_field staker `Unstaked_finalizable Tez.zero let simple_roundtrip = - stake_init + init_staker_delegate_or_external --> stake_init --> (Tag "full unstake" --> unstake "staker" All |+ Tag "half unstake" --> unstake "staker" Half) --> wait_for_unfreeze_and_check unstake_wait --> finalize "staker" --> next_cycle let double_roundtrip = - stake_init --> unstake "staker" Half + init_staker_delegate_or_external --> stake_init --> unstake "staker" Half --> (Tag "half then full unstake" --> wait_n_cycles 2 --> unstake "staker" All |+ Tag "half then half unstake" --> wait_n_cycles 2 --> unstake "staker" Half) @@ -87,7 +117,8 @@ let status_quo_rountrip = let full_amount = Tez.of_mutez 10_000_000L in let amount_1 = Tez.of_mutez 2_999_999L in let amount_2 = Tez.of_mutez 7_000_001L in - snapshot_balances "init" ["staker"] + init_staker_delegate_or_external + --> snapshot_balances "init" ["staker"] --> stake "staker" (Amount full_amount) --> next_cycle --> (Tag "1 unstake" --> unstake "staker" (Amount full_amount) @@ -100,7 +131,8 @@ let status_quo_rountrip = --> check_snapshot_balances "init" let scenario_finalize = - no_tag --> stake "staker" Half --> next_cycle --> unstake "staker" Half + init_staker_delegate_or_external --> stake "staker" Half --> next_cycle + --> unstake "staker" Half --> wait_n_cycles_f (unstake_wait ++ 2) --> assert_failure (check_balance_field "staker" `Unstaked_finalizable Tez.zero) @@ -113,7 +145,8 @@ let scenario_finalize = (* Finalize does not go through when unstake does nothing *) (* Todo: there might be other cases... like changing delegates *) let scenario_not_finalize = - no_tag --> stake "staker" Half --> next_cycle --> unstake "staker" All + init_staker_delegate_or_external --> stake "staker" Half --> next_cycle + --> unstake "staker" All --> wait_n_cycles_f (unstake_wait ++ 2) --> assert_failure (check_balance_field "staker" `Unstaked_finalizable Tez.zero) @@ -133,10 +166,10 @@ let scenario_forbidden_operations = failwith "_self_delegate_exit_" else return input) in - no_tag - (* Staking everything works for self delegates, but not for delegated accounts *) - --> assert_failure - (fail_if_staker_is_self_delegate "staker" --> stake "staker" All) + init_staker_delegate_or_external + --> (* Staking everything works for self delegates, but not for delegated accounts *) + assert_failure + (fail_if_staker_is_self_delegate "staker" --> stake "staker" All) (* stake is always forbidden when amount is zero *) --> assert_failure (stake "staker" Nothing) (* One cannot stake more that one has *) @@ -145,10 +178,11 @@ let scenario_forbidden_operations = --> unstake "staker" Nothing let full_balance_in_finalizable = - add_account_with_funds - "dummy" - ~funder:"staker" - (Amount (Tez.of_mutez 10_000_000L)) + init_staker_delegate_or_external + --> add_account_with_funds + "dummy" + ~funder:"staker" + (Amount (Tez.of_mutez 10_000_000L)) --> stake "staker" All_but_one --> next_cycle --> unstake "staker" All --> wait_n_cycles_f (unstake_wait ++ 2) (* At this point, almost all the balance (but one mutez) of the stake is in finalizable *) @@ -161,6 +195,8 @@ let full_balance_in_finalizable = (* Stress test: what happens if someone were to stake and unstake every cycle? *) let odd_behavior = + init_staker_delegate_or_external + --> let one_cycle = no_tag --> stake "staker" Half --> unstake "staker" Half --> next_cycle in @@ -274,16 +310,14 @@ let forbid_costaking = let tests = tests_of_scenarios @@ [ - ("Test simple roundtrip", init_scenario () --> simple_roundtrip); - ("Test double roundtrip", init_scenario () --> double_roundtrip); - ("Test preserved balance", init_scenario () --> status_quo_rountrip); - ("Test finalize", init_scenario () --> scenario_finalize); - ("Test no finalize", init_scenario () --> scenario_not_finalize); - ( "Test forbidden operations", - init_scenario () --> scenario_forbidden_operations ); - ( "Test full balance in finalizable", - init_scenario () --> full_balance_in_finalizable ); - ("Test stake unstake every cycle", init_scenario () --> odd_behavior); + ("Test simple roundtrip", simple_roundtrip); + ("Test double roundtrip", double_roundtrip); + ("Test preserved balance", status_quo_rountrip); + ("Test finalize", scenario_finalize); + ("Test no finalize", scenario_not_finalize); + ("Test forbidden operations", scenario_forbidden_operations); + ("Test full balance in finalizable", full_balance_in_finalizable); + ("Test stake unstake every cycle", odd_behavior); ("Test change delegate", change_delegate); ("Test unset delegate", unset_delegate); ("Test forbid costake", forbid_costaking); -- GitLab From 04f70514aa4a54efd2f94142924e4955eaaf975d Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Tue, 12 Mar 2024 10:04:18 +0100 Subject: [PATCH 4/5] Proto/AI/test_scenario_stake: add comments --- .../test/integration/test_scenario_stake.ml | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml index 9b4ca2a377fc..7507c3063362 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml @@ -78,6 +78,17 @@ let finalize staker = --> finalize_unstake staker --> check_balance_field staker `Unstaked_finalizable Tez.zero +(* Simple stake - unstake - finalize roundtrip. + + - Note that the test framework automatically checks, whenever a + block is baked, that the staker's fully detailed balance (liquid, + bonds, staked, unstaked frozen, unstaked finalizable, and costaking + values) is the same as predicted in the simulated state. + + - Moreover, we explicitly check that after the unstake operation, + the staker's balance doesn't change until the last cycle of the + unfreeze delay (which is [consensus_rights_delay + + max_slashing_period = 2 + 2]). *) let simple_roundtrip = init_staker_delegate_or_external --> stake_init --> (Tag "full unstake" --> unstake "staker" All @@ -85,6 +96,7 @@ let simple_roundtrip = --> wait_for_unfreeze_and_check unstake_wait --> finalize "staker" --> next_cycle +(* Same as above, except with two separate unstake operations. *) let double_roundtrip = init_staker_delegate_or_external --> stake_init --> unstake "staker" Half --> (Tag "half then full unstake" --> wait_n_cycles 2 --> unstake "staker" All @@ -94,6 +106,7 @@ let double_roundtrip = --> wait_for_unfreeze_and_check (Fun.const 2) --> finalize "staker" --> next_cycle +(* Test that a baker can stake from unstaked frozen funds. *) let shorter_roundtrip_for_baker = let amount = Amount (Tez.of_mutez 333_000_000_000L) in let consensus_rights_delay = @@ -106,13 +119,19 @@ let shorter_roundtrip_for_baker = --> next_cycle --> snapshot_balances "init" ["delegate"] --> unstake "delegate" amount - --> List.fold_left - (fun acc i -> acc |+ Tag (fs "wait %i cycles" i) --> wait_n_cycles i) - (Tag "wait 0 cycles" --> Empty) - (Stdlib.List.init (consensus_rights_delay + 1) (fun i -> i + 1)) + --> (* Wait [n] cycles where [0 <= n <= consensus_rights_delay + 1]. *) + List.fold_left + (fun acc i -> acc |+ Tag (fs "wait %i cycles" i) --> wait_n_cycles i) + (Tag "wait 0 cycles" --> Empty) + (Stdlib.List.init (consensus_rights_delay + 1) (fun i -> i + 1)) --> stake "delegate" amount --> check_snapshot_balances "init" +(* Roundtrip where the unstaked amount matches the initially staked + amount (either from one unstake operation of this amount, or two + unstake operations summing up to it). This lets us explicitly check + that the detailed balance of the staker at the end is identical to + its balance before the stake operation. *) let status_quo_rountrip = let full_amount = Tez.of_mutez 10_000_000L in let amount_1 = Tez.of_mutez 2_999_999L in @@ -130,6 +149,13 @@ let status_quo_rountrip = --> finalize "staker" --> check_snapshot_balances "init" +(* Test three different ways to finalize unstake requests: + - finalize_unstake operation + - stake operation (of 1 mutez) + - unstake operation (of 1 mutez) + + Check that the finalizable unstaked balance is non-zero before, and + becomes zero after the finalization. *) let scenario_finalize = init_staker_delegate_or_external --> stake "staker" Half --> next_cycle --> unstake "staker" Half @@ -142,7 +168,9 @@ let scenario_finalize = ) --> check_balance_field "staker" `Unstaked_finalizable Tez.zero -(* Finalize does not go through when unstake does nothing *) +(* Test that an unstake operation doesn't cause finalization when + there are zero staked funds (so the unstake operation doesn't do + anything). *) (* Todo: there might be other cases... like changing delegates *) let scenario_not_finalize = init_staker_delegate_or_external --> stake "staker" Half --> next_cycle @@ -251,6 +279,10 @@ let unset_delegate = --> wait_n_cycles_f (unstake_wait ++ 1) --> finalize_unstake "staker" +(* Test that external stakers cannot stake when a delegate sets the + limit of staking over baking to zero, then can stake again when the + limit is set back to one. Changes take effect only after + [delegate_parameters_activation_delay + 1] cycles. *) let forbid_costaking = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} -- GitLab From 95e5a519d360d240e7ee2b1769a03a9d4bdebbc6 Mon Sep 17 00:00:00 2001 From: Diane Gallois-Wong Date: Tue, 12 Mar 2024 14:26:43 +0100 Subject: [PATCH 5/5] Proto/AI/test: move status_quo_roundtrip right after other roundtrips --- .../test/integration/test_scenario_stake.ml | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml index 7507c3063362..fb1d2313ab71 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_stake.ml @@ -106,27 +106,6 @@ let double_roundtrip = --> wait_for_unfreeze_and_check (Fun.const 2) --> finalize "staker" --> next_cycle -(* Test that a baker can stake from unstaked frozen funds. *) -let shorter_roundtrip_for_baker = - let amount = Amount (Tez.of_mutez 333_000_000_000L) in - let consensus_rights_delay = - Default_parameters.constants_test.consensus_rights_delay - in - init_constants () - --> set S.Adaptive_issuance.autostaking_enable false - --> activate_ai `Force --> begin_test ["delegate"] - --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) - --> next_cycle - --> snapshot_balances "init" ["delegate"] - --> unstake "delegate" amount - --> (* Wait [n] cycles where [0 <= n <= consensus_rights_delay + 1]. *) - List.fold_left - (fun acc i -> acc |+ Tag (fs "wait %i cycles" i) --> wait_n_cycles i) - (Tag "wait 0 cycles" --> Empty) - (Stdlib.List.init (consensus_rights_delay + 1) (fun i -> i + 1)) - --> stake "delegate" amount - --> check_snapshot_balances "init" - (* Roundtrip where the unstaked amount matches the initially staked amount (either from one unstake operation of this amount, or two unstake operations summing up to it). This lets us explicitly check @@ -149,6 +128,27 @@ let status_quo_rountrip = --> finalize "staker" --> check_snapshot_balances "init" +(* Test that a baker can stake from unstaked frozen funds. *) +let shorter_roundtrip_for_baker = + let amount = Amount (Tez.of_mutez 333_000_000_000L) in + let consensus_rights_delay = + Default_parameters.constants_test.consensus_rights_delay + in + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false + --> activate_ai `Force --> begin_test ["delegate"] + --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) + --> next_cycle + --> snapshot_balances "init" ["delegate"] + --> unstake "delegate" amount + --> (* Wait [n] cycles where [0 <= n <= consensus_rights_delay + 1]. *) + List.fold_left + (fun acc i -> acc |+ Tag (fs "wait %i cycles" i) --> wait_n_cycles i) + (Tag "wait 0 cycles" --> Empty) + (Stdlib.List.init (consensus_rights_delay + 1) (fun i -> i + 1)) + --> stake "delegate" amount + --> check_snapshot_balances "init" + (* Test three different ways to finalize unstake requests: - finalize_unstake operation - stake operation (of 1 mutez) -- GitLab