From e6ef4ec65b843bf346128222174ddf62a204ced8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Tue, 13 Feb 2024 13:19:20 +0000 Subject: [PATCH] Adds test_unloaded(). --- program-runtime/src/loaded_programs.rs | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 351fe594ac1b61..b1e26addc88830 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -2375,6 +2375,38 @@ mod tests { assert!(match_missing(&missing, &program3, true)); } + #[test] + fn test_unloaded() { + let env = Arc::new(BuiltinProgram::new_mock()); + for loaded_program_type in [ + LoadedProgramType::FailedVerification(env.clone()), + LoadedProgramType::Closed, + LoadedProgramType::DelayVisibility, + LoadedProgramType::Unloaded(env), + LoadedProgramType::Builtin(BuiltinProgram::new_mock()), + ] { + assert!(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(), + } + .to_unloaded() + .is_none()); + } + + 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::();