From 1cf3530b25b2584ecbc28a69e14148e9f837936e Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Fri, 13 Sep 2024 15:05:27 -0400 Subject: [PATCH] chore: update tests --- air/src/constraints/stack/op_flags/tests.rs | 4 +- assembly/src/assembler/tests.rs | 39 +++++++++++++++++-- .../integration/operations/io_ops/adv_ops.rs | 8 ++++ processor/src/decoder/tests.rs | 7 ++-- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/air/src/constraints/stack/op_flags/tests.rs b/air/src/constraints/stack/op_flags/tests.rs index bfbc594f0..b122e6d28 100644 --- a/air/src/constraints/stack/op_flags/tests.rs +++ b/air/src/constraints/stack/op_flags/tests.rs @@ -144,7 +144,7 @@ fn degree_4_op_flags() { fn composite_flags() { // ------ no change 0 --------------------------------------------------------------------- - let op_no_change_0 = [Operation::MpVerify(0), Operation::Span, Operation::Halt]; + let op_no_change_0 = [Operation::MpVerify(0), Operation::Span, Operation::Halt, Operation::Emit(42)]; for op in op_no_change_0 { // frame initialised with an op operation. let frame = generate_evaluation_frame(op.op_code().into()); @@ -168,7 +168,7 @@ fn composite_flags() { assert_eq!(op_flags.left_shift(), ZERO); assert_eq!(op_flags.top_binary(), ZERO); - if op == Operation::MpVerify(0) { + if op == Operation::MpVerify(0) || op == Operation::Emit(42) { assert_eq!(op_flags.control_flow(), ZERO); } else if op == Operation::Span || op == Operation::Halt { assert_eq!(op_flags.control_flow(), ONE); diff --git a/assembly/src/assembler/tests.rs b/assembly/src/assembler/tests.rs index 597b4826d..f8442d1db 100644 --- a/assembly/src/assembler/tests.rs +++ b/assembly/src/assembler/tests.rs @@ -1,8 +1,7 @@ +use alloc::vec::Vec; use pretty_assertions::assert_eq; use vm_core::{ - assert_matches, - mast::{MastForest, MastNode}, - Program, + assert_matches, crypto::hash::RpoDigest, mast::{MastForest, MastNode}, Program }; use super::{Assembler, Operation}; @@ -158,6 +157,40 @@ fn nested_blocks() -> Result<(), Report> { Ok(()) } +/// Ensures that the arguments of `emit` does indeed modify the digest of a basic block +#[test] +fn emit_instruction_digest() { + let context = TestContext::new(); + + let program_source = r#" + proc.foo + emit.1 + end + + proc.bar + emit.2 + end + + begin + # specific impl irrelevant + exec.foo + exec.bar + end + "#; + + let program = context.assemble(program_source).unwrap(); + + let procedure_digests: Vec = program.mast_forest().procedure_digests().collect(); + + // foo, bar and entrypoint + assert_eq!(3, procedure_digests.len()); + + // Ensure that foo, bar and entrypoint all have different digests + assert_ne!(procedure_digests[0], procedure_digests[1]); + assert_ne!(procedure_digests[0], procedure_digests[2]); + assert_ne!(procedure_digests[1], procedure_digests[2]); +} + /// Since `foo` and `bar` have the same body, we only expect them to be added once to the program. #[test] fn duplicate_procedure() { diff --git a/miden/tests/integration/operations/io_ops/adv_ops.rs b/miden/tests/integration/operations/io_ops/adv_ops.rs index 09f91e9af..08e2a1ccd 100644 --- a/miden/tests/integration/operations/io_ops/adv_ops.rs +++ b/miden/tests/integration/operations/io_ops/adv_ops.rs @@ -116,3 +116,11 @@ fn adv_pipe_with_hperm() { let test = build_test!(source, &[], &advice_stack); test.expect_stack(&final_stack); } + +// EMITTING EVENTS + +#[test] +fn emit() { + let test = build_op_test!("emit.42", &[0, 0, 0, 0]); + test.prove_and_verify(vec![], false); +} diff --git a/processor/src/decoder/tests.rs b/processor/src/decoder/tests.rs index 1f5d7b404..d0e1cead0 100644 --- a/processor/src/decoder/tests.rs +++ b/processor/src/decoder/tests.rs @@ -92,8 +92,7 @@ fn basic_block_one_group() { #[test] fn basic_block_small() { - let iv = [ONE, TWO]; - let ops = vec![Operation::Push(iv[0]), Operation::Push(iv[1]), Operation::Add]; + let ops = vec![Operation::Push(ONE), Operation::Emit(1), Operation::Add]; let basic_block = BasicBlockNode::new(ops.clone(), None).unwrap(); let program = { let mut mast_forest = MastForest::new(); @@ -109,8 +108,8 @@ fn basic_block_small() { // --- check block address, op_bits, group count, op_index, and in_span columns --------------- check_op_decoding(&trace, 0, ZERO, Operation::Span, 4, 0, 0); - check_op_decoding(&trace, 1, INIT_ADDR, Operation::Push(iv[0]), 3, 0, 1); - check_op_decoding(&trace, 2, INIT_ADDR, Operation::Push(iv[1]), 2, 1, 1); + check_op_decoding(&trace, 1, INIT_ADDR, Operation::Push(ONE), 3, 0, 1); + check_op_decoding(&trace, 2, INIT_ADDR, Operation::Emit(1), 2, 1, 1); check_op_decoding(&trace, 3, INIT_ADDR, Operation::Add, 1, 2, 1); // starting new group: NOOP group is inserted by the processor to make sure number of groups // is a power of two