From 1f3c1b6b09336ab8aa1bfe5443b9ef5a4461e63a Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 21 Feb 2024 14:13:04 +0100 Subject: [PATCH 01/10] Proto/tests: move begin_test in a dedicated file --- .../test/helpers/scenario_base.ml | 113 ---------------- .../test/helpers/scenario_begin.ml | 123 ++++++++++++++++++ .../integration/test_scenario_autostaking.ml | 1 + .../test/integration/test_scenario_base.ml | 1 + .../test/integration/test_scenario_rewards.ml | 1 + .../integration/test_scenario_slashing.ml | 1 + .../test/integration/test_scenario_stake.ml | 1 + 7 files changed, 128 insertions(+), 113 deletions(-) create mode 100644 src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_base.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_base.ml index 8121a1ac723b..6831d193a07d 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_base.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_base.ml @@ -15,9 +15,6 @@ open Scenario_dsl open Log_helpers open Adaptive_issuance_helpers -(** Returns when the number of bootstrap accounts created by [Context.init_n n] is not equal to [n] *) -type error += Inconsistent_number_of_bootstrap_accounts - (** For [assert_failure], when expected error does not match the actual error. *) type error += Unexpected_error @@ -336,116 +333,6 @@ let exec_op f = return (block, state)) --> next_block -(* ======== Definition of basic actions ======== *) - -(** Initialize the test, given some initial parameters *) -let begin_test ~activate_ai ?(burn_rewards = false) ?(ns_enable_fork = false) - ?(constants : Protocol.Alpha_context.Constants.Parametric.t option) - ?(constants_list : - (string * Protocol.Alpha_context.Constants.Parametric.t) list option) - delegates_name_list : (unit, t) scenarios = - let f ns_enable = - (match (constants, constants_list) with - | None, None -> Stdlib.failwith "No constants provided to begin_test" - | Some _, Some _ -> - Stdlib.failwith - "You cannot provide ~constants and ~constants_list to begin_test" - | None, Some constants_list -> list_to_branch constants_list - | Some constants, None -> Action (fun () -> return constants)) - --> exec (fun (constants : Protocol.Alpha_context.Constants.Parametric.t) -> - let open Lwt_result_syntax in - Log.info ~color:begin_end_color "-- Begin test --" ; - let bootstrap = "__bootstrap__" in - let delegates_name_list = bootstrap :: delegates_name_list in - (* Override threshold value if activate *) - let constants = - if activate_ai then ( - Log.info ~color:event_color "Setting ai threshold to 0" ; - { - constants with - adaptive_issuance = - { - constants.adaptive_issuance with - launch_ema_threshold = 0l; - activation_vote_enable = true; - ns_enable; - }; - }) - else constants - in - let n = List.length delegates_name_list in - let* block, delegates = Context.init_with_constants_n constants n in - let*? init_level = Context.get_level (B block) in - let init_staked = Tez.of_mutez 200_000_000_000L in - let*? account_map = - List.fold_left2 - ~when_different_lengths: - [Inconsistent_number_of_bootstrap_accounts] - (fun account_map name contract -> - let liquid = - Tez.(Account.default_initial_balance -! init_staked) - in - let frozen_deposits = Frozen_tez.init init_staked name name in - let frozen_rights = - List.fold_left - (fun map cycle -> CycleMap.add cycle init_staked map) - CycleMap.empty - Cycle.( - root ---> add root constants.consensus_rights_delay) - in - let pkh = Context.Contract.pkh contract in - let account = - init_account - ~delegate:name - ~pkh - ~contract - ~parameters:default_params - ~liquid - ~frozen_deposits - ~frozen_rights - () - in - let account_map = String.Map.add name account account_map in - let balance, total_balance = - balance_and_total_balance_of_account name account_map - in - Log.debug - "Initial balance for %s:\n%a" - name - balance_pp - balance ; - Log.debug "Initial total balance: %a" Tez.pp total_balance ; - account_map) - String.Map.empty - delegates_name_list - delegates - in - let* total_supply = Context.get_total_supply (B block) in - let state = - State. - { - account_map; - total_supply; - constants; - param_requests = []; - activate_ai; - baking_policy = None; - last_level_rewards = init_level; - snapshot_balances = String.Map.empty; - saved_rate = None; - burn_rewards; - pending_operations = []; - pending_slashes = []; - double_signings = []; - } - in - let* () = check_all_balances block state in - return (block, state)) - in - if ns_enable_fork then - Tag "ns_enable = true" --> f true |+ Tag "ns_enable = false" --> f false - else f false - (* ======== Misc functions ========*) let check_failure_aux ?expected_error : diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml new file mode 100644 index 000000000000..a08f8f83976d --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -0,0 +1,123 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2024 Nomadic Labs, *) +(* *) +(*****************************************************************************) + +open State_account +open Scenario_dsl +open Scenario_base +open Log_helpers +open Adaptive_issuance_helpers + +(** Returns when the number of bootstrap accounts created by [Context.init_n n] is not equal to [n] *) +type error += Inconsistent_number_of_bootstrap_accounts + +(** Initialize the test, given some initial parameters *) +let begin_test ~activate_ai ?(burn_rewards = false) ?(ns_enable_fork = false) + ?(constants : Protocol.Alpha_context.Constants.Parametric.t option) + ?(constants_list : + (string * Protocol.Alpha_context.Constants.Parametric.t) list option) + delegates_name_list : (unit, t) scenarios = + let f ns_enable = + (match (constants, constants_list) with + | None, None -> Stdlib.failwith "No constants provided to begin_test" + | Some _, Some _ -> + Stdlib.failwith + "You cannot provide ~constants and ~constants_list to begin_test" + | None, Some constants_list -> list_to_branch constants_list + | Some constants, None -> Action (fun () -> return constants)) + --> exec (fun (constants : Protocol.Alpha_context.Constants.Parametric.t) -> + let open Lwt_result_syntax in + Log.info ~color:begin_end_color "-- Begin test --" ; + let bootstrap = "__bootstrap__" in + let delegates_name_list = bootstrap :: delegates_name_list in + (* Override threshold value if activate *) + let constants = + if activate_ai then ( + Log.info ~color:event_color "Setting ai threshold to 0" ; + { + constants with + adaptive_issuance = + { + constants.adaptive_issuance with + launch_ema_threshold = 0l; + activation_vote_enable = true; + ns_enable; + }; + }) + else constants + in + let n = List.length delegates_name_list in + let* block, delegates = Context.init_with_constants_n constants n in + let*? init_level = Context.get_level (B block) in + let init_staked = Tez.of_mutez 200_000_000_000L in + let*? account_map = + List.fold_left2 + ~when_different_lengths: + [Inconsistent_number_of_bootstrap_accounts] + (fun account_map name contract -> + let liquid = + Tez.(Account.default_initial_balance -! init_staked) + in + let frozen_deposits = Frozen_tez.init init_staked name name in + let frozen_rights = + List.fold_left + (fun map cycle -> CycleMap.add cycle init_staked map) + CycleMap.empty + Cycle.( + root ---> add root constants.consensus_rights_delay) + in + let pkh = Context.Contract.pkh contract in + let account = + init_account + ~delegate:name + ~pkh + ~contract + ~parameters:default_params + ~liquid + ~frozen_deposits + ~frozen_rights + () + in + let account_map = String.Map.add name account account_map in + let balance, total_balance = + balance_and_total_balance_of_account name account_map + in + Log.debug + "Initial balance for %s:\n%a" + name + balance_pp + balance ; + Log.debug "Initial total balance: %a" Tez.pp total_balance ; + account_map) + String.Map.empty + delegates_name_list + delegates + in + let* total_supply = Context.get_total_supply (B block) in + let state = + State. + { + account_map; + total_supply; + constants; + param_requests = []; + activate_ai; + baking_policy = None; + last_level_rewards = init_level; + snapshot_balances = String.Map.empty; + saved_rate = None; + burn_rewards; + pending_operations = []; + pending_slashes = []; + double_signings = []; + } + in + let* () = check_all_balances block state in + return (block, state)) + in + if ns_enable_fork then + Tag "ns_enable = true" --> f true |+ Tag "ns_enable = false" --> f false + else f false 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 2239559e442c..dbace497d2e2 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 @@ -20,6 +20,7 @@ open Scenario_base open Scenario_op open Test_scenario_base open Log_helpers +open Scenario_begin let assert_balance_evolution ~loc ~for_accounts ~part ~name ~old_balance ~new_balance compare = 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 d4f8a14ae732..eeeee8c3f6fd 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 @@ -19,6 +19,7 @@ open Tez_helpers.Ez_tez open Scenario_dsl open Scenario_base open Scenario_op +open Scenario_begin let default_param_wait, default_unstake_wait = let constants = Default_parameters.constants_test in 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 4a042ae3452a..507e515354d1 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 @@ -20,6 +20,7 @@ open Scenario_dsl open Scenario_base open Scenario_op open Test_scenario_base +open Scenario_begin let test_wait_with_rewards = let constants = 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 5e85c36b61d5..01528729cc84 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 @@ -38,6 +38,7 @@ open Scenario_dsl open Scenario_base open Scenario_op open Test_scenario_base +open Scenario_begin let fs = Format.asprintf 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 f5474e2eeaa4..84b16141a8bd 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 @@ -20,6 +20,7 @@ open Scenario_dsl open Scenario_base open Scenario_op open Test_scenario_base +open Scenario_begin let fs = Format.asprintf -- GitLab From 3d6d0f29c1fd51f96124e526140f8cbc611ae444 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 21 Feb 2024 14:17:55 +0100 Subject: [PATCH 02/10] Proto/tests: create Scenario module For convenience: tests only need ot include one module --- .../lib_protocol/test/helpers/scenario.ml | 15 +++++++++++++++ .../test/integration/test_scenario_autostaking.ml | 5 +---- .../test/integration/test_scenario_base.ml | 5 +---- .../test/integration/test_scenario_rewards.ml | 5 +---- .../test/integration/test_scenario_slashing.ml | 5 +---- .../test/integration/test_scenario_stake.ml | 5 +---- 6 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 src/proto_alpha/lib_protocol/test/helpers/scenario.ml diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario.ml new file mode 100644 index 000000000000..4d329f8fc5f9 --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario.ml @@ -0,0 +1,15 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2024 Nomadic Labs, *) +(* *) +(*****************************************************************************) + +(** This module centralises all modules related to [Scenario] writing and + execution. Most scenario tests would use most if not all of them, so + they only need to [open Scenario]. *) + +include Scenario_base +include Scenario_op +include Scenario_dsl +include Scenario_begin 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 dbace497d2e2..814f2eda9ea4 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 @@ -15,12 +15,9 @@ open State_account open Tez_helpers.Ez_tez -open Scenario_dsl -open Scenario_base -open Scenario_op +open Scenario open Test_scenario_base open Log_helpers -open Scenario_begin let assert_balance_evolution ~loc ~for_accounts ~part ~name ~old_balance ~new_balance compare = 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 eeeee8c3f6fd..55982ffa69cd 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 @@ -16,10 +16,7 @@ open Adaptive_issuance_helpers open State_account open Tez_helpers.Ez_tez -open Scenario_dsl -open Scenario_base -open Scenario_op -open Scenario_begin +open Scenario let default_param_wait, default_unstake_wait = let constants = Default_parameters.constants_test in 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 507e515354d1..d4217c96780b 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 @@ -16,11 +16,8 @@ open Adaptive_issuance_helpers open State_account open Tez_helpers.Ez_tez -open Scenario_dsl -open Scenario_base -open Scenario_op +open Scenario open Test_scenario_base -open Scenario_begin let test_wait_with_rewards = let constants = 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 01528729cc84..18420110fd6b 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 @@ -34,11 +34,8 @@ open Adaptive_issuance_helpers open State_account open Tez_helpers.Ez_tez -open Scenario_dsl -open Scenario_base -open Scenario_op +open Scenario open Test_scenario_base -open Scenario_begin let fs = Format.asprintf 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 84b16141a8bd..7122fb2e85ee 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 @@ -16,11 +16,8 @@ open Adaptive_issuance_helpers open State_account open Tez_helpers.Ez_tez -open Scenario_dsl -open Scenario_base -open Scenario_op +open Scenario open Test_scenario_base -open Scenario_begin let fs = Format.asprintf -- GitLab From bba34377a28a2aa808211094937bda08e12a2e16 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 21 Feb 2024 15:30:23 +0100 Subject: [PATCH 03/10] Proto/tests: separate protocol start and constants definition --- .../test/helpers/scenario_begin.ml | 53 ++++++++++++++++--- .../lib_protocol/test/helpers/scenario_dsl.ml | 14 ----- 2 files changed, 45 insertions(+), 22 deletions(-) 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 a08f8f83976d..3b0e009ceeb3 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -14,23 +14,60 @@ open Adaptive_issuance_helpers (** Returns when the number of bootstrap accounts created by [Context.init_n n] is not equal to [n] *) type error += Inconsistent_number_of_bootstrap_accounts +type starter_constants = Mainnet | Sandbox | Test + +type constants = Protocol.Alpha_context.Constants.Parametric.t + +let start ~(constants : starter_constants) : (unit, constants) scenarios = + let constants, name = + match constants with + | Mainnet -> (Default_parameters.constants_mainnet, "mainnet") + | Sandbox -> (Default_parameters.constants_sandbox, "sandbox") + | Test -> (Default_parameters.constants_test, "test") + in + Action + (fun () -> + Log.info ~color:begin_end_color "-- Begin test --" ; + Log.info "Loading constants_%s." name ; + return constants) + +let start_with ~(constants : constants) : (unit, constants) scenarios = + Action + (fun () -> + Log.info ~color:begin_end_color "-- Begin test --" ; + Log.info "Loading custom constants." ; + return constants) + +let start_with_list ~(constants : (string * constants) list) : + (unit, constants) scenarios = + match constants with + | [] -> + Stdlib.failwith + (Format.asprintf + "%s: Cannot build scenarios from\n empty list" + __LOC__) + | (tag, constants) :: t -> + List.fold_left + (fun scenarios (tag, constants) -> + scenarios |+ Tag tag --> start_with ~constants) + (Tag tag --> start_with ~constants) + t + (** Initialize the test, given some initial parameters *) let begin_test ~activate_ai ?(burn_rewards = false) ?(ns_enable_fork = false) - ?(constants : Protocol.Alpha_context.Constants.Parametric.t option) - ?(constants_list : - (string * Protocol.Alpha_context.Constants.Parametric.t) list option) - delegates_name_list : (unit, t) scenarios = + ?(constants : constants option) + ?(constants_list : (string * constants) list option) delegates_name_list : + (unit, t) scenarios = let f ns_enable = (match (constants, constants_list) with | None, None -> Stdlib.failwith "No constants provided to begin_test" | Some _, Some _ -> Stdlib.failwith "You cannot provide ~constants and ~constants_list to begin_test" - | None, Some constants_list -> list_to_branch constants_list - | Some constants, None -> Action (fun () -> return constants)) - --> exec (fun (constants : Protocol.Alpha_context.Constants.Parametric.t) -> + | None, Some constants -> start_with_list ~constants + | Some constants, None -> start_with ~constants) + --> exec (fun (constants : constants) -> let open Lwt_result_syntax in - Log.info ~color:begin_end_color "-- Begin test --" ; let bootstrap = "__bootstrap__" in let delegates_name_list = bootstrap :: delegates_name_list in (* Override threshold value if activate *) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_dsl.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_dsl.ml index efb4686a6592..000fb217ae37 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_dsl.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_dsl.ml @@ -130,20 +130,6 @@ let ( --> ) a b = concat a b (** Branching connector: creates two tests with different execution paths *) let ( |+ ) a b = branch a b -let list_to_branch (list : (string * 'a) list) : (unit, 'a) scenarios = - match list with - | [] -> - Stdlib.failwith - (Format.asprintf - "%s: Cannot build scenarios from\n empty list" - __LOC__) - | (tag, h) :: t -> - List.fold_left - (fun scenarios (tag, elt) -> - scenarios |+ Tag tag --> Action (fun () -> return elt)) - (Tag tag --> Action (fun () -> return h)) - t - (** Ends the test. Dump the state, returns [unit] *) let end_test : ('a, unit) scenarios = let open Lwt_result_syntax in -- GitLab From afb5137ec35b6d4221d526f417b3ff445d052fe7 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Fri, 23 Feb 2024 11:32:30 +0100 Subject: [PATCH 04/10] Proto/tests: add helpers for constants setting --- .../test/helpers/constants_helpers.ml | 34 ++++++++++++++ .../test/helpers/scenario_begin.ml | 15 ++----- .../test/helpers/scenario_constants.ml | 44 +++++++++++++++++++ .../lib_protocol/test/helpers/scenario_dsl.ml | 31 +++++++++++++ 4 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml create mode 100644 src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml diff --git a/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml new file mode 100644 index 000000000000..25a5cd680596 --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml @@ -0,0 +1,34 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2024 Nomadic Labs, *) +(* *) +(*****************************************************************************) + +type t = Protocol.Alpha_context.Constants.Parametric.t + +(* Warning: not a Set *) +module Set = struct + let issuance_weights (c : t) issuance_weights = {c with issuance_weights} + + module Issuance_weights = struct + let base_total_issued_per_minute (c : t) base_total_issued_per_minute = + issuance_weights c {c.issuance_weights with base_total_issued_per_minute} + end + + let adaptive_issuance (c : t) adaptive_issuance = {c with adaptive_issuance} + + module Adaptive_issuance = struct + let activation_vote_enable (c : t) activation_vote_enable = + adaptive_issuance c {c.adaptive_issuance with activation_vote_enable} + + let autostaking_enable (c : t) autostaking_enable = + adaptive_issuance c {c.adaptive_issuance with autostaking_enable} + + let force_activation (c : t) force_activation = + adaptive_issuance c {c.adaptive_issuance with force_activation} + + let ns_enable (c : t) ns_enable = + adaptive_issuance c {c.adaptive_issuance with ns_enable} + end +end 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 3b0e009ceeb3..51cb2fdad5e9 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -11,13 +11,13 @@ open Scenario_base open Log_helpers open Adaptive_issuance_helpers +type constants = Constants_helpers.t + (** Returns when the number of bootstrap accounts created by [Context.init_n n] is not equal to [n] *) type error += Inconsistent_number_of_bootstrap_accounts type starter_constants = Mainnet | Sandbox | Test -type constants = Protocol.Alpha_context.Constants.Parametric.t - let start ~(constants : starter_constants) : (unit, constants) scenarios = let constants, name = match constants with @@ -43,15 +43,8 @@ let start_with_list ~(constants : (string * constants) list) : match constants with | [] -> Stdlib.failwith - (Format.asprintf - "%s: Cannot build scenarios from\n empty list" - __LOC__) - | (tag, constants) :: t -> - List.fold_left - (fun scenarios (tag, constants) -> - scenarios |+ Tag tag --> start_with ~constants) - (Tag tag --> start_with ~constants) - t + (Format.asprintf "%s: Cannot build scenarios from empty list" __LOC__) + | _ -> fold_tag (fun constants -> start_with ~constants) constants (** Initialize the test, given some initial parameters *) let begin_test ~activate_ai ?(burn_rewards = false) ?(ns_enable_fork = false) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml new file mode 100644 index 000000000000..d310d91a97eb --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml @@ -0,0 +1,44 @@ +(*****************************************************************************) +(* *) +(* SPDX-License-Identifier: MIT *) +(* Copyright (c) 2024 Nomadic Labs, *) +(* *) +(*****************************************************************************) + +open Scenario_dsl + +type constants = Constants_helpers.t + +(* Not a Set *) +include Constants_helpers.Set + +let set : + (constants -> 'a -> constants) -> 'a -> (constants, constants) scenarios = + fun f x -> Action (fun csts -> return @@ f csts x) + +let sets : + (constants -> 'a -> constants) -> + (string * 'a) list -> + (constants, constants) scenarios = + fun f -> fold_tag (set f) + +let sets_f : + (constants -> 'a -> constants) -> + ('a -> string) -> + 'a list -> + (constants, constants) scenarios = + fun f f_tag -> fold_tag_f (set f) f_tag + +let any_flag : + (constants -> bool -> constants) -> (constants, constants) scenarios = + fun f -> sets f [("true", true); ("false", false)] + +let rec any_flags : + (constants -> bool -> constants) list -> (constants, constants) scenarios = + unfold any_flag + +let sets_int : + (constants -> int -> constants) -> + int list -> + (constants, constants) scenarios = + fun f -> sets_f f string_of_int diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_dsl.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_dsl.ml index 000fb217ae37..2f8b87ed57ea 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_dsl.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_dsl.ml @@ -166,3 +166,34 @@ let exec_unit f = (fun input -> let* () = f input in return input) + +(** [fold f l] folds [f] over [l], fails on empty list *) +let rec fold : ('a -> ('b, 'c) scenarios) -> 'a list -> ('b, 'c) scenarios = + fun f list -> + match list with + | [] -> Stdlib.failwith "Scenario_dsl.fold: empty list" + | [x] -> f x + | h :: t -> f h |+ fold f t + +(** [fold_tag f l] folds [f] over [l], [l] has a tag for each of its elements. + Fails on empty list. *) +let fold_tag : + ('a -> ('b, 'c) scenarios) -> (string * 'a) list -> ('b, 'c) scenarios = + fun f -> + let f (s, x) = Tag s --> f x in + fold f + +(** [fold_tag_f f tag l] folds [f] over [l], [tag] returns a tag for each element of [l]. + Fails on empty list. *) +let fold_tag_f : + ('a -> ('b, 'c) scenarios) -> + ('a -> string) -> + 'a list -> + ('b, 'c) scenarios = + fun f tag -> + let f x = Tag (tag x) --> f x in + fold f + +(** [unfold f l] maps [f] over [l], and runs them in order *) +let rec unfold : ('a -> ('b, 'b) scenarios) -> 'a list -> ('b, 'b) scenarios = + fun f -> function [] -> Empty | [x] -> f x | h :: t -> f h --> unfold f t -- GitLab From a70bc77e616195337d7df06e0cc17e7a853eecda Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Fri, 23 Feb 2024 14:41:24 +0100 Subject: [PATCH 05/10] Proto/tests: make begin_test a (constants, t) scenarios --- .../test/helpers/constants_helpers.ml | 3 + .../test/helpers/scenario_base.ml | 6 + .../test/helpers/scenario_begin.ml | 177 ++++++++---------- .../test/helpers/scenario_constants.ml | 2 +- .../integration/test_scenario_autostaking.ml | 10 +- .../test/integration/test_scenario_base.ml | 11 +- .../test/integration/test_scenario_rewards.ml | 9 +- .../integration/test_scenario_slashing.ml | 87 ++++----- .../test/integration/test_scenario_stake.ml | 14 +- 9 files changed, 143 insertions(+), 176 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml index 25a5cd680596..6f987ed41722 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml @@ -30,5 +30,8 @@ module Set = struct let ns_enable (c : t) ns_enable = adaptive_issuance c {c.adaptive_issuance with ns_enable} + + let launch_ema_threshold (c : t) launch_ema_threshold = + adaptive_issuance c {c.adaptive_issuance with launch_ema_threshold} end end diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_base.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_base.ml index 6831d193a07d..9bb65e47cede 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_base.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_base.ml @@ -22,6 +22,12 @@ type error += Unexpected_error and the known [State.t] *) type t = Block.t * State.t +let log ?color s = + let open Lwt_result_syntax in + exec_unit (fun _ -> + Log.info ?color s ; + return_unit) + (* ======== Baking ======== *) (** After baking and applying rewards in state *) 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 51cb2fdad5e9..6caa0bb15e65 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -10,8 +10,7 @@ open Scenario_dsl open Scenario_base open Log_helpers open Adaptive_issuance_helpers - -type constants = Constants_helpers.t +open Scenario_constants (** Returns when the number of bootstrap accounts created by [Context.init_n n] is not equal to [n] *) type error += Inconsistent_number_of_bootstrap_accounts @@ -46,108 +45,80 @@ let start_with_list ~(constants : (string * constants) list) : (Format.asprintf "%s: Cannot build scenarios from empty list" __LOC__) | _ -> fold_tag (fun constants -> start_with ~constants) constants +let activate_ai flag = + if flag then + log ~color:event_color "Setting ai threshold to 0" + --> set Adaptive_issuance.launch_ema_threshold 0l + --> set Adaptive_issuance.activation_vote_enable true + else Empty + (** Initialize the test, given some initial parameters *) -let begin_test ~activate_ai ?(burn_rewards = false) ?(ns_enable_fork = false) - ?(constants : constants option) - ?(constants_list : (string * constants) list option) delegates_name_list : - (unit, t) scenarios = - let f ns_enable = - (match (constants, constants_list) with - | None, None -> Stdlib.failwith "No constants provided to begin_test" - | Some _, Some _ -> - Stdlib.failwith - "You cannot provide ~constants and ~constants_list to begin_test" - | None, Some constants -> start_with_list ~constants - | Some constants, None -> start_with ~constants) - --> exec (fun (constants : constants) -> - let open Lwt_result_syntax in - let bootstrap = "__bootstrap__" in - let delegates_name_list = bootstrap :: delegates_name_list in - (* Override threshold value if activate *) - let constants = - if activate_ai then ( - Log.info ~color:event_color "Setting ai threshold to 0" ; - { - constants with - adaptive_issuance = - { - constants.adaptive_issuance with - launch_ema_threshold = 0l; - activation_vote_enable = true; - ns_enable; - }; - }) - else constants +let begin_test ?(burn_rewards = false) delegates_name_list : + (constants, t) scenarios = + exec (fun (constants : constants) -> + let open Lwt_result_syntax in + let bootstrap = "__bootstrap__" in + let delegates_name_list = bootstrap :: delegates_name_list in + (* Override threshold value if activate *) + let n = List.length delegates_name_list in + let* block, delegates = Context.init_with_constants_n constants n in + let*? init_level = Context.get_level (B block) in + let init_staked = Tez.of_mutez 200_000_000_000L in + let*? account_map = + List.fold_left2 + ~when_different_lengths:[Inconsistent_number_of_bootstrap_accounts] + (fun account_map name contract -> + let liquid = Tez.(Account.default_initial_balance -! init_staked) in + let frozen_deposits = Frozen_tez.init init_staked name name in + let frozen_rights = + List.fold_left + (fun map cycle -> CycleMap.add cycle init_staked map) + CycleMap.empty + Cycle.(root ---> add root constants.consensus_rights_delay) in - let n = List.length delegates_name_list in - let* block, delegates = Context.init_with_constants_n constants n in - let*? init_level = Context.get_level (B block) in - let init_staked = Tez.of_mutez 200_000_000_000L in - let*? account_map = - List.fold_left2 - ~when_different_lengths: - [Inconsistent_number_of_bootstrap_accounts] - (fun account_map name contract -> - let liquid = - Tez.(Account.default_initial_balance -! init_staked) - in - let frozen_deposits = Frozen_tez.init init_staked name name in - let frozen_rights = - List.fold_left - (fun map cycle -> CycleMap.add cycle init_staked map) - CycleMap.empty - Cycle.( - root ---> add root constants.consensus_rights_delay) - in - let pkh = Context.Contract.pkh contract in - let account = - init_account - ~delegate:name - ~pkh - ~contract - ~parameters:default_params - ~liquid - ~frozen_deposits - ~frozen_rights - () - in - let account_map = String.Map.add name account account_map in - let balance, total_balance = - balance_and_total_balance_of_account name account_map - in - Log.debug - "Initial balance for %s:\n%a" - name - balance_pp - balance ; - Log.debug "Initial total balance: %a" Tez.pp total_balance ; - account_map) - String.Map.empty - delegates_name_list - delegates + let pkh = Context.Contract.pkh contract in + let account = + init_account + ~delegate:name + ~pkh + ~contract + ~parameters:default_params + ~liquid + ~frozen_deposits + ~frozen_rights + () in - let* total_supply = Context.get_total_supply (B block) in - let state = - State. - { - account_map; - total_supply; - constants; - param_requests = []; - activate_ai; - baking_policy = None; - last_level_rewards = init_level; - snapshot_balances = String.Map.empty; - saved_rate = None; - burn_rewards; - pending_operations = []; - pending_slashes = []; - double_signings = []; - } + let account_map = String.Map.add name account account_map in + let balance, total_balance = + balance_and_total_balance_of_account name account_map in - let* () = check_all_balances block state in - return (block, state)) - in - if ns_enable_fork then - Tag "ns_enable = true" --> f true |+ Tag "ns_enable = false" --> f false - else f false + Log.debug "Initial balance for %s:\n%a" name balance_pp balance ; + Log.debug "Initial total balance: %a" Tez.pp total_balance ; + account_map) + String.Map.empty + delegates_name_list + delegates + in + let* total_supply = Context.get_total_supply (B block) in + let state = + State. + { + account_map; + total_supply; + constants; + param_requests = []; + activate_ai = + constants.adaptive_issuance.activation_vote_enable + && constants.adaptive_issuance.launch_ema_threshold = 0l; + baking_policy = None; + last_level_rewards = init_level; + snapshot_balances = String.Map.empty; + saved_rate = None; + burn_rewards; + pending_operations = []; + pending_slashes = []; + double_signings = []; + } + in + let* () = check_all_balances block state in + return (block, state)) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml index d310d91a97eb..19013f13ab34 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml @@ -33,7 +33,7 @@ let any_flag : (constants -> bool -> constants) -> (constants, constants) scenarios = fun f -> sets f [("true", true); ("false", false)] -let rec any_flags : +let any_flags : (constants -> bool -> constants) list -> (constants, constants) scenarios = unfold any_flag 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 814f2eda9ea4..75359a2a536a 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 @@ -52,7 +52,9 @@ and delegator2 = "delegator2" let setup ~activate_ai = let constants = init_constants ~autostaking_enable:true () in - begin_test ~activate_ai ~constants [delegate] + start_with ~constants + --> Scenario_begin.activate_ai activate_ai + --> begin_test [delegate] --> add_account_with_funds delegator1 "__bootstrap__" @@ -141,10 +143,8 @@ let test_overdelegation = (* This test assumes that all delegate accounts created in [begin_test] begin with 4M tz, with 5% staked *) let constants = init_constants ~autostaking_enable:true () in - begin_test - ~activate_ai:false - ~constants - ["delegate"; "faucet1"; "faucet2"; "faucet3"] + start_with ~constants --> activate_ai false + --> begin_test ["delegate"; "faucet1"; "faucet2"; "faucet3"] --> add_account_with_funds "delegator_to_fund" "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 55982ffa69cd..f6982b0d0601 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 @@ -77,7 +77,12 @@ let init_constants ?reward_per_block ?(deactivate_dynamic = false) else adaptive_issuance.adaptive_rewards_params in let adaptive_issuance = - {adaptive_issuance with adaptive_rewards_params; autostaking_enable} + { + adaptive_issuance with + adaptive_rewards_params; + autostaking_enable; + ns_enable = false; + } in { default_constants with @@ -106,7 +111,9 @@ let init_scenario ?(force_ai = true) ?reward_per_block () = in let begin_test ~activate_ai ~self_stake = let name = if self_stake then "staker" else "delegate" in - begin_test ~activate_ai ~constants [name] + start_with ~constants + --> Scenario_begin.activate_ai activate_ai + --> begin_test [name] --> set_delegate_params name init_params --> set_baker "__bootstrap__" in 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 d4217c96780b..f46576158504 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 @@ -32,7 +32,8 @@ let test_wait_with_rewards = in set_delegate_params "delegate" params in - begin_test ~activate_ai:true ~constants ["delegate"; "faucet"] + start_with ~constants --> activate_ai true + --> begin_test ["delegate"; "faucet"] --> set_baker "faucet" --> (Tag "edge = 0" --> set_edge 0. |+ Tag "edge = 0.24" --> set_edge 0.24 @@ -83,7 +84,8 @@ let test_ai_curve_activation_time = () in let pc = constants.consensus_rights_delay in - begin_test ~activate_ai:true ~burn_rewards:true ~constants [""] + start_with ~constants --> activate_ai true + --> begin_test ~burn_rewards:true [""] --> next_block --> save_current_rate (* before AI rate *) --> wait_ai_activation (* Rate remains unchanged right after AI activation, we must wait [pc + 1] cycles *) @@ -119,7 +121,8 @@ let test_static = let cycle_stable = save_current_rate --> next_cycle --> check_rate_evolution Q.equal in - begin_test ~activate_ai:true ~burn_rewards:true ~constants ["delegate"] + start_with ~constants --> activate_ai true + --> begin_test ~burn_rewards:true ["delegate"] --> set_delegate_params "delegate" init_params --> save_current_rate --> wait_ai_activation (* We stake about 50% of the total supply *) 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 18420110fd6b..8e213fe169a5 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 @@ -36,6 +36,7 @@ open State_account open Tez_helpers.Ez_tez open Scenario open Test_scenario_base +open Scenario_constants let fs = Format.asprintf @@ -48,11 +49,9 @@ let test_simple_slash = |+ Tag "double preattesting" --> double_preattest ~other_bakers:("bootstrap2", "bootstrap3") delegate in - begin_test - ~activate_ai:true - ~ns_enable_fork:true - ~constants - ["delegate"; "bootstrap1"; "bootstrap2"; "bootstrap3"] + start_with ~constants --> activate_ai true + --> any_flag Adaptive_issuance.ns_enable + --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"; "bootstrap3"] --> (Tag "No AI" --> next_cycle |+ Tag "Yes AI" --> next_block --> wait_ai_activation) --> any_slash "delegate" @@ -129,11 +128,9 @@ let test_delegate_forbidden = let constants = init_constants ~blocks_per_cycle:30l ~autostaking_enable:false () in - begin_test - ~activate_ai:false - ~ns_enable_fork:true - ~constants - ["delegate"; "bootstrap1"; "bootstrap2"] + start_with ~constants --> activate_ai false + --> any_flag Adaptive_issuance.ns_enable + --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] --> set_baker "bootstrap1" --> (Tag "Many double bakes" --> loop_action 14 (double_bake_ "delegate") @@ -175,11 +172,9 @@ let test_delegate_forbidden = let test_slash_unstake = let constants = init_constants ~autostaking_enable:false () in - begin_test - ~activate_ai:false - ~ns_enable_fork:true - ~constants - ["delegate"; "bootstrap1"; "bootstrap2"] + start_with ~constants --> activate_ai false + --> any_flag Adaptive_issuance.ns_enable + --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] --> set_baker "bootstrap1" --> next_cycle --> unstake "delegate" Half --> next_cycle --> double_bake "delegate" --> make_denunciations () --> (Empty |+ Tag "unstake twice" --> unstake "delegate" Half) @@ -191,11 +186,9 @@ let test_slash_monotonous_stake = let constants = init_constants ~blocks_per_cycle:16l ~autostaking_enable:false () in - begin_test - ~activate_ai:false - ~ns_enable_fork:true - ~constants - ["delegate"; "bootstrap1"] + start_with ~constants --> activate_ai false + --> any_flag Adaptive_issuance.ns_enable + --> begin_test ["delegate"; "bootstrap1"] --> next_cycle --> loop 6 @@ -244,8 +237,9 @@ let test_slash_timing = let constants = init_constants ~blocks_per_cycle:8l ~autostaking_enable:false () in - begin_test ~activate_ai:false ~ns_enable_fork:true ~constants ["delegate"] - --> next_cycle + start_with ~constants --> activate_ai false + --> any_flag Adaptive_issuance.ns_enable + --> begin_test ["delegate"] --> next_cycle --> (Tag "stake" --> stake "delegate" Half |+ Tag "unstake" --> unstake "delegate" Half) --> (Tag "with a first slash" --> double_bake "delegate" @@ -273,11 +267,9 @@ let init_scenario_with_delegators delegate_name faucet_name delegators_list = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - begin_test - ~activate_ai:true - ~ns_enable_fork:true - ~constants - [delegate_name; faucet_name] + start_with ~constants --> activate_ai true + --> any_flag Adaptive_issuance.ns_enable + --> begin_test [delegate_name; faucet_name] --> set_baker faucet_name --> set_delegate_params "delegate" init_params --> init_delegators delegators_list @@ -328,11 +320,8 @@ let test_no_shortcut_for_cheaters = let constants = init_constants ~autostaking_enable:false () in let amount = Amount (Tez.of_mutez 333_000_000_000L) in let consensus_rights_delay = constants.consensus_rights_delay in - begin_test - ~activate_ai:true - ~ns_enable_fork:false - ~constants - ["delegate"; "bootstrap1"] + start_with ~constants --> activate_ai true + --> begin_test ["delegate"; "bootstrap1"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) --> next_cycle --> double_bake "delegate" --> make_denunciations () @@ -357,11 +346,8 @@ let test_slash_correct_amount_after_stake_from_unstake = let amount_to_restake = Amount (Tez.of_mutez 100_000_000_000L) in let amount_expected_in_unstake_after_slash = Tez.of_mutez 50_000_000_000L in let consensus_rights_delay = constants.consensus_rights_delay in - begin_test - ~activate_ai:true - ~ns_enable_fork:false - ~constants - ["delegate"; "bootstrap1"] + start_with ~constants --> activate_ai true + --> begin_test ["delegate"; "bootstrap1"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) --> next_cycle @@ -382,19 +368,12 @@ let test_slash_correct_amount_after_stake_from_unstake = (* Test a non-zero request finalizes for a non-zero amount if it hasn't been slashed 100% *) let test_mini_slash = let constants = init_constants ~autostaking_enable:false () in - (Tag "Yes AI" - --> begin_test - ~activate_ai:true - ~ns_enable_fork:false - ~constants - ["delegate"; "baker"] - --> next_block --> wait_ai_activation - |+ Tag "No AI" - --> begin_test - ~activate_ai:false - ~ns_enable_fork:false - ~constants - ["delegate"; "baker"]) + start_with ~constants + --> (Tag "Yes AI" --> activate_ai true + --> begin_test ["delegate"; "baker"] + --> next_block --> wait_ai_activation + |+ Tag "No AI" --> activate_ai false --> begin_test ["delegate"; "baker"] + ) --> unstake "delegate" (Amount Tez.one_mutez) --> set_baker "baker" --> next_cycle --> (Tag "5% slash" --> double_bake "delegate" --> make_denunciations () @@ -409,11 +388,9 @@ let test_mini_slash = let test_slash_rounding = let constants = init_constants ~autostaking_enable:false () in - begin_test - ~activate_ai:true - ~ns_enable_fork:true - ~constants - ["delegate"; "baker"] + start_with ~constants --> activate_ai true + --> any_flag Adaptive_issuance.ns_enable + --> begin_test ["delegate"; "baker"] --> set_baker "baker" --> next_block --> wait_ai_activation --> unstake "delegate" (Amount (Tez.of_mutez 2L)) --> next_cycle --> double_bake "delegate" --> double_bake "delegate" 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 7122fb2e85ee..13785b6d0262 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 @@ -59,7 +59,7 @@ let shorter_roundtrip_for_baker = let constants = init_constants ~autostaking_enable:false () in let amount = Amount (Tez.of_mutez 333_000_000_000L) in let consensus_rights_delay = constants.consensus_rights_delay in - begin_test ~activate_ai:true ~constants ["delegate"] + start_with ~constants --> activate_ai true --> begin_test ["delegate"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) --> next_cycle @@ -157,7 +157,8 @@ let change_delegate = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - begin_test ~activate_ai:true ~constants ["delegate1"; "delegate2"] + start_with ~constants --> activate_ai true + --> begin_test ["delegate1"; "delegate2"] --> set_delegate_params "delegate1" init_params --> set_delegate_params "delegate2" init_params --> add_account_with_funds @@ -177,7 +178,7 @@ let unset_delegate = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - begin_test ~activate_ai:true ~constants ["delegate"] + start_with ~constants --> activate_ai true --> begin_test ["delegate"] --> set_delegate_params "delegate" init_params --> add_account_with_funds "staker" @@ -223,15 +224,14 @@ let forbid_costaking = in let amount = Amount (Tez.of_mutez 1_000_000L) in (* init *) - begin_test - ~activate_ai:true - ~constants_list: + start_with_list + ~constants: [ default_constants; small_delegate_parameter_constants; large_delegate_parameter_constants; ] - ["delegate"] + --> activate_ai true --> begin_test ["delegate"] --> set_delegate_params "delegate" init_params --> add_account_with_funds "staker" -- GitLab From bf6a206b00aa46e572d2d680429e84be4a062f54 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Tue, 27 Feb 2024 10:08:09 +0100 Subject: [PATCH 06/10] Proto/tests: all the constants (almost) --- .../test/helpers/constants_helpers.ml | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml index 6f987ed41722..8ae4d2913f1b 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml @@ -9,6 +9,121 @@ type t = Protocol.Alpha_context.Constants.Parametric.t (* Warning: not a Set *) module Set = struct + let consensus_rights_delay (c : t) consensus_rights_delay = + {c with consensus_rights_delay} + + let blocks_preservation_cycles (c : t) blocks_preservation_cycles = + {c with blocks_preservation_cycles} + + let delegate_parameters_activation_delay (c : t) + delegate_parameters_activation_delay = + {c with delegate_parameters_activation_delay} + + let blocks_per_cycle (c : t) blocks_per_cycle = {c with blocks_per_cycle} + + let blocks_per_commitment (c : t) blocks_per_commitment = + {c with blocks_per_commitment} + + let nonce_revelation_threshold (c : t) nonce_revelation_threshold = + {c with nonce_revelation_threshold} + + let cycles_per_voting_period (c : t) cycles_per_voting_period = + {c with cycles_per_voting_period} + + let hard_gas_limit_per_operation (c : t) hard_gas_limit_per_operation = + {c with hard_gas_limit_per_operation} + + let hard_gas_limit_per_block (c : t) hard_gas_limit_per_block = + {c with hard_gas_limit_per_block} + + let proof_of_work_threshold (c : t) proof_of_work_threshold = + {c with proof_of_work_threshold} + + let minimal_stake (c : t) minimal_stake = {c with minimal_stake} + + let minimal_frozen_stake (c : t) minimal_frozen_stake = + {c with minimal_frozen_stake} + + let vdf_difficulty (c : t) vdf_difficulty = {c with vdf_difficulty} + + let origination_size (c : t) origination_size = {c with origination_size} + + let cost_per_byte (c : t) cost_per_byte = {c with cost_per_byte} + + let hard_storage_limit_per_operation (c : t) hard_storage_limit_per_operation + = + {c with hard_storage_limit_per_operation} + + let quorum_min (c : t) quorum_min = {c with quorum_min} + + let quorum_max (c : t) quorum_max = {c with quorum_max} + + let min_proposal_quorum (c : t) min_proposal_quorum = + {c with min_proposal_quorum} + + let liquidity_baking_subsidy (c : t) liquidity_baking_subsidy = + {c with liquidity_baking_subsidy} + + let liquidity_baking_toggle_ema_threshold (c : t) + liquidity_baking_toggle_ema_threshold = + {c with liquidity_baking_toggle_ema_threshold} + + let max_operations_time_to_live (c : t) max_operations_time_to_live = + {c with max_operations_time_to_live} + + let minimal_block_delay (c : t) minimal_block_delay = + {c with minimal_block_delay} + + let delay_increment_per_round (c : t) delay_increment_per_round = + {c with delay_increment_per_round} + + let minimal_participation_ratio (c : t) minimal_participation_ratio = + {c with minimal_participation_ratio} + + let consensus_committee_size (c : t) consensus_committee_size = + {c with consensus_committee_size} + + let consensus_threshold (c : t) consensus_threshold = + {c with consensus_threshold} + + let limit_of_delegation_over_baking (c : t) limit_of_delegation_over_baking = + {c with limit_of_delegation_over_baking} + + let percentage_of_frozen_deposits_slashed_per_double_baking (c : t) + percentage_of_frozen_deposits_slashed_per_double_baking = + {c with percentage_of_frozen_deposits_slashed_per_double_baking} + + let percentage_of_frozen_deposits_slashed_per_double_attestation (c : t) + percentage_of_frozen_deposits_slashed_per_double_attestation = + {c with percentage_of_frozen_deposits_slashed_per_double_attestation} + + let max_slashing_per_block (c : t) max_slashing_per_block = + {c with max_slashing_per_block} + + let max_slashing_threshold (c : t) max_slashing_threshold = + {c with max_slashing_threshold} + + let testnet_dictator (c : t) testnet_dictator = {c with testnet_dictator} + + let initial_seed (c : t) initial_seed = {c with initial_seed} + + let cache_script_size (c : t) cache_script_size = {c with cache_script_size} + + let cache_stake_distribution_cycles (c : t) cache_stake_distribution_cycles = + {c with cache_stake_distribution_cycles} + + let cache_sampler_state_cycles (c : t) cache_sampler_state_cycles = + {c with cache_sampler_state_cycles} + + let dal (c : t) dal = {c with dal} + + let sc_rollup (c : t) sc_rollup = {c with sc_rollup} + + let zk_rollup (c : t) zk_rollup = {c with zk_rollup} + + let direct_ticket_spending_enable (c : t) direct_ticket_spending_enable = + {c with direct_ticket_spending_enable} + let issuance_weights (c : t) issuance_weights = {c with issuance_weights} module Issuance_weights = struct @@ -33,5 +148,15 @@ module Set = struct let launch_ema_threshold (c : t) launch_ema_threshold = adaptive_issuance c {c.adaptive_issuance with launch_ema_threshold} + + let adaptive_rewards_params (c : t) adaptive_rewards_params = + adaptive_issuance c {c.adaptive_issuance with adaptive_rewards_params} + + module Adaptive_rewards_params = struct + let max_bonus (c : t) max_bonus = + adaptive_rewards_params + c + {c.adaptive_issuance.adaptive_rewards_params with max_bonus} + end end end -- GitLab From b230306aff5dad9384a1d78ede9ef3845cc11977 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Tue, 27 Feb 2024 10:09:16 +0100 Subject: [PATCH 07/10] Proto/tests: refactor init_constants --- .../test/helpers/scenario_begin.ml | 4 +- .../test/helpers/scenario_constants.ml | 8 +- .../integration/test_scenario_autostaking.ml | 7 +- .../test/integration/test_scenario_base.ml | 96 +++++++------------ .../test/integration/test_scenario_rewards.ml | 38 ++++---- .../integration/test_scenario_slashing.ml | 72 +++++++------- .../test/integration/test_scenario_stake.ml | 60 +++++------- 7 files changed, 124 insertions(+), 161 deletions(-) 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 6caa0bb15e65..d1a2bfe9bb5e 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -48,8 +48,8 @@ let start_with_list ~(constants : (string * constants) list) : let activate_ai flag = if flag then log ~color:event_color "Setting ai threshold to 0" - --> set Adaptive_issuance.launch_ema_threshold 0l - --> set Adaptive_issuance.activation_vote_enable true + --> set S.Adaptive_issuance.launch_ema_threshold 0l + --> set S.Adaptive_issuance.activation_vote_enable true else Empty (** Initialize the test, given some initial parameters *) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml index 19013f13ab34..c467470c2c55 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml @@ -10,12 +10,18 @@ open Scenario_dsl type constants = Constants_helpers.t (* Not a Set *) -include Constants_helpers.Set +module S = Constants_helpers.Set let set : (constants -> 'a -> constants) -> 'a -> (constants, constants) scenarios = fun f x -> Action (fun csts -> return @@ f csts x) +let set_opt : + (constants -> 'a -> constants) -> + 'a option -> + (constants, constants) scenarios = + fun f -> function None -> Empty | Some x -> set f x + let sets : (constants -> 'a -> constants) -> (string * 'a) list -> 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 75359a2a536a..138b717cdac8 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 @@ -51,8 +51,7 @@ and delegator1 = "delegator1" and delegator2 = "delegator2" let setup ~activate_ai = - let constants = init_constants ~autostaking_enable:true () in - start_with ~constants + init_constants ~autostaking_enable:true () --> Scenario_begin.activate_ai activate_ai --> begin_test [delegate] --> add_account_with_funds @@ -142,8 +141,8 @@ let test_autostaking = let test_overdelegation = (* This test assumes that all delegate accounts created in [begin_test] begin with 4M tz, with 5% staked *) - let constants = init_constants ~autostaking_enable:true () in - start_with ~constants --> activate_ai false + init_constants ~autostaking_enable:true () + --> activate_ai false --> begin_test ["delegate"; "faucet1"; "faucet2"; "faucet3"] --> add_account_with_funds "delegator_to_fund" 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 f6982b0d0601..f333b36d4904 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 @@ -36,65 +36,40 @@ let test_expected_error = [Inconsistent_number_of_bootstrap_accounts]) (exec (fun _ -> failwith ""))) -let init_constants ?reward_per_block ?(deactivate_dynamic = false) - ?blocks_per_cycle ?delegate_parameters_activation_delay ~autostaking_enable - () = - let reward_per_block = Option.value ~default:0L reward_per_block in +(** Initializes the constants for testing, with well chosen default values. + Recommended over [start] or [start_with] *) +let init_constants ?(default = Test) ?(reward_per_block = 0L) + ?(deactivate_dynamic = false) ?blocks_per_cycle + ?delegate_parameters_activation_delay ~autostaking_enable () = + let open Scenario_constants in let base_total_issued_per_minute = Tez.of_mutez reward_per_block in - let default_constants = Default_parameters.constants_test in - (* default for tests: 12 *) - let blocks_per_cycle = - Option.value ~default:default_constants.blocks_per_cycle blocks_per_cycle - in - let delegate_parameters_activation_delay = - Option.value - ~default:default_constants.delegate_parameters_activation_delay - delegate_parameters_activation_delay - in - let issuance_weights = - Protocol.Alpha_context.Constants.Parametric. - { - base_total_issued_per_minute; - baking_reward_fixed_portion_weight = 1; - baking_reward_bonus_weight = 0; - attesting_reward_weight = 0; - seed_nonce_revelation_tip_weight = 0; - vdf_revelation_tip_weight = 0; - } - in - let liquidity_baking_subsidy = Tez.zero in - let minimal_block_delay = Protocol.Alpha_context.Period.one_minute in - let cost_per_byte = Tez.zero in - let consensus_threshold = 0 in - let adaptive_issuance = default_constants.adaptive_issuance in - let adaptive_rewards_params = - if deactivate_dynamic then - { - adaptive_issuance.adaptive_rewards_params with - max_bonus = - Protocol.Issuance_bonus_repr.max_bonus_parameter_of_Q_exn Q.zero; - } - else adaptive_issuance.adaptive_rewards_params - in - let adaptive_issuance = - { - adaptive_issuance with - adaptive_rewards_params; - autostaking_enable; - ns_enable = false; - } - in - { - default_constants with - delegate_parameters_activation_delay; - consensus_threshold; - issuance_weights; - minimal_block_delay; - cost_per_byte; - adaptive_issuance; - blocks_per_cycle; - liquidity_baking_subsidy; - } + start ~constants:default + --> (* default for tests: 12 *) + set_opt S.blocks_per_cycle blocks_per_cycle + --> set_opt + S.delegate_parameters_activation_delay + delegate_parameters_activation_delay + --> set + S.issuance_weights + { + base_total_issued_per_minute; + baking_reward_fixed_portion_weight = 1; + baking_reward_bonus_weight = 0; + attesting_reward_weight = 0; + seed_nonce_revelation_tip_weight = 0; + vdf_revelation_tip_weight = 0; + } + --> set S.liquidity_baking_subsidy Tez.zero + --> set S.minimal_block_delay Protocol.Alpha_context.Period.one_minute + --> set S.cost_per_byte Tez.zero + --> set S.consensus_threshold 0 + --> (if deactivate_dynamic then + set + S.Adaptive_issuance.Adaptive_rewards_params.max_bonus + (Protocol.Issuance_bonus_repr.max_bonus_parameter_of_Q_exn Q.zero) + else Empty) + --> set S.Adaptive_issuance.ns_enable false + --> set S.Adaptive_issuance.autostaking_enable autostaking_enable (** Initialization of scenarios with 3 cases: - AI activated, staker = delegate @@ -103,15 +78,12 @@ let init_constants ?reward_per_block ?(deactivate_dynamic = false) Any scenario that begins with this will be triplicated. *) let init_scenario ?(force_ai = true) ?reward_per_block () = - let constants = - init_constants ?reward_per_block ~autostaking_enable:false () - in 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 name = if self_stake then "staker" else "delegate" in - start_with ~constants + init_constants ?reward_per_block ~autostaking_enable:false () --> Scenario_begin.activate_ai activate_ai --> begin_test [name] --> set_delegate_params name init_params 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 f46576158504..f7cf16a0874e 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 @@ -20,9 +20,6 @@ open Scenario open Test_scenario_base let test_wait_with_rewards = - let constants = - init_constants ~reward_per_block:1_000_000_000L ~autostaking_enable:false () - in let set_edge pct = let params = { @@ -32,7 +29,8 @@ let test_wait_with_rewards = in set_delegate_params "delegate" params in - start_with ~constants --> activate_ai true + init_constants ~reward_per_block:1_000_000_000L ~autostaking_enable:false () + --> activate_ai true --> begin_test ["delegate"; "faucet"] --> set_baker "faucet" --> (Tag "edge = 0" --> set_edge 0. @@ -76,15 +74,13 @@ let test_wait_with_rewards = |+ Tag "cycle step" --> wait_n_cycles 10) let test_ai_curve_activation_time = - let constants = - init_constants - ~reward_per_block:1_000_000_000L - ~deactivate_dynamic:true - ~autostaking_enable:false - () - in - let pc = constants.consensus_rights_delay in - start_with ~constants --> activate_ai true + let pc = Default_parameters.constants_test.consensus_rights_delay in + init_constants + ~reward_per_block:1_000_000_000L + ~deactivate_dynamic:true + ~autostaking_enable:false + () + --> activate_ai true --> begin_test ~burn_rewards:true [""] --> next_block --> save_current_rate (* before AI rate *) --> wait_ai_activation @@ -98,14 +94,7 @@ let test_ai_curve_activation_time = --> check_rate_evolution Q.gt let test_static = - let constants = - init_constants - ~reward_per_block:1_000_000_000L - ~deactivate_dynamic:true - ~autostaking_enable:false - () - in - let rate_var_lag = constants.consensus_rights_delay in + let rate_var_lag = Default_parameters.constants_test.consensus_rights_delay in let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in @@ -121,7 +110,12 @@ let test_static = let cycle_stable = save_current_rate --> next_cycle --> check_rate_evolution Q.equal in - start_with ~constants --> activate_ai true + init_constants + ~reward_per_block:1_000_000_000L + ~deactivate_dynamic:true + ~autostaking_enable:false + () + --> activate_ai true --> begin_test ~burn_rewards:true ["delegate"] --> set_delegate_params "delegate" init_params --> save_current_rate --> wait_ai_activation 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 8e213fe169a5..85ac7dde76da 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 @@ -41,7 +41,6 @@ open Scenario_constants let fs = Format.asprintf let test_simple_slash = - let constants = init_constants ~autostaking_enable:false () in let any_slash delegate = Tag "double baking" --> double_bake delegate |+ Tag "double attesting" @@ -49,8 +48,9 @@ let test_simple_slash = |+ Tag "double preattesting" --> double_preattest ~other_bakers:("bootstrap2", "bootstrap3") delegate in - start_with ~constants --> activate_ai true - --> any_flag Adaptive_issuance.ns_enable + init_constants ~autostaking_enable:false () + --> activate_ai true + --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"; "bootstrap3"] --> (Tag "No AI" --> next_cycle |+ Tag "Yes AI" --> next_block --> wait_ai_activation) @@ -125,11 +125,9 @@ let check_is_not_forbidden baker = return input) let test_delegate_forbidden = - let constants = - init_constants ~blocks_per_cycle:30l ~autostaking_enable:false () - in - start_with ~constants --> activate_ai false - --> any_flag Adaptive_issuance.ns_enable + init_constants ~blocks_per_cycle:30l ~autostaking_enable:false () + --> activate_ai false + --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] --> set_baker "bootstrap1" --> (Tag "Many double bakes" @@ -171,9 +169,9 @@ let test_delegate_forbidden = --> check_is_forbidden "delegate") let test_slash_unstake = - let constants = init_constants ~autostaking_enable:false () in - start_with ~constants --> activate_ai false - --> any_flag Adaptive_issuance.ns_enable + init_constants ~autostaking_enable:false () + --> activate_ai false + --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] --> set_baker "bootstrap1" --> next_cycle --> unstake "delegate" Half --> next_cycle --> double_bake "delegate" --> make_denunciations () @@ -183,11 +181,9 @@ let test_slash_unstake = let test_slash_monotonous_stake = let scenario ~offending_op ~op ~early_d = - let constants = - init_constants ~blocks_per_cycle:16l ~autostaking_enable:false () - in - start_with ~constants --> activate_ai false - --> any_flag Adaptive_issuance.ns_enable + init_constants ~blocks_per_cycle:16l ~autostaking_enable:false () + --> activate_ai false + --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"] --> next_cycle --> loop @@ -234,11 +230,9 @@ let test_slash_monotonous_stake = --> make_denunciations () let test_slash_timing = - let constants = - init_constants ~blocks_per_cycle:8l ~autostaking_enable:false () - in - start_with ~constants --> activate_ai false - --> any_flag Adaptive_issuance.ns_enable + init_constants ~blocks_per_cycle:8l ~autostaking_enable:false () + --> activate_ai false + --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"] --> next_cycle --> (Tag "stake" --> stake "delegate" Half |+ Tag "unstake" --> unstake "delegate" Half) @@ -253,7 +247,6 @@ let test_slash_timing = --> double_bake "delegate" --> make_denunciations () --> next_cycle let init_scenario_with_delegators delegate_name faucet_name delegators_list = - let constants = init_constants ~autostaking_enable:false () in let rec init_delegators = function | [] -> Empty | (delegator, amount) :: t -> @@ -267,8 +260,9 @@ let init_scenario_with_delegators delegate_name faucet_name delegators_list = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - start_with ~constants --> activate_ai true - --> any_flag Adaptive_issuance.ns_enable + init_constants ~autostaking_enable:false () + --> activate_ai true + --> any_flag S.Adaptive_issuance.ns_enable --> begin_test [delegate_name; faucet_name] --> set_baker faucet_name --> set_delegate_params "delegate" init_params @@ -317,10 +311,12 @@ let test_many_slashes = --> slash "delegate" --> next_cycle))*) let test_no_shortcut_for_cheaters = - let constants = init_constants ~autostaking_enable:false () in let amount = Amount (Tez.of_mutez 333_000_000_000L) in - let consensus_rights_delay = constants.consensus_rights_delay in - start_with ~constants --> activate_ai true + let consensus_rights_delay = + Default_parameters.constants_test.consensus_rights_delay + in + init_constants ~autostaking_enable:false () + --> activate_ai true --> begin_test ["delegate"; "bootstrap1"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) @@ -341,12 +337,14 @@ let test_no_shortcut_for_cheaters = --> check_snapshot_balances "init") let test_slash_correct_amount_after_stake_from_unstake = - let constants = init_constants ~autostaking_enable:false () in let amount_to_unstake = Amount (Tez.of_mutez 200_000_000_000L) in let amount_to_restake = Amount (Tez.of_mutez 100_000_000_000L) in let amount_expected_in_unstake_after_slash = Tez.of_mutez 50_000_000_000L in - let consensus_rights_delay = constants.consensus_rights_delay in - start_with ~constants --> activate_ai true + let consensus_rights_delay = + Default_parameters.constants_test.consensus_rights_delay + in + init_constants ~autostaking_enable:false () + --> activate_ai true --> begin_test ["delegate"; "bootstrap1"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) @@ -367,8 +365,10 @@ let test_slash_correct_amount_after_stake_from_unstake = (* Test a non-zero request finalizes for a non-zero amount if it hasn't been slashed 100% *) let test_mini_slash = - let constants = init_constants ~autostaking_enable:false () in - start_with ~constants + let consensus_rights_delay = + Default_parameters.constants_test.consensus_rights_delay + in + init_constants ~autostaking_enable:false () --> (Tag "Yes AI" --> activate_ai true --> begin_test ["delegate"; "baker"] --> next_block --> wait_ai_activation @@ -384,12 +384,12 @@ let test_mini_slash = --> next_cycle --> next_cycle --> check_balance_field "delegate" `Unstaked_frozen_total Tez.zero - --> wait_n_cycles (constants.consensus_rights_delay + 1) + --> wait_n_cycles (consensus_rights_delay + 1) let test_slash_rounding = - let constants = init_constants ~autostaking_enable:false () in - start_with ~constants --> activate_ai true - --> any_flag Adaptive_issuance.ns_enable + init_constants ~autostaking_enable:false () + --> activate_ai true + --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "baker"] --> set_baker "baker" --> next_block --> wait_ai_activation --> unstake "delegate" (Amount (Tez.of_mutez 2L)) 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 13785b6d0262..b177895b810f 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 @@ -56,11 +56,13 @@ let double_roundtrip = --> finalize "staker" --> next_cycle let shorter_roundtrip_for_baker = - let constants = init_constants ~autostaking_enable:false () in let amount = Amount (Tez.of_mutez 333_000_000_000L) in - let consensus_rights_delay = constants.consensus_rights_delay in - start_with ~constants --> activate_ai true --> begin_test ["delegate"] - --> next_block --> wait_ai_activation + let consensus_rights_delay = + Default_parameters.constants_test.consensus_rights_delay + in + init_constants ~autostaking_enable:false () + --> activate_ai true --> begin_test ["delegate"] --> next_block + --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) --> next_cycle --> snapshot_balances "init" ["delegate"] @@ -153,11 +155,11 @@ let odd_behavior = loop 20 one_cycle let change_delegate = - let constants = init_constants ~autostaking_enable:false () in let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - start_with ~constants --> activate_ai true + init_constants ~autostaking_enable:false () + --> activate_ai true --> begin_test ["delegate1"; "delegate2"] --> set_delegate_params "delegate1" init_params --> set_delegate_params "delegate2" init_params @@ -174,11 +176,11 @@ let change_delegate = --> stake "staker" Half let unset_delegate = - let constants = init_constants ~autostaking_enable:false () in let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - start_with ~constants --> activate_ai true --> begin_test ["delegate"] + init_constants ~autostaking_enable:false () + --> activate_ai true --> begin_test ["delegate"] --> set_delegate_params "delegate" init_params --> add_account_with_funds "staker" @@ -199,23 +201,6 @@ let unset_delegate = --> finalize_unstake "staker" let forbid_costaking = - let default_constants = - ("default protocol constants", init_constants ~autostaking_enable:false ()) - in - let small_delegate_parameter_constants = - ( "small delegate parameters delay", - init_constants - ~delegate_parameters_activation_delay:0 - ~autostaking_enable:false - () ) - in - let large_delegate_parameter_constants = - ( "large delegate parameters delay", - init_constants - ~delegate_parameters_activation_delay:10 - ~autostaking_enable:false - () ) - in let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in @@ -223,15 +208,22 @@ let forbid_costaking = {limit_of_staking_over_baking = Q.zero; edge_of_baking_over_staking = Q.one} in let amount = Amount (Tez.of_mutez 1_000_000L) in - (* init *) - start_with_list - ~constants: - [ - default_constants; - small_delegate_parameter_constants; - large_delegate_parameter_constants; - ] - --> activate_ai true --> begin_test ["delegate"] + (* init constants *) + (Tag "default protocol constants" + --> init_constants ~autostaking_enable:false () + |+ Tag "small delegate parameters delay" + --> init_constants + ~delegate_parameters_activation_delay:0 + ~autostaking_enable:false + () + |+ Tag "large delegate parameters delay" + --> init_constants + ~delegate_parameters_activation_delay:10 + ~autostaking_enable:false + ()) + (* Start scenario *) + --> activate_ai true + --> begin_test ["delegate"] --> set_delegate_params "delegate" init_params --> add_account_with_funds "staker" -- GitLab From 9b9a9287c04a36ad8cbd8ca7a461190a1bb37bbb Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Tue, 27 Feb 2024 10:16:51 +0100 Subject: [PATCH 08/10] Proto/tests: remove autostaking flag from init_constants --- .../lib_protocol/test/helpers/scenario.ml | 1 + .../integration/test_scenario_autostaking.ml | 6 ++-- .../test/integration/test_scenario_base.ml | 7 ++--- .../test/integration/test_scenario_rewards.ml | 17 ++++------- .../integration/test_scenario_slashing.ml | 30 ++++++++++++------- .../test/integration/test_scenario_stake.ml | 26 ++++++++-------- 6 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario.ml index 4d329f8fc5f9..6d493167b1ea 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario.ml @@ -13,3 +13,4 @@ include Scenario_base include Scenario_op include Scenario_dsl include Scenario_begin +include Scenario_constants 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 138b717cdac8..bb8ae0d9a345 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 @@ -51,7 +51,8 @@ and delegator1 = "delegator1" and delegator2 = "delegator2" let setup ~activate_ai = - init_constants ~autostaking_enable:true () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable true --> Scenario_begin.activate_ai activate_ai --> begin_test [delegate] --> add_account_with_funds @@ -141,7 +142,8 @@ let test_autostaking = let test_overdelegation = (* This test assumes that all delegate accounts created in [begin_test] begin with 4M tz, with 5% staked *) - init_constants ~autostaking_enable:true () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable true --> activate_ai false --> begin_test ["delegate"; "faucet1"; "faucet2"; "faucet3"] --> add_account_with_funds 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 f333b36d4904..40b08f28b562 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 @@ -40,8 +40,7 @@ let test_expected_error = Recommended over [start] or [start_with] *) let init_constants ?(default = Test) ?(reward_per_block = 0L) ?(deactivate_dynamic = false) ?blocks_per_cycle - ?delegate_parameters_activation_delay ~autostaking_enable () = - let open Scenario_constants in + ?delegate_parameters_activation_delay () = let base_total_issued_per_minute = Tez.of_mutez reward_per_block in start ~constants:default --> (* default for tests: 12 *) @@ -69,7 +68,6 @@ let init_constants ?(default = Test) ?(reward_per_block = 0L) (Protocol.Issuance_bonus_repr.max_bonus_parameter_of_Q_exn Q.zero) else Empty) --> set S.Adaptive_issuance.ns_enable false - --> set S.Adaptive_issuance.autostaking_enable autostaking_enable (** Initialization of scenarios with 3 cases: - AI activated, staker = delegate @@ -83,7 +81,8 @@ let init_scenario ?(force_ai = true) ?reward_per_block () = in let begin_test ~activate_ai ~self_stake = let name = if self_stake then "staker" else "delegate" in - init_constants ?reward_per_block ~autostaking_enable:false () + init_constants ?reward_per_block () + --> set S.Adaptive_issuance.autostaking_enable false --> Scenario_begin.activate_ai activate_ai --> begin_test [name] --> set_delegate_params name init_params 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 f7cf16a0874e..9824094a96ce 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 @@ -29,7 +29,8 @@ let test_wait_with_rewards = in set_delegate_params "delegate" params in - init_constants ~reward_per_block:1_000_000_000L ~autostaking_enable:false () + init_constants ~reward_per_block:1_000_000_000L () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> begin_test ["delegate"; "faucet"] --> set_baker "faucet" @@ -75,11 +76,8 @@ let test_wait_with_rewards = let test_ai_curve_activation_time = let pc = Default_parameters.constants_test.consensus_rights_delay in - init_constants - ~reward_per_block:1_000_000_000L - ~deactivate_dynamic:true - ~autostaking_enable:false - () + init_constants ~reward_per_block:1_000_000_000L ~deactivate_dynamic:true () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> begin_test ~burn_rewards:true [""] --> next_block --> save_current_rate (* before AI rate *) @@ -110,11 +108,8 @@ let test_static = let cycle_stable = save_current_rate --> next_cycle --> check_rate_evolution Q.equal in - init_constants - ~reward_per_block:1_000_000_000L - ~deactivate_dynamic:true - ~autostaking_enable:false - () + init_constants ~reward_per_block:1_000_000_000L ~deactivate_dynamic:true () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> begin_test ~burn_rewards:true ["delegate"] --> set_delegate_params "delegate" init_params 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 85ac7dde76da..b1a161e16393 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 @@ -48,7 +48,8 @@ let test_simple_slash = |+ Tag "double preattesting" --> double_preattest ~other_bakers:("bootstrap2", "bootstrap3") delegate in - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"; "bootstrap3"] @@ -125,7 +126,8 @@ let check_is_not_forbidden baker = return input) let test_delegate_forbidden = - init_constants ~blocks_per_cycle:30l ~autostaking_enable:false () + init_constants ~blocks_per_cycle:30l () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai false --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] @@ -169,7 +171,8 @@ let test_delegate_forbidden = --> check_is_forbidden "delegate") let test_slash_unstake = - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai false --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] @@ -181,7 +184,8 @@ let test_slash_unstake = let test_slash_monotonous_stake = let scenario ~offending_op ~op ~early_d = - init_constants ~blocks_per_cycle:16l ~autostaking_enable:false () + init_constants ~blocks_per_cycle:16l () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai false --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"] @@ -230,7 +234,8 @@ let test_slash_monotonous_stake = --> make_denunciations () let test_slash_timing = - init_constants ~blocks_per_cycle:8l ~autostaking_enable:false () + init_constants ~blocks_per_cycle:8l () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai false --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"] --> next_cycle @@ -260,7 +265,8 @@ let init_scenario_with_delegators delegate_name faucet_name delegators_list = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> any_flag S.Adaptive_issuance.ns_enable --> begin_test [delegate_name; faucet_name] @@ -315,7 +321,8 @@ let test_no_shortcut_for_cheaters = let consensus_rights_delay = Default_parameters.constants_test.consensus_rights_delay in - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> begin_test ["delegate"; "bootstrap1"] --> next_block --> wait_ai_activation @@ -343,7 +350,8 @@ let test_slash_correct_amount_after_stake_from_unstake = let consensus_rights_delay = Default_parameters.constants_test.consensus_rights_delay in - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> begin_test ["delegate"; "bootstrap1"] --> next_block --> wait_ai_activation @@ -368,7 +376,8 @@ let test_mini_slash = let consensus_rights_delay = Default_parameters.constants_test.consensus_rights_delay in - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> (Tag "Yes AI" --> activate_ai true --> begin_test ["delegate"; "baker"] --> next_block --> wait_ai_activation @@ -387,7 +396,8 @@ let test_mini_slash = --> wait_n_cycles (consensus_rights_delay + 1) let test_slash_rounding = - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> any_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "baker"] 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 b177895b810f..b9f2dec68536 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 @@ -60,7 +60,8 @@ let shorter_roundtrip_for_baker = let consensus_rights_delay = Default_parameters.constants_test.consensus_rights_delay in - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> begin_test ["delegate"] --> next_block --> wait_ai_activation --> stake "delegate" (Amount (Tez.of_mutez 1_800_000_000_000L)) @@ -158,7 +159,8 @@ let change_delegate = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> begin_test ["delegate1"; "delegate2"] --> set_delegate_params "delegate1" init_params @@ -179,7 +181,8 @@ let unset_delegate = let init_params = {limit_of_staking_over_baking = Q.one; edge_of_baking_over_staking = Q.one} in - init_constants ~autostaking_enable:false () + init_constants () + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true --> begin_test ["delegate"] --> set_delegate_params "delegate" init_params --> add_account_with_funds @@ -209,20 +212,15 @@ let forbid_costaking = in let amount = Amount (Tez.of_mutez 1_000_000L) in (* init constants *) - (Tag "default protocol constants" - --> init_constants ~autostaking_enable:false () + (Tag "default protocol constants" --> init_constants () |+ Tag "small delegate parameters delay" - --> init_constants - ~delegate_parameters_activation_delay:0 - ~autostaking_enable:false - () + --> init_constants ~delegate_parameters_activation_delay:0 () |+ Tag "large delegate parameters delay" - --> init_constants - ~delegate_parameters_activation_delay:10 - ~autostaking_enable:false - ()) - (* Start scenario *) + --> init_constants ~delegate_parameters_activation_delay:10 ()) + (* Set flags *) + --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true + (* Start scenario *) --> begin_test ["delegate"] --> set_delegate_params "delegate" init_params --> add_account_with_funds -- GitLab From c4f54aba9204a3f7f71d24e52bdc5af12ebfdc54 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Thu, 29 Feb 2024 10:57:08 +0100 Subject: [PATCH 09/10] Proto/tests/scenario: move init_constants to helpers --- .../test/helpers/scenario_begin.ml | 33 +++++++++++++++++++ .../integration/test_scenario_autostaking.ml | 1 - .../test/integration/test_scenario_base.ml | 33 ------------------- .../test/integration/test_scenario_rewards.ml | 1 - .../integration/test_scenario_slashing.ml | 1 - 5 files changed, 33 insertions(+), 36 deletions(-) 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 d1a2bfe9bb5e..5c21b92705f0 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_begin.ml @@ -52,6 +52,39 @@ let activate_ai flag = --> set S.Adaptive_issuance.activation_vote_enable true else Empty +(** Initializes the constants for testing, with well chosen default values. + Recommended over [start] or [start_with] *) +let init_constants ?(default = Test) ?(reward_per_block = 0L) + ?(deactivate_dynamic = false) ?blocks_per_cycle + ?delegate_parameters_activation_delay () = + let base_total_issued_per_minute = Tez.of_mutez reward_per_block in + start ~constants:default + --> (* default for tests: 12 *) + set_opt S.blocks_per_cycle blocks_per_cycle + --> set_opt + S.delegate_parameters_activation_delay + delegate_parameters_activation_delay + --> set + S.issuance_weights + { + base_total_issued_per_minute; + baking_reward_fixed_portion_weight = 1; + baking_reward_bonus_weight = 0; + attesting_reward_weight = 0; + seed_nonce_revelation_tip_weight = 0; + vdf_revelation_tip_weight = 0; + } + --> set S.liquidity_baking_subsidy Tez.zero + --> set S.minimal_block_delay Protocol.Alpha_context.Period.one_minute + --> set S.cost_per_byte Tez.zero + --> set S.consensus_threshold 0 + --> (if deactivate_dynamic then + set + S.Adaptive_issuance.Adaptive_rewards_params.max_bonus + (Protocol.Issuance_bonus_repr.max_bonus_parameter_of_Q_exn Q.zero) + else Empty) + --> set S.Adaptive_issuance.ns_enable false + (** Initialize the test, given some initial parameters *) let begin_test ?(burn_rewards = false) delegates_name_list : (constants, t) scenarios = 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 bb8ae0d9a345..d539e73d8207 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 @@ -16,7 +16,6 @@ open State_account open Tez_helpers.Ez_tez open Scenario -open Test_scenario_base open Log_helpers let assert_balance_evolution ~loc ~for_accounts ~part ~name ~old_balance 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 40b08f28b562..28aff544119c 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 @@ -36,39 +36,6 @@ let test_expected_error = [Inconsistent_number_of_bootstrap_accounts]) (exec (fun _ -> failwith ""))) -(** Initializes the constants for testing, with well chosen default values. - Recommended over [start] or [start_with] *) -let init_constants ?(default = Test) ?(reward_per_block = 0L) - ?(deactivate_dynamic = false) ?blocks_per_cycle - ?delegate_parameters_activation_delay () = - let base_total_issued_per_minute = Tez.of_mutez reward_per_block in - start ~constants:default - --> (* default for tests: 12 *) - set_opt S.blocks_per_cycle blocks_per_cycle - --> set_opt - S.delegate_parameters_activation_delay - delegate_parameters_activation_delay - --> set - S.issuance_weights - { - base_total_issued_per_minute; - baking_reward_fixed_portion_weight = 1; - baking_reward_bonus_weight = 0; - attesting_reward_weight = 0; - seed_nonce_revelation_tip_weight = 0; - vdf_revelation_tip_weight = 0; - } - --> set S.liquidity_baking_subsidy Tez.zero - --> set S.minimal_block_delay Protocol.Alpha_context.Period.one_minute - --> set S.cost_per_byte Tez.zero - --> set S.consensus_threshold 0 - --> (if deactivate_dynamic then - set - S.Adaptive_issuance.Adaptive_rewards_params.max_bonus - (Protocol.Issuance_bonus_repr.max_bonus_parameter_of_Q_exn Q.zero) - else Empty) - --> set S.Adaptive_issuance.ns_enable false - (** Initialization of scenarios with 3 cases: - AI activated, staker = delegate - AI activated, staker != delegate 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 9824094a96ce..9cf97ea447fe 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 @@ -17,7 +17,6 @@ open Adaptive_issuance_helpers open State_account open Tez_helpers.Ez_tez open Scenario -open Test_scenario_base let test_wait_with_rewards = let set_edge pct = 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 b1a161e16393..eaba37d31900 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 @@ -35,7 +35,6 @@ open Adaptive_issuance_helpers open State_account open Tez_helpers.Ez_tez open Scenario -open Test_scenario_base open Scenario_constants let fs = Format.asprintf -- GitLab From f7761b45bf9b5c099ed92565dd1fcf6b1ab1e424 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Fri, 1 Mar 2024 15:50:02 +0100 Subject: [PATCH 10/10] Proto/tests: rename any_flag -> branch_flag --- .../test/helpers/scenario_constants.ml | 6 +++--- .../test/integration/test_scenario_slashing.ml | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml index c467470c2c55..266776606147 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml @@ -35,13 +35,13 @@ let sets_f : (constants, constants) scenarios = fun f f_tag -> fold_tag_f (set f) f_tag -let any_flag : +let branch_flag : (constants -> bool -> constants) -> (constants, constants) scenarios = fun f -> sets f [("true", true); ("false", false)] -let any_flags : +let branch_flags : (constants -> bool -> constants) list -> (constants, constants) scenarios = - unfold any_flag + unfold branch_flag let sets_int : (constants -> int -> constants) -> 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 eaba37d31900..9e040ca87016 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 @@ -50,7 +50,7 @@ let test_simple_slash = init_constants () --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true - --> any_flag S.Adaptive_issuance.ns_enable + --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"; "bootstrap3"] --> (Tag "No AI" --> next_cycle |+ Tag "Yes AI" --> next_block --> wait_ai_activation) @@ -128,7 +128,7 @@ let test_delegate_forbidden = init_constants ~blocks_per_cycle:30l () --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai false - --> any_flag S.Adaptive_issuance.ns_enable + --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] --> set_baker "bootstrap1" --> (Tag "Many double bakes" @@ -173,7 +173,7 @@ let test_slash_unstake = init_constants () --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai false - --> any_flag S.Adaptive_issuance.ns_enable + --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"; "bootstrap2"] --> set_baker "bootstrap1" --> next_cycle --> unstake "delegate" Half --> next_cycle --> double_bake "delegate" --> make_denunciations () @@ -186,7 +186,7 @@ let test_slash_monotonous_stake = init_constants ~blocks_per_cycle:16l () --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai false - --> any_flag S.Adaptive_issuance.ns_enable + --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "bootstrap1"] --> next_cycle --> loop @@ -236,7 +236,7 @@ let test_slash_timing = init_constants ~blocks_per_cycle:8l () --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai false - --> any_flag S.Adaptive_issuance.ns_enable + --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"] --> next_cycle --> (Tag "stake" --> stake "delegate" Half |+ Tag "unstake" --> unstake "delegate" Half) @@ -267,7 +267,7 @@ let init_scenario_with_delegators delegate_name faucet_name delegators_list = init_constants () --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true - --> any_flag S.Adaptive_issuance.ns_enable + --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test [delegate_name; faucet_name] --> set_baker faucet_name --> set_delegate_params "delegate" init_params @@ -398,7 +398,7 @@ let test_slash_rounding = init_constants () --> set S.Adaptive_issuance.autostaking_enable false --> activate_ai true - --> any_flag S.Adaptive_issuance.ns_enable + --> branch_flag S.Adaptive_issuance.ns_enable --> begin_test ["delegate"; "baker"] --> set_baker "baker" --> next_block --> wait_ai_activation --> unstake "delegate" (Amount (Tez.of_mutez 2L)) -- GitLab