Skip to content

Commit 7462d37

Browse files
committed
test: staker migration more flows
1 parent fdd38dd commit 7462d37

File tree

3 files changed

+168
-5
lines changed

3 files changed

+168
-5
lines changed

src/flow_test/flow_ideas.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ more ideas:
4444
- staker enter in V2, advance epoch, advance epoch, upgrade to V3, attest, update balance,advance epoch, attest, advance epoch, attest, test rewards
4545
- staker enter in V2, advance epoch, update balance, upgrade to V3, attest, advance epoch, attest, advance epoch, attest, test rewards
4646
- staker enter in V2, advance epoch, upgrade to V3, advance epoch, attest,
47-
- staker enter in V0, upgrade to V3, attest
48-
- staker enter in V0, advance epoch, update balance, upgrade to V3, attest, update balance, advance epoch, attest
49-
- staker enter in V1, advance epoch, update balance, upgrade to V3, attest, update balance, advance epoch, attest
50-
- staker enter in V0, advance epoch, update balance, advance epoch, update balance, upgrade to V3, attest
51-
- staker enter in V1, advance epoch, update balance, advance epoch, update balance, upgrade to V3, attest
5247
- staker in V2, update balance staker+update balance pool, upgrade, attest in current epoch, attest in next epoch, attest in next next epoch
5348
- staker in V2, update balance staker+update balance pool, upgrade, update balance staker+update balance pool, attest in current epoch, attest in next epoch, attest in next next epoch
5449
- staker in V2, advance epoch, update balance staker+update balance pool, advance epoch, update balance staker+update balance pool, upgrade, update balance staker+update balance pool, attest in current epoch, attest in next epoch, attest in next next epoch

