Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: convert quick start guides into e2e tests #1726

Merged
merged 20 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ jobs:
command: ./scripts/cond_run_script end-to-end $JOB_NAME ./scripts/run_tests_local e2e_lending_contract.test.ts
working_directory: yarn-project/end-to-end

e2e-zk-token-contract:
e2e-private-token-contract:
machine:
image: ubuntu-2004:202010-01
resource_class: large
Expand All @@ -715,6 +715,17 @@ jobs:
command: ./scripts/cond_run_script end-to-end $JOB_NAME ./scripts/run_tests_local e2e_private_token_contract.test.ts
working_directory: yarn-project/end-to-end

e2e-sandbox-example:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: cond_spot_run_tests end-to-end e2e_sandbox_example.test.ts docker-compose-e2e-sandbox.yml

e2e-multi-transfer-contract:
docker:
- image: aztecprotocol/alpine-build-image
Expand Down Expand Up @@ -1310,7 +1321,8 @@ workflows:
- e2e-2-rpc-servers: *e2e_test
- e2e-deploy-contract: *e2e_test
- e2e-lending-contract: *e2e_test
- e2e-zk-token-contract: *e2e_test
- e2e-private-token-contract: *e2e_test
- e2e-sandbox-example: *e2e_test
- e2e-multi-transfer-contract: *e2e_test
- e2e-block-building: *e2e_test
- e2e-nested-contract: *e2e_test
Expand Down Expand Up @@ -1338,7 +1350,8 @@ workflows:
- e2e-2-rpc-servers
- e2e-deploy-contract
- e2e-lending-contract
- e2e-zk-token-contract
- e2e-private-token-contract
- e2e-sandbox-example
- e2e-multi-transfer-contract
- e2e-block-building
- e2e-nested-contract
Expand Down
20 changes: 12 additions & 8 deletions docs/docs/dev_docs/getting_started/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,13 @@ Add a `tsconfig.json` file into the project root, here is an example:
yarn add @aztec/aztec.js @aztec/noir-contracts
```

7. Create an `index.ts` file in the `src` directory and add the following snippet
7. Create an `index.ts` file in the `src` directory and add the following imports:

#include_code index /docs/src/code_examples/sandbox_example.ts typescript
#include_code imports /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

and the following setup code:

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

8. Finally, run the package:

Expand All @@ -198,7 +202,7 @@ The next step is to create some accounts. An in-depth explaining about accounts

Continue with adding the following to the `index.ts` file in our example:

#include_code Accounts /docs/src/code_examples/sandbox_example.ts typescript
#include_code Accounts /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

Running `yarn start` should now output:

Expand All @@ -224,7 +228,7 @@ If you were looking at your terminal that is running the Sandbox you should hope

Now that we have our accounts setup, let's move on to deploy our private token contract. Add this to `index.ts`:

#include_code Deployment /docs/src/code_examples/sandbox_example.ts typescript
#include_code Deployment /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

`yarn start` will now give the following output:

Expand Down Expand Up @@ -252,7 +256,7 @@ The Private Token Contract emits an unencrypted log message during construction:

We can retrieve this emitted log using the `getUnencryptedLogs()` api:

#include_code Logs /docs/src/code_examples/sandbox_example.ts typescript
#include_code Logs /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

Our output will now be:

Expand All @@ -278,7 +282,7 @@ A token contract wouldn't be very useful if you aren't able to query the balance

Call this function using the following code:

#include_code Balance /docs/src/code_examples/sandbox_example.ts typescript
#include_code Balance /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

Running now should yield output:

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

We will again view the unencrypted logs emitted by the function and check the balances after the transfer:

#include_code Transfer /docs/src/code_examples/sandbox_example.ts typescript
#include_code Transfer /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

Our output should now look like this:

Expand Down Expand Up @@ -346,7 +350,7 @@ Finally, the contract has a `mint` function that can be used to generate new tok

Let's mint some tokens to Bob's account:

#include_code Mint /docs/src/code_examples/sandbox_example.ts typescript
#include_code Mint /yarn-project/end-to-end/src/e2e_sandbox_example.test.ts typescript

Our complete output should now be:

Expand Down
151 changes: 0 additions & 151 deletions docs/src/code_examples/sandbox_example.ts

This file was deleted.

1 change: 1 addition & 0 deletions yarn-project/end-to-end/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/e2e_sandbox_example.test.ts
6 changes: 3 additions & 3 deletions yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('e2e_2_rpc_servers', () => {
await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance);
await expectTokenBalance(walletB, tokenAddress, userB.address, 0n);
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Balance set in constructor']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Balance set in constructor']);

// Transfer funds from A to B via RPC server A
const contractWithWalletA = await PrivateTokenContract.at(tokenAddress, walletA);
Expand All @@ -130,7 +130,7 @@ describe('e2e_2_rpc_servers', () => {
await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1);
await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1);
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Coins transferred']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Coins transferred']);

// Transfer funds from B to A via RPC server B
const contractWithWalletB = await PrivateTokenContract.at(tokenAddress, walletB);
Expand All @@ -147,7 +147,7 @@ describe('e2e_2_rpc_servers', () => {
await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1 + transferAmount2);
await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1 - transferAmount2);
await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Coins transferred']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServerA, ['Coins transferred']);
}, 120_000);

const deployChildContractViaServerA = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => {
}

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Coins transferred']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins transferred']);

logger(`Transfer ${transferAmount} from ${sender} to ${receiver} successful`);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('e2e_private_token_contract', () => {
await expectBalance(receiver, 0n);

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Balance set in constructor']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Balance set in constructor']);
}, 30_000);

/**
Expand All @@ -81,7 +81,7 @@ describe('e2e_private_token_contract', () => {
await expectBalance(owner, mintAmount);

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Coins minted']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins minted']);
}, 60_000);

/**
Expand All @@ -97,7 +97,7 @@ describe('e2e_private_token_contract', () => {
await expectBalance(receiver, 0n);

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Balance set in constructor']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Balance set in constructor']);

const tx = contract.methods.transfer(transferAmount, owner, receiver).send({ origin: owner });

Expand All @@ -110,6 +110,6 @@ describe('e2e_private_token_contract', () => {
await expectBalance(receiver, transferAmount);

await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2);
await expectUnencryptedLogsFromLastBlockToBe(aztecNode, ['Coins transferred']);
await expectUnencryptedLogsFromLastBlockToBe(aztecRpcServer, ['Coins transferred']);
}, 60_000);
});
Loading