Skip to content

Commit 3bc74af

Browse files
test: add attest after upgrade test (#71)
<!-- 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/71) <!-- Reviewable:end --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds a flow testing attestation behavior immediately after upgrade (fail then succeed post-epoch) and wires it into mainnet-fork tests. > > - **Flow tests**: > - Add `AttestAfterUpgradeFlow` in `src/flow_test/flows.cairo` to validate attestation immediately after upgrade: > - First attest via `IAttestationSafeDispatcherTrait` fails (no previous-epoch trace), then after advancing an epoch attestation succeeds and rewards equal `calculate_staker_strk_rewards_v2`. > - Register test `attest_after_upgrade_flow_test` in `src/flow_test/fork_test.cairo`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0becc70. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent b42160b commit 3bc74af

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/flow_test/flows.cairo

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::num::traits::Zero;
33
use core::num::traits::ops::pow::Pow;
44
use snforge_std::{Token, TokenImpl, get_class_hash, start_cheat_block_number_global};
55
use staking::attestation::attestation::Attestation::MIN_ATTESTATION_WINDOW;
6+
use staking::attestation::interface::IAttestationSafeDispatcherTrait;
67
use staking::constants::{ALPHA, ALPHA_DENOMINATOR, K, STRK_IN_FRIS, STRK_TOKEN_ADDRESS};
78
use staking::errors::{GenericError, InternalError};
89
use staking::flow_test::utils::MainnetClassHashes::{
@@ -7197,6 +7198,55 @@ pub(crate) impl GetStakersAfterUpgradeFlowImpl of FlowTrait<GetStakersAfterUpgra
71977198
}
71987199
}
71997200

7201+
/// Flow:
7202+
/// Stake
7203+
/// Upgrade
7204+
/// Attempt attest - fail
7205+
/// Advance epoch
7206+
/// Attest - test rewards
7207+
#[derive(Drop, Copy)]
7208+
pub(crate) struct AttestAfterUpgradeFlow {
7209+
pub(crate) staker: Option<Staker>,
7210+
}
7211+
pub(crate) impl AttestAfterUpgradeFlowImpl of FlowTrait<AttestAfterUpgradeFlow> {
7212+
fn setup_v2(ref self: AttestAfterUpgradeFlow, ref system: SystemState) {
7213+
let amount = system.staking.get_min_stake();
7214+
let staker = system.new_staker(:amount);
7215+
system.stake(:staker, :amount, pool_enabled: false, commission: 200);
7216+
7217+
system.set_staker_for_migration(staker_address: staker.staker.address);
7218+
self.staker = Option::Some(staker);
7219+
}
7220+
7221+
#[feature("safe_dispatcher")]
7222+
fn test(self: AttestAfterUpgradeFlow, ref system: SystemState) {
7223+
let staker = self.staker.unwrap();
7224+
let attestation_safe = system.attestation.unwrap().safe_dispatcher();
7225+
7226+
cheat_caller_address_once(
7227+
contract_address: system.attestation.unwrap().address,
7228+
caller_address: staker.operational.address,
7229+
);
7230+
let result = attestation_safe.attest(block_hash: Zero::zero());
7231+
// This error is due to the staker trace having no entry for the previous epoch.
7232+
// Had the staker been initialized in V3, the error would have been
7233+
// ATTEST_WITH_ZERO_BALANCE.
7234+
assert_panic_with_error(:result, expected_error: "Index out of bounds");
7235+
7236+
system.advance_epoch();
7237+
system.advance_block_into_attestation_window(:staker);
7238+
system.attest(:staker);
7239+
7240+
let rewards = system.staker_claim_rewards(:staker);
7241+
let (expected_rewards, _) = calculate_staker_strk_rewards_v2(
7242+
staker_info: system.staker_info_v1(:staker),
7243+
staking_contract: system.staking.address,
7244+
minting_curve_contract: system.minting_curve.address,
7245+
);
7246+
assert!(rewards == expected_rewards);
7247+
}
7248+
}
7249+
72007250
/// Flow:
72017251
/// Add tokens A and B
72027252
/// Enable token B

src/flow_test/fork_test.cairo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,13 @@ fn get_stakers_after_upgrade_flow_test() {
444444
test_flow_mainnet(ref :flow);
445445
}
446446

447+
#[test]
448+
#[fork("MAINNET_LATEST")]
449+
fn attest_after_upgrade_flow_test() {
450+
let mut flow = flows::AttestAfterUpgradeFlow { staker: Option::None };
451+
test_flow_mainnet(ref :flow);
452+
}
453+
447454
#[test]
448455
#[fork("MAINNET_LATEST")]
449456
fn toggle_tokens_before_after_upgrade_flow_test() {

0 commit comments

Comments
 (0)