Skip to content

Commit aca4787

Browse files
test: add attest after upgrade test
1 parent 6c46b05 commit aca4787

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/flow_test/flows.cairo

Lines changed: 47 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::{
@@ -7102,6 +7103,52 @@ pub(crate) impl GetStakersAfterUpgradeFlowImpl of FlowTrait<GetStakersAfterUpgra
71027103
}
71037104
}
71047105

7106+
/// Flow:
7107+
/// Stake
7108+
/// Upgrade
7109+
/// Attempt attest (fail)
7110+
/// Advance epoch
7111+
/// Attempt attest - test rewards
7112+
#[derive(Drop, Copy)]
7113+
pub(crate) struct AttestAfterUpgradeFlow {
7114+
pub(crate) staker: Option<Staker>,
7115+
}
7116+
pub(crate) impl AttestAfterUpgradeFlowImpl of FlowTrait<AttestAfterUpgradeFlow> {
7117+
fn setup_v2(ref self: AttestAfterUpgradeFlow, ref system: SystemState) {
7118+
let amount = system.staking.get_min_stake();
7119+
let staker = system.new_staker(:amount);
7120+
system.stake(:staker, :amount, pool_enabled: false, commission: 200);
7121+
7122+
system.set_staker_for_migration(staker_address: staker.staker.address);
7123+
self.staker = Option::Some(staker);
7124+
}
7125+
7126+
#[feature("safe_dispatcher")]
7127+
fn test(self: AttestAfterUpgradeFlow, ref system: SystemState) {
7128+
let staker = self.staker.unwrap();
7129+
let attestation_safe = system.attestation.unwrap().safe_dispatcher();
7130+
7131+
cheat_caller_address_once(
7132+
contract_address: system.attestation.unwrap().address,
7133+
caller_address: staker.operational.address,
7134+
);
7135+
let result = attestation_safe.attest(block_hash: Zero::zero());
7136+
assert_panic_with_error(:result, expected_error: "Index out of bounds");
7137+
7138+
system.advance_epoch();
7139+
system.advance_block_into_attestation_window(:staker);
7140+
system.attest(:staker);
7141+
7142+
let rewards = system.staker_claim_rewards(:staker);
7143+
let (expected_rewards, _) = calculate_staker_strk_rewards_v2(
7144+
staker_info: system.staker_info_v1(:staker),
7145+
staking_contract: system.staking.address,
7146+
minting_curve_contract: system.minting_curve.address,
7147+
);
7148+
assert!(rewards == expected_rewards);
7149+
}
7150+
}
7151+
71057152
/// Flow:
71067153
/// Add tokens A and B
71077154
/// 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)