impl record type tests

This commit is contained in:
collin 2022-06-27 16:59:06 -10:00
parent 3a5d7720c8
commit 1cb4afe5f9
18 changed files with 256 additions and 2 deletions

View File

@ -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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View File

View 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;
}

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: no input
initial_ast: b2600a36152f9e343c88ceb57304cbdef218cddbb34903fb206fe5a353862a72
symbol_table: c49906bcded430e36886bfabc35c5740e4657ac82761b80b871f6d19ec6d9dda

View File

@ -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"

View File

@ -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 | ^^^^^"

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: no input
initial_ast: d056f3b9b387a76349e8eb7e5e685bbcd60b4dbe72157449303e022d934496fe
symbol_table: 926c2f494fbb7914574e7b95bedd8992eaf028143e19bebcdcdf474fcb5eb1c5

View File

@ -0,0 +1,8 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: no input
initial_ast: 49dacc0f90849a18fc1e19d0c4b3e6661e1c9027210498ceda7b88f8586692d3
symbol_table: de1844db50840db6655f51a2903da4287d51c03a6e693843bdd6be95c6d627f8

View File

@ -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"

View File

@ -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"

View File

@ -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 | ^^^^^^"