-
Notifications
You must be signed in to change notification settings - Fork 598
chore(docs): Fix token bridge tutorial #3935
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
Changes from all commits
37c9d7e
35d94f4
f10b91b
33a50bf
53160e5
7a3412d
5931960
2d5ca74
5a12b54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,12 @@ title: Deploy & Call Contracts with Typescript | |
|
|
||
| In this step we will write a Typescript test to interact with the sandbox and call our contracts! | ||
|
|
||
| Go to the `src/test` directory in your `packages` dir and create a new file called `cross_chain_messaging.test.ts`: | ||
|
|
||
| ```bash | ||
| cd src/test | ||
| touch cross_chain_messaging.test.ts | ||
| ``` | ||
|
|
||
| ## Test imports and setup | ||
|
|
||
| We need some helper files that can keep our code clean. Inside your `src/test` directory: | ||
|
|
||
| ```bash | ||
| mkdir fixtures && cd fixtures | ||
| cd fixtures | ||
| touch utils.ts | ||
| cd .. && mkdir shared && cd shared | ||
| touch cross_chain_test_harness.ts | ||
|
|
@@ -47,8 +40,8 @@ Open `cross_chain_messaging.test.ts` and paste the initial description of the te | |
|
|
||
| ```typescript | ||
| import { expect, jest} from '@jest/globals' | ||
| import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForPXE } from '@aztec/aztec.js'; | ||
| import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a heads up, I the name of this function will change back after the next release.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh. that's tomorrow then - maybe we should just keep it |
||
| import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForSandbox } from '@aztec/aztec.js'; | ||
| import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we update this code block to import code directly from the tests?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the tests themselves have a MUCH more complicated setup than the e2e code we use in the tutorials. it requires 4 extra files with a bunch of new imports. the tutorial setup code is not referenced anywhere else in the codebase the only solutions are to overcomplicate the tutorial or manually keep an eye on ~15 lines of code. i'm happy to test every release - it's all in devrel repo anyway
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok cool, works for me! |
||
| import { TokenContract } from '@aztec/noir-contracts/Token'; | ||
| import { TokenBridgeContract } from '@aztec/noir-contracts/TokenBridge'; | ||
|
|
||
|
|
@@ -80,8 +73,8 @@ describe('e2e_cross_chain_messaging', () => { | |
| beforeEach(async () => { | ||
| logger = createDebugLogger('aztec:e2e_uniswap'); | ||
| const pxe = createPXEClient(PXE_URL); | ||
| await waitForPXE(pxe); | ||
| const wallets = await getInitialTestAccountsWallets(pxe); | ||
| await waitForSandbox(pxe); | ||
| const wallets = await getSandboxAccountsWallets(pxe); | ||
|
|
||
| const walletClient = createWalletClient({ | ||
| account: hdAccount, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,8 +42,10 @@ For both the public and private flow, we use the same mechanism to determine the | |
| After the transaction is completed on L2, the portal must call the outbox to successfully transfer funds to the user on L1. Like with deposits, things can be complex here. For example, what happens if the transaction was done on L2 to burn tokens but can’t be withdrawn to L1? Then the funds are lost forever! How do we prevent this? | ||
|
|
||
| Paste this in your `TokenPortal.sol`: | ||
|
|
||
| #include_code token_portal_withdraw /l1-contracts/test/portals/TokenPortal.sol solidity | ||
| ```solidity | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? Running the docs locally, this removes the link to source at the bottom of the code snippet. Is it just for the closing curly brace? If so, I agree with the change. Do you think we should add a link to the source below the reference?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it's just for the closing curly brace. this contract is referenced a lot throughout the rest of the include_code snippets so im not sure we should reference - might be confusing, makes it seem like it's a new contract. wdyt?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok that makes sense. If there are links to source elsewhere, not a big deal. |
||
| #include_code token_portal_withdraw /l1-contracts/test/portals/TokenPortal.sol raw | ||
| } | ||
| ``` | ||
|
|
||
| Here we reconstruct the L2 to L1 message and check that this message exists on the outbox. If so, we consume it and transfer the funds to the recipient. As part of the reconstruction, the content hash looks similar to what we did in our bridge contract on aztec where we pass the amount and recipient to the the hash. This way a malicious actor can’t change the recipient parameter to the address and withdraw funds to themselves. | ||
|
|
||
|
|
@@ -53,13 +55,17 @@ We call this pattern _designed caller_ which enables a new paradigm **where we c | |
|
|
||
| Before we can compile and use the contract, we need to add two additional functions. | ||
|
|
||
| We need a function that let's us read the token value. | ||
| We need a function that lets us read the token value. Paste this into `main.nr`: | ||
|
|
||
| #include_code read_token /yarn-project/noir-contracts/contracts/token_bridge_contract/src/main.nr rust | ||
|
|
||
| And the `compute_note_hash_and_nullifier` required on every contract. | ||
| And the `compute_note_hash_and_nullifier` required on every contract: | ||
|
|
||
| ```rust | ||
| #include_code compute_note_hash_and_nullifier_placeholder /yarn-project/noir-contracts/contracts/token_bridge_contract/src/main.nr raw | ||
| } | ||
critesjosh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| #include_code compute_note_hash_and_nullifier_placeholder /yarn-project/noir-contracts/contracts/token_bridge_contract/src/main.nr rust | ||
|
|
||
| ## Compile code | ||
|
|
||
|
|
@@ -75,14 +81,14 @@ npx hardhat compile | |
| And compile your Aztec.nr contracts like this: | ||
|
|
||
| ```bash | ||
| cd aztec-contracts/token-bridge | ||
| cd aztec-contracts/token_bridge | ||
| aztec-nargo compile | ||
| ``` | ||
|
|
||
| And generate the TypeScript interface for the contract and add it to the test dir: | ||
|
|
||
| ```bash | ||
| aztec-cli codegen target -o ../../../src/test/fixtures --ts | ||
| aztec-cli codegen target -o ../../src/test/fixtures --ts | ||
| ``` | ||
|
|
||
| This will create a TS interface in our `src/test` folder! | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.