Skip to content

Commit

Permalink
Merge pull request #2458 from o1-labs/dw/turshi-memory-tests
Browse files Browse the repository at this point in the history
Turshi/Tests: move into subdirectory - memory
  • Loading branch information
dannywillems authored Jul 30, 2024
2 parents dfea94d + 33b55e4 commit 894ec44
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 37 deletions.
37 changes: 0 additions & 37 deletions turshi/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,40 +100,3 @@ impl<F: Field> CairoMemory<F> {
self[addr].map(|x| x.word())
}
}

#[cfg(test)]
mod tests {
use super::*;
use ark_ff::One;
use mina_curves::pasta::Fp as F;

#[test]
fn test_cairo_bytecode() {
// This test starts with the public memory corresponding to a simple Cairo program
// func main{}():
// tempvar x = 10;
// return()
// end
// And checks that memory writing and reading works as expected by completing
// the total memory of executing the program
let instrs = [0x480680017fff8000, 10, 0x208b7fff7fff7ffe]
.iter()
.map(|&i: &i64| F::from(i))
.collect();
let mut memory = CairoMemory::new(instrs);
memory.write(F::from(memory.len()), F::from(7u64));
memory.write(F::from(memory.len()), F::from(7u64));
memory.write(F::from(memory.len()), F::from(10u64));
println!("{memory}");
// Check content of an address
assert_eq!(
memory.read(F::one()).unwrap(),
F::from(0x480680017fff8000u64)
);
// Check that the program contained 3 words
assert_eq!(3, memory.get_codelen());
// Check we have 6 words, excluding the dummy entry
assert_eq!(6, memory.len() - 1);
memory.read(F::from(10u32));
}
}
33 changes: 33 additions & 0 deletions turshi/tests/memory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use ark_ff::One;
use mina_curves::pasta::Fp as F;
use turshi::CairoMemory;

#[test]
fn test_cairo_bytecode() {
// This test starts with the public memory corresponding to a simple Cairo program
// func main{}():
// tempvar x = 10;
// return()
// end
// And checks that memory writing and reading works as expected by completing
// the total memory of executing the program
let instrs = [0x480680017fff8000, 10, 0x208b7fff7fff7ffe]
.iter()
.map(|&i: &i64| F::from(i))
.collect();
let mut memory = CairoMemory::new(instrs);
memory.write(F::from(memory.len()), F::from(7u64));
memory.write(F::from(memory.len()), F::from(7u64));
memory.write(F::from(memory.len()), F::from(10u64));
println!("{memory}");
// Check content of an address
assert_eq!(
memory.read(F::one()).unwrap(),
F::from(0x480680017fff8000u64)
);
// Check that the program contained 3 words
assert_eq!(3, memory.get_codelen());
// Check we have 6 words, excluding the dummy entry
assert_eq!(6, memory.len() - 1);
memory.read(F::from(10u32));
}

0 comments on commit 894ec44

Please sign in to comment.