Skip to content

Commit 1c68e3b

Browse files
critesjoshcatmcgeebenesjan
authored
chore(docs): Update testing pages (AztecProtocol#3733)
- Update the dapp tutorial testing page to not reference the npm setup - Update the testing tutorials page to mention the debug options on waiting for a transaction closes AztecProtocol#2913 # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist). --------- Co-authored-by: Cat McGee <helloworld@mcgee.cat> Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
1 parent 5118d44 commit 1c68e3b

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

docs/docs/dev_docs/tutorials/testing.md

+14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ Instead of creating new accounts in our test suite, we can use the ones already
8080

8181
#include_code use-existing-wallets /yarn-project/end-to-end/src/guides/dapp_testing.test.ts typescript
8282

83+
### Using debug options
84+
85+
You can use the `debug` option in the `wait` method to get more information about the effects of the transaction. At the time of writing, this includes information about new note hashes added to the note hash tree, new nullifiers, public data writes, new L2 to L1 messages, new contract information and newly visible notes.
86+
87+
This debug information will be populated in the transaction receipt. You can log it to the console or use it to make assertions about the transaction.
88+
89+
If a note doesn't appear when you expect it to, check the visible notes returned by the debug options. See the following example for reference on how it's done in the token contract tests.
90+
91+
#include_code debug /yarn-project/end-to-end/src/e2e_token_contract.test.ts typescript
92+
93+
If the note appears in the visible notes and it contains the expected values there is probably an issue with how you fetch the notes. Check that the note getter (or note viewer) parameters are set correctly. If the note doesn't appear, ensure that you have emitted the corresponding encrypted log (usually by passing in a `broadcast = true` param to the `create_note` function). You can also check the Sandbox logs to see if the `emitEncryptedLog` was emitted. Run `export DEBUG="aztec:\*" before spinning up sandbox to see all the logs.
94+
95+
For debugging and logging in Aztec contracts, see [this page](../debugging/main.md).
96+
8397
## Assertions
8498

8599
We will now see how to use `aztec.js` to write assertions about transaction statuses, about chain state both public and private, and about logs.

docs/docs/dev_docs/tutorials/writing_dapp/testing.md

+23-7
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,33 @@ We'll need to [install and run the Sandbox](../../cli/sandbox-reference.md#insta
2121
Create a new file `src/index.test.mjs` with the imports we'll be using and an empty test suite to begin with:
2222

2323
```js
24-
import { Contract, createAccount } from "@aztec/aztec.js";
25-
import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" };
26-
27-
describe("token", () => {});
24+
import {
25+
Contract,
26+
ExtendedNote,
27+
Fr,
28+
Note,
29+
computeMessageSecretHash,
30+
createAccount,
31+
createPXEClient,
32+
waitForSandbox,
33+
} from "@aztec/aztec.js";
34+
import { TokenContractArtifact } from "@aztec/noir-contracts/artifacts";
35+
36+
const {
37+
PXE_URL = "http://localhost:8080",
38+
ETHEREUM_HOST = "http://localhost:8545",
39+
} = process.env;
40+
41+
describe("token contract", () => {});
2842
```
2943

30-
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:
44+
Let's set up our test suite. We'll make sure the Sandbox is running, create two fresh accounts to test with, and deploy an instance of our contract. `aztec.js` provides the helper functions we need to do this:
3145

3246
#include_code setup yarn-project/end-to-end/src/sample-dapp/index.test.mjs javascript
3347

34-
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.
48+
:::tip
49+
Instead of creating new accounts in our test suite, we can use the ones already initialized by the Sandbox upon startup. This can provide a speed boost to your tests setup. However, bear in mind that you may accidentally introduce an interdependency across test suites by reusing the same accounts. Read more [here](../testing.md#using-sandbox-initial-accounts).
50+
:::
3551

3652
## Writing our test
3753

@@ -43,7 +59,7 @@ In this example, we assert that the `recipient`'s balance is increased by the am
4359

4460
## Running our tests
4561

46-
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:
62+
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:
4763

4864
```sh
4965
yarn node --experimental-vm-modules $(yarn bin jest) --testRegex '.*\.test\.mjs$'

yarn-project/end-to-end/src/e2e_token_contract.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ describe('e2e_token_contract', () => {
172172
it('redeem as recipient', async () => {
173173
await addPendingShieldNoteToPXE(0, amount, secretHash, txHash);
174174
const txClaim = asset.methods.redeem_shield(accounts[0].address, amount, secret).send();
175+
// docs:start:debug
175176
const receiptClaim = await txClaim.wait({ debug: true });
177+
// docs:end:debug
176178
expect(receiptClaim.status).toBe(TxStatus.MINED);
177179
tokenSim.redeemShield(accounts[0].address, amount);
178180
// 1 note should be created containing `amount` of tokens

yarn-project/end-to-end/src/sample-dapp/index.test.mjs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
import { createSandbox } from '@aztec/aztec-sandbox';
2-
import { Contract, ExtendedNote, Fr, Note, computeMessageSecretHash, createAccount } from '@aztec/aztec.js';
2+
import {
3+
Contract,
4+
ExtendedNote,
5+
Fr,
6+
Note,
7+
computeMessageSecretHash,
8+
createAccount,
9+
createPXEClient,
10+
waitForSandbox,
11+
} from '@aztec/aztec.js';
312
import { TokenContractArtifact } from '@aztec/noir-contracts/artifacts';
413

14+
const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env;
15+
516
describe('token', () => {
617
// docs:start:setup
718
let pxe, stop, owner, recipient, token;
819
beforeAll(async () => {
9-
({ pxe, stop } = await createSandbox());
20+
const pxe = createPXEClient(PXE_URL);
21+
await waitForSandbox(pxe);
1022
owner = await createAccount(pxe);
1123
recipient = await createAccount(pxe);
1224

@@ -24,8 +36,6 @@ describe('token', () => {
2436

2537
await token.methods.redeem_shield({ address: owner.getAddress() }, initialBalance, secret).send().wait();
2638
}, 120_000);
27-
28-
afterAll(() => stop());
2939
// docs:end:setup
3040

3141
// docs:start:test

0 commit comments

Comments
 (0)