Skip to content

Commit 6638029

Browse files
test: add attest after upgrade test
1 parent a64f3df commit 6638029

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, STRK_IN_FRIS, STRK_TOKEN_ADDRESS};
78
use staking::errors::{GenericError, InternalError};
89
use staking::flow_test::utils::MainnetClassHashes::{
@@ -7064,6 +7065,52 @@ pub(crate) impl GetStakersAfterUpgradeFlowImpl of FlowTrait<GetStakersAfterUpgra
70647065
}
70657066
}
70667067

7068+
/// Flow:
7069+
/// Stake
7070+
/// Upgrade
7071+
/// Attempt attest (fail)
7072+
/// Advance epoch
7073+
/// Attempt attest - test rewards
7074+
#[derive(Drop, Copy)]
7075+
pub(crate) struct AttestAfterUpgradeFlow {
7076+
pub(crate) staker: Option<Staker>,
7077+
}
7078+
pub(crate) impl AttestAfterUpgradeFlowImpl of FlowTrait<AttestAfterUpgradeFlow> {
7079+
fn setup_v2(ref self: AttestAfterUpgradeFlow, ref system: SystemState) {
7080+
let amount = system.staking.get_min_stake();
7081+
let staker = system.new_staker(:amount);
7082+
system.stake(:staker, :amount, pool_enabled: false, commission: 200);
7083+
7084+
system.set_staker_for_migration(staker_address: staker.staker.address);
7085+
self.staker = Option::Some(staker);
7086+
}
7087+
7088+
#[feature("safe_dispatcher")]
7089+
fn test(self: AttestAfterUpgradeFlow, ref system: SystemState) {
7090+
let staker = self.staker.unwrap();
7091+
let attestation_safe = system.attestation.unwrap().safe_dispatcher();
7092+
7093+
cheat_caller_address_once(
7094+
contract_address: system.attestation.unwrap().address,
7095+
caller_address: staker.operational.address,
7096+
);
7097+
let result = attestation_safe.attest(block_hash: Zero::zero());
7098+
assert_panic_with_error(:result, expected_error: "Index out of bounds");
7099+
7100+
system.advance_epoch();
7101+
system.advance_block_into_attestation_window(:staker);
7102+
system.attest(:staker);
7103+
7104+
let rewards = system.staker_claim_rewards(:staker);
7105+
let (expected_rewards, _) = calculate_staker_strk_rewards_v2(
7106+
staker_info: system.staker_info_v1(:staker),
7107+
staking_contract: system.staking.address,
7108+
minting_curve_contract: system.minting_curve.address,
7109+
);
7110+
assert!(rewards == expected_rewards);
7111+
}
7112+
}
7113+
70677114
/// Flow:
70687115
/// Add tokens A and B
70697116
/// 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)