Skip to content

Commit

Permalink
Moves the tests of program.rs into a separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Jan 7, 2025
1 parent 894f5a6 commit ef3f356
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
36 changes: 0 additions & 36 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,39 +415,3 @@ macro_rules! declare_builtin_function {
}
};
}

#[cfg(test)]
mod tests {
use super::*;
use crate::{syscalls, vm::TestContextObject};

#[test]
fn test_builtin_program_eq() {
let mut function_registry_a =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry_a
.register_function_hashed(*b"log", syscalls::SyscallString::vm)
.unwrap();
function_registry_a
.register_function_hashed(*b"log_64", syscalls::SyscallU64::vm)
.unwrap();
let mut function_registry_b =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry_b
.register_function_hashed(*b"log_64", syscalls::SyscallU64::vm)
.unwrap();
function_registry_b
.register_function_hashed(*b"log", syscalls::SyscallString::vm)
.unwrap();
let mut function_registry_c =
FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry_c
.register_function_hashed(*b"log_64", syscalls::SyscallU64::vm)
.unwrap();
let builtin_program_a = BuiltinProgram::new_loader(Config::default(), function_registry_a);
let builtin_program_b = BuiltinProgram::new_loader(Config::default(), function_registry_b);
assert_eq!(builtin_program_a, builtin_program_b);
let builtin_program_c = BuiltinProgram::new_loader(Config::default(), function_registry_c);
assert_ne!(builtin_program_a, builtin_program_c);
}
}
32 changes: 30 additions & 2 deletions tests/vm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use solana_sbpf::{
elf::Executable,
program::BuiltinProgram,
vm::{RuntimeEnvironmentSlot, TestContextObject},
program::{BuiltinProgram, BuiltinFunction, FunctionRegistry},
syscalls,
vm::{RuntimeEnvironmentSlot, TestContextObject, Config},
};
use std::{fs::File, io::Read, sync::Arc};
use test_utils::create_vm;
Expand Down Expand Up @@ -49,3 +50,30 @@ fn test_runtime_environment_slots() {
check_slot!(env, program_result, ProgramResult);
check_slot!(env, memory_mapping, MemoryMapping);
}

#[test]
fn test_builtin_program_eq() {
let mut function_registry_a = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry_a
.register_function_hashed(*b"log", syscalls::SyscallString::vm)
.unwrap();
function_registry_a
.register_function_hashed(*b"log_64", syscalls::SyscallU64::vm)
.unwrap();
let mut function_registry_b = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry_b
.register_function_hashed(*b"log_64", syscalls::SyscallU64::vm)
.unwrap();
function_registry_b
.register_function_hashed(*b"log", syscalls::SyscallString::vm)
.unwrap();
let mut function_registry_c = FunctionRegistry::<BuiltinFunction<TestContextObject>>::default();
function_registry_c
.register_function_hashed(*b"log_64", syscalls::SyscallU64::vm)
.unwrap();
let builtin_program_a = BuiltinProgram::new_loader(Config::default(), function_registry_a);
let builtin_program_b = BuiltinProgram::new_loader(Config::default(), function_registry_b);
assert_eq!(builtin_program_a, builtin_program_b);
let builtin_program_c = BuiltinProgram::new_loader(Config::default(), function_registry_c);
assert_ne!(builtin_program_a, builtin_program_c);
}

0 comments on commit ef3f356

Please sign in to comment.