|
| 1 | +use forester_utils::forester_epoch::Epoch; |
| 2 | +use light_program_test::{ |
| 3 | + program_test::{LightProgramTest, TestRpc}, |
| 4 | + ProgramTestConfig, |
| 5 | +}; |
| 6 | +use light_registry::{ |
| 7 | + protocol_config::state::{ProtocolConfig, ProtocolConfigPda}, |
| 8 | + ForesterConfig, ForesterEpochPda, |
| 9 | +}; |
| 10 | +use light_test_utils::{ |
| 11 | + assert_epoch::{assert_epoch_pda, assert_registered_forester_pda}, |
| 12 | + register_test_forester, Rpc, |
| 13 | +}; |
| 14 | +use serial_test::serial; |
| 15 | +use solana_sdk::{signature::Keypair, signer::Signer}; |
| 16 | + |
| 17 | +/// Verifies that foresters can register for an epoch outside the original |
| 18 | +/// registration window (slots 0-99 with default config). Previously this |
| 19 | +/// would fail with `NotInRegistrationPeriod`. |
| 20 | +#[serial] |
| 21 | +#[tokio::test] |
| 22 | +async fn test_forester_register_outside_registration_phase() { |
| 23 | + let config = ProgramTestConfig { |
| 24 | + protocol_config: ProtocolConfig::default(), |
| 25 | + with_prover: false, |
| 26 | + with_forester: false, |
| 27 | + ..Default::default() |
| 28 | + }; |
| 29 | + let mut rpc = LightProgramTest::new(config).await.unwrap(); |
| 30 | + rpc.indexer = None; |
| 31 | + let env = rpc.test_accounts.clone(); |
| 32 | + |
| 33 | + let forester_keypair = Keypair::new(); |
| 34 | + rpc.airdrop_lamports(&forester_keypair.pubkey(), 1_000_000_000) |
| 35 | + .await |
| 36 | + .unwrap(); |
| 37 | + |
| 38 | + // Register the base forester PDA. |
| 39 | + register_test_forester( |
| 40 | + &mut rpc, |
| 41 | + &env.protocol.governance_authority, |
| 42 | + &forester_keypair.pubkey(), |
| 43 | + ForesterConfig { fee: 1 }, |
| 44 | + ) |
| 45 | + .await |
| 46 | + .unwrap(); |
| 47 | + |
| 48 | + let protocol_config = rpc |
| 49 | + .get_anchor_account::<ProtocolConfigPda>(&env.protocol.governance_authority_pda) |
| 50 | + .await |
| 51 | + .unwrap() |
| 52 | + .unwrap() |
| 53 | + .config; |
| 54 | + |
| 55 | + // Warp to slot 500 -- well past the old registration window (0-99). |
| 56 | + // With ProtocolConfig::default() the active phase starts at slot 100. |
| 57 | + rpc.warp_to_slot(500).unwrap(); |
| 58 | + |
| 59 | + // Register for epoch 0 with explicit epoch to bypass client-side |
| 60 | + // auto-detection (which would skip if not in registration phase). |
| 61 | + let registered_epoch = Epoch::register( |
| 62 | + &mut rpc, |
| 63 | + &protocol_config, |
| 64 | + &forester_keypair, |
| 65 | + &forester_keypair.pubkey(), |
| 66 | + Some(0), |
| 67 | + ) |
| 68 | + .await |
| 69 | + .unwrap(); |
| 70 | + |
| 71 | + assert!( |
| 72 | + registered_epoch.is_some(), |
| 73 | + "Forester should be able to register outside the original registration window" |
| 74 | + ); |
| 75 | + let registered_epoch = registered_epoch.unwrap(); |
| 76 | + |
| 77 | + let forester_epoch_pda = rpc |
| 78 | + .get_anchor_account::<ForesterEpochPda>(®istered_epoch.forester_epoch_pda) |
| 79 | + .await |
| 80 | + .unwrap() |
| 81 | + .unwrap(); |
| 82 | + assert_eq!(forester_epoch_pda.epoch, 0); |
| 83 | + assert!(forester_epoch_pda.total_epoch_weight.is_none()); |
| 84 | + |
| 85 | + assert_epoch_pda(&mut rpc, 0, 1).await; |
| 86 | + assert_registered_forester_pda( |
| 87 | + &mut rpc, |
| 88 | + ®istered_epoch.forester_epoch_pda, |
| 89 | + &forester_keypair.pubkey(), |
| 90 | + 0, |
| 91 | + ) |
| 92 | + .await; |
| 93 | +} |
0 commit comments