Skip to content

Commit

Permalink
Add legacy_system_instruction_processor0 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Jun 3, 2020
1 parent fd0c689 commit bc07294
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
72 changes: 72 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/builtin_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down

0 comments on commit bc07294

Please sign in to comment.