use alloc::vec;
use miden_core::{
Felt, ONE, ZERO,
mast::MastForest,
program::{MIN_STACK_DEPTH, StackInputs},
};
use super::{op_assert, op_clk, op_sdepth};
use crate::{
execution::operations::stack_ops::op_push,
fast::FastProcessor,
processor::{Processor, StackInterface, SystemInterface},
};
#[test]
fn test_op_assert() {
let program = MastForest::default();
let mut processor = FastProcessor::new(StackInputs::new(&[ONE]).unwrap());
assert!(op_assert(&mut processor, ZERO, &program).is_ok());
}
#[test]
fn test_op_sdepth() {
let mut processor = FastProcessor::new(StackInputs::default());
op_sdepth(&mut processor).unwrap();
let expected = build_expected(&[MIN_STACK_DEPTH as u64]);
assert_eq!(expected, processor.stack_top());
assert_eq!(MIN_STACK_DEPTH as u32 + 1, processor.stack_depth());
op_sdepth(&mut processor).unwrap();
let expected = build_expected(&[MIN_STACK_DEPTH as u64 + 1, MIN_STACK_DEPTH as u64]);
assert_eq!(expected, processor.stack_top());
assert_eq!(MIN_STACK_DEPTH as u32 + 2, processor.stack_depth());
Processor::stack_mut(&mut processor).increment_size().unwrap();
processor.stack_write(0, ZERO);
op_sdepth(&mut processor).unwrap();
let expected = build_expected(&[
MIN_STACK_DEPTH as u64 + 3,
0,
MIN_STACK_DEPTH as u64 + 1,
MIN_STACK_DEPTH as u64,
]);
assert_eq!(expected, processor.stack_top());
assert_eq!(MIN_STACK_DEPTH as u32 + 4, processor.stack_depth());
}
#[test]
fn test_op_clk() {
let mut processor = FastProcessor::new(StackInputs::default());
op_clk(&mut processor).unwrap();
processor.system_mut().increment_clock();
let expected = build_expected(&[0]);
assert_eq!(expected, processor.stack_top());
op_push(&mut processor, ONE).unwrap();
processor.system_mut().increment_clock();
op_clk(&mut processor).unwrap();
processor.system_mut().increment_clock();
let expected = build_expected(&[2, 1, 0]);
assert_eq!(expected, processor.stack_top());
}
fn build_expected(values: &[u64]) -> alloc::vec::Vec<Felt> {
let mut expected = vec![ZERO; 16];
for (i, &value) in values.iter().enumerate() {
expected[15 - i] = Felt::new(value);
}
expected
}