mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-22 22:44:47 +03:00
impl record type tests
This commit is contained in:
parent
3a5d7720c8
commit
1cb4afe5f9
@ -1,3 +1,23 @@
|
||||
function main(a: u8) -> group {
|
||||
return Pedersen64::hash(a);
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function mint(owner: address, amount: u64) -> Token {
|
||||
return Token {
|
||||
owner,
|
||||
balance: 0u64,
|
||||
amount,
|
||||
};
|
||||
}
|
||||
|
||||
function main(x: address) -> u64 {
|
||||
const c: u64 = 1u64;
|
||||
let t: Token = mint(x, c);
|
||||
|
||||
return t.balance;
|
||||
}
|
17
tests/compiler/records/declaration.leo
Normal file
17
tests/compiler/records/declaration.leo
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function main() -> bool {
|
||||
return true;
|
||||
}
|
21
tests/compiler/records/duplicate_circuit_name_fail.leo
Normal file
21
tests/compiler/records/duplicate_circuit_name_fail.leo
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
circuit Token { // This circuit cannot have the same name as the record defined above it.
|
||||
x: u32,
|
||||
}
|
||||
|
||||
function main() -> bool {
|
||||
return true;
|
||||
}
|
19
tests/compiler/records/duplicate_var_fail.leo
Normal file
19
tests/compiler/records/duplicate_var_fail.leo
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The token owner.
|
||||
owner: address, // Cannot define two record variables with the same name.
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function main() -> bool {
|
||||
return true;
|
||||
}
|
28
tests/compiler/records/init_expression.leo
Normal file
28
tests/compiler/records/init_expression.leo
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function mint(r0: address, r1: u64) -> Token {
|
||||
return Token {
|
||||
owner: r0,
|
||||
balance: 0u64,
|
||||
amount: r1,
|
||||
};
|
||||
}
|
||||
|
||||
function main(x: address) -> u64 {
|
||||
const c: u64 = 1u64;
|
||||
let t: Token = mint(x, c);
|
||||
|
||||
return t.balance;
|
||||
}
|
28
tests/compiler/records/init_expression_shorthand.leo
Normal file
28
tests/compiler/records/init_expression_shorthand.leo
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function mint(owner: address, amount: u64) -> Token {
|
||||
return Token {
|
||||
owner,
|
||||
balance: 0u64,
|
||||
amount,
|
||||
};
|
||||
}
|
||||
|
||||
function main(x: address) -> u64 {
|
||||
const c: u64 = 1u64;
|
||||
let t: Token = mint(x, c);
|
||||
|
||||
return t.balance;
|
||||
}
|
28
tests/compiler/records/init_expression_type_fail.leo
Normal file
28
tests/compiler/records/init_expression_type_fail.leo
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function mint(r0: address, r1: u64) -> Token {
|
||||
return Token {
|
||||
owner: r1, // This variable should be type address.
|
||||
balance: 0u64,
|
||||
amount: r0, // This variable should be type u64.
|
||||
};
|
||||
}
|
||||
|
||||
function main(x: address) -> u64 {
|
||||
const c: u64 = 1u64;
|
||||
let t: Token = mint(x, c);
|
||||
|
||||
return t.balance;
|
||||
}
|
28
tests/compiler/records/init_expression_var_fail.leo
Normal file
28
tests/compiler/records/init_expression_var_fail.leo
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
record Token {
|
||||
// The token owner.
|
||||
owner: address,
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function mint(r0: address, r1: u64) -> Token {
|
||||
return Token {
|
||||
sender: r0, // This variable should be named `owner`.
|
||||
balance: 0u64,
|
||||
amount: r1,
|
||||
};
|
||||
}
|
||||
|
||||
function main(x: address) -> u64 {
|
||||
const c: u64 = 1u64;
|
||||
let t: Token = mint(x, c);
|
||||
|
||||
return t.balance;
|
||||
}
|
0
tests/compiler/records/inputs/address.in
Normal file
0
tests/compiler/records/inputs/address.in
Normal file
16
tests/compiler/records/no_owner_fail.leo
Normal file
16
tests/compiler/records/no_owner_fail.leo
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
// This record does not define the `owner` variable required for a record type.
|
||||
record Token {
|
||||
// The Aleo balance (in gates).
|
||||
balance: u64,
|
||||
// The token amount.
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
function main() -> bool {
|
||||
return true;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- output:
|
||||
- initial_input_ast: no input
|
||||
initial_ast: b2600a36152f9e343c88ceb57304cbdef218cddbb34903fb206fe5a353862a72
|
||||
symbol_table: c49906bcded430e36886bfabc35c5740e4657ac82761b80b871f6d19ec6d9dda
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EAST0372015]: circuit `Token` shadowed by\n --> compiler-test:3:1\n |\n 3 | record Token {\n 4 | // The token owner.\n 5 | owner: address,\n 6 | // The Aleo balance (in gates).\n 7 | balance: u64,\n 8 | // The token amount.\n 9 | amount: u64,\n 10 | }\n | ^\n"
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370045]: The `record` type requires the variable `balance: u64` and enforces ordering.\n --> compiler-test:7:5\n |\n 7 | owner: address, // Cannot define two record variables with the same name.\n | ^^^^^"
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- output:
|
||||
- initial_input_ast: no input
|
||||
initial_ast: d056f3b9b387a76349e8eb7e5e685bbcd60b4dbe72157449303e022d934496fe
|
||||
symbol_table: 926c2f494fbb7914574e7b95bedd8992eaf028143e19bebcdcdf474fcb5eb1c5
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- output:
|
||||
- initial_input_ast: no input
|
||||
initial_ast: 49dacc0f90849a18fc1e19d0c4b3e6661e1c9027210498ceda7b88f8586692d3
|
||||
symbol_table: de1844db50840db6655f51a2903da4287d51c03a6e693843bdd6be95c6d627f8
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [ETYC0372003]: Found type `u64` but type `address` was expected\n --> compiler-test:12:28\n |\n 12 | function mint(r0: address, r1: u64) -> Token {\n | ^^\nError [ETYC0372003]: Found type `address` but type `u64` was expected\n --> compiler-test:12:15\n |\n 12 | function mint(r0: address, r1: u64) -> Token {\n | ^^\n"
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [ETYC0372005]: Unknown record variable `sender`\n --> compiler-test:14:9\n |\n 14 | sender: r0, // This variable should be named `owner`.\n | ^^^^^^\n"
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370045]: The `record` type requires the variable `owner: address` and enforces ordering.\n --> compiler-test:6:5\n |\n 6 | balance: u64,\n | ^^^^^^^\nError [EPAR0370045]: The `record` type requires the variable `balance: u64` and enforces ordering.\n --> compiler-test:8:5\n |\n 8 | amount: u64,\n | ^^^^^^"
|
Loading…
Reference in New Issue
Block a user