This directory contains test contracts that test common compilation errors that were hard to understand in Aztec contracts. These tests are based on the private_token_contract example, with modifications to trigger specific error scenarios.
Modification: Removed the #[storage] attribute from the Storage struct.
Original Code:
#[storage]
struct Storage<Context> {
balances: Map<AztecAddress, EasyPrivateUint<Context>, Context>,
}Modified Code:
struct Storage<Context> {
balances: Map<AztecAddress, EasyPrivateUint<Context>, Context>,
}Modification: Added and empty Arbitrary struct. Changed the mint function parameter from u64 to a custom Arbitrary struct.
Original Code:
fn mint(amount: u64, owner: AztecAddress) {
let balances = storage.balances;
balances.at(owner).add(amount, owner);
}Modified Code:
pub struct Arbitrary {}
fn mint(amount: Arbitrary, owner: AztecAddress) {
//let balances = storage.balances;
//balances.at(owner).add(amount, owner);
}Expected Errors:
No matching impl found for Arbitrary: Serialize<N = _>- The custom struct doesn't implement theSerializetrait required for function parametersType annotation needed- Generic type inference fails due to the serialization error
Purpose: The reason we see this error is function arguments need to be serialized. We need to define Serialize/Deserialize trait implementation for the new struct,
Modification: Added a private struct Arbitrary and used it as a function parameter in a #[private] function.
Original Code:
#[private]
fn mint(amount: u64, owner: AztecAddress) {
let balances = storage.balances;
balances.at(owner).add(amount, owner);
}Modified Code:
#[derive(Serialize, Deserialize)]
struct Arbitrary {
value: u64,
}
#[private]
fn mint(amount: Arbitrary, owner: AztecAddress) {
//let balances = storage.balances;
//balances.at(owner).add(amount, owner);
}Expected Errors:
Type Arbitrary is more private than item mint_parameters::amountType Arbitrary is more private than item mint
Purpose: It might be confusing to see mint function labelled as #[private], but got error Type Arbitrary is more private than item mint
Modification: Removed the #[utility] attribute from the get_balance function.
Original Code:
#[utility]
unconstrained fn get_balance(owner: AztecAddress) -> Field {
storage.balances.at(owner).get_value()
}Modified Code:
unconstrained fn get_balance(owner: AztecAddress) -> Field {
storage.balances.at(owner).get_value()
}Expected Errors:
Function get_balance must be marked as either #[private], #[public], #[utility], #[contract_library_method], or #[test]
These test contracts are designed to fail compilation and capture the error output. To run the tests:
./scripts/test.shThe script will:
- Compile each test contract (expecting failures)
- Capture the error output
- Compare against expected error messages
- Report whether the error messages match expectations