Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions aztec-up/test/counter_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@ set -euo pipefail
export LOG_LEVEL=silent

# Execute commands as per: https://docs.aztec.network/tutorials/codealong/contract_tutorials/counter_contract
aztec new counter_contract
aztec new counter

# Verify workspace structure
if [ ! -f counter_contract/Nargo.toml ]; then
if [ ! -f counter/Nargo.toml ]; then
echo "Failed to create workspace Nargo.toml."
exit 1
fi
if [ ! -f counter_contract/contract/Nargo.toml ] || [ ! -f counter_contract/contract/src/main.nr ]; then
if [ ! -f counter/counter_contract/Nargo.toml ] || [ ! -f counter/counter_contract/src/main.nr ]; then
echo "Failed to create contract crate."
exit 1
fi
if [ ! -f counter_contract/test/Nargo.toml ] || [ ! -f counter_contract/test/src/lib.nr ]; then
if [ ! -f counter/counter_test/Nargo.toml ] || [ ! -f counter/counter_test/src/lib.nr ]; then
echo "Failed to create test crate."
exit 1
fi

# Check counter_contract dir is owned by ubuntu.
if [ "$(stat -c %U counter_contract)" != "ubuntu" ]; then
echo "counter_contract dir is not owned by ubuntu."
# Check counter dir is owned by ubuntu.
if [ "$(stat -c %U counter)" != "ubuntu" ]; then
echo "counter dir is not owned by ubuntu."
exit 1
fi

