@@ -11,6 +11,8 @@ use staking::pool::pool::Pool::STRK_CONFIG;
1111use staking :: pool :: utils :: compute_rewards_rounded_down;
1212use staking :: staking :: errors :: Error as StakingError ;
1313use staking :: staking :: interface :: {
14+ IStakingAttestationDispatcher , IStakingAttestationDispatcherTrait ,
15+ IStakingAttestationSafeDispatcher , IStakingAttestationSafeDispatcherTrait ,
1416 IStakingConsensusDispatcherTrait , IStakingDispatcherTrait ,
1517 IStakingRewardsManagerSafeDispatcherTrait ,
1618};
@@ -2627,6 +2629,137 @@ fn get_stakers_staking_power_100_flow_test() {
26272629 assert! (stakers == expected_stakers );
26282630}
26292631
2632+ /// Flow:
2633+ /// Staker stake
2634+ /// Update rewards from attestation - test rewards
2635+ /// Update_rewards - test no rewards
2636+ /// Set consensus epoch (in K epochs)
2637+ /// Update rewards from attestation - test rewards
2638+ /// Update_rewards - test no rewards
2639+ /// Advance to consensus epoch
2640+ /// Update rewards from attestation - panic
2641+ /// Update_rewards - test rewards
2642+ /// Advance epoch
2643+ /// Update rewards from attestation - panic
2644+ /// Update_rewards - test rewards
2645+ /// Advance epoch
2646+ /// Update rewards from attestation - panic
2647+ /// Update_rewards with disable_rewards = true - test no rewards
2648+ #[test]
2649+ #[feature(" safe_dispatcher" )]
2650+ fn update_rewards_transition_from_attestation_to_consensus_flow_test () {
2651+ let cfg : StakingInitConfig = Default :: default ();
2652+ let mut system = SystemConfigTrait :: basic_stake_flow_cfg (: cfg ). deploy ();
2653+ let stake_amount = system . staking. get_min_stake ();
2654+ let minting_curve_contract = system . minting_curve. address;
2655+ let staking_contract = system . staking. address;
2656+ let staker = system . new_staker (amount : stake_amount );
2657+ let staking_attestation = IStakingAttestationDispatcher { contract_address : staking_contract };
2658+ let staking_attestation_safe = IStakingAttestationSafeDispatcher {
2659+ contract_address : staking_contract ,
2660+ };
2661+ let commission = 200 ;
2662+ system . stake (: staker , amount : stake_amount , pool_enabled : false , : commission );
2663+ system . advance_k_epochs ();
2664+
2665+ // Update rewards from attestation
2666+ cheat_caller_address_once (
2667+ contract_address : system . staking. address,
2668+ caller_address : system . attestation. unwrap (). address,
2669+ );
2670+ staking_attestation
2671+ . update_rewards_from_attestation_contract (staker_address : staker . staker. address);
2672+ let rewards = system . staker_claim_rewards (: staker );
2673+ let (expected_rewards_v2 , _ ) = calculate_staker_strk_rewards_with_balances_v2 (
2674+ amount_own : stake_amount ,
2675+ pool_amount : Zero :: zero (),
2676+ : commission ,
2677+ : staking_contract ,
2678+ : minting_curve_contract ,
2679+ );
2680+ assert! (expected_rewards_v2 . is_non_zero ());
2681+ assert! (rewards == expected_rewards_v2 );
2682+
2683+ // Call update_rewards - no rewards
2684+ system . update_rewards (: staker , disable_rewards : false );
2685+ let rewards = system . staker_claim_rewards (: staker );
2686+ assert! (rewards == Zero :: zero ());
2687+
2688+ // Set consensus rewards first epoch
2689+ system . advance_epoch ();
2690+ system
2691+ . staking
2692+ . set_consensus_rewards_first_epoch (epoch_id : system . staking. get_current_epoch () + K . into ());
2693+
2694+ // Update rewards from attestation - test rewards
2695+ cheat_caller_address_once (
2696+ contract_address : system . staking. address,
2697+ caller_address : system . attestation. unwrap (). address,
2698+ );
2699+ staking_attestation
2700+ . update_rewards_from_attestation_contract (staker_address : staker . staker. address);
2701+ let rewards = system . staker_claim_rewards (: staker );
2702+ assert! (rewards == expected_rewards_v2 );
2703+
2704+ // Call update_rewards - no rewards
2705+ system . update_rewards (: staker , disable_rewards : false );
2706+ let rewards = system . staker_claim_rewards (: staker );
2707+ assert! (rewards == Zero :: zero ());
2708+
2709+ // Advance to consensus epoch
2710+ system . advance_k_epochs ();
2711+
2712+ // Update rewards from attestation - panic
2713+ let result = staking_attestation_safe
2714+ . update_rewards_from_attestation_contract (staker_address : staker . staker. address);
2715+ assert_panic_with_error (
2716+ : result , expected_error : StakingError :: CONSENSUS_REWARDS_IS_ACTIVE . describe (),
2717+ );
2718+
2719+ // Call update_rewards - test rewards
2720+ system . update_rewards (: staker , disable_rewards : false );
2721+ let rewards = system . staker_claim_rewards (: staker );
2722+ let (expected_rewards_v3 , _ ) = calculate_staker_strk_rewards_with_balances_v3 (
2723+ amount_own : stake_amount ,
2724+ pool_amount : Zero :: zero (),
2725+ : commission ,
2726+ : staking_contract ,
2727+ : minting_curve_contract ,
2728+ );
2729+ assert! (expected_rewards_v3 . is_non_zero ());
2730+ assert! (rewards == expected_rewards_v3 );
2731+
2732+ // Advance epoch
2733+ system . advance_epoch ();
2734+
2735+ // Update rewards from attestation - panic
2736+ let result = staking_attestation_safe
2737+ . update_rewards_from_attestation_contract (staker_address : staker . staker. address);
2738+ assert_panic_with_error (
2739+ : result , expected_error : StakingError :: CONSENSUS_REWARDS_IS_ACTIVE . describe (),
2740+ );
2741+
2742+ // Call update_rewards - test rewards
2743+ system . update_rewards (: staker , disable_rewards : false );
2744+ let rewards = system . staker_claim_rewards (: staker );
2745+ assert! (rewards == expected_rewards_v3 );
2746+
2747+ // Advance epoch
2748+ system . advance_epoch ();
2749+
2750+ // Update rewards from attestation - panic
2751+ let result = staking_attestation_safe
2752+ . update_rewards_from_attestation_contract (staker_address : staker . staker. address);
2753+ assert_panic_with_error (
2754+ : result , expected_error : StakingError :: CONSENSUS_REWARDS_IS_ACTIVE . describe (),
2755+ );
2756+
2757+ // Call update_rewards with disable rewards = true - no rewards
2758+ system . update_rewards (: staker , disable_rewards : true );
2759+ let rewards = system . staker_claim_rewards (: staker );
2760+ assert! (rewards == Zero :: zero ());
2761+ }
2762+
26302763/// Flow:
26312764/// Staker stake
26322765/// Disable rewards is true with consensus off - test no rewards
0 commit comments