From 86536841ac6ce004615f23d96cad062a6e8d5a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Fri, 23 Jun 2023 15:29:43 +0200 Subject: [PATCH 1/3] Tests/AI/Launch: more 0-fee transactions --- .../integration/test_adaptive_inflation_launch.ml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml index bef383bf7284..f852bb1e39eb 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml @@ -190,12 +190,21 @@ let test_launch threshold expected_vote_duration () = Block.bake ~operation ~adaptive_inflation_vote:Toggle_vote_on block in let* block = - let* operation = Op.revelation (B block) wannabe_costaker_account.pk in + let* operation = + Op.revelation + ~fee:Protocol.Alpha_context.Tez.zero + (B block) + wannabe_costaker_account.pk + in Block.bake ~operation ~adaptive_inflation_vote:Toggle_vote_on block in let* block = let* operation = - Op.delegation (B block) wannabe_costaker (Some delegate_pkh) + Op.delegation + ~fee:Protocol.Alpha_context.Tez.zero + (B block) + wannabe_costaker + (Some delegate_pkh) in Block.bake ~operation ~adaptive_inflation_vote:Toggle_vote_on block in -- GitLab From 12e409546020352961989f2c978d5ca8d0dfa549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Wed, 21 Jun 2023 17:49:28 +0200 Subject: [PATCH 2/3] Tests/AI/Launch: add a function to assert the voting power --- .../test_adaptive_inflation_launch.ml | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml index f852bb1e39eb..19bbbba43841 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml @@ -101,6 +101,39 @@ let assert_total_frozen_stake ~loc block expected = let* actual = Context.get_total_frozen_stake (B block) in Assert.equal_tez ~loc actual expected +(* Assert that the voting power of a delegate in the next vote listing + will be the expected one. The expectation is computed based on the + expected self-staked, delegated, and costaked tez. The delegate's + own liquid balance is measured at the level at which the listing + will be taken to account for future rewards. *) +let assert_voting_power ~loc block delegate ~ai_enabled ~expected_staked + ~expected_delegated ~expected_costaked = + let open Lwt_result_syntax in + (* Wait until the first block of the next voting period. *) + let* block = + let* period_info = Context.Vote.get_current_period (B block) in + let remaining_blocks = Int32.to_int period_info.remaining in + Block.bake_n remaining_blocks block + in + let* balance = Context.Contract.balance (B block) (Implicit delegate) in + let balance = Protocol.Alpha_context.Tez.to_mutez balance in + let expected_liquid = Int64.add balance expected_delegated in + let expected_frozen = Int64.add expected_staked expected_costaked in + let* constants = Context.get_constants (B block) in + let staking_over_delegation_edge = + Int64.of_int + constants.parametric.adaptive_inflation.staking_over_delegation_edge + in + let expected_power = + if ai_enabled then + Int64.add + expected_frozen + (Int64.div expected_liquid staking_over_delegation_edge) + else Int64.add expected_frozen expected_liquid + in + let* actual = Context.get_voting_power (B block) delegate in + Assert.equal_int64 ~loc actual expected_power + (* Test that: - the EMA of the adaptive inflation vote reaches the threshold after the expected duration, -- GitLab From 169ba8248293584c4239e99d652da0f130615af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Wed, 21 Jun 2023 17:50:03 +0200 Subject: [PATCH 3/3] Tests/AI/Launch: use it --- .../test_adaptive_inflation_launch.ml | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml index 19bbbba43841..713550ffddc0 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_adaptive_inflation_launch.ml @@ -298,6 +298,16 @@ let test_launch threshold expected_vote_duration () = i "Staking for a non-delegate while co-staking is disabled" in + let* () = + assert_voting_power + ~loc:__LOC__ + block + delegate_pkh + ~ai_enabled:false + ~expected_staked:2_000_000_000_000L + ~expected_delegated:2_000_000_000_000L + ~expected_costaked:0L + in let* launch_cycle = get_launch_cycle ~loc:__LOC__ block in (* Bake until the activation. *) @@ -320,6 +330,16 @@ let test_launch threshold expected_vote_duration () = block (Protocol.Alpha_context.Tez.of_mutez_exn 2_000_000_000_000L) in + let* () = + assert_voting_power + ~loc:__LOC__ + block + delegate_pkh + ~ai_enabled:true + ~expected_staked:2_000_000_000_000L + ~expected_delegated:2_000_000_000_000L + ~expected_costaked:0L + in (* Test that the wannabe costaker is now allowed to stake almost all its balance. It cannot totally costake it however because this is @@ -353,6 +373,16 @@ let test_launch threshold expected_vote_duration () = block (Protocol.Alpha_context.Tez.of_mutez_exn 3_999_999_000_000L) in + let* () = + assert_voting_power + ~loc:__LOC__ + block + delegate_pkh + ~ai_enabled:true + ~expected_staked:2_000_000_000_000L + ~expected_delegated:1_000_000L + ~expected_costaked:1_999_999_000_000L + in return_unit let tests = -- GitLab