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
2 changes: 1 addition & 1 deletion aztec-up/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ EOF
}

function test_cmds {
for test in amm_flow bridge_and_claim basic_install counter_contract; do
for test in amm_flow bridge_and_claim basic_install counter_contract default_scaffold; do
echo "$hash:TIMEOUT=15m aztec-up/scripts/run_test.sh $test"
done
}
Expand Down
34 changes: 22 additions & 12 deletions aztec-up/test/counter_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +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
if [ ! -f counter_contract/Nargo.toml ] || [ ! -f counter_contract/src/main.nr ]; then
echo "Failed to create contract."
aztec new counter

# Verify workspace structure
if [ ! -f counter/Nargo.toml ]; then
echo "Failed to create workspace Nargo.toml."
exit 1
fi
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/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 aztec-dev.
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.
cp -Rf ./aztec-packages/noir-projects/noir-contracts/contracts/test/counter_contract .
cd counter_contract
sed -i 's|\.\./\.\./\.\./\.\./|/home/ubuntu/aztec-packages/noir-projects/|g' Nargo.toml
# "Write" our contract over the scaffold.
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 src/artifacts target
if [ ! -d 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
66 changes: 66 additions & 0 deletions aztec-up/test/default_scaffold.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -euo pipefail

# Tests that the default scaffold generated by `aztec new` compiles and passes its tests without any modifications.
# Also tests that a second contract can be added to the workspace with `aztec new`.

export LOG_LEVEL=silent

aztec new my_workspace

# 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_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_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_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" }|' \
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
2 changes: 2 additions & 0 deletions boxes/init/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
codegenCache.json
8 changes: 2 additions & 6 deletions boxes/init/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
[package]
name = "init"
type = "contract"

[dependencies]
aztec = { path = "../../noir-projects/aztec-nr/aztec" }
[workspace]
members = ["contract", "test"]
27 changes: 27 additions & 0 deletions boxes/init/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# init

An Aztec Noir contract project.

## Compile

```bash
aztec compile
```

This compiles the contract in `contract/` and outputs artifacts to `target/`.

## Test

```bash
aztec test
```

This runs the tests in `test/`.

## Generate TypeScript bindings

```bash
aztec codegen target -o src/artifacts
```

This generates TypeScript contract artifacts from the compiled output in `target/` into `src/artifacts/`.
6 changes: 6 additions & 0 deletions boxes/init/contract/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "init"
type = "contract"

[dependencies]
aztec = { path = "../../../noir-projects/aztec-nr/aztec" }
10 changes: 10 additions & 0 deletions boxes/init/contract/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use aztec::macros::aztec;

#[aztec]
pub contract Main {
use aztec::macros::functions::{external, initializer};

#[initializer]
#[external("private")]
fn constructor() {}
}
9 changes: 0 additions & 9 deletions boxes/init/src/main.nr

This file was deleted.

7 changes: 7 additions & 0 deletions boxes/init/test/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "init_test"
type = "lib"

[dependencies]
aztec = { path = "../../../noir-projects/aztec-nr/aztec" }
init = { path = "../contract" }
17 changes: 17 additions & 0 deletions boxes/init/test/src/lib.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use aztec::test::helpers::test_environment::TestEnvironment;
use init::Main;

#[test]
unconstrained fn test_constructor() {
let mut env = TestEnvironment::new();
let deployer = env.create_light_account();

// Deploy the contract with the default constructor:
let contract_address = env.deploy("@init/Main").with_private_initializer(
deployer,
Main::interface().constructor(),
);

// Deploy without an initializer:
let contract_address = env.deploy("@init/Main").without_initializer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,17 @@ aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_aztec_
### Aztec (required)

```toml
aztec = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/aztec" }
aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_aztec_version", directory="aztec" }
```

The core Aztec library required for every Aztec.nr smart contract.

### Protocol Types

```toml
protocol = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/noir-protocol-circuits/crates/types"}
```

Contains types used in the Aztec protocol (addresses, constants, hashes, etc.).

## Note Types

### Address Note

```toml
address_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="#include_aztec_version", directory="noir-projects/aztec-nr/address-note" }
address_note = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_aztec_version", directory="address-note" }
```

Provides `AddressNote`, a note type for storing `AztecAddress` values.
Expand Down Expand Up @@ -76,3 +68,24 @@ compressed_string = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#in
```

Provides `CompressedString` and `FieldCompressedString` utilities for working with compressed string data.

## Updating your aztec dependencies

When `aztec compile` warns that your aztec dependency tag does not match the CLI version, update
the `tag` field in every Aztec.nr entry in your `Nargo.toml` to match the CLI version you are
running.

For example, if your CLI is `v#include_aztec_version`, change:

```toml
aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="v<old-version>", directory="aztec" }
```

to:

```toml
aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="v#include_aztec_version", directory="aztec" }
```

Repeat for every other Aztec.nr dependency in your `Nargo.toml` (e.g. `address_note`,
`balance_set`, etc.). You can check your current CLI version with `aztec --version`.
5 changes: 3 additions & 2 deletions docs/docs-developers/docs/cli/aztec_cli_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ 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 Aztec 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
- `migrate-ha-db` - Run validator-ha-signer database migrations
- `new <path> [options]` - creates a new Aztec 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
- `profile` - Profile compiled Aztec artifacts.
Expand Down
Loading
Loading