Skip to content

Commit

Permalink
fix(docs): Update token bridge tutorial (#6809)
Browse files Browse the repository at this point in the history
This PR orders the pages in the token bridge tutorial and adds some
necessary imports that weren't there before. It also adds the code to
publicly deploy account contracts to the typescript setup code.

---------

Co-authored-by: José Pedro Sousa <[email protected]>
  • Loading branch information
critesjosh and signorecello authored Jun 4, 2024
1 parent 5f00f17 commit 2a3a098
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Note that while the `secret` and the `content` are both hashed, they are actuall

### Token bridge example

Computing the `content` must currently be done manually, as we are still adding a number of bytes utilities. A good example exists within the [Token bridge example](../../../../tutorials/contract_tutorials/advanced/token_bridge/minting_on_aztec.md#consume-the-l1-message).
Computing the `content` must currently be done manually, as we are still adding a number of bytes utilities. A good example exists within the [Token bridge example](../../../../tutorials/contract_tutorials/advanced/token_bridge/2_minting_on_aztec.md#consume-the-l1-message).

#include_code claim_public /noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr rust

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ touch cross_chain_test_harness.ts

In `cross_chain_test_harness.ts`, add:

#include_code cross_chain_test_harness /yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts typescript
```ts
import { expect } from '@jest/globals'
#include_code cross_chain_test_harness /yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts raw
```

This

Expand All @@ -35,27 +38,44 @@ We will write two tests:
Open `cross_chain_messaging.test.ts` and paste the initial description of the test:

```typescript
import { expect, jest} from '@jest/globals'
import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForPXE } from '@aztec/aztec.js';
import { beforeAll, describe, beforeEach, expect, jest, it} from '@jest/globals'
import { AccountWallet, AztecAddress, BatchCall, type DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForPXE, L1ToL2Message, L1Actor, L2Actor, type Wallet } from '@aztec/aztec.js';
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
import { TokenContract } from '@aztec/noir-contracts.js/Token';
import { sha256ToField } from '@aztec/foundation/crypto';
import { TokenBridgeContract } from './fixtures/TokenBridge.js';
import { createAztecNodeClient } from '@aztec/circuit-types';
import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment';
import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';


import { CrossChainTestHarness } from './shared/cross_chain_test_harness.js';
import { mnemonicToAccount } from 'viem/accounts';
import { createPublicClient, createWalletClient, http } from 'viem';
import { createPublicClient, createWalletClient, http, toFunctionSelector } from 'viem';
import { foundry } from 'viem/chains';

const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env;
const MNEMONIC = 'test test test test test test test test test test test junk';
const hdAccount = mnemonicToAccount(MNEMONIC);
const aztecNode = createAztecNodeClient(PXE_URL);
export const NO_L1_TO_L2_MSG_ERROR =
/No non-nullified L1 to L2 message found for message hash|Tried to consume nonexistent L1-to-L2 message/;

async function publicDeployAccounts(sender: Wallet, accountsToDeploy: Wallet[]) {
const accountAddressesToDeploy = accountsToDeploy.map(a => a.getAddress());
const instances = await Promise.all(accountAddressesToDeploy.map(account => sender.getContractInstance(account)));
const batch = new BatchCall(sender, [
(await registerContractClass(sender, SchnorrAccountContractArtifact)).request(),
...instances.map(instance => deployInstance(sender, instance!).request()),
]);
await batch.send().wait();
}

describe('e2e_cross_chain_messaging', () => {
jest.setTimeout(90_000);

let logger: DebugLogger;
let wallets: AccountWallet[];
let user1Wallet: AccountWallet;
let user2Wallet: AccountWallet;
let ethAccount: EthAddress;
Expand All @@ -66,11 +86,20 @@ describe('e2e_cross_chain_messaging', () => {
let l2Bridge: TokenBridgeContract;
let outbox: any;

beforeAll(async () => {
logger = createDebugLogger('aztec:e2e_uniswap');
const pxe = createPXEClient(PXE_URL);
await waitForPXE(pxe);
wallets = await getInitialTestAccountsWallets(pxe);

// deploy the accounts publicly to use public authwits
await publicDeployAccounts(wallets[0], wallets);
})

beforeEach(async () => {
logger = createDebugLogger('aztec:e2e_uniswap');
const pxe = createPXEClient(PXE_URL);
await waitForPXE(pxe);
const wallets = await getInitialTestAccountsWallets(pxe);

const walletClient = createWalletClient({
account: hdAccount,
Expand Down Expand Up @@ -98,7 +127,6 @@ describe('e2e_cross_chain_messaging', () => {
outbox = crossChainTestHarness.outbox;
user1Wallet = wallets[0];
user2Wallet = wallets[1];
logger = logger;
logger('Successfully deployed contracts and initialized portal');
});
```
Expand All @@ -107,11 +135,18 @@ This fetches the wallets from the sandbox and deploys our cross chain harness on
## Private flow test
Paste the private flow test below the setup:
#include_code e2e_private_cross_chain /yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts typescript
## Public flow test
#include_code e2e_public_cross_chain /yarn-project/end-to-end/src/e2e_public_cross_chain_messaging/deposits.test.ts typescript
Paste the public flow below the private flow:
```ts
#include_code e2e_public_cross_chain /yarn-project/end-to-end/src/e2e_public_cross_chain_messaging/deposits.test.ts raw
})
```

## Running the test

Expand Down

0 comments on commit 2a3a098

Please sign in to comment.