diff --git a/.circleci/config.yml b/.circleci/config.yml index bd7238dad61..e4afb837e09 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1002,6 +1002,17 @@ jobs: name: "Test" command: ./scripts/cond_run_script end-to-end $JOB_NAME ./scripts/run_tests_local guides/dapp_testing.test.ts ./scripts/docker-compose-e2e-sandbox.yml working_directory: yarn-project/end-to-end + + guides-sample-dapp: + machine: + image: ubuntu-2004:202010-01 + steps: + - *checkout + - *setup_env + - run: + name: "Test" + command: ./scripts/cond_run_script end-to-end $JOB_NAME ./scripts/run_tests_local sample-dapp ./scripts/docker-compose-e2e-sandbox.yml + working_directory: yarn-project/end-to-end e2e-canary-test: machine: @@ -1443,6 +1454,7 @@ workflows: - cli-docs-sandbox: *e2e_test - guides-writing-an-account-contract: *e2e_test - guides-dapp-testing: *e2e_test + - guides-sample-dapp: *e2e_test - e2e-end: requires: @@ -1476,6 +1488,7 @@ workflows: - cli-docs-sandbox - guides-writing-an-account-contract - guides-dapp-testing + - guides-sample-dapp <<: *defaults - deploy-dockerhub: diff --git a/docs/docs/dev_docs/dapps/tutorials/contract_deployment.md b/docs/docs/dev_docs/dapps/tutorials/contract_deployment.md index a2cc9d4f044..9bbbbdc3669 100644 --- a/docs/docs/dev_docs/dapps/tutorials/contract_deployment.md +++ b/docs/docs/dev_docs/dapps/tutorials/contract_deployment.md @@ -1,3 +1,107 @@ ---- -title: Contract Deployment ---- +# Contract Deployment + +To add contracts to your application, we'll start by creating a new `nargo` project. We'll then compile the contracts, and write a simple script to deploy them to our Sandbox. + +:::info +Follow the instructions [here](../../getting_started/noir_contracts.md) to install `nargo` if you haven't done so already. +::: + +## Initialise nargo project + +Create a new `contracts` folder, and from there, initialise a new project called `private_token`: + +```sh +mkdir contracts && cd contracts +nargo new --contract private_token +``` + +Then, open the `contracts/private_token/Nargo.toml` configuration file, and add the `aztec.nr` and `value_note` libraries as dependencies: + +```toml +[dependencies] +aztec = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/noir-libs/noir-aztec" } +value_note = { git="https://github.com/AztecProtocol/aztec-packages", tag="master", directory="yarn-project/noir-libs/value-note" } +``` + +Last, copy-paste the code from the `PrivateToken` contract into `contracts/private_token/main.nr`: + +#include_code all yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust + +## Compile your contract + +We'll now use the [Aztec CLI](../../cli/main.md) to [compile](../../contracts/compiling.md) our project. If you haven't installed the CLI already, you can install it locally to your project running: + +```sh +yarn add -D @aztec/cli +``` + +Now run the following from your project root: + +```sh +yarn aztec-cli compile contracts/private_token +``` + +:::info +If you are using Typescript, consider including the `--typescript` option to [generate type-safe wrappers](../../contracts/compiling.md#typescript-interfaces) for your contracts. +::: + +This should have created an artifact `contracts/private_token/target/private_token-Main.json` with the interface and bytecode for your contract. + +## Adding a second contract + +For the purposes of this tutorial, we'll set up a second contract: a public token contract. Follow the same steps as above for initialising a new Nargo project, include the dependencies, and copy-paste the following code into `contracts/public_token/main.nr`: + +#include_code all yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr rust + +Compile the contract with the CLI: + +```sh +yarn aztec-cli compile contracts/public_token +``` + +With both contracts ready, we'll now proceed to deployment. + +## Deploy your contracts + +Let's now write a script for deploying your contracts to the Sandbox. We'll create an RPC client, and then use the `ContractDeployer` class to deploy our contracts, and store the deployment address to a local JSON file. + +Create a new file `src/deploy.mjs`, importing the contract artifacts we have generated plus the dependencies we'll need, and with a call to a `main` function that we'll populate in a second: + +```js +// src/deploy.mjs +import { writeFileSync } from 'fs'; +import { createAztecRpcClient, ContractDeployer } from '@aztec/aztec.js'; +import PrivateTokenArtifact from '../contracts/private_token/target/PrivateToken.json' assert { type: 'json' }; +import PublicTokenArtifact from '../contracts/public_token/target/PublicToken.json' assert { type: 'json' }; + +async function main() { } + +main().catch(err => { + console.error(`Error in deployment script: ${err}`); + process.exit(1); +}); +``` + +Now we can deploy the contracts by adding the following code to the `src/deploy.mjs` file. Here, we are using the `ContractDeployer` class with the compiled artifact to send a new deployment transaction. The `wait` method will block execution until the transaction is successfully mined, and return a receipt with the deployed contract address. + +#include_code dapp-deploy yarn-project/end-to-end/src/sample-dapp/deploy.mjs javascript + +Note that the private token constructor expects an `owner` address to mint an initial set of tokens to. We are using the first account from the Sandbox for this. + +:::info +If you are using the generated typescript classes, you can drop the generic `ContractDeployer` in favor of using the `deploy` method of the generated class, which will automatically load the artifact for you and type-check the constructor arguments: + +```typescript +await PrivateToken.deploy(client, 100n, owner.address).send().wait(); +``` +::: + +Run the snippet above as `node src/deploy.mjs`, and you should see the following output, along with a new `addresses.json` file in your project root: + +```text +Private token deployed to 0x2950b0f290422ff86b8ee8b91af4417e1464ddfd9dda26de8af52dac9ea4f869 +Public token deployed to 0x2b54f68fd1e18f7dcfa71e3be3c91bb06ecbe727a28d609e964c225a4b5549c8 +``` +## Next steps + +Now that we have our contracts set up, it's time to actually [start writing our application that will be interacting with them](./contract_interaction.md). \ No newline at end of file diff --git a/docs/docs/dev_docs/dapps/tutorials/contract_interaction.md b/docs/docs/dev_docs/dapps/tutorials/contract_interaction.md index ba0febbcfb8..108bbd69ae0 100644 --- a/docs/docs/dev_docs/dapps/tutorials/contract_interaction.md +++ b/docs/docs/dev_docs/dapps/tutorials/contract_interaction.md @@ -1,3 +1,135 @@ ---- -title: Contract Interactions ---- +# Contract interactions + +In this section, we'll write the logic in our app that will interact with the contract we have previously deployed. We'll be using the accounts already seeded in the Sandbox. + +## Showing user balance + +Let's start by showing our user balance for the private token across their accounts. To do this, we can leverage the `getBalance` [unconstrained](../../contracts/functions.md#unconstrained-functions) view function of the private token contract: + +#include_code getBalance yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr rust + +:::info +Note that this function will only return a valid response for accounts registered in the RPC Server, since it requires access to the [user's private state](../../wallets/main.md#private-state). In other words, you cannot query the balance of another user for a private token contract. +::: + +To do this, let's first initialise a new `Contract` instance using `aztec.js` that represents our deployed token contracts. Create a new `src/contracts.mjs` file with the imports for our artifacts and other dependencies: + +```js +// src/contracts.mjs +import { Contract } from '@aztec/aztec.js'; +import { readFileSync } from 'fs'; +import PrivateTokenArtifact from '../contracts/private_token/target/PrivateToken.json' assert { type: 'json' }; +import PublicTokenArtifact from '../contracts/public_token/target/PublicToken.json' assert { type: 'json' }; +``` + +And then add the following code for initialising the `Contract` instances: + +#include_code get-tokens yarn-project/end-to-end/src/sample-dapp/contracts.mjs javascript + +:::info +You can use the typescript autogenerated interface instead of the generic `Contract` class to get type-safe methods. +::: + +We can now get the private token instance in our main code in `src/index.mjs`, and query the private balance for each of the user accounts. To query a function, without sending a transaction, use the `view` function of the method: + +#include_code showPrivateBalances yarn-project/end-to-end/src/sample-dapp/index.mjs javascript + +Run this as `node src/index.mjs` and you should now see the following output: + +``` +Balance of 0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d: 100 +Balance of 0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972: 0 +Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0 +``` + +## Transferring private tokens + +Now that we can see the balance for each user, let's transfer tokens from one account to another. To do this, we will first need access to a `Wallet` object. This wraps access to an RPC Server and also provides an interface to craft and sign transactions on behalf of one of the user accounts. + +We can initialise a wallet using one of the `getAccount` methods from `aztec.js``, along with the corresponding signing and encryption keys: + +```js +import { getSchnorrAccount } from '@aztec/aztec.js'; +const wallet = await getSchnorrAccount(client, ENCRYPTION_PRIVATE_KEY, SIGNING_PRIVATE_KEY).getWallet(); +``` + +For ease of use, `aztec.js` also ships with a helper `getSandboxAccountsWallets` method that returns a wallet for each of the pre-initialised accounts in the Sandbox, so you can send transactions as any of them. We'll use one of these wallets to initialise the `Contract` instance that represents our private token contract, so every transaction sent through it will be sent through that wallet. + +#include_code transferPrivateFunds yarn-project/end-to-end/src/sample-dapp/index.mjs javascript + +Let's go step-by-step on this snippet. We first get wallets for two of the Sandbox accounts, and name them `owner` and `recipient`. Then, we initialise the private token `Contract` instance using the `owner` wallet, meaning that any transactions sent through it will have the `owner` as sender. + +Next, we send a transfer transaction, moving 1 unit of balance to the `recipient` account address. This has no immediate effect, since the transaction first needs to be simulated locally and then submitted and mined. Only once this has finished we can query the balances again and see the effect of our transaction. We are using a `showPrivateBalances` helper function here which has the code we wrote in the section above. + +Run this new snippet and you should see the following: + +```text +Sent transfer transaction 16025a7c4f6c44611d7ac884a5c27037d85d9756a4924df6d97fb25f6e83a0c8 + +Balance of 0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d: 100 +Balance of 0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972: 0 +Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0 + +Awaiting transaction to be mined +Transaction has been mind on block 4 + +Balance of 0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d: 99 +Balance of 0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972: 1 +Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0 +``` + +:::info +At the time of this writing, there are no events emitted when new private notes are received, so the only way to detect of a change in a user's private balance is via polling on every new block processed. This will change in a future release. +::: + +## Working with public state + +While they are [fundamentally differently](../../../concepts/foundation/state_model.md), the API for working with private and public functions and state from `aztec.js` is equivalent. To query the balance in public tokens for our user accounts, we can just call the `publicBalanceOf` view function in the contract: + +#include_code showPublicBalances yarn-project/end-to-end/src/sample-dapp/index.mjs javascript + +:::info +Since this is a public token contract we are working with, we can now query the balance for any address, not just those registered in our local RPC Server. We can also send funds to addresses for which we don't know their [public encryption key](../../../concepts/foundation/accounts/keys.md#encryption-keys). +::: + +Here, since the public token contract does not mint any initial funds upon deployment, the balances for all of our user's accounts will be zero. But we can send a transaction to mint tokens to change this, using very similar code to the one for sending private funds: + +#include_code mintPublicFunds yarn-project/end-to-end/src/sample-dapp/index.mjs javascript + +And get the expected results: + +```text +Sent mint transaction 041d5b4cc68bcb5c6cb45cd4c79f893d94f0df0792f66e6fddd7718c049fe925 +Balance of 0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d: 0 +Balance of 0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972: 0 +Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0 + +Awaiting transaction to be mined +Transaction has been mined on block 5 + +Balance of 0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d: 100 +Balance of 0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972: 0 +Balance of 0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b: 0 +``` + +Public functions can emit [unencrypted public logs](../../contracts/events.md#unencrypted-events), which we can query via the RPC Server interface. In particular, the public token contract emits a generic `Coins minted` whenever the `mint` method is called: + +#include_code unencrypted_log yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr rust + +We can extend our code by querying the logs emitted on the last block when the minting transaction is mined: + +#include_code showLogs yarn-project/end-to-end/src/sample-dapp/index.mjs javascript + +Running the code again would now show an extra line with: + +```text +Log: Coins minted +``` + +:::info +At the time of this writing, there is no event-based mechanism in the `aztec.js` library to subscribe to events. The only option to consume them is to poll on every new block detected. This will change in a future version. +::: + +## Next steps + +In the next and final section, we'll [set up automated tests for our application](./testing.md). \ No newline at end of file diff --git a/docs/docs/dev_docs/dapps/tutorials/creating_accounts.md b/docs/docs/dev_docs/dapps/tutorials/creating_accounts.md deleted file mode 100644 index 95e19162829..00000000000 --- a/docs/docs/dev_docs/dapps/tutorials/creating_accounts.md +++ /dev/null @@ -1,3 +0,0 @@ ---- -title: Creating Accounts ---- diff --git a/docs/docs/dev_docs/dapps/tutorials/main.md b/docs/docs/dev_docs/dapps/tutorials/main.md index 957a8f9c10e..1d576759992 100644 --- a/docs/docs/dev_docs/dapps/tutorials/main.md +++ b/docs/docs/dev_docs/dapps/tutorials/main.md @@ -1,10 +1,25 @@ --- -title: Dapp Development Tutorials +title: Dapp Development Tutorial --- -Links to specific tutorials +In this tutorial we'll go through the steps for building a simple application that interacts with the Aztec Sandbox. We'll be building a console application using Javascript and NodeJS, but you may reuse the same concepts here for a web-based app. All Aztec libraries are written in Typescript and fully typed, so you can use Typescript instead of Javascript to make the most out of its type checker. -- Connecting to the RPC Server -- Creating Accounts -- Deploying a contract -- Contract Interactions +This tutorial will focus on environment setup, including creating accounts and deployments, as well as interacting with your contracts. It will not cover [how to write contracts in Noir](../../contracts/main.md). + +The full code for this tutorial is [available on the `aztec-packages` repository](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/end-to-end/src/sample-dapp). + +## Dependencies + +- Linux or OSX environment +- [NodeJS](https://nodejs.org/) 18 or higher +- [Aztec Sandbox](../../getting_started/sandbox.md) +- [Aztec CLI](../../getting_started/cli.md) +- [Nargo](../../getting_started/noir_contracts.md) for building contracts + +## Prerequisites + +Basic understanding of NodeJS and Javascript should be enough to follow this tutorial. Along the way, we'll provide links to dig deeper into Aztec concepts as we introduce them. + +## Get started + +Let's get started with [setting up a new javascript project](./project_setup.md). diff --git a/docs/docs/dev_docs/dapps/tutorials/project_setup.md b/docs/docs/dev_docs/dapps/tutorials/project_setup.md new file mode 100644 index 00000000000..51560dd45a5 --- /dev/null +++ b/docs/docs/dev_docs/dapps/tutorials/project_setup.md @@ -0,0 +1,31 @@ +# Setting up your project + +Let's start by setting up a regular Javascript NodeJS project. Feel free to skip this part if you're already familiar with project setup and head directly to connecting to the Sandbox. + +## Create a new project + +We'll use [`yarn`](https://yarnpkg.com/) for managing our project and dependencies, though you can also use `npm` or your Javascript package manager of choice. + +1. Ensure node version is 18 or more by running. + +```sh +node -v +``` + +2. Create a new folder and initialize a new project. + +```sh +mkdir sample-dapp +cd sample-dapp +yarn init -yp +``` + +3. Add the `aztec.js` library as a dependency: + +```sh +yarn add @aztec/aztec.js +``` + +## Next steps + +With your project already set up, let's [connect to the Sandbox RPC Server and grab an account to interact with it](./rpc_server.md). diff --git a/docs/docs/dev_docs/dapps/tutorials/rpc_server.md b/docs/docs/dev_docs/dapps/tutorials/rpc_server.md index 095f49b49ad..0412ddf5fde 100644 --- a/docs/docs/dev_docs/dapps/tutorials/rpc_server.md +++ b/docs/docs/dev_docs/dapps/tutorials/rpc_server.md @@ -1,3 +1,43 @@ ---- -title: Connecting to the RPC Server ---- +# Connecting to the RPC Server + +As an app developer, the [Aztec RPC Server interface](../api/aztec_rpc.md) provides you with access to the user's accounts and their private state, as well as a connection to the network for accessing public global state. + +During the Sandbox phase, this role is fulfilled by the [Aztec Sandbox](../../sandbox/main.md), which runs a local RPC Server and an Aztec Node, both connected to a local Ethereum development node like Anvil. The Sandbox also includes a set of pre-initialised accounts that you can use from your app. + +In this section, we'll connect to the Sandbox from our project. + +## Create RPC client + +We'll use the `createAztecRpcClient` function from `aztec.js` to connect to the Sandbox, which by default runs on `localhost:8080`. To test the connection works, we'll request and print the node's chain id. + +Let's create our first file `src/index.mjs` with the following contents: + +#include_code all yarn-project/end-to-end/src/sample-dapp/connect.mjs javascript + +Run this example as `node src/index.mjs` and you should see the following output: +``` +Connected to chain 31337 +``` + +:::info +Should the above fail due to a connection error, make sure the Sandbox is running locally and on port 8080. +::: + +## Load user accounts + +With our connection to the RPC server, let's try loading the accounts that are pre-initialised in the Sandbox: + +#include_code showAccounts yarn-project/end-to-end/src/sample-dapp/index.mjs javascript + +Run again the above, and we should see: + +``` +User accounts: +0x0c8a6673d7676cc80aaebe7fa7504cf51daa90ba906861bfad70a58a98bf5a7d +0x226f8087792beff8d5009eb94e65d2a4a505b70baf4a9f28d33c8d620b0ba972 +0x0e1f60e8566e2c6d32378bdcadb7c63696e853281be798c107266b8c3a88ea9b +``` + +## Next steps + +With a working connection to the RPC Server, let's now setup our application by [compiling and deploying our contracts](./contract_deployment.md). \ No newline at end of file diff --git a/docs/docs/dev_docs/dapps/tutorials/testing.md b/docs/docs/dev_docs/dapps/tutorials/testing.md new file mode 100644 index 00000000000..91eb3c74318 --- /dev/null +++ b/docs/docs/dev_docs/dapps/tutorials/testing.md @@ -0,0 +1,59 @@ +# Testing + +To wrap up this tutorial, we'll set up a simple automated test for our dapp contracts. We will be using [jest](https://jestjs.io/), but any nodejs test runner works fine. + +Here we'll only test the happy path for a `transfer` on our private token contract, but in a real application you should be testing both happy and unhappy paths, as well as both your contracts and application logic. Refer to the full [testing guide](../testing.md) for more info on testing and assertions. + +## Dependencies + +Start by installing our test runner, in this case jest: + +```sh +yarn add -D jest +``` + +We'll also be running our Sandbox within the test suite, to avoid polluting a global instance, so we'll need to install the Sandbox itself as a dependency as well: + +```sh +yarn add -D @aztec/aztec-sandbox +``` + +## Test setup + +Create a new file `src/index.test.mjs` with the imports we'll be using and an empty test suite to begin with: + +```ts +import { createSandbox } from '@aztec/aztec-sandbox'; +import { Contract, createAccount } from '@aztec/aztec.js'; +import PrivateTokenArtifact from '../contracts/private_token/target/PrivateToken.json' assert { type: 'json' }; + +describe('private token', () => { + +}); +``` + +Let's set up our test suite. We'll start [a new Sandbox instance within the test](../testing.md#running-sandbox-in-the-nodejs-process), create two fresh accounts to test with, and deploy an instance of our contract. The `aztec-sandbox` and `aztec.js` provide the helper functions we need to do this: + +#include_code setup yarn-project/end-to-end/src/sample-dapp/index.test.mjs javascript + +Note that, since we are starting a new Sandbox instance, we need to `stop` it in the test suite teardown. Also, even though the Sandbox runs within our tests, we still need a running Ethereum development node. Make sure you are running [Anvil](https://book.getfoundry.sh/anvil/), [Hardhat Network](https://hardhat.org/hardhat-network/docs/overview), or [Ganache](https://trufflesuite.com/ganache/) along with your tests. + +## Writing our test + +Now that we have a working test environment, we can write our first test for exercising the `transfer` function on the private token contract. We will use the same `aztec.js` methods we used when building our dapp: + +#include_code test yarn-project/end-to-end/src/sample-dapp/index.test.mjs javascript + +In this example, we assert that the `recipient`'s balance is increased by the amount transferred. We could also test that the `owner`'s funds are decremented by the same amount, or that a transaction that attempts to send more funds than those available would fail. Check out the [testing guide](../testing.md) for more ideas. + +## Running our tests + +With a local Ethereum development node running in port 8545, we can run our `jest` tests using `yarn`. The quirky syntax is due to [jest limitations in ESM support](https://jestjs.io/docs/ecmascript-modules), as well as not picking up `mjs` file by default: + +```sh +yarn node --experimental-vm-modules $(yarn bin jest) --testRegex '.*\.test\.mjs$' +``` + +## Next steps + +Now that you have finished the tutorial, you can dig deeper on the [APIs for dapp development](../api/main.md), learn more about [writing contracts with Noir](../../contracts/main.md), check out the [Sandbox's architecture](../../sandbox/main.md), or read about the [fundamental concepts behind Aztec Network](../../../concepts/foundation/main.md). \ No newline at end of file diff --git a/docs/sidebars.js b/docs/sidebars.js index 518d6afe2cc..b45e933b025 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -185,10 +185,11 @@ const sidebars = { id: "dev_docs/dapps/tutorials/main", }, items: [ + "dev_docs/dapps/tutorials/project_setup", "dev_docs/dapps/tutorials/rpc_server", - "dev_docs/dapps/tutorials/creating_accounts", "dev_docs/dapps/tutorials/contract_deployment", "dev_docs/dapps/tutorials/contract_interaction", + "dev_docs/dapps/tutorials/testing", ], }, ], diff --git a/yarn-project/acir-simulator/package.json b/yarn-project/acir-simulator/package.json index 1dd64c67eed..8b0b06821c9 100644 --- a/yarn-project/acir-simulator/package.json +++ b/yarn-project/acir-simulator/package.json @@ -26,9 +26,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/archiver/package.json b/yarn-project/archiver/package.json index e3168c13f1c..4dbc4a5465e 100644 --- a/yarn-project/archiver/package.json +++ b/yarn-project/archiver/package.json @@ -30,9 +30,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/aztec-node/package.json b/yarn-project/aztec-node/package.json index c9ebdf72c20..ec5beb82863 100644 --- a/yarn-project/aztec-node/package.json +++ b/yarn-project/aztec-node/package.json @@ -27,9 +27,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/aztec-rpc/package.json b/yarn-project/aztec-rpc/package.json index 3f3eefc77de..7ac8adacfc0 100644 --- a/yarn-project/aztec-rpc/package.json +++ b/yarn-project/aztec-rpc/package.json @@ -27,9 +27,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/aztec-sandbox/package.json b/yarn-project/aztec-sandbox/package.json index f565e533ef1..041da41d296 100644 --- a/yarn-project/aztec-sandbox/package.json +++ b/yarn-project/aztec-sandbox/package.json @@ -64,9 +64,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "engines": { diff --git a/yarn-project/aztec.js/package.json b/yarn-project/aztec.js/package.json index 82c44fe8aae..0a67c34d5b3 100644 --- a/yarn-project/aztec.js/package.json +++ b/yarn-project/aztec.js/package.json @@ -33,9 +33,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts index 5f0c0aff12c..0c58f7d4e5d 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -1,7 +1,9 @@ import { ContractAbi } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { PublicKey } from '@aztec/types'; import { Wallet } from '../aztec_rpc_client/wallet.js'; +import { DeployMethod, Point } from '../index.js'; import { ContractBase } from './contract_base.js'; /** @@ -26,4 +28,25 @@ export class Contract extends ContractBase { } return new Contract(extendedContractData.getCompleteAddress(), abi, wallet); } + + /** + * Creates a tx to deploy a new instance of a contract. + * @param wallet - The wallet for executing the deployment. + * @param abi - ABI of the contract to deploy. + * @param args - Arguments for the constructor. + */ + public static deploy(wallet: Wallet, abi: ContractAbi, args: any[]) { + return new DeployMethod(Point.ZERO, wallet, abi, args); + } + + /** + * Creates a tx to deploy a new instance of a contract using the specified public key to derive the address. + * @param publicKey - Public key for deriving the address. + * @param wallet - The wallet for executing the deployment. + * @param abi - ABI of the contract to deploy. + * @param args - Arguments for the constructor. + */ + public static deployWithPublicKey(publicKey: PublicKey, wallet: Wallet, abi: ContractAbi, args: any[]) { + return new DeployMethod(publicKey, wallet, abi, args); + } } diff --git a/yarn-project/aztec.js/src/sandbox/index.ts b/yarn-project/aztec.js/src/sandbox/index.ts index 814218c3a12..3d023d0b485 100644 --- a/yarn-project/aztec.js/src/sandbox/index.ts +++ b/yarn-project/aztec.js/src/sandbox/index.ts @@ -5,7 +5,14 @@ import { sleep } from '@aztec/foundation/sleep'; import zip from 'lodash.zip'; import SchnorrAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' }; -import { AccountWallet, AztecRPC, EntrypointWallet, getAccountWallets, getSchnorrAccount } from '../index.js'; +import { + AccountWallet, + AztecRPC, + EntrypointWallet, + createAztecRpcClient, + getAccountWallets, + getSchnorrAccount, +} from '../index.js'; export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [ GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), @@ -19,6 +26,8 @@ export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO]; export const INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI = SchnorrAccountContractAbi; +export const { SANDBOX_URL = 'http://localhost:8080' } = process.env; + /** * Gets a single wallet that manages all the Aztec accounts that are initially stored in the sandbox. * @param aztecRpc - An instance of the Aztec RPC interface. @@ -84,12 +93,13 @@ export async function deployInitialSandboxAccounts(aztecRpc: AztecRPC) { /** * Function to wait until the sandbox becomes ready for use. - * @param rpcServer - The rpc client connected to the sandbox. + * @param rpc - The rpc client connected to the sandbox. */ -export async function waitForSandbox(rpcServer: AztecRPC) { +export async function waitForSandbox(rpc?: AztecRPC) { + rpc = rpc ?? createAztecRpcClient(SANDBOX_URL); while (true) { try { - await rpcServer.getNodeInfo(); + await rpc.getNodeInfo(); break; } catch (err) { await sleep(1000); diff --git a/yarn-project/aztec.js/src/utils/account.ts b/yarn-project/aztec.js/src/utils/account.ts index baa0b5110f1..9f070ec8ede 100644 --- a/yarn-project/aztec.js/src/utils/account.ts +++ b/yarn-project/aztec.js/src/utils/account.ts @@ -5,8 +5,23 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { AztecRPC, TxStatus } from '@aztec/types'; import { SingleKeyAccountEntrypoint } from '../account/entrypoint/single_key_account_entrypoint.js'; -import { EntrypointWallet, Wallet } from '../aztec_rpc_client/wallet.js'; -import { ContractDeployer, EntrypointCollection, StoredKeyAccountEntrypoint, generatePublicKey } from '../index.js'; +import { AccountWallet, EntrypointWallet, Wallet } from '../aztec_rpc_client/wallet.js'; +import { + ContractDeployer, + EntrypointCollection, + StoredKeyAccountEntrypoint, + generatePublicKey, + getSchnorrAccount, +} from '../index.js'; + +/** + * Deploys and registers a new account using random private keys and returns the associated wallet. Useful for testing. + * @param rpc - RPC client. + * @returns - A wallet for a fresh account. + */ +export function createAccount(rpc: AztecRPC): Promise { + return getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy(); +} /** * Creates an Aztec Account. diff --git a/yarn-project/circuits.js/package.json b/yarn-project/circuits.js/package.json index 2a3dee75f1b..b2fbac5e846 100644 --- a/yarn-project/circuits.js/package.json +++ b/yarn-project/circuits.js/package.json @@ -35,9 +35,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/cli/package.json b/yarn-project/cli/package.json index 845b9296eed..e2541e50de8 100644 --- a/yarn-project/cli/package.json +++ b/yarn-project/cli/package.json @@ -30,9 +30,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/end-to-end/.gitignore b/yarn-project/end-to-end/.gitignore new file mode 100644 index 00000000000..c59c6f13655 --- /dev/null +++ b/yarn-project/end-to-end/.gitignore @@ -0,0 +1 @@ +addresses.json \ No newline at end of file diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index ffcac42a743..1e7e6a34e01 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -18,9 +18,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(ts|mjs)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 19fdbd27cfc..f8adaec436b 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -4,11 +4,10 @@ import { AztecRPC, CheatCodes, Fr, - GrumpkinScalar, L2BlockL2Logs, + createAccount, createAztecRpcClient, getSandboxAccountsWallets, - getSchnorrAccount, waitForSandbox, } from '@aztec/aztec.js'; import { toBigIntBE } from '@aztec/foundation/bigint-buffer'; @@ -27,8 +26,8 @@ describe('guides/dapp/testing', () => { // docs:start:in-proc-sandbox ({ rpcServer: rpc, stop } = await createSandbox()); // docs:end:in-proc-sandbox - owner = await getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy(); - recipient = await getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy(); + owner = await createAccount(rpc); + recipient = await createAccount(rpc); token = await PrivateTokenContract.deploy(owner, 100n, owner.getAddress()).send().deployed(); }, 60_000); @@ -62,8 +61,8 @@ describe('guides/dapp/testing', () => { beforeEach(async () => { rpc = createAztecRpcClient(SANDBOX_URL); - owner = await getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy(); - recipient = await getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy(); + owner = await createAccount(rpc); + recipient = await createAccount(rpc); token = await PrivateTokenContract.deploy(owner, 100n, owner.getAddress()).send().deployed(); }, 30_000); @@ -108,7 +107,7 @@ describe('guides/dapp/testing', () => { beforeAll(async () => { rpc = createAztecRpcClient(SANDBOX_URL); - owner = await getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy(); + owner = await createAccount(rpc); testContract = await TestContract.deploy(owner).send().deployed(); cheats = await CheatCodes.create(ETHEREUM_HOST, rpc); }, 30_000); @@ -135,8 +134,8 @@ describe('guides/dapp/testing', () => { beforeAll(async () => { rpc = createAztecRpcClient(SANDBOX_URL); - owner = await getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy(); - recipient = await getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()).waitDeploy(); + owner = await createAccount(rpc); + recipient = await createAccount(rpc); token = await PrivateTokenContract.deploy(owner, 100n, owner.getAddress()).send().deployed(); nativeToken = await NativeTokenContract.deploy(owner, 100n, owner.getAddress()).send().deployed(); diff --git a/yarn-project/end-to-end/src/sample-dapp/ci/index.test.mjs b/yarn-project/end-to-end/src/sample-dapp/ci/index.test.mjs new file mode 100644 index 00000000000..4c3312a6d1d --- /dev/null +++ b/yarn-project/end-to-end/src/sample-dapp/ci/index.test.mjs @@ -0,0 +1,13 @@ +import { waitForSandbox } from '@aztec/aztec.js'; + +import { deploy } from '../deploy.mjs'; +import { main } from '../index.mjs'; + +// Tests on our CI that all scripts included in the guide work fine +describe('sample-dapp', () => { + it('deploys and runs without errors', async () => { + await waitForSandbox(); + await deploy(); + await main(); + }, 60_000); +}); diff --git a/yarn-project/end-to-end/src/sample-dapp/connect.mjs b/yarn-project/end-to-end/src/sample-dapp/connect.mjs new file mode 100644 index 00000000000..d66fbc3ba02 --- /dev/null +++ b/yarn-project/end-to-end/src/sample-dapp/connect.mjs @@ -0,0 +1,16 @@ +// docs:start:all +import { createAztecRpcClient } from '@aztec/aztec.js'; + +const { SANDBOX_URL = 'http://localhost:8080' } = process.env; + +async function main() { + const client = createAztecRpcClient(SANDBOX_URL); + const { chainId } = await client.getNodeInfo(); + console.log(`Connected to chain ${chainId}`); +} + +main().catch(err => { + console.error(`Error in app: ${err}`); + process.exit(1); +}); +// docs:end:all diff --git a/yarn-project/end-to-end/src/sample-dapp/contracts.mjs b/yarn-project/end-to-end/src/sample-dapp/contracts.mjs new file mode 100644 index 00000000000..d72e4f4bd5f --- /dev/null +++ b/yarn-project/end-to-end/src/sample-dapp/contracts.mjs @@ -0,0 +1,19 @@ +import { Contract } from '@aztec/aztec.js'; +import { + PrivateTokenContractAbi as PrivateTokenArtifact, + PublicTokenContractAbi as PublicTokenArtifact, +} from '@aztec/noir-contracts/artifacts'; + +import { readFileSync } from 'fs'; + +// docs:start:get-tokens +export async function getPrivateToken(client) { + const addresses = JSON.parse(readFileSync('addresses.json')); + return Contract.at(addresses.privateToken, PrivateTokenArtifact, client); +} + +export async function getPublicToken(client) { + const addresses = JSON.parse(readFileSync('addresses.json')); + return Contract.at(addresses.publicToken, PublicTokenArtifact, client); +} +// docs:end:get-tokens diff --git a/yarn-project/end-to-end/src/sample-dapp/deploy.mjs b/yarn-project/end-to-end/src/sample-dapp/deploy.mjs new file mode 100644 index 00000000000..bcad06487a5 --- /dev/null +++ b/yarn-project/end-to-end/src/sample-dapp/deploy.mjs @@ -0,0 +1,38 @@ +import { ContractDeployer, createAztecRpcClient } from '@aztec/aztec.js'; +import { + PrivateTokenContractAbi as PrivateTokenArtifact, + PublicTokenContractAbi as PublicTokenArtifact, +} from '@aztec/noir-contracts/artifacts'; + +import { writeFileSync } from 'fs'; +import { fileURLToPath } from 'url'; + +// docs:start:dapp-deploy +const { SANDBOX_URL = 'http://localhost:8080' } = process.env; + +async function main() { + const client = createAztecRpcClient(SANDBOX_URL); + const [owner] = await client.getAccounts(); + + const privateTokenDeployer = new ContractDeployer(PrivateTokenArtifact, client); + const { contractAddress: privateTokenAddress } = await privateTokenDeployer.deploy(100n, owner.address).send().wait(); + console.log(`Private token deployed at ${privateTokenAddress.toString()}`); + + const publicTokenDeployer = new ContractDeployer(PublicTokenArtifact, client); + const { contractAddress: publicTokenAddress } = await publicTokenDeployer.deploy().send().wait(); + console.log(`Public token deployed at ${publicTokenAddress.toString()}`); + + const addresses = { privateToken: privateTokenAddress.toString(), publicToken: publicTokenAddress.toString() }; + writeFileSync('addresses.json', JSON.stringify(addresses, null, 2)); +} +// docs:end:dapp-deploy + +// Execute main only if run directly +if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) { + main().catch(err => { + console.error(`Error in deployment script: ${err}`); + process.exit(1); + }); +} + +export { main as deploy }; diff --git a/yarn-project/end-to-end/src/sample-dapp/index.mjs b/yarn-project/end-to-end/src/sample-dapp/index.mjs new file mode 100644 index 00000000000..99bb702ffb3 --- /dev/null +++ b/yarn-project/end-to-end/src/sample-dapp/index.mjs @@ -0,0 +1,103 @@ +import { L2BlockL2Logs, createAztecRpcClient, getSandboxAccountsWallets } from '@aztec/aztec.js'; +import { fileURLToPath } from '@aztec/foundation/url'; + +import { getPrivateToken, getPublicToken } from './contracts.mjs'; + +const { SANDBOX_URL = 'http://localhost:8080' } = process.env; + +async function showAccounts(client) { + // docs:start:showAccounts + const accounts = await client.getAccounts(); + console.log(`User accounts:\n${accounts.map(a => a.address).join('\n')}`); + // docs:end:showAccounts +} + +async function showPrivateBalances(client) { + // docs:start:showPrivateBalances + const accounts = await client.getAccounts(); + const privateToken = await getPrivateToken(client); + + for (const account of accounts) { + // highlight-next-line:showPrivateBalances + const balance = await privateToken.methods.getBalance(account.address).view(); + console.log(`Balance of ${account.address}: ${balance}`); + } + // docs:end:showPrivateBalances +} + +async function transferPrivateFunds(client) { + // docs:start:transferPrivateFunds + const [owner, recipient] = await getSandboxAccountsWallets(client); + const privateToken = await getPrivateToken(owner); + + const tx = privateToken.methods.transfer(1n, recipient.getAddress()).send(); + console.log(`Sent transfer transaction ${await tx.getTxHash()}`); + await showPrivateBalances(client); + + console.log(`Awaiting transaction to be mined`); + const receipt = await tx.wait(); + console.log(`Transaction has been mined on block ${receipt.blockNumber}`); + await showPrivateBalances(client); + // docs:end:transferPrivateFunds +} + +async function showPublicBalances(client) { + // docs:start:showPublicBalances + const accounts = await client.getAccounts(); + const publicToken = await getPublicToken(client); + + for (const account of accounts) { + // highlight-next-line:showPublicBalances + const balance = await publicToken.methods.publicBalanceOf(account.address).view(); + console.log(`Balance of ${account.address}: ${balance}`); + } + // docs:end:showPublicBalances +} + +async function mintPublicFunds(client) { + // docs:start:mintPublicFunds + const [owner] = await getSandboxAccountsWallets(client); + const publicToken = await getPublicToken(owner); + + const tx = publicToken.methods.mint(100n, owner.getAddress()).send(); + console.log(`Sent mint transaction ${await tx.getTxHash()}`); + await showPublicBalances(client); + + console.log(`Awaiting transaction to be mined`); + const receipt = await tx.wait(); + console.log(`Transaction has been mined on block ${receipt.blockNumber}`); + await showPublicBalances(client); + // docs:end:mintPublicFunds + + // docs:start:showLogs + const blockNumber = await client.getBlockNumber(); + const logs = await client.getUnencryptedLogs(blockNumber, 1); + const textLogs = L2BlockL2Logs.unrollLogs(logs).map(log => log.toString('ascii')); + for (const log of textLogs) console.log(`Log emitted: ${log}`); + // docs:end:showLogs +} + +async function main() { + const client = createAztecRpcClient(SANDBOX_URL); + const { chainId } = await client.getNodeInfo(); + console.log(`Connected to chain ${chainId}`); + + await showAccounts(client); + + await transferPrivateFunds(client); + + await mintPublicFunds(client); +} + +// Execute main only if run directly +if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) { + // eslint-disable-next-line @typescript-eslint/no-floating-promises + main() + .then(() => process.exit(0)) + .catch(err => { + console.error(`Error in app: ${err}`); + process.exit(1); + }); +} + +export { main }; diff --git a/yarn-project/end-to-end/src/sample-dapp/index.test.mjs b/yarn-project/end-to-end/src/sample-dapp/index.test.mjs new file mode 100644 index 00000000000..db96a196bf8 --- /dev/null +++ b/yarn-project/end-to-end/src/sample-dapp/index.test.mjs @@ -0,0 +1,25 @@ +import { createSandbox } from '@aztec/aztec-sandbox'; +import { Contract, createAccount } from '@aztec/aztec.js'; +import { PrivateTokenContractAbi as PrivateTokenArtifact } from '@aztec/noir-contracts/artifacts'; + +describe('private token', () => { + // docs:start:setup + let rpc, stop, owner, recipient, token; + beforeAll(async () => { + ({ rpcServer: rpc, stop } = await createSandbox()); + owner = await createAccount(rpc); + recipient = await createAccount(rpc); + token = await Contract.deploy(owner, PrivateTokenArtifact, [100n, owner.getAddress()]).send().deployed(); + }, 30_000); + + afterAll(() => stop()); + // docs:end:setup + + // docs:start:test + it('increases recipient funds on transfer', async () => { + expect(await token.methods.getBalance(recipient.getAddress()).view()).toEqual(0n); + await token.methods.transfer(20n, recipient.getAddress()).send().wait(); + expect(await token.methods.getBalance(recipient.getAddress()).view()).toEqual(20n); + }); + // docs:end:test +}); diff --git a/yarn-project/ethereum/package.json b/yarn-project/ethereum/package.json index 3cf2bd85841..82a2402ad32 100644 --- a/yarn-project/ethereum/package.json +++ b/yarn-project/ethereum/package.json @@ -51,9 +51,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "engines": { diff --git a/yarn-project/foundation/package.json b/yarn-project/foundation/package.json index d1fdfc2f79f..7441da40186 100644 --- a/yarn-project/foundation/package.json +++ b/yarn-project/foundation/package.json @@ -50,9 +50,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/key-store/package.json b/yarn-project/key-store/package.json index f5f191e81fd..e9b76370219 100644 --- a/yarn-project/key-store/package.json +++ b/yarn-project/key-store/package.json @@ -26,9 +26,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/merkle-tree/package.json b/yarn-project/merkle-tree/package.json index 2cfa7a4a4bb..163d6fc8dba 100644 --- a/yarn-project/merkle-tree/package.json +++ b/yarn-project/merkle-tree/package.json @@ -27,9 +27,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src", "testTimeout": 15000 }, diff --git a/yarn-project/noir-compiler/package.json b/yarn-project/noir-compiler/package.json index c5d9365430f..067b9a5c6d9 100644 --- a/yarn-project/noir-compiler/package.json +++ b/yarn-project/noir-compiler/package.json @@ -32,9 +32,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/noir-contracts/package.json b/yarn-project/noir-contracts/package.json index fb562f7e291..35b3dc64ebf 100644 --- a/yarn-project/noir-contracts/package.json +++ b/yarn-project/noir-contracts/package.json @@ -27,9 +27,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr index 8395bbd1ea0..e03c3fa613c 100644 --- a/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/private_token_contract/src/main.nr @@ -1,3 +1,4 @@ +// docs:start:all contract PrivateToken { use dep::std::option::Option; use dep::value_note::{ @@ -109,3 +110,4 @@ contract PrivateToken { } // docs:end:compute_note_hash_and_nullifier } +// docs:end:all \ No newline at end of file diff --git a/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr index f32f3ec07bf..2dafe1baff9 100644 --- a/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/public_token_contract/src/main.nr @@ -1,3 +1,4 @@ +// docs:start:all contract PublicToken { use dep::std::option::Option; @@ -48,8 +49,8 @@ contract PublicToken { let storage = Storage::init(Context::public(&mut context)); let recipient_balance = storage.balances.at(recipient); let new_amount = recipient_balance.read() + amount; - // docs:start:unencrypted_log // TODO: Remove return value. + // docs:start:unencrypted_log let _hash = emit_unencrypted_log("Coins minted"); // docs:end:unencrypted_log recipient_balance.write(new_amount); @@ -96,3 +97,4 @@ contract PublicToken { storage.balances.at(owner).read() } } +// docs:end:all \ No newline at end of file diff --git a/yarn-project/p2p-bootstrap/package.json b/yarn-project/p2p-bootstrap/package.json index 41a42011321..89fc049dba2 100644 --- a/yarn-project/p2p-bootstrap/package.json +++ b/yarn-project/p2p-bootstrap/package.json @@ -50,9 +50,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "engines": { diff --git a/yarn-project/p2p/package.json b/yarn-project/p2p/package.json index 98b7276d297..f3213003702 100644 --- a/yarn-project/p2p/package.json +++ b/yarn-project/p2p/package.json @@ -28,9 +28,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/package.common.json b/yarn-project/package.common.json index feaf0fd5764..d6231d92f89 100644 --- a/yarn-project/package.common.json +++ b/yarn-project/package.common.json @@ -25,9 +25,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" } } diff --git a/yarn-project/prover-client/package.json b/yarn-project/prover-client/package.json index 19f2aec28b8..fb946ce8d2b 100644 --- a/yarn-project/prover-client/package.json +++ b/yarn-project/prover-client/package.json @@ -26,9 +26,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/rollup-provider/package.json b/yarn-project/rollup-provider/package.json index 604418c7338..84d68c96dc8 100644 --- a/yarn-project/rollup-provider/package.json +++ b/yarn-project/rollup-provider/package.json @@ -28,9 +28,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/sequencer-client/package.json b/yarn-project/sequencer-client/package.json index f01cad17e1b..ab89bd8f455 100644 --- a/yarn-project/sequencer-client/package.json +++ b/yarn-project/sequencer-client/package.json @@ -28,9 +28,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/types/package.json b/yarn-project/types/package.json index dd636f1278d..6aaac90d5e8 100644 --- a/yarn-project/types/package.json +++ b/yarn-project/types/package.json @@ -26,9 +26,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": { diff --git a/yarn-project/world-state/package.json b/yarn-project/world-state/package.json index 46c1b9df210..36ae514d0ea 100644 --- a/yarn-project/world-state/package.json +++ b/yarn-project/world-state/package.json @@ -26,9 +26,9 @@ "jest": { "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { - "^(\\.{1,2}/.*)\\.js$": "$1" + "^(\\.{1,2}/.*)\\.m?js$": "$1" }, - "testRegex": "./src/.*\\.test\\.ts$", + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", "rootDir": "./src" }, "dependencies": {