diff --git a/core/src/program.rs b/core/src/program.rs index 385baa942..ebff4c7b0 100644 --- a/core/src/program.rs +++ b/core/src/program.rs @@ -151,7 +151,7 @@ impl Deserializable for Program { let kernel = source.read()?; let entrypoint = MastNodeId::from_u32_safe(source.read_u32()?, &mast_forest)?; - if mast_forest.is_procedure_root(entrypoint) { + if !mast_forest.is_procedure_root(entrypoint) { return Err(DeserializationError::InvalidValue(format!( "entrypoint {entrypoint} is not a procedure" ))); diff --git a/miden/tests/integration/main.rs b/miden/tests/integration/main.rs index 10720fdb1..2eccaba67 100644 --- a/miden/tests/integration/main.rs +++ b/miden/tests/integration/main.rs @@ -7,6 +7,7 @@ mod cli; mod exec_iters; mod flow_control; mod operations; +mod program; // TESTS // ================================================================================================ diff --git a/miden/tests/integration/program.rs b/miden/tests/integration/program.rs new file mode 100644 index 000000000..7ba0670cc --- /dev/null +++ b/miden/tests/integration/program.rs @@ -0,0 +1,61 @@ +use alloc::vec::Vec; + +use assembly::Assembler; +use miden_vm::Program; +use test_utils::serde::{Deserializable, Serializable}; + +// PROGRAM SERIALIZATION AND DESERIALIZATION TESTS +// ================================================================= + +#[test] +fn test_program_serde_simple() { + let source = " + begin + push.1.2 + add + drop + end + "; + + let assembler = Assembler::default(); + let original_program = assembler.assemble_program(source).unwrap(); + + let mut target = Vec::new(); + original_program.write_into(&mut target); + let deserialized_program = Program::read_from_bytes(&target).unwrap(); + + assert_eq!(original_program, deserialized_program); +} + +#[test] +fn test_program_serde_with_decorators() { + let source = " + const.DEFAULT_CONST=100 + + proc.foo + push.1.2 add + debug.stack.8 + end + + begin + emit.DEFAULT_CONST + + exec.foo + + debug.stack.4 + + drop + + trace.DEFAULT_CONST + end + "; + + let assembler = Assembler::default().with_debug_mode(true); + let original_program = assembler.assemble_program(source).unwrap(); + + let mut target = Vec::new(); + original_program.write_into(&mut target); + let deserialized_program = Program::read_from_bytes(&target).unwrap(); + + assert_eq!(original_program, deserialized_program); +}