Skip to content

Commit

Permalink
chore: format test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Feb 26, 2024
1 parent 794516e commit 34e472f
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 108 deletions.
3 changes: 2 additions & 1 deletion test_programs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
acir_artifacts
execution_success/**/crs
execution_success/**/crs
Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ struct B<T_C> {
}

impl<T_C> B<T_C> {
fn new(new_concrete_t_c_constructor: fn () -> T_C) -> B<T_C> {
B { new_concrete_t_c_constructor }
}
fn new(new_concrete_t_c_constructor: fn() -> T_C) -> B<T_C> {
B { new_concrete_t_c_constructor }
}

fn get_t_c(self) -> T_C {
let new_concrete_t_c_constructor = self.new_concrete_t_c_constructor;
new_concrete_t_c_constructor()
}
fn get_t_c(self) -> T_C {
let new_concrete_t_c_constructor = self.new_concrete_t_c_constructor;
new_concrete_t_c_constructor()
}
}
// ---
// Set<Note>
struct C<T_D> {
t_d_interface: MethodInterface<T_D>,
}

impl<T_D> C<T_D> {
fn new (t_d_interface: MethodInterface<T_D>) -> Self {
C { t_d_interface }
}
fn new(t_d_interface: MethodInterface<T_D>) -> Self {
C { t_d_interface }
}

fn call_method_of_t_d(self, t_d: T_D) -> Field {
let some_method_on_t_d = self.t_d_interface.some_method_on_t_d;
some_method_on_t_d(t_d)
}
fn call_method_of_t_d(self, t_d: T_D) -> Field {
let some_method_on_t_d = self.t_d_interface.some_method_on_t_d;
some_method_on_t_d(t_d)
}
}
// ---
struct MethodInterface<T_D> {
some_method_on_t_d: fn(T_D)->Field,
Expand Down
4 changes: 2 additions & 2 deletions test_programs/execution_success/array_dynamic/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ fn main(
x: [u32; 5],
mut z: u32,
t: u32,
index: [Field;5],
index2: [Field;5],
index: [Field; 5],
index2: [Field; 5],
offset: Field,
sublen: Field
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ fn compute_root(leaf: [u8; 32], path: [u8; 64], _index: u32, root: [u8; 32]) {

// Regression for issue #4258
assert(root == current);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main(mut x: [Field; 10], index: u8) -> pub [Field; 10] {
x[index] = 0;
x
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
fn main(x: Field, y: pub Field) {
assert(x == y, "x and y are not equal");
assert_eq(x, y, "x and y are not equal");
}
}
10 changes: 5 additions & 5 deletions test_programs/execution_success/bigint/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use dep::std::bigint;

fn main(mut x: [u8;5], y: [u8;5]) {
let a = bigint::BigInt::secpk1_fq_from_le_bytes([x[0],x[1],x[2],x[3],x[4]]);
let b = bigint::BigInt::secpk1_fq_from_le_bytes([y[0],y[1],y[2],y[3],y[4]]);
fn main(mut x: [u8; 5], y: [u8; 5]) {
let a = bigint::BigInt::secpk1_fq_from_le_bytes([x[0], x[1], x[2], x[3], x[4]]);
let b = bigint::BigInt::secpk1_fq_from_le_bytes([y[0], y[1], y[2], y[3], y[4]]);

let a_bytes = a.to_le_bytes();
let b_bytes = b.to_le_bytes();
Expand All @@ -11,11 +11,11 @@ fn main(mut x: [u8;5], y: [u8;5]) {
assert(b_bytes[i] == y[i]);
}

let d = a*b - b;
let d = a * b - b;
let d_bytes = d.to_le_bytes();
let d1 = bigint::BigInt::secpk1_fq_from_le_bytes(597243850900842442924.to_le_bytes(10));
let d1_bytes = d1.to_le_bytes();
for i in 0..32 {
assert(d_bytes[i] == d1_bytes[i]);
assert(d_bytes[i] == d1_bytes[i]);
}
}
27 changes: 11 additions & 16 deletions test_programs/execution_success/brillig_cow/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,37 @@ struct ExecutionResult {

impl ExecutionResult {
fn is_equal(self, other: ExecutionResult) -> bool {
(self.original == other.original) &
(self.modified_once == other.modified_once) &
(self.modified_twice == other.modified_twice)
(self.original == other.original)
& (self.modified_once == other.modified_once)
& (self.modified_twice == other.modified_twice)
}
}

fn modify_in_inlined_constrained(original: [Field; ARRAY_SIZE], index: u64) -> ExecutionResult {
let mut modified = original;

modified[index] = 27;

let modified_once = modified;

modified[index+1] = 27;

ExecutionResult {
original,
modified_once,
modified_twice: modified
}
ExecutionResult { original, modified_once, modified_twice: modified }
}

unconstrained fn modify_in_unconstrained(original: [Field; ARRAY_SIZE], index: u64) -> ExecutionResult {
unconstrained fn modify_in_unconstrained(
original: [Field; ARRAY_SIZE],
index: u64
) -> ExecutionResult {
let mut modified = original;

modified[index] = 27;

let modified_once = modified;

modified[index+1] = 27;

ExecutionResult {
original,
modified_once,
modified_twice: modified
}
ExecutionResult { original, modified_once, modified_twice: modified }
}

unconstrained fn main(original: [Field; ARRAY_SIZE], index: u64, expected_result: ExecutionResult) {
Expand Down
74 changes: 37 additions & 37 deletions test_programs/execution_success/brillig_cow_regression/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,54 @@ struct U256 {
}

impl U256 {
pub fn from_bytes32(bytes : [u8;32]) -> U256 {
pub fn from_bytes32(bytes: [u8; 32]) -> U256 {
// We use addition rather than a bitwise OR as the bitshifts ensure that none of the bytes overlap each other.
let high_0 = ((bytes[0] as u64) << 56)
+ ((bytes[1] as u64) << 48)
+ ((bytes[2] as u64) << 40)
+ ((bytes[3] as u64) << 32)
+ ((bytes[4] as u64) << 24)
+ ((bytes[5] as u64) << 16)
+ ((bytes[6] as u64) << 8)
+ (bytes[7] as u64);
+ ((bytes[1] as u64) << 48)
+ ((bytes[2] as u64) << 40)
+ ((bytes[3] as u64) << 32)
+ ((bytes[4] as u64) << 24)
+ ((bytes[5] as u64) << 16)
+ ((bytes[6] as u64) << 8)
+ (bytes[7] as u64);

let high_1 = ((bytes[8] as u64) << 56)
+ ((bytes[9] as u64) << 48)
+ ((bytes[10] as u64) << 40)
+ ((bytes[11] as u64) << 32)
+ ((bytes[12] as u64) << 24)
+ ((bytes[13] as u64) << 16)
+ ((bytes[14] as u64) << 8)
+ (bytes[15] as u64);
+ ((bytes[9] as u64) << 48)
+ ((bytes[10] as u64) << 40)
+ ((bytes[11] as u64) << 32)
+ ((bytes[12] as u64) << 24)
+ ((bytes[13] as u64) << 16)
+ ((bytes[14] as u64) << 8)
+ (bytes[15] as u64);

let low_0 = ((bytes[16] as u64) << 56)
+ ((bytes[17] as u64) << 48)
+ ((bytes[18] as u64) << 40)
+ ((bytes[19] as u64) << 32)
+ ((bytes[20] as u64) << 24)
+ ((bytes[21] as u64) << 16)
+ ((bytes[22] as u64) << 8)
+ (bytes[23] as u64);
+ ((bytes[17] as u64) << 48)
+ ((bytes[18] as u64) << 40)
+ ((bytes[19] as u64) << 32)
+ ((bytes[20] as u64) << 24)
+ ((bytes[21] as u64) << 16)
+ ((bytes[22] as u64) << 8)
+ (bytes[23] as u64);

let low_1 = ((bytes[24] as u64) << 56)
+ ((bytes[25] as u64) << 48)
+ ((bytes[26] as u64) << 40)
+ ((bytes[27] as u64) << 32)
+ ((bytes[28] as u64) << 24)
+ ((bytes[29] as u64) << 16)
+ ((bytes[30] as u64) << 8)
+ (bytes[31] as u64);

U256{inner : [high_0, high_1, low_0, low_1]}
+ ((bytes[25] as u64) << 48)
+ ((bytes[26] as u64) << 40)
+ ((bytes[27] as u64) << 32)
+ ((bytes[28] as u64) << 24)
+ ((bytes[29] as u64) << 16)
+ ((bytes[30] as u64) << 8)
+ (bytes[31] as u64);

U256 { inner: [high_0, high_1, low_0, low_1] }
}

pub fn to_u128_limbs(self) -> [Field;2] {
pub fn to_u128_limbs(self) -> [Field; 2] {
let two_pow_64 = 2.pow_32(64);

let high = (self.inner[0] as Field) * two_pow_64 + self.inner[1] as Field;
let low = (self.inner[2] as Field) * two_pow_64 + self.inner[3] as Field;
[high,low]

[high, low]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main(x: u32) {
assert(increment(x) == x + 1);
}

unconstrained fn wrapper(func: fn (u32) -> u32, param: u32) -> u32 {
unconstrained fn wrapper(func: fn(u32) -> u32, param: u32) -> u32 {
func(param)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ fn test5(a: u32) {
}
}

fn issue_661_foo(array: [u32;4], b: u32) -> [u32;1] {
fn issue_661_foo(array: [u32; 4], b: u32) -> [u32; 1] {
[array[0] + b]
}

fn issue_661_bar(a: [u32;4]) -> [u32;4] {
fn issue_661_bar(a: [u32; 4]) -> [u32; 4] {
let mut b: [u32; 4] = [0; 4];
b[0]=a[0]+1;
b
Expand Down
8 changes: 4 additions & 4 deletions test_programs/execution_success/databus/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use dep::std;

fn main(mut x: u32, y: call_data u32, z: call_data [u32;4]) -> return_data u32 {
let a = z[x];
a+foo(y)
fn main(mut x: u32, y: call_data u32, z: call_data [u32; 4]) -> return_data u32 {
let a = z[x];
a + foo(y)
}

// Use an unconstrained function to force the compiler to avoid inlining
unconstrained fn foo(x: u32) -> u32 {
x+1
x + 1
}

6 changes: 3 additions & 3 deletions test_programs/execution_success/debug_logs/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main(x: Field, y: pub Field) {
fn main(x: Field, y: pub Field) {
let string = "i: {i}, j: {j}";
println(string);

Expand Down Expand Up @@ -102,8 +102,8 @@ fn regression_2903() {
let a = v[0];
println(a); // will print `1`

let bytes = [ "aaa", "bbb", "ccc" ];
println(bytes);
let bytes = ["aaa", "bbb", "ccc"];
println(bytes);
}

fn regression_2906() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Example that uses the distinct keyword
fn main(x: pub Field) -> distinct pub [Field;2] {
fn main(x: pub Field) -> distinct pub [Field; 2] {
[x + 1, x]
}
10 changes: 5 additions & 5 deletions test_programs/execution_success/ecdsa_secp256k1/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use dep::std;

fn main(
message: [u8;38],
hashed_message: [u8;32],
pub_key_x: [u8;32],
pub_key_y: [u8;32],
signature: [u8;64]
message: [u8; 38],
hashed_message: [u8; 32],
pub_key_x: [u8; 32],
pub_key_y: [u8; 32],
signature: [u8; 64]
) {
// Hash the message, since secp256k1 expects a hashed_message
let expected = std::hash::sha256(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::std;

fn main(hashed_message: [u8;32], pub_key_x: [u8;32], pub_key_y: [u8;32], signature: [u8;64]) {
fn main(hashed_message: [u8; 32], pub_key_x: [u8; 32], pub_key_y: [u8; 32], signature: [u8; 64]) {
let valid_signature = std::ecdsa_secp256r1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message);
assert(valid_signature);
}
2 changes: 1 addition & 1 deletion test_programs/execution_success/main_bool_arg/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main(x: bool, y: [bool;2]) {
fn main(x: bool, y: [bool; 2]) {
if x {
assert(1 != 2);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dep::std::ops::{ Add, Sub, Mul, Div, Rem, BitAnd, BitOr, BitXor, Shl, Shr };
use dep::std::ops::{Add, Sub, Mul, Div, Rem, BitAnd, BitOr, BitXor, Shl, Shr};
use dep::std::cmp::Ordering;

// x = 3, y = 9
Expand Down Expand Up @@ -126,10 +126,6 @@ impl Ord for Wrapper {
}
}





struct Pair {
x: Wrapper,
y: Wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ use dep::std;
fn main() {
let x : i8 = -128;
std::println(x);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ fn main(mut x: u32) {
x = (x+1) / x;
}
assert(x != 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mod Baz {
use crate::Bar::NewType;
}


fn main(works: Baz::Works, fails: Baz::BarStruct, also_fails: Bar::NewType) -> pub Field {
works.a + fails.a + also_fails.a
}
Loading

0 comments on commit 34e472f

Please sign in to comment.