diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 9657ad5d0a9d37..3b537d65cdb380 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2560,6 +2560,7 @@ mod tests { use super::*; use crate::{ accounts_index::Ancestors, + builtin_programs::new_system_program_activation_epoch, genesis_utils::{ create_genesis_config_with_leader, GenesisConfigInfo, BOOTSTRAP_VALIDATOR_LAMPORTS, }, @@ -6597,6 +6598,77 @@ mod tests { assert_eq!(bank.capitalization(), pre_capitalization - burn_amount); } + #[test] + fn test_legacy_system_instruction_processor0_stable() { + let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000); + genesis_config.operating_mode = OperatingMode::Stable; + let bank0 = Arc::new(Bank::new(&genesis_config)); + + let activation_epoch = new_system_program_activation_epoch(bank0.operating_mode()); + assert!(activation_epoch > bank0.epoch()); + + // Transfer to self is not supported by legacy_system_instruction_processor0 + bank0 + .transfer(1, &mint_keypair, &mint_keypair.pubkey()) + .unwrap_err(); + + // Activate system_instruction_processor + let bank = Bank::new_from_parent( + &bank0, + &Pubkey::default(), + genesis_config + .epoch_schedule + .get_first_slot_in_epoch(activation_epoch), + ); + + // Transfer to self is supported by system_instruction_processor + bank.transfer(2, &mint_keypair, &mint_keypair.pubkey()) + .unwrap(); + } + + #[test] + fn test_legacy_system_instruction_processor0_preview() { + let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000); + genesis_config.operating_mode = OperatingMode::Preview; + let bank0 = Arc::new(Bank::new(&genesis_config)); + + let activation_epoch = new_system_program_activation_epoch(bank0.operating_mode()); + assert!(activation_epoch > bank0.epoch()); + + // Transfer to self is not supported by legacy_system_instruction_processor0 + bank0 + .transfer(1, &mint_keypair, &mint_keypair.pubkey()) + .unwrap_err(); + + // Activate system_instruction_processor + let bank = Bank::new_from_parent( + &bank0, + &Pubkey::default(), + genesis_config + .epoch_schedule + .get_first_slot_in_epoch(activation_epoch), + ); + + // Transfer to self is supported by system_instruction_processor + bank.transfer(2, &mint_keypair, &mint_keypair.pubkey()) + .unwrap(); + } + + #[test] + fn test_legacy_system_instruction_processor0_development() { + let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000); + genesis_config.operating_mode = OperatingMode::Development; + let bank0 = Arc::new(Bank::new(&genesis_config)); + + let activation_epoch = new_system_program_activation_epoch(bank0.operating_mode()); + assert!(activation_epoch == bank0.epoch()); + + // Transfer to self is supported by system_instruction_processor + bank0 + .transfer(2, &mint_keypair, &mint_keypair.pubkey()) + .unwrap(); + } + #[test] fn test_duplicate_account_key() { solana_logger::setup(); diff --git a/runtime/src/builtin_programs.rs b/runtime/src/builtin_programs.rs index 7c6671bcdec6bd..e6a7ea0c2fac78 100644 --- a/runtime/src/builtin_programs.rs +++ b/runtime/src/builtin_programs.rs @@ -19,11 +19,11 @@ impl BuiltinProgram { } } -fn new_system_program_activation_epoch(operating_mode: OperatingMode) -> Epoch { +pub(crate) fn new_system_program_activation_epoch(operating_mode: OperatingMode) -> Epoch { match operating_mode { OperatingMode::Development => 0, - OperatingMode::Preview => std::u64::MAX / 2, - OperatingMode::Stable => std::u64::MAX / 2, + OperatingMode::Preview => 1_000_000, + OperatingMode::Stable => 1_000_000, } }