diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 42d8b87fa7a2504c6bb43231e9ece352ca6f01df..b8d17f56dc66dffd36820b5a0d8c0eef1a8d5200 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -503,6 +503,8 @@ module Delegate = struct type stake = {frozen : Tez.t; weighted_delegated : Tez.t} + let grace_period ctxt pkh = Delegate_services.grace_period rpc_ctxt ctxt pkh + let info ctxt pkh = Plugin.RPC.Delegates.info rpc_ctxt ctxt pkh let full_balance ctxt pkh = Delegate_services.full_balance rpc_ctxt ctxt pkh diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.mli b/src/proto_alpha/lib_protocol/test/helpers/context.mli index 17e4813cc4ed164b91e9a99c86659bdda5578c9a..542ae960b458b0ab8ed7de97d0b4c05b744bacbf 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/context.mli @@ -297,6 +297,8 @@ module Delegate : sig val deactivated : t -> public_key_hash -> bool tzresult Lwt.t + val grace_period : t -> public_key_hash -> Cycle.t tzresult Lwt.t + val voting_info : t -> public_key_hash -> Vote.delegate_info tzresult Lwt.t val consensus_key : diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml index 6ea7a016fc18f2516429da266f3f26066d68ce11..68fb0a3c7195d398176cbf56382686863d7e491a 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -150,6 +150,8 @@ let begin_test ?(burn_rewards = false) ?(force_attest_all = false) ~liquid ~frozen_deposits ~frozen_rights + ~last_active_cycle: + Cycle.(add root constants.consensus_rights_delay) () in let account_map = String.Map.add name account account_map in 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 d12946b258bcf35caa16240d6d9f6cb6879ede32..2754cef1579d0ef0b12947285750fd9fa2b16dc6 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_op.ml @@ -162,9 +162,9 @@ let set_delegate src_name delegate_name_opt : (t, t) scenarios = let pred_level = block.header.shell.level in let level = Int32.(succ pred_level) in let activity_cycle = - Block.current_cycle_of_level - ~blocks_per_cycle:state.constants.blocks_per_cycle - ~current_level:level + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7362 + Use delegate_parameters_activation_delay - Protocol.Constants_storage.tolerated_inactivity_period *) + Cycle.add current_cycle state.State.constants.consensus_rights_delay in (* update delegate activation status *) let state = diff --git a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml index 40fce015234a35bce17d687b5027c2ca412d6bcc..6631c2e79458d498942056ce20b349a1e6abbb25 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/state_ai_flags.ml @@ -111,9 +111,10 @@ module Autostake = struct } : account_state) state = let open Lwt_result_syntax in - (* TODO: use Protocol.Constants_storage.tolerated_inactivity_period *) + (* TODO: https://gitlab.com/tezos/tezos/-/issues/7362 + Use Protocol.Constants_storage.tolerated_inactivity_period *) let tolerated_inactivity_period = - (2 * state.constants.consensus_rights_delay) + 1 + state.constants.consensus_rights_delay + 1 in if Some name <> delegate then ( Log.debug diff --git a/src/proto_alpha/lib_protocol/test/integration/test_scenario_deactivation.ml b/src/proto_alpha/lib_protocol/test/integration/test_scenario_deactivation.ml index 104f744fab7a29f8b51e79278cf5bc0146faf0fb..3fd7918e971ca3a38341e122bb26f85a0d9b853a 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_scenario_deactivation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_scenario_deactivation.ml @@ -31,6 +31,24 @@ let check_is_not_active ~loc src_name = let* b = Context.Delegate.deactivated (B block) src.pkh in Assert.is_true ~loc b +let check_grace_period ~loc src_name = + let open Lwt_result_syntax in + exec_unit @@ fun (block, state) -> + let src = State.find_account src_name state in + let grace = + Cycle.add + src.last_active_cycle + (state.State.constants.consensus_rights_delay + 1) + in + let* rpc_grace = Context.Delegate.grace_period (B block) src.pkh in + Assert.equal + ( = ) + "Grace period is not correct: expected vs RPC" + ~loc + Cycle.pp + grace + rpc_grace + (** Test that a delegate gets deactivated after a set period of time if it is not baking. Test that with autostaking, the frozen funds are completely unstaked, which get finalizable (but not finalized) after a set period of time. @@ -40,6 +58,7 @@ let test_simple_scenario_with_autostaking = --> set S.Adaptive_issuance.autostaking_enable true --> activate_ai `No --> begin_test ["delegate"; "baker"] + --> check_grace_period ~loc:__LOC__ "baker" --> set_baker "baker" --> wait_n_cycles_f (fun (_, state) -> (2 * state.State.constants.consensus_rights_delay) + 1) @@ -48,12 +67,17 @@ let test_simple_scenario_with_autostaking = --> next_cycle --> check_is_not_active ~loc:__LOC__ "delegate" --> check_balance_field "delegate" `Staked Tez.zero + --> check_grace_period ~loc:__LOC__ "baker" + --> next_block + --> check_grace_period ~loc:__LOC__ "baker" --> check_balance_field "delegate" `Unstaked_frozen_total (Tez.of_mutez 200_000_000_000L) --> wait_n_cycles_f Test_scenario_stake.unstake_wait --> check_balance_field "delegate" `Unstaked_frozen_total Tez.zero + --> check_grace_period ~loc:__LOC__ "delegate" + --> check_grace_period ~loc:__LOC__ "baker" --> check_balance_field "delegate" `Unstaked_finalizable