Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer committed Sep 13, 2024
1 parent 82eea10 commit 1cf3530
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
4 changes: 2 additions & 2 deletions air/src/constraints/stack/op_flags/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down
39 changes: 36 additions & 3 deletions assembly/src/assembler/tests.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<RpoDigest> = 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() {
Expand Down
8 changes: 8 additions & 0 deletions miden/tests/integration/operations/io_ops/adv_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 3 additions & 4 deletions processor/src/decoder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 1cf3530

Please sign in to comment.