@@ -6,6 +6,7 @@ use staking::flow_test::utils::{
66 RewardSupplierTrait , StakingTrait , SystemConfigTrait , SystemDelegatorTrait , SystemStakerTrait ,
77 SystemTrait , TokenHelperTrait , test_flow_local,
88};
9+ use staking :: staking :: objects :: NormalizedAmountTrait ;
910use staking :: pool :: pool :: Pool ;
1011use staking :: pool :: pool :: Pool :: STRK_CONFIG ;
1112use staking :: pool :: utils :: compute_rewards_rounded_down;
@@ -22,7 +23,7 @@ use staking::test_utils::constants::{
2223 TEST_MIN_BTC_FOR_REWARDS ,
2324};
2425use staking :: test_utils :: {
25- StakingInitConfig , calculate_staker_btc_pool_rewards_v2,
26+ StakingInitConfig , calculate_staker_btc_pool_rewards_v2, calculate_staker_btc_pool_rewards_v3,
2627 calculate_staker_strk_rewards_with_balances_v2, calculate_staker_strk_rewards_with_balances_v3,
2728 calculate_strk_pool_rewards_with_pool_balance_v2, compute_rewards_per_unit,
2829 custom_decimals_token, deploy_mock_erc20_decimals_contract,
@@ -3029,3 +3030,91 @@ fn enable_disable_btc_tokens_flow_test() {
30293030 . span ();
30303031 assert! (tokens == expected_tokens );
30313032}
3033+
3034+ /// Flow:
3035+ /// Add tokens A and B
3036+ /// Enable token B
3037+ /// Advance K epochs
3038+ /// Enable token A, disable token B
3039+ /// update_rewards
3040+ /// Advance epoch - test rewards only for token B
3041+ /// update_rewards
3042+ /// Advance epoch - test rewards only for token B
3043+ /// update_rewards
3044+ /// Advance epoch - test rewards only for token A
3045+ #[test]
3046+ fn update_rewards_token_enable_disable_flow_test () {
3047+ let cfg : StakingInitConfig = Default :: default ();
3048+ let mut system = SystemConfigTrait :: basic_stake_flow_cfg (: cfg ). deploy ();
3049+ let token_a_decimals = 8 ;
3050+ let token_b_decimals = 18 ;
3051+ let token_a = system . deploy_new_btc_token (name : " Token A" , decimals : token_a_decimals );
3052+ let token_b = system . deploy_new_btc_token (name : " Token B" , decimals : token_b_decimals );
3053+
3054+ // Setup tokens
3055+ system . staking. add_token (token_address : token_a . contract_address ());
3056+ system . staking. add_token (token_address : token_b . contract_address ());
3057+ system . staking. enable_token (token_address : token_b . contract_address ());
3058+
3059+ // Stake and delegate
3060+ let stake_amount = system . staking. get_min_stake ();
3061+ let delegation_amount_a = BTC_8D_CONFIG . min_for_rewards;
3062+ let delegation_amount_b = BTC_18D_CONFIG . min_for_rewards;
3063+ let staker = system . new_staker (amount : stake_amount );
3064+ let commission = 200 ;
3065+ system . stake (: staker , amount : stake_amount , pool_enabled : true , : commission );
3066+ let pool_a = system . set_open_for_delegation (: staker , token_address : token_a . contract_address ());
3067+ let pool_b = system . set_open_for_delegation (: staker , token_address : token_b . contract_address ());
3068+ let delegator_a = system . new_btc_delegator (amount : delegation_amount_a , token : token_a );
3069+ let delegator_b = system . new_btc_delegator (amount : delegation_amount_b , token : token_b );
3070+ system
3071+ . delegate_btc (
3072+ delegator : delegator_a , pool : pool_a , amount : delegation_amount_a , token : token_a ,
3073+ );
3074+ system
3075+ . delegate_btc (
3076+ delegator : delegator_b , pool : pool_b , amount : delegation_amount_b , token : token_b ,
3077+ );
3078+ system . start_consensus_rewards ();
3079+
3080+ // Enable token A, disable token B
3081+ system . staking. enable_token (token_address : token_a . contract_address ());
3082+ system . staking. disable_token (token_address : token_b . contract_address ());
3083+
3084+ // update_rewards - test rewards only for token B
3085+ system . update_rewards (: staker , disable_rewards : false );
3086+ system . advance_epoch ();
3087+ let delegator_a_rewards = system . delegator_claim_rewards (delegator : delegator_a , pool : pool_a );
3088+ let delegator_b_rewards = system . delegator_claim_rewards (delegator : delegator_b , pool : pool_b );
3089+ let (_ , expected_delegator_rewards ) = calculate_staker_btc_pool_rewards_v3 (
3090+ normalized_pool_balance : NormalizedAmountTrait :: from_native_amount (
3091+ amount : delegation_amount_b , decimals : token_b_decimals ,
3092+ ),
3093+ normalized_staker_total_btc_balance : NormalizedAmountTrait :: from_native_amount (
3094+ amount : delegation_amount_b , decimals : token_b_decimals ,
3095+ ),
3096+ : commission ,
3097+ staking_contract : system . staking. address,
3098+ minting_curve_contract : system . minting_curve. address,
3099+ token_address : token_b . contract_address (),
3100+ );
3101+ assert! (expected_delegator_rewards . is_non_zero ());
3102+ assert! (delegator_a_rewards . is_zero ());
3103+ assert! (delegator_b_rewards == expected_delegator_rewards );
3104+
3105+ // update_rewards - test rewards only for token B
3106+ system . update_rewards (: staker , disable_rewards : false );
3107+ system . advance_epoch ();
3108+ let delegator_a_rewards = system . delegator_claim_rewards (delegator : delegator_a , pool : pool_a );
3109+ let delegator_b_rewards = system . delegator_claim_rewards (delegator : delegator_b , pool : pool_b );
3110+ assert! (delegator_a_rewards . is_zero ());
3111+ assert! (delegator_b_rewards == expected_delegator_rewards );
3112+
3113+ // update_rewards - test rewards only for token A
3114+ system . update_rewards (: staker , disable_rewards : false );
3115+ system . advance_epoch ();
3116+ let delegator_a_rewards = system . delegator_claim_rewards (delegator : delegator_a , pool : pool_a );
3117+ let delegator_b_rewards = system . delegator_claim_rewards (delegator : delegator_b , pool : pool_b );
3118+ assert! (delegator_a_rewards == expected_delegator_rewards );
3119+ assert! (delegator_b_rewards . is_zero ());
3120+ }
0 commit comments