Skip to content

Commit

Permalink
feat: modular CLI + aztec test (#7426)
Browse files Browse the repository at this point in the history
Refactors the CLI package to work as a collection of dynamically
importable commands in *actual* CLI programs, such as `aztec`.

Right now this doesn't add that much value besides avoiding code
repetition between builder and CLI, but tidies up the packages and makes
it so much easier to build different utilities by mix and matching
different commands. This is going to be very useful when we strip the
`aztec` binary of some internal commands, and even more so when we start
building the infamous CLI wallet (which will certainly pull some of
these commands in)

Besides that, it cleans up the sandbox so that no redundant
`aztecprotocol/cli` image is pulled, and some of the commands are
greatly simplified. The sandbox now does:

`aztec`: All the previous commands + all the old CLI ones without having
to prefix them with `cli`
`aztec-nargo`: Same as always

REMOVED:

`aztec-sandbox` and `aztec sandbox`: now `aztec start --sandbox`
`aztec-builder`: now `aztec codegen` + `aztec update`

ADDED:

`aztec test`: runs `aztec start --txe`&& `aztec-nargo test --use-legacy
--oracle-resolver http://aztec:8081 --silence-warnings` via
`docker-compose` allowing users to easily run contract tests using TXE


![image](https://github.com/user-attachments/assets/d77dbc5c-5415-434a-92d6-6a1d3037f15a)
  • Loading branch information
Thunkar authored Jul 15, 2024
1 parent 531b6e1 commit cca2a9b
Show file tree
Hide file tree
Showing 96 changed files with 1,213 additions and 1,606 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/devnet-deploys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ jobs:
const fileChanged = changedFiles.includes('l1-contracts/REDEPLOY');
return fileChanged
- name: "Build & Push cli image"
if: steps.check_changes_build.outputs.result == 'true'
timeout-minutes: 40
# Run the build steps for each image with version and arch, push to dockerhub
run: |
earthly-ci --no-output --push ./yarn-project+export-cli --DIST_TAG=${{ env.DEPLOY_TAG }}
terraform_deploy:
runs-on: ubuntu-latest
needs: build
Expand Down Expand Up @@ -97,8 +90,8 @@ jobs:
- name: Deploy L1 Contracts
if: steps.check_changes_release.outputs.result == 'true'
run: |
docker pull aztecprotocol/cli:${{ env.DEPLOY_TAG }}
docker run aztecprotocol/cli:${{ env.DEPLOY_TAG }} \
docker pull aztecprotocol/aztec:${{ env.DEPLOY_TAG }}
docker run aztecprotocol/aztec:${{ env.DEPLOY_TAG }} \
deploy-l1-contracts -p ${{ secrets.SEQ_1_PUBLISHER_PRIVATE_KEY }} \
-u https://${{ env.DEPLOY_TAG }}-mainnet-fork.aztec.network:8545/${{ secrets.FORK_API_KEY }} \
| tee ${{ env.FILE_PATH }}
Expand Down
52 changes: 35 additions & 17 deletions aztec-up/bin/aztec
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail

# Call cli image if used with `aztec cli ...args`
if [ -n "${1-}" ] && [ "$1" != "--help" ]; then
if [ "$1" == "cli" ]; then
shift
SKIP_PORT_ASSIGNMENT=1 $(dirname $0)/.aztec-run aztecprotocol/cli "$@"
elif [ "$1" == "sandbox" ]; then
$(dirname $0)/aztec-sandbox
else
$(dirname $0)/.aztec-run aztecprotocol/aztec "$@"
fi
else
# TODO - display help message
echo
echo "Using 'aztec' CLI:"
echo " aztec start <args> - Start aztec infrastructure components. See 'aztec start --help' for detailed command info."
echo " aztec sandbox - Run a local sandbox network (same as aztec-sandbox)."
echo " aztec cli <args> - Run the aztec client CLI. See 'aztec cli --help' for detailed command info."
function get_compose {
# Favour 'docker compose', falling back on docker-compose.
CMD="docker compose"
$CMD &>/dev/null || CMD="docker-compose"
$CMD $@
}

CALLED_FROM=$PWD

if [ "${1:-}" == "test" ]; then
# Change working dir, so relative volume mounts are in the right place.
cd $(dirname $0)/..
# Compose file to use
FILE_ARG="-f $HOME/.aztec/docker-compose.test.yml"
# Aztec contract test args for nargo
TEST_ARGS="$@ --silence-warnings --use-legacy --oracle-resolver http://aztec:8081"
get_compose -p aztec-test $FILE_ARG run -e NARGO_FOREIGN_CALL_TIMEOUT=300000 --workdir $CALLED_FROM --rm -it aztec-nargo $TEST_ARGS
elif [ $# == 2 ] && [ "$1" == "start" ] && [ "$2" == "--sandbox" ]; then
# Change working dir, so relative volume mounts are in the right place.
cd $(dirname $0)/..
# Compose file to use
FILE_ARG="-f $HOME/.aztec/docker-compose.sandbox.yml"

# Function to be executed when SIGINT is received.
cleanup() {
get_compose $FILE_ARG down
}

# Set trap to catch SIGINT and call the cleanup function.
trap cleanup SIGINT

get_compose -p sandbox $FILE_ARG up --force-recreate --remove-orphans
else
$(dirname $0)/.aztec-run aztecprotocol/aztec "$@"
fi

9 changes: 0 additions & 9 deletions aztec-up/bin/aztec-builder

This file was deleted.

10 changes: 3 additions & 7 deletions aztec-up/bin/aztec-install
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ function title() {
echo -e "${r}"
fi
echo -e "This will install the following scripts and update your PATH if necessary:"
echo -e " ${bold}${g}aztec${r} - launches various infrastructure subsystems (node, sequencer, prover, pxe, etc)."
echo -e " ${bold}${g}aztec${r} - a collection of tools to launch subsystems and interact with the aztec network."
echo -e " ${bold}${g}aztec-nargo${r} - aztec's build of nargo, the noir compiler toolchain."
echo -e " ${bold}${g}aztec-sandbox${r} - a wrapper around docker-compose that launches services needed for sandbox testing."
echo -e " ${bold}${g}aztec-up${r} - a tool to upgrade the aztec toolchain to the latest, or specific versions."
echo -e " ${bold}${g}aztec-builder${r} - a tool to generate typescript interfaces of Noir contracts"
echo
read -p "Do you wish to continue? (y/n)" -n 1 -r
echo
Expand Down Expand Up @@ -107,11 +105,11 @@ if [ -z "${SKIP_PULL:-}" ]; then
info "Pulling aztec version $VERSION..."
pull_container aztec-nargo
pull_container aztec
pull_container aztec-builder
fi

# Download the Docker Compose file. Used by aztec.
curl -fsSL http://$INSTALL_HOST/docker-compose.yml -o $AZTEC_PATH/docker-compose.yml
curl -fsSL http://$INSTALL_HOST/docker-compose.sandbox.yml -o $AZTEC_PATH/docker-compose.sandbox.yml
curl -fsSL http://$INSTALL_HOST/docker-compose.test.yml -o $AZTEC_PATH/docker-compose.test.yml

function install_bin {
curl -fsSL http://$INSTALL_HOST/$1 -o $BIN_PATH/$1
Expand All @@ -123,10 +121,8 @@ info "Installing scripts in $BIN_PATH..."
rm -f $BIN_PATH/aztec*
install_bin .aztec-run
install_bin aztec
install_bin aztec-sandbox
install_bin aztec-up
install_bin aztec-nargo
install_bin aztec-builder

function update_path_env_var {
TARGET_DIR="${1}"
Expand Down
21 changes: 0 additions & 21 deletions aztec-up/bin/aztec-sandbox

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:
ethereum:
image: ghcr.io/foundry-rs/foundry@sha256:29ba6e34379e79c342ec02d437beb7929c9e254261e8032b17e187be71a2609f
Expand Down Expand Up @@ -36,3 +35,6 @@ services:
TEST_ACCOUNTS: ${TEST_ACCOUNTS:-true}
volumes:
- ./log:/usr/src/yarn-project/aztec/log:rw
depends_on:
- ethereum
command: "start --sandbox"
19 changes: 19 additions & 0 deletions aztec-up/bin/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
aztec:
image: "aztecprotocol/aztec"
environment:
DEBUG: # Loaded from the user shell if explicitly set
HOST_WORKDIR: "${PWD}" # Loaded from the user shell to show log files absolute path in host
volumes:
- ./log:/usr/src/yarn-project/aztec/log:rw
command: start --txe

aztec-nargo:
image: "aztecprotocol/aztec-nargo"
environment:
HOME: # Loaded from the user shell
NARGO_FOREIGN_CALL_TIMEOUT: 300000 # To avoid timeouts when many tests run at once
volumes:
- ${HOME}:${HOME}
depends_on:
- aztec
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/headless-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"chalk": "^5.3.0",
"commander": "^12.0.0",
"commander": "^12.1.0",
"playwright": "^1.42.1",
"puppeteer": "^22.4.1"
},
Expand Down
14 changes: 8 additions & 6 deletions barretenberg/acir_tests/headless-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ function formatAndPrintLog(message: string): void {
}

const readBytecodeFile = (path: string): Uint8Array => {
const extension = path.substring(path.lastIndexOf('.') + 1);
const extension = path.substring(path.lastIndexOf(".") + 1);

if (extension == 'json') {
const encodedCircuit = JSON.parse(fs.readFileSync(path, 'utf8'));
const decompressed = gunzipSync(Uint8Array.from(atob(encodedCircuit.bytecode), c => c.charCodeAt(0)));
if (extension == "json") {
const encodedCircuit = JSON.parse(fs.readFileSync(path, "utf8"));
const decompressed = gunzipSync(
Uint8Array.from(atob(encodedCircuit.bytecode), (c) => c.charCodeAt(0))
);
return decompressed;
}

Expand All @@ -57,7 +59,7 @@ const readWitnessFile = (path: string): Uint8Array => {
};

// Set up the command-line interface
const program = new Command();
const program = new Command("headless_test");
program.option("-v, --verbose", "verbose logging");
program.option("-c, --crs-path <path>", "ignored (here for compatibility)");

Expand All @@ -84,7 +86,7 @@ program
const browsers = { chrome: chromium, firefox: firefox, webkit: webkit };

for (const [name, browserType] of Object.entries(browsers)) {
if (BROWSER && !BROWSER.split(',').includes(name)) {
if (BROWSER && !BROWSER.split(",").includes(name)) {
continue;
}
console.log(chalk.blue(`Testing ${bytecodePath} in ${name}...`));
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export async function vkAsFieldsUltraHonk(vkPath: string, vkeyOutputPath: string
}
}

const program = new Command();
const program = new Command('bb');

program.option('-v, --verbose', 'enable verbose logging', false);
program.option('-c, --crs-path <path>', 'set crs path', './crs');
Expand Down
5 changes: 5 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# clean: Force a complete clean of the repo. Erases untracked files, be careful!
set -eu

if [ "$(uname)" == "Darwin" ]; then
shopt -s expand_aliases
alias clang++-16="clang++"
fi

cd "$(dirname "$0")"

CMD=${1:-}
Expand Down
1 change: 1 addition & 0 deletions boxes/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:

aztec:
image: aztecprotocol/aztec:${AZTEC_DOCKER_TAG:-latest}
command: 'start --sandbox'
environment:
ETHEREUM_HOST: http://ethereum:8545
CHAIN_ID: 31337
Expand Down
2 changes: 1 addition & 1 deletion boxes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@inquirer/input": "^2.0.0",
"@inquirer/select": "^2.0.0",
"axios": "^1.6.7",
"commander": "^12.0.0",
"commander": "^12.1.0",
"ora": "^8.0.1",
"pino": "^8.19.0",
"pino-pretty": "^10.3.1",
Expand Down
10 changes: 5 additions & 5 deletions boxes/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@ __metadata:
"@inquirer/select": "npm:^2.0.0"
"@playwright/test": "npm:1.42.0"
axios: "npm:^1.6.7"
commander: "npm:^12.0.0"
commander: "npm:^12.1.0"
ora: "npm:^8.0.1"
pino: "npm:^8.19.0"
pino-pretty: "npm:^10.3.1"
Expand Down Expand Up @@ -2966,10 +2966,10 @@ __metadata:
languageName: node
linkType: hard

"commander@npm:^12.0.0":
version: 12.0.0
resolution: "commander@npm:12.0.0"
checksum: e51cac1d1d0aa1f76581981d2256a9249497e08f5a370bf63b0dfc7e76a647fc8cbc3ddd507928f2bdca6c514c83834e87e2687ace2fe2fc7cc7e631bf80f83d
"commander@npm:^12.1.0":
version: 12.1.0
resolution: "commander@npm:12.1.0"
checksum: 6e1996680c083b3b897bfc1cfe1c58dfbcd9842fd43e1aaf8a795fbc237f65efcc860a3ef457b318e73f29a4f4a28f6403c3d653d021d960e4632dd45bde54a9
languageName: node
linkType: hard

Expand Down
11 changes: 2 additions & 9 deletions docs/docs/guides/smart_contracts/testing_contracts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,14 @@ So to summarize:
In order to use the TXE, it must be running on a known address.

:::tip
If you have [the sandbox](../../../getting_started.md) installed, you can quickly deploy a TXE by running:
If you have [the sandbox](../../../getting_started.md) installed, you can run TXE tests using:

`docker run --workdir /usr/src/yarn-project --entrypoint bash --name txe -p 8080:8080 --rm -it aztecprotocol/aztec -c "yarn workspaces focus @aztec/txe && cd txe && yarn build && yarn start"`
`aztec test`

This will be improved in the future with a dedicated command.
:::

By default, TXE runs at `http://localhost:8080`. Using `aztec-nargo`, contract tests can be run with:

`aztec-nargo test --use-legacy --silence-warnings --oracle-resolver http://host.docker.internal:8080`

:::warning
Since TXE tests are written in Noir and executed with `aztec-nargo`, they all run in parallel. This also means every test creates their own isolated environment, so state modifications are local to each one of them.

Executing many tests in parallel might slow processing of the RPC calls down to the point of making them timeout. To control this timeout the `NARGO_FOREIGN_CALL_TIMEOUT` env variable is used.
:::

### Writing TXE tests
Expand Down
19 changes: 18 additions & 1 deletion docs/docs/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,24 @@ keywords: [sandbox, aztec, notes, migration, updating, upgrading]

Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them.

## 0.45.0
## 0.xx.0
### [Aztec sandbox] Command refactor and unification + `aztec test`

Sandbox commands have been cleaned up and simplified. Doing `aztec-up` now gets you the following top-level commands:

`aztec`: All the previous commands + all the CLI ones without having to prefix them with cli. Run `aztec` for help!
`aztec-nargo`: No changes

**REMOVED/RENAMED**:

* `aztec-sandbox` and `aztec sandbox`: now `aztec start --sandbox`
* `aztec-builder`: now `aztec codegen` and `aztec update`

**ADDED**:

* `aztec test [options]`: runs `aztec start --txe && aztec-nargo test --use-legacy --oracle-resolver http://aztec:8081 --silence-warnings [options]` via docker-compose allowing users to easily run contract tests using TXE

## 0.45.0
### [Aztec.nr] Remove unencrypted logs from private
They leak privacy so is a footgun!

Expand Down
31 changes: 0 additions & 31 deletions yarn-project/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -185,37 +185,6 @@ export-aztec-faucet:
ARG ARCH
SAVE IMAGE --push aztecprotocol/aztec-faucet:${DIST_TAG}${ARCH:+-$ARCH}

cli-build:
FROM +build
RUN yarn workspaces focus @aztec/cli --production && yarn cache clean
RUN rm -rf \
../noir-projects \
../l1-contracts \
../barretenberg/ts/src \
../barretenberg/ts/dest/node-cjs \
../barretenberg/ts/dest/browser \
aztec.js/dest/main.js \
end-to-end \
**/src \
**/artifacts
SAVE ARTIFACT /usr/src /usr/src

cli:
FROM ubuntu:noble
RUN apt update && apt install nodejs curl -y && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY +cli-build/usr/src /usr/src

RUN mkdir /cache && chmod 777 /cache
ENV XDG_CACHE_HOME /cache
VOLUME "/cache"
ENTRYPOINT ["node", "--no-warnings", "/usr/src/yarn-project/cli/dest/bin/index.js"]

export-cli:
FROM +cli
ARG DIST_TAG="latest"
ARG ARCH
SAVE IMAGE --push aztecprotocol/cli:${DIST_TAG}${ARCH:+-$ARCH}

# We care about creating a slimmed down e2e image because we have to serialize it from earthly to docker for running.
end-to-end-prod:
FROM +build
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/aztec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@aztec/builder": "workspace:^",
"@aztec/circuit-types": "workspace:^",
"@aztec/circuits.js": "workspace:^",
"@aztec/cli": "workspace:^",
"@aztec/entrypoints": "workspace:^",
"@aztec/ethereum": "workspace:^",
"@aztec/foundation": "workspace:^",
Expand All @@ -48,8 +49,9 @@
"@aztec/prover-client": "workspace:^",
"@aztec/pxe": "workspace:^",
"@aztec/telemetry-client": "workspace:^",
"@aztec/txe": "workspace:^",
"abitype": "^0.8.11",
"commander": "^11.1.0",
"commander": "^12.1.0",
"koa": "^2.14.2",
"koa-router": "^12.0.0",
"viem": "^2.7.15",
Expand Down
Empty file.
Loading

0 comments on commit cca2a9b

Please sign in to comment.