Add legacy_system_instruction_processor0 tests
This commit is contained in:
		| @@ -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(); | ||||
|   | ||||
| @@ -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, | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user