src/flow_test/flows.cairo

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8570,3 +8570,150 @@ pub(crate) impl MemberChangeBalanceClaimRewardsOneRewardsFlowImpl of MultiVersio
85708570
);
85718571
}
85728572
}
8573+
8574+
/// Flow:
8575+
/// Staker stake in V0
8576+
/// Upgrade
8577+
/// Advance Epoch
8578+
/// Attest
8579+
/// Increase stake
8580+
/// Advance Epoch
8581+
/// Attest
8582+
/// Advance K epochs
8583+
/// Attest
8584+
#[derive(Drop, Copy)]
8585+
pub(crate) struct StakerV0AttestFlow {
8586+
pub(crate) staker: Option<Staker>,
8587+
}
8588+
pub(crate) impl StakerV0AttestFlowImpl of FlowTrait<StakerV0AttestFlow> {
8589+
fn setup(ref self: StakerV0AttestFlow, ref system: SystemState) {
8590+
let amount = system.staking.get_min_stake();
8591+
let staker = system.new_staker(amount: 2 * amount);
8592+
system.stake(:staker, :amount, pool_enabled: false, commission: 0);
8593+
self.staker = Option::Some(staker);
8594+
system.set_staker_for_migration(staker_address: staker.staker.address);
8595+
}
8596+
fn test(self: StakerV0AttestFlow, ref system: SystemState) {
8597+
let staker = self.staker.unwrap();
8598+
let amount = system.staker_info_v1(:staker).amount_own;
8599+
system.advance_epoch();
8600+
system.advance_block_custom_and_attest(:staker, stake: amount);
8601+
let (expected_rewards, _) = calculate_staker_strk_rewards_with_balances_v2(
8602+
amount_own: amount,
8603+
pool_amount: 0,
8604+
commission: 0,
8605+
staking_contract: system.staking.address,
8606+
minting_curve_contract: system.minting_curve.address,
8607+
);
8608+
assert!(system.staker_claim_rewards(:staker) == expected_rewards);
8609+
system.increase_stake(:staker, :amount);
8610+
system.advance_epoch();
8611+
system.advance_block_custom_and_attest(:staker, stake: amount);
8612+
assert!(system.staker_claim_rewards(:staker) == expected_rewards);
8613+
system.advance_k_epochs_and_attest(:staker);
8614+
let (expected_rewards, _) = calculate_staker_strk_rewards_with_balances_v2(
8615+
amount_own: 2 * amount,
8616+
pool_amount: 0,
8617+
commission: 0,
8618+
staking_contract: system.staking.address,
8619+
minting_curve_contract: system.minting_curve.address,
8620+
);
8621+
assert!(system.staker_claim_rewards(:staker) == expected_rewards);
8622+
}
8623+
}
8624+
8625+
/// Flow:
8626+
/// Staker stake in V1
8627+
/// Advance Epoch
8628+
/// Increase stake
8629+
/// Advance Epoch
8630+
/// Upgrade
8631+
/// Attest
8632+
/// Increase stake
8633+
/// Advance Epoch
8634+
/// Attest
8635+
/// Advance K epochs
8636+
/// Attest
8637+
#[derive(Drop, Copy)]
8638+
pub(crate) struct StakerV1AttestFlow {
8639+
pub(crate) staker: Option<Staker>,
8640+
}
8641+
pub(crate) impl StakerV1AttestFlowImpl of FlowTrait<StakerV1AttestFlow> {
8642+
fn setup_v1(ref self: StakerV1AttestFlow, ref system: SystemState) {
8643+
let amount = system.staking.get_min_stake();
8644+
let staker = system.new_staker(amount: 3 * amount);
8645+
system.stake(:staker, :amount, pool_enabled: false, commission: 0);
8646+
system.advance_epoch();
8647+
system.increase_stake(:staker, :amount);
8648+
system.advance_epoch();
8649+
self.staker = Option::Some(staker);
8650+
system.set_staker_for_migration(staker_address: staker.staker.address);
8651+
}
8652+
fn test(self: StakerV1AttestFlow, ref system: SystemState) {
8653+
let staker = self.staker.unwrap();
8654+
let amount = system.staker_info_v1(:staker).amount_own / 2;
8655+
system.advance_block_custom_and_attest(:staker, stake: 2 * amount);
8656+
let (expected_rewards, _) = calculate_staker_strk_rewards_with_balances_v2(
8657+
amount_own: 2 * amount,
8658+
pool_amount: 0,
8659+
commission: 0,
8660+
staking_contract: system.staking.address,
8661+
minting_curve_contract: system.minting_curve.address,
8662+
);
8663+
assert!(system.staker_claim_rewards(:staker) == expected_rewards);
8664+
system.increase_stake(:staker, :amount);
8665+
system.advance_epoch();
8666+
system.advance_block_custom_and_attest(:staker, stake: 2 * amount);
8667+
assert!(system.staker_claim_rewards(:staker) == expected_rewards);
8668+
system.advance_k_epochs_and_attest(:staker);
8669+
let (expected_rewards, _) = calculate_staker_strk_rewards_with_balances_v2(
8670+
amount_own: 3 * amount,
8671+
pool_amount: 0,
8672+
commission: 0,
8673+
staking_contract: system.staking.address,
8674+
minting_curve_contract: system.minting_curve.address,
8675+
);
8676+
assert!(system.staker_claim_rewards(:staker) == expected_rewards);
8677+
}
8678+
}
8679+
8680+
/// Flow:
8681+
/// Staker stake in V1
8682+
/// Advance Epoch
8683+
/// Increase stake
8684+
/// Advance Epoch
8685+
/// Increase stake
8686+
/// Advance Epoch
8687+
/// Upgrade
8688+
/// Attest
8689+
#[derive(Drop, Copy)]
8690+
pub(crate) struct StakerV1ChangeBalanceAttestFlow {
8691+
pub(crate) staker: Option<Staker>,
8692+
}
8693+
pub(crate) impl StakerV1ChangeBalanceAttestFlowImpl of FlowTrait<StakerV1ChangeBalanceAttestFlow> {
8694+
fn setup_v1(ref self: StakerV1ChangeBalanceAttestFlow, ref system: SystemState) {
8695+
let amount = system.staking.get_min_stake();
8696+
let staker = system.new_staker(amount: 3 * amount);
8697+
system.stake(:staker, :amount, pool_enabled: false, commission: 0);
8698+
system.advance_epoch();
8699+
system.increase_stake(:staker, :amount);
8700+
system.advance_epoch();
8701+
system.increase_stake(:staker, :amount);
8702+
system.advance_epoch();
8703+
self.staker = Option::Some(staker);
8704+
system.set_staker_for_migration(staker_address: staker.staker.address);
8705+
}
8706+
fn test(self: StakerV1ChangeBalanceAttestFlow, ref system: SystemState) {
8707+
let staker = self.staker.unwrap();
8708+
let stake_amount = system.staker_info_v1(:staker).amount_own;
8709+
system.advance_block_custom_and_attest(:staker, stake: stake_amount);
8710+
let (expected_rewards, _) = calculate_staker_strk_rewards_with_balances_v2(
8711+
amount_own: stake_amount,
8712+
pool_amount: 0,
8713+
commission: 0,
8714+
staking_contract: system.staking.address,
8715+
minting_curve_contract: system.minting_curve.address,
8716+
);
8717+
assert!(system.staker_claim_rewards(:staker) == expected_rewards);
8718+
}
8719+
}

src/flow_test/fork_test.cairo

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,24 @@ fn delegator_change_balance_before_upgrade_rewards_consensus_flow_test() {
545545
};
546546
test_flow_mainnet(ref :flow);
547547
}
548+
549+
#[test]
550+
#[fork("MAINNET_LATEST")]
551+
fn staker_v0_attest_flow_test() {
552+
let mut flow = flows::StakerV0AttestFlow { staker: Option::None };
553+
test_flow_mainnet(ref :flow);
554+
}
555+
556+
#[test]
557+
#[fork("MAINNET_LATEST")]
558+
fn staker_v1_attest_flow_test() {
559+
let mut flow = flows::StakerV1AttestFlow { staker: Option::None };
560+
test_flow_mainnet(ref :flow);
561+
}
562+
563+
#[test]
564+
#[fork("MAINNET_LATEST")]
565+
fn staker_v1_change_balance_attest_flow_test() {
566+
let mut flow = flows::StakerV1ChangeBalanceAttestFlow { staker: Option::None };
567+
test_flow_mainnet(ref :flow);
568+
}

0 commit comments

Comments
 (0)