diff --git a/aztec-up/bin/aztec b/aztec-up/bin/aztec index 0989bb64469..998d05478de 100755 --- a/aztec-up/bin/aztec +++ b/aztec-up/bin/aztec @@ -20,6 +20,10 @@ function parse_ts_file { grep -oE "\| '[^']+'" "$LOCAL_TS_FILE" | sed "s/| '//; s/'//g" >"$LOCAL_ENV_VAR_FILE" } +function cleanup { + get_compose $@ down +} + CALLED_FROM=$PWD if [ "${1:-}" == "test" ]; then @@ -27,22 +31,23 @@ if [ "${1:-}" == "test" ]; then cd $(dirname $0)/.. # Compose file to use FILE_ARG="-f $HOME/.aztec/docker-compose.test.yml" + + # Set trap to catch SIGINT and call the cleanup function. + trap "cleanup $FILE_ARG" SIGINT + # Aztec contract test args for nargo - TEST_ARGS="$@ --silence-warnings --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 + export TEST_ARGS="$@ --silence-warnings --oracle-resolver http://txe:8081" + export NARGO_FOREIGN_CALL_TIMEOUT=300000 + export WORKDIR=$CALLED_FROM + get_compose -p aztec-test $FILE_ARG up --force-recreate --remove-orphans --abort-on-container-exit 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 + trap "cleanup $FILE_ARG" SIGINT get_compose -p sandbox $FILE_ARG up --force-recreate --remove-orphans elif [ "${1:-}" == "start" ]; then diff --git a/aztec-up/bin/docker-compose.test.yml b/aztec-up/bin/docker-compose.test.yml index 604d3294e3c..91b48742c93 100644 --- a/aztec-up/bin/docker-compose.test.yml +++ b/aztec-up/bin/docker-compose.test.yml @@ -1,20 +1,23 @@ services: - aztec: + txe: image: "aztecprotocol/aztec" environment: DEBUG: # Loaded from the user shell if explicitly set + LOG_LEVEL: # 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 - ${HOME}:${HOME} command: start --txe --port 8081 - + 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 + NARGO_FOREIGN_CALL_TIMEOUT: "${NARGO_FOREIGN_CALL_TIMEOUT}" # To avoid timeouts when many tests run at once + working_dir: "${WORKDIR}" + command: "${TEST_ARGS}" volumes: - ${HOME}:${HOME} depends_on: - - aztec \ No newline at end of file + - txe \ No newline at end of file diff --git a/docs/docs/guides/developer_guides/smart_contracts/testing_contracts/testing.md b/docs/docs/guides/developer_guides/smart_contracts/testing_contracts/testing.md index b6463a0f222..dc933c32927 100644 --- a/docs/docs/guides/developer_guides/smart_contracts/testing_contracts/testing.md +++ b/docs/docs/guides/developer_guides/smart_contracts/testing_contracts/testing.md @@ -210,6 +210,18 @@ You can also use the `assert_public_call_fails` or `assert_private_call_fails` m #include_code assert_public_fail /noir-projects/noir-contracts/contracts/token_contract/src/test/transfer_public.nr rust +### Logging + +You can use `aztec.nr`'s oracles as usual for debug logging, as explained [here](../../../../reference/developer_references/debugging.md) + +:::warning +Remember to set the following environment variables to activate debug logging: +```bash +export DEBUG="aztec:*" +export LOG_LEVEL="debug" +``` +::: + ### All Cheatcodes You can find the full list of cheatcodes available in the TXE [here](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr) diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/test/access_control.nr b/noir-projects/noir-contracts/contracts/token_contract/src/test/access_control.nr index 588cc71d9a4..7e83b3c16fe 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/test/access_control.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/test/access_control.nr @@ -42,11 +42,11 @@ unconstrained fn access_control() { // Impersonate original admin env.impersonate(owner); - // Try to set ourselves as admin, fail miserably + // Try to set ourselves as admin, fail miserably let set_admin_call_interface = Token::at(token_contract_address).set_admin(recipient); env.assert_public_call_fails(set_admin_call_interface); - // Try to revoke minter status to recipient, fail miserably + // Try to revoke minter status to recipient, fail miserably let set_minter_call_interface = Token::at(token_contract_address).set_minter(recipient, false); env.assert_public_call_fails(set_minter_call_interface); } diff --git a/yarn-project/txe/src/index.ts b/yarn-project/txe/src/index.ts index 3af1dee03de..3b03e89c2e6 100644 --- a/yarn-project/txe/src/index.ts +++ b/yarn-project/txe/src/index.ts @@ -65,14 +65,14 @@ class TXEDispatcher { this.logger.debug(`Calling ${functionName} on session ${sessionId}`); if (!TXESessions.has(sessionId) && functionName != 'reset') { - this.logger.info(`Creating new session ${sessionId}`); + this.logger.debug(`Creating new session ${sessionId}`); TXESessions.set(sessionId, await TXEService.init(this.logger)); } switch (functionName) { case 'reset': { TXESessions.delete(sessionId) && - this.logger.info(`Called reset on session ${sessionId}, yeeting it out of existence`); + this.logger.debug(`Called reset on session ${sessionId}, yeeting it out of existence`); return toForeignCallResult([]); } case 'deploy': { diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 36a429e0fda..8b57088aade 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -45,7 +45,7 @@ export class TXEService { const noteCache = new ExecutionNoteCache(txHash); const keyStore = new KeyStore(store); const txeDatabase = new TXEDatabase(store); - logger.info(`TXE service initialized`); + logger.debug(`TXE service initialized`); const txe = new TXE(logger, trees, packedValuesCache, noteCache, keyStore, txeDatabase); const service = new TXEService(logger, txe); await service.advanceBlocksBy(toSingle(new Fr(1n))); @@ -308,6 +308,16 @@ export class TXEService { return toForeignCallResult([toSingle(functionSelector.toField())]); } + async avmOpcodeChainId() { + const chainId = await (this.typedOracle as TXE).getChainId(); + return toForeignCallResult([toSingle(chainId)]); + } + + async avmOpcodeVersion() { + const version = await (this.typedOracle as TXE).getVersion(); + return toForeignCallResult([toSingle(version)]); + } + async packArgumentsArray(args: ForeignCallArray) { const packed = await this.typedOracle.packArgumentsArray(fromArray(args)); return toForeignCallResult([toSingle(packed)]);