Skip to content

Commit c8b0f3b

Browse files
test: add update_rewards strk pool flow (#46)
<!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/starkware-libs/starknet-staking/46) <!-- Reviewable:end --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds a flow test for `update_rewards` with a STRK pool under consensus rewards and a `start_consensus_rewards` helper; updates flow ideas. > > - **Tests**: > - Add `update_rewards_strk_pool_flow_test` in `src/flow_test/test.cairo` to validate staker rewards post-`update_rewards` and delegator rewards after next epoch under consensus STRK pool. > - **Utilities**: > - Add `SystemState.start_consensus_rewards()` in `src/flow_test/utils.cairo` to set `consensus_rewards_first_epoch` and advance `K` epochs. > - **Docs**: > - Update `src/flow_test/flow_ideas.md` by removing STRK-only pool case from `update_rewards` ideas. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5b22f3d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 197c090 commit c8b0f3b

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/flow_test/flow_ideas.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
- Get staker info while staker has zero balance.
44

55
## `update_rewards`
6-
- staker with only strk pool.
76
- staker with only btc pool.
87
- staker with empty pool (STRK + BTC).
98
- staker with 2 btc pools with different decimals.

src/flow_test/test.cairo

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,3 +2888,47 @@ fn update_rewards_disable_rewards_consensus_rewards_flow_test() {
28882888
:result, expected_error: StakingError::REWARDS_ALREADY_UPDATED.describe(),
28892889
);
28902890
}
2891+
2892+
/// Flow:
2893+
/// Start consensus rewards.
2894+
/// Staker stake with STRK pool.
2895+
/// Delegator delegate STRK.
2896+
/// Advance K epochs.
2897+
/// update_rewards.
2898+
/// Test staker rewards.
2899+
/// Test delegator rewards.
2900+
/// Advance epoch.
2901+
/// Test delegator rewards.
2902+
#[test]
2903+
fn update_rewards_strk_pool_flow_test() {
2904+
let cfg: StakingInitConfig = Default::default();
2905+
let mut system = SystemConfigTrait::basic_stake_flow_cfg(:cfg).deploy();
2906+
system.start_consensus_rewards();
2907+
let stake_amount = system.staking.get_min_stake();
2908+
let delegation_amount = STRK_CONFIG.min_for_rewards;
2909+
let staker = system.new_staker(amount: stake_amount);
2910+
let commission = 200;
2911+
system.stake(:staker, amount: stake_amount, pool_enabled: true, :commission);
2912+
let pool = system.staking.get_pool(:staker);
2913+
let delegator = system.new_delegator(amount: delegation_amount);
2914+
system.delegate(:delegator, :pool, amount: delegation_amount);
2915+
system.advance_k_epochs();
2916+
2917+
system.update_rewards(:staker, disable_rewards: false);
2918+
let (expected_staker_rewards, expected_pool_rewards) =
2919+
calculate_staker_strk_rewards_with_balances_v3(
2920+
amount_own: stake_amount,
2921+
pool_amount: delegation_amount,
2922+
:commission,
2923+
staking_contract: system.staking.address,
2924+
minting_curve_contract: system.minting_curve.address,
2925+
);
2926+
let staker_rewards = system.staker_claim_rewards(:staker);
2927+
let delegator_rewards = system.delegator_claim_rewards(:delegator, :pool);
2928+
assert!(staker_rewards == expected_staker_rewards);
2929+
assert!(delegator_rewards.is_zero());
2930+
2931+
system.advance_epoch();
2932+
let delegator_rewards = system.delegator_claim_rewards(:delegator, :pool);
2933+
assert!(delegator_rewards == expected_pool_rewards);
2934+
}

src/flow_test/utils.cairo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,12 @@ pub(crate) impl SystemImpl of SystemTrait {
12631263
.deploy_btc_token(:decimals);
12641264
btc_token
12651265
}
1266+
1267+
fn start_consensus_rewards(self: SystemState) {
1268+
let epoch_id = self.staking.get_current_epoch() + K.into();
1269+
self.staking.set_consensus_rewards_first_epoch(:epoch_id);
1270+
self.advance_k_epochs();
1271+
}
12661272
}
12671273

12681274
#[generate_trait]

0 commit comments

Comments
 (0)