mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-26 11:45:00 +03:00
folder of compiler tests for constants definitions and usages
This commit is contained in:
parent
3d573f046e
commit
02422ca411
22
tests/tests/compiler/constants/constant_finalize.leo
Normal file
22
tests/tests/compiler/constants/constant_finalize.leo
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Pass
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
mapping account: address => u64;
|
||||||
|
mapping values: u8 => u8;
|
||||||
|
const BIG_NUMBER: u8 = 1u8;
|
||||||
|
|
||||||
|
transition finalize_self_caller() -> () {
|
||||||
|
return then finalize(self.caller);
|
||||||
|
}
|
||||||
|
|
||||||
|
finalize finalize_self_caller(caller: address) -> () {
|
||||||
|
const TINY: u8 = 3u8;
|
||||||
|
let current_value: u8 = Mapping::get_or_use(values, 0u8, 0u8) + TINY + BIG_NUMBER;
|
||||||
|
Mapping::set(values, 0u8, current_value + 1u8);
|
||||||
|
let current_amount: u64 = Mapping::get_or_use(account, caller, 0u64);
|
||||||
|
Mapping::set(account, caller, current_amount + 1u64);
|
||||||
|
}
|
||||||
|
}
|
27
tests/tests/compiler/constants/constant_loop_bound.leo
Normal file
27
tests/tests/compiler/constants/constant_loop_bound.leo
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Pass
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const START: u8 = 0u8;
|
||||||
|
const START_2: u8 = 1u8;
|
||||||
|
const STOP_2: u8 = 20u8;
|
||||||
|
transition foo(a: u8, b: u8, flag: bool) -> u8 {
|
||||||
|
const STOP: u8 = 10u8;
|
||||||
|
let c:u8 = 1u8;
|
||||||
|
for i: u8 in START..STOP {
|
||||||
|
c = c + i;
|
||||||
|
}
|
||||||
|
for i: u8 in 0u8..STOP {
|
||||||
|
c = c + i;
|
||||||
|
}
|
||||||
|
for i: u8 in START..10u8 {
|
||||||
|
c = c + i;
|
||||||
|
}
|
||||||
|
for i: u8 in START_2..STOP_2 {
|
||||||
|
c = c + i;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Fail
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const START: u32 = 0u32;
|
||||||
|
transition foo(a: u8, b: u8, flag: bool) -> u8 {
|
||||||
|
const STOP: u8 = 10u8;
|
||||||
|
let c:u8 = 1u8;
|
||||||
|
for i: u8 in START..STOP {
|
||||||
|
c = c + i;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Fail
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const START: u8 = 10u8;
|
||||||
|
transition foo(a: u8, b: u8, flag: bool) -> u8 {
|
||||||
|
const STOP: u8 = 0u8;
|
||||||
|
let c:u8 = 1u8;
|
||||||
|
for i: u8 in START..STOP {
|
||||||
|
c = c + i;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
19
tests/tests/compiler/constants/local_shadowing_fail.leo
Normal file
19
tests/tests/compiler/constants/local_shadowing_fail.leo
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Fail
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const HELLO: u8 = 0u8;
|
||||||
|
transition foo(a: u8, b: u8, flag: bool) -> u8 {
|
||||||
|
let start: (u8, u8) = (a, b);
|
||||||
|
for i: u8 in 0u8..16u8 {
|
||||||
|
start = (start.0 + start.1, start.1 + 1u8);
|
||||||
|
if flag {
|
||||||
|
start = (start.1, start.0 + start.0);
|
||||||
|
const HELLO:u8 = 1u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return start.0 + start.1;
|
||||||
|
}
|
||||||
|
}
|
28
tests/tests/compiler/constants/loop_unrolling.leo
Normal file
28
tests/tests/compiler/constants/loop_unrolling.leo
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Pass
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const START: u32 = 0u32;
|
||||||
|
transition foo(a: u32, b: u32, flag: bool) -> u32 {
|
||||||
|
const STOP: u32 = 10u32;
|
||||||
|
let c:u32 = 1u32;
|
||||||
|
for i: u32 in START..STOP {
|
||||||
|
for j: u32 in START..STOP {
|
||||||
|
const BIG_NUMBER:u32 = 1u32;
|
||||||
|
if flag {
|
||||||
|
const SUPER_SMALL_NUMBER:u32 = 99u32;
|
||||||
|
c = c + a + b + BIG_NUMBER + SUPER_SMALL_NUMBER;
|
||||||
|
} else {
|
||||||
|
const SUPER_SMALL_NUMBER:u32 = 88u32;
|
||||||
|
c = c + a - b + BIG_NUMBER + SUPER_SMALL_NUMBER;
|
||||||
|
for k: u32 in START..STOP {
|
||||||
|
c = c + a - b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
19
tests/tests/compiler/constants/reassignment_fail.leo
Normal file
19
tests/tests/compiler/constants/reassignment_fail.leo
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Fail
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const HELLO: u8 = 0u8;
|
||||||
|
transition foo(a: u8, b: u8, flag: bool) -> u8 {
|
||||||
|
let start: (u8, u8) = (a, b);
|
||||||
|
for i: u8 in 0u8..16u8 {
|
||||||
|
start = (start.0 + start.1, start.1 + 1u8);
|
||||||
|
if flag {
|
||||||
|
start = (start.1, start.0 + start.0);
|
||||||
|
HELLO = 1u8 + 1u8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return start.0 + start.1;
|
||||||
|
}
|
||||||
|
}
|
11
tests/tests/compiler/constants/tuple_definition.leo
Normal file
11
tests/tests/compiler/constants/tuple_definition.leo
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Pass
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const (HELLO,GOODBYE): (u8,u8) = (1u8, 1u8);
|
||||||
|
transition foo(a: u8, b: u8, flag: bool) -> u8 {
|
||||||
|
return GOODBYE;
|
||||||
|
}
|
||||||
|
}
|
11
tests/tests/compiler/constants/tuple_definition_fail.leo
Normal file
11
tests/tests/compiler/constants/tuple_definition_fail.leo
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Fail
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const (GOODBYE,HELLO): (u8,u8) = (0u8,(1u8,1u8));
|
||||||
|
transition foo(a: u8, b: u8, flag: bool) -> u8 {
|
||||||
|
return GOODBYE;
|
||||||
|
}
|
||||||
|
}
|
12
tests/tests/compiler/constants/tuple_shadow_fail.leo
Normal file
12
tests/tests/compiler/constants/tuple_shadow_fail.leo
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
namespace: Compile
|
||||||
|
expectation: Fail
|
||||||
|
*/
|
||||||
|
|
||||||
|
program test.aleo {
|
||||||
|
const (HELLO,GOODBYE): (u8,u8) = (0u8,0u8);
|
||||||
|
const HELLO: u8 = 0u8;
|
||||||
|
transition foo(a: u8, b: u8, flag: bool) -> u8 {
|
||||||
|
return 1u8;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user