From 51fa79083cdd4c352cff7d441b6d87efbe15b771 Mon Sep 17 00:00:00 2001 From: Lucas Randazzo Date: Wed, 6 Mar 2024 16:57:03 +0100 Subject: [PATCH] Proto/tests: change order of arguments in Constants_helpers --- .../test/helpers/constants_helpers.ml | 126 +++++++++--------- .../test/helpers/scenario_constants.ml | 16 +-- .../test/unit/test_slashing_percentage.ml | 21 +-- 3 files changed, 77 insertions(+), 86 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 8ae4d2913f1b..7fbf4df38301 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/constants_helpers.ml @@ -9,154 +9,154 @@ type t = Protocol.Alpha_context.Constants.Parametric.t (* Warning: not a Set *) module Set = struct - let consensus_rights_delay (c : t) consensus_rights_delay = + let consensus_rights_delay consensus_rights_delay (c : t) = {c with consensus_rights_delay} - let blocks_preservation_cycles (c : t) blocks_preservation_cycles = + let blocks_preservation_cycles blocks_preservation_cycles (c : t) = {c with blocks_preservation_cycles} - let delegate_parameters_activation_delay (c : t) - delegate_parameters_activation_delay = + let delegate_parameters_activation_delay delegate_parameters_activation_delay + (c : t) = {c with delegate_parameters_activation_delay} - let blocks_per_cycle (c : t) blocks_per_cycle = {c with blocks_per_cycle} + let blocks_per_cycle blocks_per_cycle (c : t) = {c with blocks_per_cycle} - let blocks_per_commitment (c : t) blocks_per_commitment = + let blocks_per_commitment blocks_per_commitment (c : t) = {c with blocks_per_commitment} - let nonce_revelation_threshold (c : t) nonce_revelation_threshold = + let nonce_revelation_threshold nonce_revelation_threshold (c : t) = {c with nonce_revelation_threshold} - let cycles_per_voting_period (c : t) cycles_per_voting_period = + let cycles_per_voting_period cycles_per_voting_period (c : t) = {c with cycles_per_voting_period} - let hard_gas_limit_per_operation (c : t) hard_gas_limit_per_operation = + let hard_gas_limit_per_operation hard_gas_limit_per_operation (c : t) = {c with hard_gas_limit_per_operation} - let hard_gas_limit_per_block (c : t) hard_gas_limit_per_block = + let hard_gas_limit_per_block hard_gas_limit_per_block (c : t) = {c with hard_gas_limit_per_block} - let proof_of_work_threshold (c : t) proof_of_work_threshold = + let proof_of_work_threshold proof_of_work_threshold (c : t) = {c with proof_of_work_threshold} - let minimal_stake (c : t) minimal_stake = {c with minimal_stake} + let minimal_stake minimal_stake (c : t) = {c with minimal_stake} - let minimal_frozen_stake (c : t) minimal_frozen_stake = + let minimal_frozen_stake minimal_frozen_stake (c : t) = {c with minimal_frozen_stake} - let vdf_difficulty (c : t) vdf_difficulty = {c with vdf_difficulty} + let vdf_difficulty vdf_difficulty (c : t) = {c with vdf_difficulty} - let origination_size (c : t) origination_size = {c with origination_size} + let origination_size origination_size (c : t) = {c with origination_size} - let cost_per_byte (c : t) cost_per_byte = {c with cost_per_byte} + let cost_per_byte cost_per_byte (c : t) = {c with cost_per_byte} - let hard_storage_limit_per_operation (c : t) hard_storage_limit_per_operation + let hard_storage_limit_per_operation hard_storage_limit_per_operation (c : t) = {c with hard_storage_limit_per_operation} - let quorum_min (c : t) quorum_min = {c with quorum_min} + let quorum_min quorum_min (c : t) = {c with quorum_min} - let quorum_max (c : t) quorum_max = {c with quorum_max} + let quorum_max quorum_max (c : t) = {c with quorum_max} - let min_proposal_quorum (c : t) min_proposal_quorum = + let min_proposal_quorum min_proposal_quorum (c : t) = {c with min_proposal_quorum} - let liquidity_baking_subsidy (c : t) liquidity_baking_subsidy = + let liquidity_baking_subsidy liquidity_baking_subsidy (c : t) = {c with liquidity_baking_subsidy} - let liquidity_baking_toggle_ema_threshold (c : t) - liquidity_baking_toggle_ema_threshold = + let liquidity_baking_toggle_ema_threshold + liquidity_baking_toggle_ema_threshold (c : t) = {c with liquidity_baking_toggle_ema_threshold} - let max_operations_time_to_live (c : t) max_operations_time_to_live = + let max_operations_time_to_live max_operations_time_to_live (c : t) = {c with max_operations_time_to_live} - let minimal_block_delay (c : t) minimal_block_delay = + let minimal_block_delay minimal_block_delay (c : t) = {c with minimal_block_delay} - let delay_increment_per_round (c : t) delay_increment_per_round = + let delay_increment_per_round delay_increment_per_round (c : t) = {c with delay_increment_per_round} - let minimal_participation_ratio (c : t) minimal_participation_ratio = + let minimal_participation_ratio minimal_participation_ratio (c : t) = {c with minimal_participation_ratio} - let consensus_committee_size (c : t) consensus_committee_size = + let consensus_committee_size consensus_committee_size (c : t) = {c with consensus_committee_size} - let consensus_threshold (c : t) consensus_threshold = + let consensus_threshold consensus_threshold (c : t) = {c with consensus_threshold} - let limit_of_delegation_over_baking (c : t) limit_of_delegation_over_baking = + let limit_of_delegation_over_baking limit_of_delegation_over_baking (c : t) = {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 = + let percentage_of_frozen_deposits_slashed_per_double_baking + percentage_of_frozen_deposits_slashed_per_double_baking (c : t) = {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 = + let percentage_of_frozen_deposits_slashed_per_double_attestation + percentage_of_frozen_deposits_slashed_per_double_attestation (c : t) = {c with percentage_of_frozen_deposits_slashed_per_double_attestation} - let max_slashing_per_block (c : t) max_slashing_per_block = + let max_slashing_per_block max_slashing_per_block (c : t) = {c with max_slashing_per_block} - let max_slashing_threshold (c : t) max_slashing_threshold = + let max_slashing_threshold max_slashing_threshold (c : t) = {c with max_slashing_threshold} - let testnet_dictator (c : t) testnet_dictator = {c with testnet_dictator} + let testnet_dictator testnet_dictator (c : t) = {c with testnet_dictator} - let initial_seed (c : t) initial_seed = {c with initial_seed} + let initial_seed initial_seed (c : t) = {c with initial_seed} - let cache_script_size (c : t) cache_script_size = {c with cache_script_size} + let cache_script_size cache_script_size (c : t) = {c with cache_script_size} - let cache_stake_distribution_cycles (c : t) cache_stake_distribution_cycles = + let cache_stake_distribution_cycles cache_stake_distribution_cycles (c : t) = {c with cache_stake_distribution_cycles} - let cache_sampler_state_cycles (c : t) cache_sampler_state_cycles = + let cache_sampler_state_cycles cache_sampler_state_cycles (c : t) = {c with cache_sampler_state_cycles} - let dal (c : t) dal = {c with dal} + let dal dal (c : t) = {c with dal} - let sc_rollup (c : t) sc_rollup = {c with sc_rollup} + let sc_rollup sc_rollup (c : t) = {c with sc_rollup} - let zk_rollup (c : t) zk_rollup = {c with zk_rollup} + let zk_rollup zk_rollup (c : t) = {c with zk_rollup} - let direct_ticket_spending_enable (c : t) direct_ticket_spending_enable = + let direct_ticket_spending_enable direct_ticket_spending_enable (c : t) = {c with direct_ticket_spending_enable} - let issuance_weights (c : t) issuance_weights = {c with issuance_weights} + let issuance_weights issuance_weights (c : t) = {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} + let base_total_issued_per_minute base_total_issued_per_minute (c : t) = + issuance_weights {c.issuance_weights with base_total_issued_per_minute} c end - let adaptive_issuance (c : t) adaptive_issuance = {c with adaptive_issuance} + let adaptive_issuance adaptive_issuance (c : t) = {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 activation_vote_enable activation_vote_enable (c : t) = + adaptive_issuance {c.adaptive_issuance with activation_vote_enable} c - let autostaking_enable (c : t) autostaking_enable = - adaptive_issuance c {c.adaptive_issuance with autostaking_enable} + let autostaking_enable autostaking_enable (c : t) = + adaptive_issuance {c.adaptive_issuance with autostaking_enable} c - let force_activation (c : t) force_activation = - adaptive_issuance c {c.adaptive_issuance with force_activation} + let force_activation force_activation (c : t) = + adaptive_issuance {c.adaptive_issuance with force_activation} c - let ns_enable (c : t) ns_enable = - adaptive_issuance c {c.adaptive_issuance with ns_enable} + let ns_enable ns_enable (c : t) = + adaptive_issuance {c.adaptive_issuance with ns_enable} c - let launch_ema_threshold (c : t) launch_ema_threshold = - adaptive_issuance c {c.adaptive_issuance with launch_ema_threshold} + let launch_ema_threshold launch_ema_threshold (c : t) = + adaptive_issuance {c.adaptive_issuance with launch_ema_threshold} c - let adaptive_rewards_params (c : t) adaptive_rewards_params = - adaptive_issuance c {c.adaptive_issuance with adaptive_rewards_params} + let adaptive_rewards_params adaptive_rewards_params (c : t) = + adaptive_issuance {c.adaptive_issuance with adaptive_rewards_params} c module Adaptive_rewards_params = struct - let max_bonus (c : t) max_bonus = + let max_bonus max_bonus (c : t) = adaptive_rewards_params - c {c.adaptive_issuance.adaptive_rewards_params with max_bonus} + c end end end 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 266776606147..dc99e333a923 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/scenario_constants.ml @@ -13,38 +13,38 @@ type constants = Constants_helpers.t module S = Constants_helpers.Set let set : - (constants -> 'a -> constants) -> 'a -> (constants, constants) scenarios = - fun f x -> Action (fun csts -> return @@ f csts x) + ('a -> constants -> constants) -> 'a -> (constants, constants) scenarios = + fun f x -> Action (fun csts -> return @@ f x csts) let set_opt : - (constants -> 'a -> constants) -> + ('a -> constants -> constants) -> 'a option -> (constants, constants) scenarios = fun f -> function None -> Empty | Some x -> set f x let sets : - (constants -> 'a -> constants) -> + ('a -> constants -> constants) -> (string * 'a) list -> (constants, constants) scenarios = fun f -> fold_tag (set f) let sets_f : - (constants -> 'a -> constants) -> + ('a -> constants -> constants) -> ('a -> string) -> 'a list -> (constants, constants) scenarios = fun f f_tag -> fold_tag_f (set f) f_tag let branch_flag : - (constants -> bool -> constants) -> (constants, constants) scenarios = + (bool -> constants -> constants) -> (constants, constants) scenarios = fun f -> sets f [("true", true); ("false", false)] let branch_flags : - (constants -> bool -> constants) list -> (constants, constants) scenarios = + (bool -> constants -> constants) list -> (constants, constants) scenarios = unfold branch_flag let sets_int : - (constants -> int -> constants) -> + (int -> constants -> constants) -> int list -> (constants, constants) scenarios = fun f -> sets_f f string_of_int diff --git a/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml b/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml index 0eab94a43fcd..e3ded8d6879d 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_slashing_percentage.ml @@ -36,22 +36,13 @@ let assert_not_equal_int ~loc n (pct : Percentage.t tzresult Lwt.t) = Assert.not_equal ~loc Q.equal "Values are equal" Q.pp_print Q.(n // 100) pct_q let raw_context ~max_slashing_threshold ~max_slashing_per_block ~ns_enable () = - let constants = Default_parameters.constants_test in + let open Constants_helpers in let constants = - Constants_helpers.Set.Adaptive_issuance.force_activation constants true - in - let constants = - Constants_helpers.Set.Adaptive_issuance.ns_enable constants ns_enable - in - let constants = - Constants_helpers.Set.max_slashing_threshold - constants - max_slashing_threshold - in - let constants = - Constants_helpers.Set.max_slashing_per_block - constants - max_slashing_per_block + Default_parameters.constants_test + |> Set.Adaptive_issuance.force_activation true + |> Set.Adaptive_issuance.ns_enable ns_enable + |> Set.max_slashing_threshold max_slashing_threshold + |> Set.max_slashing_per_block max_slashing_per_block in Context.raw_context_from_constants constants -- GitLab