-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix bug in the Program deser, add tests
- Loading branch information
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |