@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.b655e406

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +61 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +261 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +73 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.js +311 -0
  7. package/dest/bench/client_flows/config.d.ts +14 -0
  8. package/dest/bench/client_flows/config.d.ts.map +1 -0
  9. package/dest/bench/client_flows/config.js +106 -0
  10. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  12. package/dest/bench/client_flows/data_extractor.js +99 -0
  13. package/dest/bench/utils.d.ts +10 -36
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +26 -66
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +20 -12
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +85 -57
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +18 -24
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +48 -69
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +14 -6
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +13 -19
  25. package/dest/e2e_epochs/epochs_test.d.ts +58 -17
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +224 -43
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  29. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  30. package/dest/e2e_fees/bridging_race.notest.js +63 -0
  31. package/dest/e2e_fees/fees_test.d.ts +20 -9
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +98 -107
  34. package/dest/e2e_l1_publisher/write_json.d.ts +10 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +57 -0
  37. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  38. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  39. package/dest/e2e_multi_validator/utils.js +214 -0
  40. package/dest/e2e_nested_contract/nested_contract_test.d.ts +9 -6
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +22 -19
  43. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.js +135 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +69 -22
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +180 -129
  49. package/dest/e2e_p2p/shared.d.ts +41 -5
  50. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  51. package/dest/e2e_p2p/shared.js +163 -19
  52. package/dest/e2e_token_contract/token_contract_test.d.ts +11 -5
  53. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  54. package/dest/e2e_token_contract/token_contract_test.js +50 -26
  55. package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +14 -9
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +95 -100
  58. package/dest/fixtures/fixtures.d.ts +5 -6
  59. package/dest/fixtures/fixtures.d.ts.map +1 -1
  60. package/dest/fixtures/fixtures.js +4 -3
  61. package/dest/fixtures/get_acvm_config.d.ts +1 -1
  62. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  63. package/dest/fixtures/get_acvm_config.js +2 -14
  64. package/dest/fixtures/get_bb_config.d.ts +1 -1
  65. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  66. package/dest/fixtures/get_bb_config.js +10 -17
  67. package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
  68. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  69. package/dest/fixtures/l1_to_l2_messaging.js +44 -18
  70. package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
  71. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  72. package/dest/fixtures/setup_l1_contracts.js +4 -4
  73. package/dest/fixtures/setup_p2p_test.d.ts +14 -13
  74. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  75. package/dest/fixtures/setup_p2p_test.js +73 -21
  76. package/dest/fixtures/snapshot_manager.d.ts +15 -7
  77. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  78. package/dest/fixtures/snapshot_manager.js +147 -121
  79. package/dest/fixtures/token_utils.d.ts +6 -3
  80. package/dest/fixtures/token_utils.d.ts.map +1 -1
  81. package/dest/fixtures/token_utils.js +23 -10
  82. package/dest/fixtures/utils.d.ts +76 -37
  83. package/dest/fixtures/utils.d.ts.map +1 -1
  84. package/dest/fixtures/utils.js +464 -368
  85. package/dest/fixtures/web3signer.d.ts +5 -0
  86. package/dest/fixtures/web3signer.d.ts.map +1 -0
  87. package/dest/fixtures/web3signer.js +53 -0
  88. package/dest/quality_of_service/alert_checker.d.ts +1 -1
  89. package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
  90. package/dest/shared/cross_chain_test_harness.d.ts +41 -25
  91. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  92. package/dest/shared/cross_chain_test_harness.js +104 -50
  93. package/dest/shared/gas_portal_test_harness.d.ts +32 -24
  94. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  95. package/dest/shared/gas_portal_test_harness.js +50 -29
  96. package/dest/shared/jest_setup.js +1 -1
  97. package/dest/shared/submit-transactions.d.ts +5 -3
  98. package/dest/shared/submit-transactions.d.ts.map +1 -1
  99. package/dest/shared/submit-transactions.js +8 -7
  100. package/dest/shared/uniswap_l1_l2.d.ts +13 -11
  101. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  102. package/dest/shared/uniswap_l1_l2.js +138 -108
  103. package/dest/simulators/lending_simulator.d.ts +6 -6
  104. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  105. package/dest/simulators/lending_simulator.js +13 -16
  106. package/dest/simulators/token_simulator.d.ts +5 -2
  107. package/dest/simulators/token_simulator.d.ts.map +1 -1
  108. package/dest/simulators/token_simulator.js +16 -13
  109. package/dest/spartan/setup_test_wallets.d.ts +23 -10
  110. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  111. package/dest/spartan/setup_test_wallets.js +167 -58
  112. package/dest/spartan/utils.d.ts +106 -303
  113. package/dest/spartan/utils.d.ts.map +1 -1
  114. package/dest/spartan/utils.js +434 -130
  115. package/package.json +61 -56
  116. package/src/bench/client_flows/benchmark.ts +341 -0
  117. package/src/bench/client_flows/client_flows_benchmark.ts +402 -0
  118. package/src/bench/client_flows/config.ts +61 -0
  119. package/src/bench/client_flows/data_extractor.ts +111 -0
  120. package/src/bench/utils.ts +22 -76
  121. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
  122. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +63 -105
  123. package/src/e2e_deploy_contract/deploy_test.ts +23 -38
  124. package/src/e2e_epochs/epochs_test.ts +274 -54
  125. package/src/e2e_fees/bridging_race.notest.ts +80 -0
  126. package/src/e2e_fees/fees_test.ts +137 -136
  127. package/src/e2e_l1_publisher/write_json.ts +76 -0
  128. package/src/e2e_multi_validator/utils.ts +258 -0
  129. package/src/e2e_nested_contract/nested_contract_test.ts +27 -18
  130. package/src/e2e_p2p/inactivity_slash_test.ts +178 -0
  131. package/src/e2e_p2p/p2p_network.ts +272 -166
  132. package/src/e2e_p2p/shared.ts +244 -29
  133. package/src/e2e_token_contract/token_contract_test.ts +43 -39
  134. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  135. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +101 -145
  136. package/src/fixtures/fixtures.ts +4 -3
  137. package/src/fixtures/get_acvm_config.ts +3 -11
  138. package/src/fixtures/get_bb_config.ts +18 -13
  139. package/src/fixtures/l1_to_l2_messaging.ts +53 -23
  140. package/src/fixtures/setup_l1_contracts.ts +6 -7
  141. package/src/fixtures/setup_p2p_test.ts +112 -38
  142. package/src/fixtures/snapshot_manager.ts +187 -139
  143. package/src/fixtures/token_utils.ts +29 -12
  144. package/src/fixtures/utils.ts +552 -425
  145. package/src/fixtures/web3signer.ts +63 -0
  146. package/src/guides/up_quick_start.sh +6 -14
  147. package/src/quality_of_service/alert_checker.ts +1 -1
  148. package/src/shared/cross_chain_test_harness.ts +108 -79
  149. package/src/shared/gas_portal_test_harness.ts +58 -49
  150. package/src/shared/jest_setup.ts +1 -1
  151. package/src/shared/submit-transactions.ts +12 -8
  152. package/src/shared/uniswap_l1_l2.ts +173 -176
  153. package/src/simulators/lending_simulator.ts +12 -15
  154. package/src/simulators/token_simulator.ts +21 -13
  155. package/src/spartan/DEVELOP.md +121 -0
  156. package/src/spartan/setup_test_wallets.ts +215 -93
  157. package/src/spartan/utils.ts +490 -130
  158. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  159. package/dest/sample-dapp/connect.js +0 -12
  160. package/dest/sample-dapp/contracts.js +0 -10
  161. package/dest/sample-dapp/deploy.js +0 -35
  162. package/dest/sample-dapp/index.js +0 -98
  163. package/src/sample-dapp/connect.mjs +0 -16
  164. package/src/sample-dapp/contracts.mjs +0 -14
  165. package/src/sample-dapp/deploy.mjs +0 -40
  166. package/src/sample-dapp/index.mjs +0 -128
@@ -0,0 +1,63 @@
1
+ import { randomBytes } from '@aztec/foundation/crypto';
2
+ import { retryUntil } from '@aztec/foundation/retry';
3
+ import { sleep } from '@aztec/foundation/sleep';
4
+ import { RemoteSigner } from '@aztec/node-keystore';
5
+
6
+ import { mkdirSync } from 'node:fs';
7
+ import { writeFile } from 'node:fs/promises';
8
+ import { join } from 'node:path';
9
+
10
+ export async function createWeb3SignerKeystore(dir: string, ...privateKeys: string[]) {
11
+ const yaml = privateKeys
12
+ .map(
13
+ pk => `\
14
+ type: file-raw
15
+ keyType: SECP256K1
16
+ privateKey: ${pk}`,
17
+ )
18
+ .join('\n---\n');
19
+
20
+ // NOTE: nodejs stdlib can only create temp directories, not temp files!
21
+ // this write uses wx (write-exclusive) so it'll throw if the file already exists
22
+ const path = join(dir, `keystore-${randomBytes(4).toString('hex')}.yaml`);
23
+ await writeFile(path, yaml, { flag: 'wx' });
24
+ }
25
+
26
+ export async function refreshWeb3Signer(url: string, ...expectedAddresses: string[]) {
27
+ await fetch(new URL('reload', url), { method: 'POST' });
28
+
29
+ if (expectedAddresses.length > 0) {
30
+ await retryUntil(
31
+ async () => {
32
+ try {
33
+ await RemoteSigner.validateAccess(url, expectedAddresses);
34
+ return true;
35
+ } catch {
36
+ return false;
37
+ }
38
+ },
39
+ 'web3signer refresh',
40
+ 10,
41
+ 0.5,
42
+ );
43
+ } else {
44
+ await sleep(1000);
45
+ }
46
+ }
47
+
48
+ export function getWeb3SignerTestKeystoreDir(): string {
49
+ if (process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR) {
50
+ mkdirSync(process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR, { recursive: true });
51
+ return process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR;
52
+ } else {
53
+ throw new Error('Web3signer not running');
54
+ }
55
+ }
56
+
57
+ export function getWeb3SignerUrl(): string {
58
+ if (process.env.WEB3_SIGNER_URL) {
59
+ return process.env.WEB3_SIGNER_URL;
60
+ } else {
61
+ throw new Error('Web3signer not running');
62
+ }
63
+ }
@@ -1,9 +1,10 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
  # Run locally from end-to-end folder while running anvil and sandbox with:
3
3
  # PATH=$PATH:../node_modules/.bin ./src/guides/up_quick_start.sh
4
4
  set -eux
5
5
 
6
6
  export WALLET_DATA_DIRECTORY=$(mktemp -d)/up_quick_start
7
+ export PXE_PROVER="none"
7
8
 
8
9
  function on_exit {
9
10
  echo "Cleaning up $WALLET_DATA_DIRECTORY..."
@@ -18,37 +19,28 @@ aztec-wallet() {
18
19
  aztec-wallet import-test-accounts
19
20
 
20
21
  # docs:start:declare-accounts
21
- aztec-wallet create-account -a alice --payment method=fee_juice,feePayer=test0
22
- aztec-wallet create-account -a bob --payment method=fee_juice,feePayer=test0
22
+ aztec-wallet create-account -a alice -f test0
23
+ aztec-wallet create-account -a bob -f test0
23
24
  # docs:end:declare-accounts
24
25
 
25
- # docs:start:deploy
26
26
  DEPLOY_OUTPUT=$(aztec-wallet deploy ../noir-contracts.js/artifacts/token_contract-Token.json --args accounts:test0 Test TST 18 -f test0)
27
27
  TOKEN_ADDRESS=$(echo "$DEPLOY_OUTPUT" | grep -oE 'Contract deployed at 0x[0-9a-fA-F]+' | cut -d ' ' -f4)
28
28
  echo "Deployed contract at $TOKEN_ADDRESS"
29
- # docs:end:deploy
30
29
 
31
- # docs:start:mint-private
32
30
  MINT_AMOUNT=69
33
- aztec-wallet send mint_to_private -ca last --args accounts:test0 accounts:alice $MINT_AMOUNT -f test0
34
- # docs:end:mint-private
31
+ aztec-wallet send mint_to_private -ca last --args accounts:alice $MINT_AMOUNT -f test0
35
32
 
36
- # docs:start:get-balance
37
33
  ALICE_BALANCE=$(aztec-wallet simulate balance_of_private -ca last --args accounts:alice -f alice)
38
34
  if ! echo $ALICE_BALANCE | grep -q $MINT_AMOUNT; then
39
35
  echo "Incorrect Alice balance after transaction (expected $MINT_AMOUNT but got $ALICE_BALANCE)"
40
36
  exit 1
41
37
  fi
42
- # docs:end:get-balance
43
38
 
44
- # docs:start:transfer
45
39
  TRANSFER_AMOUNT=42
46
40
 
47
41
  aztec-wallet create-authwit transfer_in_private accounts:test0 -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -f alice
48
- aztec-wallet add-authwit authwits:last alice -f test0
49
42
 
50
- aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -f test0
51
- # docs:end:transfer
43
+ aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -aw authwits:last -f test0
52
44
 
53
45
  # Test end result
54
46
  ALICE_BALANCE=$(aztec-wallet simulate balance_of_private -ca last --args accounts:alice -f alice)
@@ -1,4 +1,4 @@
1
- import type { Logger } from '@aztec/aztec.js';
1
+ import type { Logger } from '@aztec/aztec.js/log';
2
2
 
3
3
  import * as fs from 'fs';
4
4
  import * as yaml from 'js-yaml';
@@ -1,24 +1,21 @@
1
- // docs:start:cross_chain_test_harness
1
+ import type { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { EthAddress } from '@aztec/aztec.js/addresses';
3
+ import { AuthWitness } from '@aztec/aztec.js/authorization';
2
4
  import {
3
- type AccountWallet,
4
- type AztecAddress,
5
- type AztecNode,
6
- EthAddress,
7
- type FieldsOf,
8
- Fr,
9
5
  type L1TokenManager,
10
6
  L1TokenPortalManager,
11
7
  type L2AmountClaim,
12
8
  type L2AmountClaimWithRecipient,
13
- type Logger,
14
- type PXE,
15
- type SiblingPath,
16
- type TxReceipt,
17
- type Wallet,
18
- deployL1Contract,
19
- retryUntil,
20
- } from '@aztec/aztec.js';
21
- import type { L1ContractAddresses, ViemPublicClient, ViemWalletClient } from '@aztec/ethereum';
9
+ } from '@aztec/aztec.js/ethereum';
10
+ import { Fr } from '@aztec/aztec.js/fields';
11
+ import type { Logger } from '@aztec/aztec.js/log';
12
+ import type { AztecNode } from '@aztec/aztec.js/node';
13
+ import type { SiblingPath } from '@aztec/aztec.js/trees';
14
+ import type { TxReceipt } from '@aztec/aztec.js/tx';
15
+ import type { Wallet } from '@aztec/aztec.js/wallet';
16
+ import { type ExtendedViemWalletClient, type L1ContractAddresses, deployL1Contract } from '@aztec/ethereum';
17
+ import { retryUntil } from '@aztec/foundation/retry';
18
+ import type { FieldsOf } from '@aztec/foundation/types';
22
19
  import { TestERC20Abi, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts';
23
20
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
24
21
  import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
@@ -27,7 +24,6 @@ import { type Hex, getContract } from 'viem';
27
24
 
28
25
  import { mintTokensToPrivate } from '../fixtures/token_utils.js';
29
26
 
30
- // docs:start:deployAndInitializeTokenAndBridgeContracts
31
27
  /**
32
28
  * Deploy L1 token and portal, initialize portal, deploy a non native l2 token contract, its L2 bridge contract and attach is to the portal.
33
29
  * @param wallet - the wallet instance
@@ -40,8 +36,7 @@ import { mintTokensToPrivate } from '../fixtures/token_utils.js';
40
36
  */
41
37
  export async function deployAndInitializeTokenAndBridgeContracts(
42
38
  wallet: Wallet,
43
- walletClient: ViemWalletClient,
44
- publicClient: ViemPublicClient,
39
+ l1Client: ExtendedViemWalletClient,
45
40
  rollupRegistryAddress: EthAddress,
46
41
  owner: AztecAddress,
47
42
  underlyingERC20Address: EthAddress,
@@ -68,35 +63,34 @@ export async function deployAndInitializeTokenAndBridgeContracts(
68
63
  underlyingERC20: any;
69
64
  }> {
70
65
  // deploy the token portal
71
- const { address: tokenPortalAddress } = await deployL1Contract(
72
- walletClient,
73
- publicClient,
74
- TokenPortalAbi,
75
- TokenPortalBytecode,
76
- );
66
+ const { address: tokenPortalAddress } = await deployL1Contract(l1Client, TokenPortalAbi, TokenPortalBytecode);
77
67
  const tokenPortal = getContract({
78
68
  address: tokenPortalAddress.toString(),
79
69
  abi: TokenPortalAbi,
80
- client: walletClient,
70
+ client: l1Client,
81
71
  });
82
72
 
83
73
  // deploy l2 token
84
- const token = await TokenContract.deploy(wallet, owner, 'TokenName', 'TokenSymbol', 18).send().deployed();
74
+ const token = await TokenContract.deploy(wallet, owner, 'TokenName', 'TokenSymbol', 18)
75
+ .send({ from: owner })
76
+ .deployed();
85
77
 
86
78
  // deploy l2 token bridge and attach to the portal
87
- const bridge = await TokenBridgeContract.deploy(wallet, token.address, tokenPortalAddress).send().deployed();
79
+ const bridge = await TokenBridgeContract.deploy(wallet, token.address, tokenPortalAddress)
80
+ .send({ from: owner })
81
+ .deployed();
88
82
 
89
- if ((await token.methods.get_admin().simulate()) !== owner.toBigInt()) {
83
+ if ((await token.methods.get_admin().simulate({ from: owner })) !== owner.toBigInt()) {
90
84
  throw new Error(`Token admin is not ${owner}`);
91
85
  }
92
86
 
93
- if (!(await bridge.methods.get_config().simulate()).token.equals(token.address)) {
87
+ if (!(await bridge.methods.get_config().simulate({ from: owner })).token.equals(token.address)) {
94
88
  throw new Error(`Bridge token is not ${token.address}`);
95
89
  }
96
90
 
97
91
  // make the bridge a minter on the token:
98
- await token.methods.set_minter(bridge.address, true).send().wait();
99
- if ((await token.methods.is_minter(bridge.address).simulate()) === 1n) {
92
+ await token.methods.set_minter(bridge.address, true).send({ from: owner }).wait();
93
+ if ((await token.methods.is_minter(bridge.address).simulate({ from: owner })) === 1n) {
100
94
  throw new Error(`Bridge is not a minter`);
101
95
  }
102
96
 
@@ -109,12 +103,22 @@ export async function deployAndInitializeTokenAndBridgeContracts(
109
103
  const underlyingERC20 = getContract({
110
104
  address: underlyingERC20Address.toString(),
111
105
  abi: TestERC20Abi,
112
- client: walletClient,
106
+ client: l1Client,
113
107
  });
114
108
 
115
109
  return { token, bridge, tokenPortalAddress, tokenPortal, underlyingERC20 };
116
110
  }
117
- // docs:end:deployAndInitializeTokenAndBridgeContracts
111
+
112
+ export type CrossChainContext = {
113
+ l2Token: AztecAddress;
114
+ l2Bridge: AztecAddress;
115
+ tokenPortal: EthAddress;
116
+ underlying: EthAddress;
117
+ ethAccount: EthAddress;
118
+ ownerAddress: AztecAddress;
119
+ inbox: EthAddress;
120
+ outbox: EthAddress;
121
+ };
118
122
 
119
123
  /**
120
124
  * A Class for testing cross chain interactions, contains common interactions
@@ -123,54 +127,47 @@ export async function deployAndInitializeTokenAndBridgeContracts(
123
127
  export class CrossChainTestHarness {
124
128
  static async new(
125
129
  aztecNode: AztecNode,
126
- pxeService: PXE,
127
- publicClient: ViemPublicClient,
128
- walletClient: ViemWalletClient,
129
- wallet: AccountWallet,
130
+ l1Client: ExtendedViemWalletClient,
131
+ wallet: Wallet,
132
+ ownerAddress: AztecAddress,
130
133
  logger: Logger,
131
134
  underlyingERC20Address: EthAddress,
132
135
  ): Promise<CrossChainTestHarness> {
133
- const ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]);
134
- const l1ContractAddresses = (await pxeService.getNodeInfo()).l1ContractAddresses;
136
+ const ethAccount = EthAddress.fromString((await l1Client.getAddresses())[0]);
137
+ const l1ContractAddresses = (await aztecNode.getNodeInfo()).l1ContractAddresses;
135
138
 
136
139
  // Deploy and initialize all required contracts
137
140
  logger.info('Deploying and initializing token, portal and its bridge...');
138
141
  const { token, bridge, tokenPortalAddress, underlyingERC20 } = await deployAndInitializeTokenAndBridgeContracts(
139
142
  wallet,
140
- walletClient,
141
- publicClient,
143
+ l1Client,
142
144
  l1ContractAddresses.registryAddress,
143
- wallet.getAddress(),
145
+ ownerAddress,
144
146
  underlyingERC20Address,
145
147
  );
146
148
  logger.info('Deployed and initialized token, portal and its bridge.');
147
149
 
148
150
  return new CrossChainTestHarness(
149
151
  aztecNode,
150
- pxeService,
151
152
  logger,
152
153
  token,
153
154
  bridge,
154
155
  ethAccount,
155
156
  tokenPortalAddress,
156
157
  underlyingERC20.address,
157
- publicClient,
158
- walletClient,
158
+ l1Client,
159
159
  l1ContractAddresses,
160
160
  wallet,
161
+ ownerAddress,
161
162
  );
162
163
  }
163
164
 
164
165
  private readonly l1TokenManager: L1TokenManager;
165
166
  private readonly l1TokenPortalManager: L1TokenPortalManager;
166
167
 
167
- public readonly ownerAddress: AztecAddress;
168
-
169
168
  constructor(
170
169
  /** Aztec node instance. */
171
170
  public aztecNode: AztecNode,
172
- /** Private eXecution Environment (PXE). */
173
- public pxeService: PXE,
174
171
  /** Logger. */
175
172
  public logger: Logger,
176
173
 
@@ -186,32 +183,39 @@ export class CrossChainTestHarness {
186
183
  public tokenPortalAddress: EthAddress,
187
184
  /** Underlying token for portal tests. */
188
185
  public underlyingERC20Address: EthAddress,
189
- /** Viem Public client instance. */
190
- public publicClient: ViemPublicClient,
191
- /** Viem Wallet Client instance. */
192
- public walletClient: ViemWalletClient,
186
+ /** Viem Extended client instance. */
187
+ public l1Client: ExtendedViemWalletClient,
193
188
 
194
189
  /** Deployment addresses for all L1 contracts */
195
190
  public readonly l1ContractAddresses: L1ContractAddresses,
196
191
 
197
- /** Wallet of the owner. */
198
- public readonly ownerWallet: AccountWallet,
192
+ /** Wallet to simulate and send txs from. */
193
+ public readonly wallet: Wallet,
194
+
195
+ /** Owner of the l2 token and bridge */
196
+ public readonly ownerAddress: AztecAddress,
199
197
  ) {
200
198
  this.l1TokenPortalManager = new L1TokenPortalManager(
201
199
  this.tokenPortalAddress,
202
200
  this.underlyingERC20Address,
201
+ this.l1ContractAddresses.feeAssetHandlerAddress,
203
202
  this.l1ContractAddresses.outboxAddress,
204
- this.publicClient,
205
- this.walletClient,
203
+ this.l1Client,
206
204
  this.logger,
207
205
  );
208
206
  this.l1TokenManager = this.l1TokenPortalManager.getTokenManager();
209
- this.ownerAddress = this.ownerWallet.getAddress();
210
207
  }
211
208
 
212
209
  async mintTokensOnL1(amount: bigint) {
213
- await this.l1TokenManager.mint(amount, this.ethAccount.toString());
214
- expect(await this.l1TokenManager.getL1TokenBalance(this.ethAccount.toString())).toEqual(amount);
210
+ const contract = getContract({
211
+ abi: TestERC20Abi,
212
+ address: this.l1TokenManager.tokenAddress.toString(),
213
+ client: this.l1Client,
214
+ });
215
+ const balanceBefore = await this.l1TokenManager.getL1TokenBalance(this.ethAccount.toString());
216
+ const hash = await contract.write.mint([this.ethAccount.toString(), amount]);
217
+ await this.l1Client.waitForTransactionReceipt({ hash });
218
+ expect(await this.l1TokenManager.getL1TokenBalance(this.ethAccount.toString())).toEqual(balanceBefore + amount);
215
219
  }
216
220
 
217
221
  getL1BalanceOf(address: EthAddress) {
@@ -228,16 +232,19 @@ export class CrossChainTestHarness {
228
232
 
229
233
  async mintTokensPublicOnL2(amount: bigint) {
230
234
  this.logger.info('Minting tokens on L2 publicly');
231
- await this.l2Token.methods.mint_to_public(this.ownerAddress, amount).send().wait();
235
+ await this.l2Token.methods.mint_to_public(this.ownerAddress, amount).send({ from: this.ownerAddress }).wait();
232
236
  }
233
237
 
234
238
  async mintTokensPrivateOnL2(amount: bigint) {
235
- await mintTokensToPrivate(this.l2Token, this.ownerWallet, this.ownerAddress, amount);
239
+ await mintTokensToPrivate(this.l2Token, this.ownerAddress, this.ownerAddress, amount);
236
240
  }
237
241
 
238
242
  async sendL2PublicTransfer(transferAmount: bigint, receiverAddress: AztecAddress) {
239
243
  // send a transfer tx to force through rollup with the message included
240
- await this.l2Token.methods.transfer_in_public(this.ownerAddress, receiverAddress, transferAmount, 0).send().wait();
244
+ await this.l2Token.methods
245
+ .transfer_in_public(this.ownerAddress, receiverAddress, transferAmount, 0)
246
+ .send({ from: this.ownerAddress })
247
+ .wait();
241
248
  }
242
249
 
243
250
  async consumeMessageOnAztecAndMintPrivately(
@@ -247,7 +254,7 @@ export class CrossChainTestHarness {
247
254
  const { recipient, claimAmount, claimSecret: secretForL2MessageConsumption, messageLeafIndex } = claim;
248
255
  await this.l2Bridge.methods
249
256
  .claim_private(recipient, claimAmount, secretForL2MessageConsumption, messageLeafIndex)
250
- .send()
257
+ .send({ from: this.ownerAddress })
251
258
  .wait();
252
259
  }
253
260
 
@@ -258,23 +265,27 @@ export class CrossChainTestHarness {
258
265
  const { claimAmount, claimSecret, messageLeafIndex } = claim;
259
266
  await this.l2Bridge.methods
260
267
  .claim_public(this.ownerAddress, claimAmount, claimSecret, messageLeafIndex)
261
- .send()
268
+ .send({ from: this.ownerAddress })
262
269
  .wait();
263
270
  }
264
271
 
265
- async withdrawPrivateFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise<FieldsOf<TxReceipt>> {
272
+ async withdrawPrivateFromAztecToL1(
273
+ withdrawAmount: bigint,
274
+ authwitNonce: Fr = Fr.ZERO,
275
+ authWitness: AuthWitness,
276
+ ): Promise<FieldsOf<TxReceipt>> {
266
277
  const withdrawReceipt = await this.l2Bridge.methods
267
- .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce)
268
- .send()
278
+ .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, authwitNonce)
279
+ .send({ authWitnesses: [authWitness], from: this.ownerAddress })
269
280
  .wait();
270
281
 
271
282
  return withdrawReceipt;
272
283
  }
273
284
 
274
- async withdrawPublicFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise<FieldsOf<TxReceipt>> {
285
+ async withdrawPublicFromAztecToL1(withdrawAmount: bigint, authwitNonce: Fr = Fr.ZERO): Promise<FieldsOf<TxReceipt>> {
275
286
  const withdrawReceipt = await this.l2Bridge.methods
276
- .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce)
277
- .send()
287
+ .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, authwitNonce)
288
+ .send({ from: this.ownerAddress })
278
289
  .wait();
279
290
 
280
291
  return withdrawReceipt;
@@ -291,7 +302,7 @@ export class CrossChainTestHarness {
291
302
  }
292
303
 
293
304
  async getL2PublicBalanceOf(owner: AztecAddress) {
294
- return await this.l2Token.methods.balance_of_public(owner).simulate();
305
+ return await this.l2Token.methods.balance_of_public(owner).simulate({ from: this.ownerAddress });
295
306
  }
296
307
 
297
308
  async expectPublicBalanceOnL2(owner: AztecAddress, expectedBalance: bigint) {
@@ -299,8 +310,8 @@ export class CrossChainTestHarness {
299
310
  expect(balance).toBe(expectedBalance);
300
311
  }
301
312
 
302
- getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Fr {
303
- return this.l1TokenPortalManager.getL2ToL1MessageLeaf(
313
+ async getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Promise<Fr> {
314
+ return await this.l1TokenPortalManager.getL2ToL1MessageLeaf(
304
315
  withdrawAmount,
305
316
  this.ethAccount,
306
317
  this.l2Bridge.address,
@@ -325,12 +336,18 @@ export class CrossChainTestHarness {
325
336
 
326
337
  async transferToPrivateOnL2(shieldAmount: bigint) {
327
338
  this.logger.info('Transferring to private on L2');
328
- await this.l2Token.methods.transfer_to_private(this.ownerAddress, shieldAmount).send().wait();
339
+ await this.l2Token.methods
340
+ .transfer_to_private(this.ownerAddress, shieldAmount)
341
+ .send({ from: this.ownerAddress })
342
+ .wait();
329
343
  }
330
344
 
331
- async transferToPublicOnL2(amount: bigint, nonce = Fr.ZERO) {
345
+ async transferToPublicOnL2(amount: bigint, authwitNonce = Fr.ZERO) {
332
346
  this.logger.info('Transferring tokens to public');
333
- await this.l2Token.methods.transfer_to_public(this.ownerAddress, this.ownerAddress, amount, nonce).send().wait();
347
+ await this.l2Token.methods
348
+ .transfer_to_public(this.ownerAddress, this.ownerAddress, amount, authwitNonce)
349
+ .send({ from: this.ownerAddress })
350
+ .wait();
334
351
  }
335
352
 
336
353
  /**
@@ -348,5 +365,17 @@ export class CrossChainTestHarness {
348
365
  await this.mintTokensPublicOnL2(0n);
349
366
  await this.mintTokensPublicOnL2(0n);
350
367
  }
368
+
369
+ toCrossChainContext(): CrossChainContext {
370
+ return {
371
+ l2Token: this.l2Token.address,
372
+ l2Bridge: this.l2Bridge.address,
373
+ tokenPortal: this.tokenPortalAddress,
374
+ underlying: this.underlyingERC20Address,
375
+ ethAccount: this.ethAccount,
376
+ ownerAddress: this.ownerAddress,
377
+ inbox: this.l1ContractAddresses.inboxAddress,
378
+ outbox: this.l1ContractAddresses.outboxAddress,
379
+ };
380
+ }
351
381
  }
352
- // docs:end:cross_chain_test_harness