Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Apr 27, 2023
1 parent 6935dae commit 00f8d1c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 49 deletions.
25 changes: 8 additions & 17 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn from_relocatable_to_indexes(relocatable: Relocatable) -> (usize, usize) {
pub mod test_utils {
use crate::types::exec_scope::ExecutionScopes;
use crate::types::relocatable::MaybeRelocatable;
use crate::vm::trace::trace_entry::TraceEntry;

#[macro_export]
macro_rules! bigint {
Expand Down Expand Up @@ -354,23 +355,13 @@ pub mod test_utils {
}
pub(crate) use non_continuous_ids_data;

macro_rules! trace_check {
( $trace: expr, [ $( ($off_pc:expr, $off_ap:expr, $off_fp:expr) ),+ ] ) => {
let mut index = -1;
$(
index += 1;
assert_eq!(
$trace[index as usize],
TraceEntry {
pc: $off_pc,
ap: $off_ap,
fp: $off_fp,
}
);
)*
};
#[track_caller]
pub(crate) fn trace_check(actual: &[TraceEntry], expected: &[(usize, usize, usize)]) {
assert_eq!(actual.len(), expected.len());
for (entry, expected) in actual.iter().zip(expected.iter()) {
assert_eq!(&(entry.pc, entry.ap, entry.fp), expected);
}
}
pub(crate) use trace_check;

macro_rules! exec_scopes_ref {
() => {
Expand Down Expand Up @@ -668,7 +659,7 @@ mod test {
fp: 7,
},
];
trace_check!(trace, [(2, 7, 1), (5, 1, 0), (9, 5, 7)]);
trace_check(&trace, &[(2, 7, 1), (5, 1, 0), (9, 5, 7)]);
}

#[test]
Expand Down
36 changes: 18 additions & 18 deletions src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,9 +1886,9 @@ mod tests {
//Check each TraceEntry in trace
let trace = vm.trace.unwrap();
assert_eq!(trace.len(), 5);
trace_check!(
trace,
[(3, 2, 2), (5, 3, 2), (0, 5, 5), (2, 6, 5), (7, 6, 2)]
trace_check(
&trace,
&[(3, 2, 2), (5, 3, 2), (0, 5, 5), (2, 6, 5), (7, 6, 2)],
);
}

Expand Down Expand Up @@ -1962,9 +1962,9 @@ mod tests {
//Check each TraceEntry in trace
let trace = vm.trace.unwrap();
assert_eq!(trace.len(), 10);
trace_check!(
trace,
[
trace_check(
&trace,
&[
(8, 3, 3),
(9, 4, 3),
(11, 5, 3),
Expand All @@ -1974,8 +1974,8 @@ mod tests {
(4, 9, 7),
(5, 9, 7),
(7, 10, 7),
(13, 10, 3)
]
(13, 10, 3),
],
);
//Check the range_check builtin segment
assert_eq!(vm.builtin_runners[0].name(), RANGE_CHECK_BUILTIN_NAME);
Expand Down Expand Up @@ -2078,9 +2078,9 @@ mod tests {
//Check each TraceEntry in trace
let trace = vm.trace.unwrap();
assert_eq!(trace.len(), 12);
trace_check!(
trace,
[
trace_check(
&trace,
&[
(4, 3, 3),
(5, 4, 3),
(7, 5, 3),
Expand All @@ -2092,8 +2092,8 @@ mod tests {
(0, 11, 11),
(1, 11, 11),
(3, 12, 11),
(13, 12, 3)
]
(13, 12, 3),
],
);
//Check that the output to be printed is correct
assert_eq!(vm.builtin_runners[0].name(), OUTPUT_BUILTIN_NAME);
Expand Down Expand Up @@ -2216,9 +2216,9 @@ mod tests {
//Check each TraceEntry in trace
let trace = vm.trace.unwrap();
assert_eq!(trace.len(), 18);
trace_check!(
trace,
[
trace_check(
&trace,
&[
(13, 4, 4),
(14, 5, 4),
(16, 6, 4),
Expand All @@ -2236,8 +2236,8 @@ mod tests {
(1, 16, 16),
(3, 17, 16),
(22, 17, 4),
(23, 18, 4)
]
(23, 18, 4),
],
);
//Check the range_check builtin segment
assert_eq!(vm.builtin_runners[1].name(), RANGE_CHECK_BUILTIN_NAME);
Expand Down
6 changes: 1 addition & 5 deletions src/vm/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ pub fn get_perm_range_check_limits(
#[cfg(test)]
mod test {
use super::*;
use crate::{
types::relocatable::MaybeRelocatable, utils::test_utils::*,
utils::test_utils::*,
vm::errors::memory_errors::MemoryError,
};
use crate::utils::test_utils::*;
use assert_matches::assert_matches;

#[cfg(target_arch = "wasm32")]
Expand Down
18 changes: 9 additions & 9 deletions src/vm/vm_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2863,7 +2863,7 @@ mod tests {
Ok(())
);
let trace = vm.trace.unwrap();
trace_check!(trace, [(0, 2, 2)]);
trace_check(&trace, &[(0, 2, 2)]);

assert_eq!(vm.run_context.pc, Relocatable::from((3, 0)));
assert_eq!(vm.run_context.ap, 2);
Expand Down Expand Up @@ -2955,9 +2955,9 @@ mod tests {
//Check each TraceEntry in trace
let trace = vm.trace.unwrap();
assert_eq!(trace.len(), 5);
trace_check!(
trace,
[(3, 2, 2), (5, 3, 2), (0, 5, 5), (2, 6, 5), (7, 6, 2)]
trace_check(
&trace,
&[(3, 2, 2), (5, 3, 2), (0, 5, 5), (2, 6, 5), (7, 6, 2)],
);
//Check that the following addresses have been accessed:
// Addresses have been copied from python execution:
Expand Down Expand Up @@ -3652,16 +3652,16 @@ mod tests {
}
//Compare trace
let trace = vm.trace.unwrap();
trace_check!(
trace,
[
trace_check(
&trace,
&[
(3, 2, 2),
(0, 4, 4),
(2, 5, 4),
(5, 5, 2),
(7, 6, 2),
(8, 6, 2)
]
(8, 6, 2),
],
);

//Compare final register values
Expand Down

0 comments on commit 00f8d1c

Please sign in to comment.