Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Adds test_unloaded().
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Feb 14, 2024
1 parent 1e5df9d commit 1c46990
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,44 @@ mod tests {
assert!(match_missing(&missing, &program3, true));
}

#[test]
fn test_unloaded() {
let mut cache = new_mock_cache::<TestForkGraph>();
for loaded_program_type in [
LoadedProgramType::FailedVerification(cache.environments.program_runtime_v1.clone()),
LoadedProgramType::Closed,
LoadedProgramType::DelayVisibility,
LoadedProgramType::Unloaded(cache.environments.program_runtime_v1.clone()),
LoadedProgramType::Builtin(BuiltinProgram::new_mock()),
] {
let entry = Arc::new(LoadedProgram {
program: loaded_program_type,
account_size: 0,
deployment_slot: 0,
effective_slot: 0,
tx_usage_counter: AtomicU64::default(),
ix_usage_counter: AtomicU64::default(),
latest_access_slot: AtomicU64::default(),
});
assert!(entry.to_unloaded().is_none());
let program_id = Pubkey::new_unique();
cache.assign_program(program_id, entry.clone());
cache.unload_program_entry(&program_id, &entry);
assert_eq!(
cache.entries.get(&program_id).unwrap().slot_versions.len(),
1
);
}

let unloaded_entry = new_test_loaded_program_with_usage(1, 2, AtomicU64::new(3))
.to_unloaded()
.unwrap();
assert_eq!(unloaded_entry.deployment_slot, 1);
assert_eq!(unloaded_entry.effective_slot, 2);
assert_eq!(unloaded_entry.latest_access_slot.load(Ordering::Relaxed), 1);
assert_eq!(unloaded_entry.tx_usage_counter.load(Ordering::Relaxed), 3);
}

#[test]
fn test_fork_prune_find_first_ancestor() {
let mut cache = new_mock_cache::<TestForkGraphSpecific>();
Expand Down

0 comments on commit 1c46990

Please sign in to comment.