Skip to content

Commit

Permalink
add extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
vezenovm committed Feb 14, 2024
1 parent b2ff529 commit 3c01836
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "array_dynamic_nested_blackbox_input"
type = "bin"
authors = [""]
compiler_version = ">=0.24.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
y = "3"
hash_result = [50, 53, 90, 252, 105, 236, 223, 30, 135, 229, 193, 172, 51, 139, 8, 32, 188, 104, 151, 115, 129, 168, 27, 71, 203, 47, 40, 228, 89, 177, 129, 100]

[[x]]
a = "1"
b = ["2", "3", "20"]

[x.bar]
inner = ["100", "101", "102"]

[[x]]
a = "4" # idx = 3, flattened start idx = 7
b = ["5", "6", "21"] # idx = 4, flattened start idx = 8

[x.bar]
inner = ["103", "104", "105"] # idx = 5, flattened start idx = 11

[[x]]
a = "7"
b = ["8", "9", "22"]

[x.bar]
inner = ["106", "107", "108"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
struct Bar {
inner: [u8; 3],
}

struct Foo {
a: Field,
b: [Field; 3],
bar: Bar,
}

fn main(mut x: [Foo; 3], y: pub Field, hash_result: pub [u8; 32]) {
// Simple dynamic array set for entire inner most array
x[y - 1].bar.inner = [106, 107, 10];
let mut hash_input = x[y - 1].bar.inner;
// Make sure that we are passing a dynamic array to the black box function call
// by setting the array using a dynamic index here
hash_input[y - 1] = 0;
let hash = dep::std::hash::sha256(hash_input);
assert_eq(hash, hash_result);
}

0 comments on commit 3c01836

Please sign in to comment.