Skip to content

Commit

Permalink
chore: We can run 35 of our e2e tests just using jest. (#5643)
Browse files Browse the repository at this point in the history
It's overkill docker-composing and independently running our ever
increasing set of e2e tests.
This PR runs most of our e2e tests now as simple `jest test ./src/e2e`
run.
The "outliers" we still run with docker compose i moved to a `composed`
folder.
We maybe able to run some of these outliers as part of straight jest
test as well, but baby steps.
I reduce logging which felt mostly like spam anyway, just print
`aztec:e2e*`.
  • Loading branch information
charlielye authored Apr 12, 2024
1 parent d4ff340 commit 4fcaeae
Show file tree
Hide file tree
Showing 27 changed files with 81 additions and 639 deletions.
462 changes: 24 additions & 438 deletions .circleci/config.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build-system/scripts/cond_run_container
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ if ! check_rebuild $SUCCESS_TAG $REPOSITORY; then
# Login to pull our ecr images with docker.
retry ecr_login
retry docker pull $IMAGE_URI
docker run --rm -t $IMAGE_URI $@
docker run --rm $IMAGE_URI $@
retry tag_remote_image $REPOSITORY $BASE_TAG $SUCCESS_TAG
fi
9 changes: 5 additions & 4 deletions docs/docs/developers/aztecjs/guides/call_view_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ You can learn how to deploy a contract [here](./deploy_contract.md).

You will need to import this from Aztec.js:

#include_code import_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code import_contract yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

## Define contract

Get a previously deployed contract like this:

#include_code get_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code get_contract yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

## Simulating function calls

Call the `simulate` function on the typescript contract wrapper like this:

#include_code simulate_function yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code simulate_function yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

:::info Note

- If the simulated function is `unconstrained` you will get a properly typed value.
- If the simulated function is `public` or `private` it will return a Field array of size 4.
:::
:::
7 changes: 3 additions & 4 deletions docs/docs/developers/aztecjs/guides/create_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ To do this from the CLI, go [here](../../sandbox/references/cli-commands.md#crea

You will need to import these libraries:

#include_code create_account_imports yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code create_account_imports yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

## Define arguments needed

#include_code define_account_vars yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code define_account_vars yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

## Create the wallet with these args

#include_code create_wallet yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code create_wallet yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

Now you have a new wallet in your PXE! To learn how to use this wallet to deploy a contract, read [this guide](./deploy_contract.md).

8 changes: 4 additions & 4 deletions docs/docs/developers/aztecjs/guides/deploy_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ You can read about contract artifacts [here](../../contracts/compiling_contracts

## Import the contract artifact

In this guide we are using a Token contract artifact. This comes from the [token contract tutorial](../../tutorials/writing_token_contract.md).
In this guide we are using a Token contract artifact. This comes from the [token contract tutorial](../../tutorials/writing_token_contract.md).

#include_code import_token_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code import_token_contract yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

## Deploy contract

#include_code deploy_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code deploy_contract yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

To learn how to send a transaction from Aztec.js read [this guide](./send_transaction.md). You can also call a `view` function from Aztec.js by reading [this guide](./call_view_function.md).
To learn how to send a transaction from Aztec.js read [this guide](./send_transaction.md). You can also call a `view` function from Aztec.js by reading [this guide](./call_view_function.md).
6 changes: 3 additions & 3 deletions docs/docs/developers/aztecjs/guides/send_transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ You can learn how to deploy a contract [here](./deploy_contract.md).

You will need to import this library:

#include_code import_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code import_contract yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

## Define contract

Get a previously deployed contract like this:

#include_code get_contract yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code get_contract yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript

## Call method

#include_code send_transaction yarn-project/end-to-end/src/docs_examples.test.ts typescript
#include_code send_transaction yarn-project/end-to-end/src/composed/docs_examples.test.ts typescript
14 changes: 7 additions & 7 deletions docs/docs/developers/getting_started/aztecjs-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ yarn add @aztec/aztec.js @aztec/accounts @aztec/noir-contracts.js typescript @ty
6. Create an `index.ts` file in the `src` directory with the following sandbox connection setup:

```ts
#include_code imports /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts raw
#include_code imports /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts raw

async function main() {
#include_code setup /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts raw
#include_code setup /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts raw
}

main();
Expand Down Expand Up @@ -147,7 +147,7 @@ Great! The Sandbox is running and we are able to interact with it.

The sandbox is preloaded with multiple accounts so you don't have to sit and create them. Let's load these accounts. Add this code to the `main()` function in `index.ts` below the code that's there:

#include_code load_accounts /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript
#include_code load_accounts /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts typescript

An explanation on accounts on Aztec can be found [here](../../learn/concepts/accounts/main.md).

Expand All @@ -157,7 +157,7 @@ If you want more accounts, you can find instructions in the [Account creation se

Now that we have our accounts loaded, let's move on to deploy our pre-compiled token smart contract. You can find the full code for the contract [here](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts/token_contract/src). Add this to `index.ts` below the code you added earlier:

#include_code Deployment /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript
#include_code Deployment /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts typescript

`yarn start` will now give something like this:

Expand Down Expand Up @@ -205,7 +205,7 @@ A token contract wouldn't be very useful if you aren't able to query the balance

Call the `balance_of_private` function using the following code (paste this):

#include_code Balance /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript
#include_code Balance /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts typescript

Running now should yield output:

Expand Down Expand Up @@ -263,7 +263,7 @@ Now lets transfer some funds from Alice to Bob by calling the `transfer` functio

Here is the Typescript code to call the `transfer` function, add this to your `index.ts` at the bottom of the `main` function:

#include_code Transfer /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript
#include_code Transfer /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts typescript

Our output should now look like this:

Expand Down Expand Up @@ -316,7 +316,7 @@ To make the note spendable the note has to be redeemed. A user can do that by ca

Let's now use these functions to mint some tokens to Bob's account using Typescript, add this to `index.ts`:

#include_code Mint /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript
#include_code Mint /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts typescript

Our complete output should now be something like:

Expand Down
16 changes: 8 additions & 8 deletions docs/docs/developers/sandbox/references/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ You can find more information about compiling contracts [on this page](../../con

The first thing we want to do is create a couple of accounts. We will use the `create-account` command which will generate a new private key for us, register the account on the sandbox, and deploy a simple account contract which [uses a single key for privacy and authentication](../../../learn/concepts/accounts/keys.md):

#include_code create-account yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
#include_code create-account yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts bash

Once the account is set up, the CLI returns the resulting address, its privacy key, and partial address. You can read more about these [here](../../../learn/concepts/accounts/keys.md#addresses-partial-addresses-and-public-keys).

Expand All @@ -62,13 +62,13 @@ export PRIVATE_KEY=<Private key printed when you run the command>

Alternatively, we can also manually generate a private key and use it for creating the account, either via a `-k` option or by setting the `PRIVATE_KEY` environment variable.

#include_code create-account-from-private-key yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
#include_code create-account-from-private-key yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts bash

For all commands that require a user's private key, the CLI will look for the `PRIVATE_KEY` environment variable in absence of an optional argument.

Let's double check that the accounts have been registered with the sandbox using the `get-accounts` command:

#include_code get-accounts yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
#include_code get-accounts yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts bash

You will see that a number of accounts exist that we did not create. The Sandbox initializes itself with 3 default accounts. Save one of the printed accounts (not the one that you generated above) in an environment variable. We will use it later.

Expand All @@ -81,7 +81,7 @@ export ADDRESS2=<Account address printed by the above command>
We will now deploy a token contract using the `deploy` command, and set an address of the admin via a constructor argument. You can find the contract we are deploying [here](https://github.com/AztecProtocol/aztec-packages/blob/master/noir-projects/noir-contracts/contracts/token_contract/src/main.nr) (or write it for yourself in [this tutorial!](../../tutorials/writing_token_contract.md))
Make sure to replace this address with one of the two you created earlier.

#include_code deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
#include_code deploy yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts bash

Save the contract address as an environment variable. We will use it later.

Expand All @@ -93,7 +93,7 @@ export CONTRACT_ADDRESS=<Your new contract address>

The CLI tells us that the contract was successfully deployed. We can use the `check-deploy` command to verify that a contract has been successfully deployed to that address:

#include_code check-deploy yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
#include_code check-deploy yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts bash

## Sending a Transaction

Expand All @@ -106,19 +106,19 @@ The `send` command expect the function name as the first unnamed argument and th
- `--contract-address` - The deployed address of the contract to call.
- `--private-key` - The private key of the sender.

#include_code send yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
#include_code send yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts bash

We called the [`mint_public`](https://github.com/AztecProtocol/aztec-packages/blob/87fa621347e55f82e36c70515c1824161eee5282/noir-projects/noir-contracts/contracts/token_contract/src/main.nr#L157C10-L157C10) function and provided it with the 2 arguments it expects: the recipient's address and the amount to be minted. Make sure to replace all addresses in this command with yours.

The command output tells us the details of the transaction such as its hash and status. We can use this hash to query the receipt of the transaction at a later time:

#include_code get-tx-receipt yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
#include_code get-tx-receipt yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts bash

## Calling an Unconstrained (View) Function

Now that the `mint_public` tx has been settled we can call the `balance_of_public` unconstrained function:

#include_code call yarn-project/end-to-end/src/cli_docs_sandbox.test.ts bash
#include_code call yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts bash

The `call` command calls a read-only method on a contract, one that will not generate a transaction to be sent to the network. The arguments here are:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,6 @@ TokenContractArtifact
UniswapContractArtifact
```

> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/master//yarn-project/end-to-end/src/cli_docs_sandbox.test.ts#L95-L118" target="_blank" rel="noopener noreferrer">Source code: /yarn-project/end-to-end/src/cli_docs_sandbox.test.ts#L95-L118</a></sub></sup>
> <sup><sub><a href="https://github.com/AztecProtocol/aztec-packages/blob/master//yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts#L95-L118" target="_blank" rel="noopener noreferrer">Source code: /yarn-project/end-to-end/src/composed/cli_docs_sandbox.test.ts#L95-L118</a></sub></sup>
You can see all of our example contracts in the monorepo [here](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts).
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const hdAccount = mnemonicToAccount(MNEMONIC);
const expectedForkBlockNumber = 17514288;

#include_code uniswap_l1_l2_test_setup_const yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts raw
#include_code uniswap_setup yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts raw
#include_code uniswap_setup yarn-project/end-to-end/src/composed/uniswap_trade_on_l1_from_l2.test.ts raw
#include_code uniswap_l1_l2_test_beforeAll yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts raw
```

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/developers/wallets/creating_schnorr_accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Let's assume you have a file `src/index.ts` from the example used in the Sandbox

1. Import relevant modules:

#include_code imports /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript
#include_code imports /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts typescript

2. Code to create an account. You must run this inside of a function:

#include_code create_accounts /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript
#include_code create_accounts /yarn-project/end-to-end/src/composed/e2e_sandbox_example.test.ts typescript

3. Running `yarn start` should now output:

Expand Down
Loading

0 comments on commit 4fcaeae

Please sign in to comment.