# "Write" our contract over the scaffold.
cp -Rf ./aztec-packages/noir-projects/noir-contracts/contracts/test/counter_contract/* counter_contract/
cd counter_contract
sed -i 's|\.\./\.\./\.\./\.\./\.\./|/home/ubuntu/aztec-packages/noir-projects/|g' contract/Nargo.toml test/Nargo.toml
cp -Rf ./aztec-packages/noir-projects/noir-contracts/contracts/test/counter/* counter/
cd counter
sed -i 's|\.\./\.\./\.\./\.\./\.\./|/home/ubuntu/aztec-packages/noir-projects/|g' counter_contract/Nargo.toml counter_test/Nargo.toml

# Compile the contract.
aztec compile
# Codegen
aztec codegen -o contract/src/artifacts target
if [ ! -d contract/src/artifacts ]; then
aztec codegen -o counter_contract/src/artifacts target
if [ ! -d counter_contract/src/artifacts ]; then
echo "Failed to codegen TypeScript."
exit 1
fi
Expand Down
48 changes: 39 additions & 9 deletions aztec-up/test/default_scaffold.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,65 @@
set -euo pipefail

# Tests that the default scaffold generated by `aztec new` compiles and passes its tests without any modifications.
# This catches regressions in the template files produced by setup_workspace.sh (e.g. syntax errors, stale imports,
# or API changes in aztec-nr) that would otherwise go unnoticed until a user runs `aztec new` themselves.
# Also tests that a second contract can be added to the workspace with `aztec new`.

export LOG_LEVEL=silent

aztec new my_contract
aztec new my_workspace

# Verify workspace structure.
if [ ! -f my_contract/Nargo.toml ]; then
# Verify workspace structure with named crate directories.
if [ ! -f my_workspace/Nargo.toml ]; then
echo "Failed to create workspace Nargo.toml."
exit 1
fi
if [ ! -f my_contract/contract/Nargo.toml ] || [ ! -f my_contract/contract/src/main.nr ]; then
if [ ! -f my_workspace/my_workspace_contract/Nargo.toml ] || [ ! -f my_workspace/my_workspace_contract/src/main.nr ]; then
echo "Failed to create contract crate."
exit 1
fi
if [ ! -f my_contract/test/Nargo.toml ] || [ ! -f my_contract/test/src/lib.nr ]; then
if [ ! -f my_workspace/my_workspace_test/Nargo.toml ] || [ ! -f my_workspace/my_workspace_test/src/lib.nr ]; then
echo "Failed to create test crate."
exit 1
fi

cd my_contract
cd my_workspace

# This is unfortunate as it makes the test worse but in CI setting the aztec version is 0.0.1 which doesn't exist as
# a remote git tag, so we need to rewrite dependencies to use local aztec-nr.
sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' contract/Nargo.toml test/Nargo.toml
sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \
my_workspace_contract/Nargo.toml my_workspace_test/Nargo.toml

# Compile the default scaffold contract.
aztec compile

# Run the default scaffold tests.
aztec test

# --- Test adding a second contract to the workspace ---
aztec new token

# Verify token crates were created.
if [ ! -f token_contract/Nargo.toml ] || [ ! -f token_contract/src/main.nr ]; then
echo "Failed to create token contract crate."
exit 1
fi
if [ ! -f token_test/Nargo.toml ] || [ ! -f token_test/src/lib.nr ]; then
echo "Failed to create token test crate."
exit 1
fi

# Verify workspace Nargo.toml contains all four members.
if ! grep -q '"my_workspace_contract"' Nargo.toml || \
! grep -q '"my_workspace_test"' Nargo.toml || \
! grep -q '"token_contract"' Nargo.toml || \
! grep -q '"token_test"' Nargo.toml; then
echo "Workspace Nargo.toml does not contain all expected members."
exit 1
fi

# Rewrite aztec deps for token crates too.
sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \
token_contract/Nargo.toml token_test/Nargo.toml

# Compile and test the full workspace (both contracts).
aztec compile
aztec test
1 change: 1 addition & 0 deletions docs/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ The description should:
- ❌ Legal disclaimers or license text
- ❌ Direct quotes from external sources
- ❌ API endpoint URLs or configuration values
- ❌ Existing migration notes in `resources/migration_notes.md` — never modify already-published migration entries. Instead, add new migration notes to the `## TBD` section at the top of the file.

## Review Output Format

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ High-level structure of how Aztec smart contracts including the different compon

## Directory structure

When you create a new project with `aztec new`, it generates a workspace with two crates: a `contract` crate for your smart contract and a `test` crate for Noir tests.
When you create a new project with `aztec new my_project`, it generates a workspace with two crates named after your project: a `my_project_contract` crate for your smart contract and a `my_project_test` crate for Noir tests.

```text title="layout of an aztec contract project"
─── my_aztec_contract_project
├── Nargo.toml <-- workspace root
├── contract
─── my_project
├── Nargo.toml <-- workspace root
├── my_project_contract
│ ├── src
│ │ └── main.nr <-- your contract
│ └── Nargo.toml <-- contract package and dependencies
└── test
│ │ └── main.nr <-- your contract
│ └── Nargo.toml <-- contract package and dependencies
└── my_project_test
├── src
│ └── lib.nr <-- your tests
└── Nargo.toml <-- test package and dependencies
│ └── lib.nr <-- your tests
└── Nargo.toml <-- test package and dependencies
```

The workspace root `Nargo.toml` declares both crates as workspace members. The contract code lives in `contract/src/main.nr`, and tests live in a separate `test` crate that depends on the contract crate.
The workspace root `Nargo.toml` declares both crates as workspace members. The contract code lives in `my_project_contract/src/main.nr`, and tests live in a separate `my_project_test` crate that depends on the contract crate.

You can add more contracts to an existing workspace by running `aztec new <name>` from inside the workspace directory. This creates a new `<name>_contract` and `<name>_test` crate pair and adds them to the workspace.

:::warning Keep tests out of the contract crate
Do not add `#[test]` functions to the `contract` crate. Because the contract artifact depends on everything in its crate, any change — including a test-only change — forces a full recompilation of the contract. The separate `test` crate lets you iterate on tests without rebuilding the contract. See [Testing Contracts](../testing_contracts.md#keep-tests-in-the-test-crate) for details.
Do not add `#[test]` functions to the `<name>_contract` crate. Because the contract artifact depends on everything in its crate, any change — including a test-only change — forces a full recompilation of the contract. The separate `<name>_test` crate lets you iterate on tests without rebuilding the contract. See [Testing Contracts](../testing_contracts.md#keep-tests-in-the-test-crate) for details.
:::

See the vanilla Noir docs for [more info on packages](https://noir-lang.org/docs/noir/modules_packages_crates/crates_and_packages).
Expand Down
6 changes: 3 additions & 3 deletions docs/docs-developers/docs/aztec-nr/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ storage.votes.insert(new_vote).deliver(vote_counter); // the vote counter accoun

### Flow

1. Write your contract and specify your contract dependencies. Create a new project with `aztec new my_project`, which sets up a workspace with a `contract` crate and a `test` crate, with the `aztec` dependency already configured. If you need additional dependencies, add them to `contract/Nargo.toml`:
1. Write your contract and specify your contract dependencies. Create a new project with `aztec new my_project`, which sets up a workspace with a `my_project_contract` crate and a `my_project_test` crate, with the `aztec` dependency already configured. If you need additional dependencies, add them to `my_project_contract/Nargo.toml`:

```toml
# contract/Nargo.toml
# my_project_contract/Nargo.toml
[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_aztec_version", directory="aztec" }
```

Update your `contract/src/main.nr` contract file to use the Aztec.nr macros for writing contracts.
Update your `my_project_contract/src/main.nr` contract file to use the Aztec.nr macros for writing contracts.

#include_code setup /docs/examples/contracts/counter_contract/src/main.nr rust

Expand Down
12 changes: 6 additions & 6 deletions docs/docs-developers/docs/aztec-nr/testing_contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Always use `aztec test` instead of `nargo test`. The `TestEnvironment` requires

## Keep tests in the test crate

When you create a project with `aztec new` or `aztec init`, the generated workspace has two crates: `contract` and `test`. It is important that all tests live in the `test` crate, **not** in the `contract` crate.
When you create a project with `aztec new` or `aztec init`, the generated workspace has two crates: `<name>_contract` and `<name>_test`. It is important that all tests live in the `<name>_test` crate, **not** in the `<name>_contract` crate.

If you place `#[test]` functions inside the contract crate, `aztec compile` will emit a warning:

Expand All @@ -60,7 +60,7 @@ The reason is **unnecessary recompilation**: the contract artifact depends on ev

## Basic test structure

Tests live in `test/src/lib.nr` and import the contract crate by name (not `crate::`):
Tests live in `<name>_test/src/lib.nr` and import the contract crate by name (not `crate::`):

```rust
use my_contract::MyContract;
Expand Down Expand Up @@ -88,11 +88,11 @@ unconstrained fn test_basic_flow() {
:::

:::tip Organizing test files
Tests live in the separate `test` crate that `aztec new` creates. You can organize them into modules:
Tests live in the separate `<name>_test` crate that `aztec new` creates. You can organize them into modules:

- Split tests into modules like `test/src/transfer_tests.nr`, `test/src/auth_tests.nr`
- Import them in `test/src/lib.nr` with `mod transfer_tests;`, `mod auth_tests;`
- Share setup functions in `test/src/utils.nr`
- Split tests into modules like `<name>_test/src/transfer_tests.nr`, `<name>_test/src/auth_tests.nr`
- Import them in `<name>_test/src/lib.nr` with `mod transfer_tests;`, `mod auth_tests;`
- Share setup functions in `<name>_test/src/utils.nr`
:::

## Deploying contracts
Expand Down
4 changes: 2 additions & 2 deletions docs/docs-developers/docs/cli/aztec_cli_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ aztec [options] [command]
- `get-logs [options]` - Gets all the public logs from an intersection of all the filter params.
- `get-node-info [options]` - Gets the information of an Aztec node from a PXE or directly from an Aztec node.
- `help [command]` - display help for command
- `init [folder] [options]` - creates a new Noir project
- `init [options]` - creates a new Noir workspace in the current directory
- `inspect-contract <contractArtifactFile>` - Shows list of external callable functions for a contract
- `lsp` - starts the Nargo Language Server Protocol server
- `new <path> [options]` - creates a new Noir project in a new directory
- `new <name> [options]` - creates a new Noir workspace (or adds a contract to an existing workspace)
- `parse-parameter-struct [options] <encodedString>` - Helper for parsing an encoded string into a contract's parameter struct.
- `preload-crs` - Preload the points data needed for proving and verifying
- `propose-with-lock [options]` - Makes a proposal to governance with a lock
Expand Down
41 changes: 41 additions & 0 deletions docs/docs-developers/docs/resources/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,47 @@ Aztec is in active development. Each version may introduce breaking changes that

## TBD

### `aztec new` crate directories are now named after the contract

`aztec new` and `aztec init` now name the generated crate directories after the contract instead of using generic `contract/` and `test/` names. For example, `aztec new counter` now creates:

```
counter/
├── Nargo.toml # [workspace] members = ["counter_contract", "counter_test"]
├── counter_contract/
│ ├── src/main.nr
│ └── Nargo.toml # type = "contract"
└── counter_test/
├── src/lib.nr
└── Nargo.toml # type = "lib"
```

This enables adding multiple contracts to a single workspace. Running `aztec new <name>` inside an existing workspace (a directory with a `Nargo.toml` containing `[workspace]`) now adds a new `<name>_contract` and `<name>_test` crate pair to the workspace instead of creating a new directory.

**What changed:**
- Crate directories are now `<name>_contract/` and `<name>_test/` instead of `contract/` and `test/`.
- Contract code is now at `<name>_contract/src/main.nr` instead of `contract/src/main.nr`.
- Contract dependencies go in `<name>_contract/Nargo.toml` instead of `contract/Nargo.toml`.
- Tests import the contract by its new crate name (e.g., `use counter_contract::Main;` instead of `use counter::Main;`).

### [CLI] `--name` flag removed from `aztec new` and `aztec init`

The `--name` flag has been removed from both `aztec new` and `aztec init`. For `aztec new`, the positional argument now serves as both the contract name and the directory name. For `aztec init`, the directory name is always used as the contract name.

**Migration:**

```diff
- aztec new my_project --name counter
+ aztec new counter
```

```diff
- aztec init --name counter
+ aztec init
```

**Impact**: If you were using `--name` to set a contract name different from the directory name, rename your directory or use `aztec new` with the desired contract name directly.

### [Aztec.js] Removed `SingleKeyAccountContract`

The `SchnorrSingleKeyAccount` contract and its TypeScript wrapper `SingleKeyAccountContract` have been removed. This contract was insecure: it used `ivpk_m` (incoming viewing public key) as its Schnorr signing key, meaning anyone who received a user's viewing key could sign transactions on their behalf.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ Your structure should look like this:
```tree
.
|-counter
| |-Nargo.toml <-- workspace root
| |-contract
| |-Nargo.toml <-- workspace root
| |-counter_contract
| | |-src
| | | |-main.nr
| | |-Nargo.toml <-- contract package config
| |-test
| | |-Nargo.toml <-- contract package config
| |-counter_test
| | |-src
| | | |-lib.nr
| | |-Nargo.toml <-- test package config
| | |-Nargo.toml <-- test package config
```

The `aztec new` command creates a workspace with two crates: a `contract` crate for your smart contract code and a `test` crate for Noir tests. The file `contract/src/main.nr` will soon turn into our smart contract!
The `aztec new` command creates a workspace with two crates: a `counter_contract` crate for your smart contract code and a `counter_test` crate for Noir tests. The file `counter_contract/src/main.nr` will soon turn into our smart contract!

Add the following dependency to `contract/Nargo.toml` under the existing `aztec` dependency:
Add the following dependency to `counter_contract/Nargo.toml` under the existing `aztec` dependency:

```toml
[dependencies]
Expand All @@ -53,7 +53,7 @@ balance_set = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_

## Define the functions

Go to `contract/src/main.nr`, and replace the boilerplate code with this contract initialization:
Go to `counter_contract/src/main.nr`, and replace the boilerplate code with this contract initialization:

```rust
#include_code setup /docs/examples/contracts/counter_contract/src/main.nr raw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ We'll create BOB tokens with:
Let's create a simple yarn + aztec.nr project:

```bash
mkdir bob_token_contract
cd bob_token_contract
mkdir bob_token
cd bob_token
yarn init
# This is to ensure yarn uses node_modules instead of pnp for dependency installation
yarn config set nodeLinker node-modules
Expand All @@ -50,7 +50,7 @@ aztec init

## Contract structure

The `aztec init` command created a workspace with two crates: a `contract` crate for your smart contract code and a `test` crate for Noir tests. In `contract/src/main.nr` we even have a proto-contract. Let's replace it with a simple starting point:
The `aztec init` command created a workspace with two crates: a `bob_token_contract` crate for your smart contract code and a `bob_token_test` crate for Noir tests. In `bob_token_contract/src/main.nr` we even have a proto-contract. Let's replace it with a simple starting point:

```rust
#include_code start /docs/examples/contracts/bob_token_contract/src/main.nr raw
Expand All @@ -60,7 +60,7 @@ The `aztec init` command created a workspace with two crates: a `contract` crate

The `#[aztec]` macro transforms our contract code to work with Aztec's privacy protocol.

Let's make sure the Aztec.nr library is listed in our dependencies in `contract/Nargo.toml`:
Let's make sure the Aztec.nr library is listed in our dependencies in `bob_token_contract/Nargo.toml`:

```toml
[package]
Expand Down Expand Up @@ -254,7 +254,7 @@ In this case, all that the network sees (including Giggle) is just "something ha

### Updating Storage for Privacy

For something like balances, you can use a simple library called `easy_private_state` which abstracts away a custom private Note. A Note is at the core of how private state works in Aztec and you can read about it [here](../../foundational-topics/state_management.md). For now, let's just import the library in `contract/Nargo.toml`:
For something like balances, you can use a simple library called `easy_private_state` which abstracts away a custom private Note. A Note is at the core of how private state works in Aztec and you can read about it [here](../../foundational-topics/state_management.md). For now, let's just import the library in `bob_token_contract/Nargo.toml`:

```toml
[dependencies]
Expand Down
Loading
Loading