-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modules can be imported with this syntax: `use super::<module_name>::*`.
- Loading branch information
1 parent
6516cf1
commit 162caea
Showing
4 changed files
with
152 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
mod hash_varlen; | ||
mod import_type_declaration; | ||
mod nested_tuples; | ||
#[allow(dead_code)] | ||
mod removal_record_integrity_partial; | ||
mod returning_block_expr_u32; | ||
mod simple_encode; | ||
mod simple_map_on_bfe; | ||
mod simple_struct; | ||
mod value; |
67 changes: 67 additions & 0 deletions
67
src/tests_and_benchmarks/ozk/programs/other/import_type_declaration.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use super::simple_struct::*; | ||
use crate::tests_and_benchmarks::ozk::rust_shadows as tasm; | ||
use triton_vm::BFieldElement; | ||
use twenty_first::shared_math::bfield_codec::BFieldCodec; | ||
|
||
fn main() { | ||
let ts: Box<SimpleStruct> = | ||
SimpleStruct::decode(&tasm::load_from_memory(BFieldElement::new(300))).unwrap(); | ||
|
||
tasm::tasm_io_write_to_stdout___u128(ts.a); | ||
tasm::tasm_io_write_to_stdout___bfe(ts.b); | ||
tasm::tasm_io_write_to_stdout___bool(ts.c); | ||
tasm::tasm_io_write_to_stdout___u32(ts.d.len() as u32); | ||
tasm::tasm_io_write_to_stdout___digest(ts.e); | ||
|
||
return; | ||
} | ||
|
||
mod tests { | ||
use super::*; | ||
use crate::tests_and_benchmarks::ozk::ozk_parsing; | ||
use crate::tests_and_benchmarks::ozk::rust_shadows; | ||
use crate::tests_and_benchmarks::test_helpers::shared_test::execute_compiled_with_stack_memory_and_ins_for_test; | ||
use crate::tests_and_benchmarks::test_helpers::shared_test::init_memory_from; | ||
use arbitrary::Arbitrary; | ||
use arbitrary::Unstructured; | ||
use itertools::Itertools; | ||
use rand::random; | ||
use std::collections::HashMap; | ||
|
||
#[test] | ||
fn import_type_declaration_test() { | ||
let rand: [u8; 2000] = random(); | ||
let test_struct = SimpleStruct::arbitrary(&mut Unstructured::new(&rand)).unwrap(); | ||
let non_determinism = init_memory_from(&test_struct, BFieldElement::new(300)); | ||
let stdin = vec![]; | ||
|
||
// Run test on host machine | ||
let native_output = | ||
rust_shadows::wrap_main_with_io(&main)(stdin.clone(), non_determinism.clone()); | ||
|
||
// Run test on Triton-VM | ||
let test_program = ozk_parsing::compile_for_test( | ||
"other", | ||
"import_type_declaration", | ||
"main", | ||
crate::ast_types::ListType::Unsafe, | ||
); | ||
let vm_output = execute_compiled_with_stack_memory_and_ins_for_test( | ||
&test_program, | ||
vec![], | ||
&mut HashMap::default(), | ||
stdin, | ||
non_determinism, | ||
0, | ||
) | ||
.unwrap(); | ||
if native_output != vm_output.output { | ||
panic!( | ||
"native_output:\n {}, got:\n{}. Code was:\n{}", | ||
native_output.iter().join(", "), | ||
vm_output.output.iter().join(", "), | ||
test_program.iter().join("\n") | ||
); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/tests_and_benchmarks/ozk/programs/other/simple_struct.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use arbitrary::Arbitrary; | ||
use tasm_lib::structure::tasm_object::TasmObject; | ||
use triton_vm::{BFieldElement, Digest}; | ||
use twenty_first::shared_math::bfield_codec::BFieldCodec; | ||
|
||
#[derive(TasmObject, BFieldCodec, Clone, Arbitrary)] | ||
pub(super) struct SimpleStruct { | ||
pub a: u128, | ||
pub b: BFieldElement, | ||
pub c: bool, | ||
pub d: Vec<Digest>, | ||
pub e: Digest, | ||
} |