From 5174b50e43045d184d88d6153bb1df93364324bd Mon Sep 17 00:00:00 2001 From: thunkar Date: Thu, 29 Aug 2024 14:36:51 +0000 Subject: [PATCH 1/4] wip --- yarn-project/simulator/src/avm/avm_simulator.ts | 2 +- yarn-project/txe/src/txe_service/txe_service.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/yarn-project/simulator/src/avm/avm_simulator.ts b/yarn-project/simulator/src/avm/avm_simulator.ts index e62b2a57c74e..581e21f647e4 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.ts @@ -54,7 +54,7 @@ export class AvmSimulator { */ public async executeBytecode(bytecode: Buffer): Promise { const decompressedBytecode = await decompressBytecodeIfCompressed(bytecode); - assert(isAvmBytecode(decompressedBytecode), "AVM simulator can't execute non-AVM bytecode"); + assert(await isAvmBytecode(decompressedBytecode), "AVM simulator can't execute non-AVM bytecode"); this.bytecode = decompressedBytecode; return await this.executeInstructions(decodeFromBytecode(decompressedBytecode)); diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index a1699e7ac987..d319b2883b7d 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -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)]); From e52d04c13dd17765320d7e186168d65a0667471a Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 4 Sep 2024 09:50:18 +0000 Subject: [PATCH 2/4] better logging --- aztec-up/bin/aztec | 21 +++++++++++++-------- aztec-up/bin/docker-compose.test.yml | 11 +++++++---- yarn-project/txe/src/index.ts | 4 ++-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/aztec-up/bin/aztec b/aztec-up/bin/aztec index 0989bb64469f..998d05478dec 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 604d3294e3c9..91b48742c930 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/yarn-project/txe/src/index.ts b/yarn-project/txe/src/index.ts index 3af1dee03de1..3b03e89c2e6b 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': { From 00d2d6a74b6fb407a5ef20053318ce44e0345127 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 4 Sep 2024 10:08:55 +0000 Subject: [PATCH 3/4] reduced verbosity --- .../contracts/token_contract/src/test/access_control.nr | 4 ++-- yarn-project/txe/src/txe_service/txe_service.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 588cc71d9a42..7e83b3c16fe8 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/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 3aa63f36739d..8b57088aadeb 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))); From 09c962960d9ef054d71932db1135b07b36115b87 Mon Sep 17 00:00:00 2001 From: thunkar Date: Wed, 4 Sep 2024 10:27:17 +0000 Subject: [PATCH 4/4] docs --- .../smart_contracts/testing_contracts/testing.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 b6463a0f2225..dc933c32927d 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)