@aztec/end-to-end 0.0.0-test.1 → 0.0.1-fake-ceab37513c

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 (156) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +60 -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 +69 -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 +315 -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 -27
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +27 -43
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +15 -7
  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 +66 -38
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +10 -18
  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 +34 -53
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -2
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +9 -6
  25. package/dest/e2e_epochs/epochs_test.d.ts +56 -17
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +222 -42
  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 +60 -0
  31. package/dest/e2e_fees/fees_test.d.ts +16 -5
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +87 -88
  34. package/dest/e2e_l1_publisher/write_json.d.ts +8 -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 +5 -5
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +19 -14
  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 +132 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +56 -21
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +154 -125
  49. package/dest/e2e_p2p/shared.d.ts +41 -3
  50. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  51. package/dest/e2e_p2p/shared.js +146 -6
  52. package/dest/e2e_token_contract/token_contract_test.d.ts +10 -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 +51 -24
  55. package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +7 -4
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +67 -62
  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.map +1 -1
  62. package/dest/fixtures/get_acvm_config.js +2 -14
  63. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  64. package/dest/fixtures/get_bb_config.js +8 -15
  65. package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
  66. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  67. package/dest/fixtures/l1_to_l2_messaging.js +44 -18
  68. package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
  69. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  70. package/dest/fixtures/setup_l1_contracts.js +3 -3
  71. package/dest/fixtures/setup_p2p_test.d.ts +14 -6
  72. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  73. package/dest/fixtures/setup_p2p_test.js +73 -21
  74. package/dest/fixtures/snapshot_manager.d.ts +8 -3
  75. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  76. package/dest/fixtures/snapshot_manager.js +120 -104
  77. package/dest/fixtures/token_utils.d.ts +4 -3
  78. package/dest/fixtures/token_utils.d.ts.map +1 -1
  79. package/dest/fixtures/token_utils.js +24 -7
  80. package/dest/fixtures/utils.d.ts +65 -22
  81. package/dest/fixtures/utils.d.ts.map +1 -1
  82. package/dest/fixtures/utils.js +439 -318
  83. package/dest/fixtures/web3signer.d.ts +5 -0
  84. package/dest/fixtures/web3signer.d.ts.map +1 -0
  85. package/dest/fixtures/web3signer.js +42 -0
  86. package/dest/shared/cross_chain_test_harness.d.ts +28 -18
  87. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  88. package/dest/shared/cross_chain_test_harness.js +97 -41
  89. package/dest/shared/gas_portal_test_harness.d.ts +23 -18
  90. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  91. package/dest/shared/gas_portal_test_harness.js +43 -25
  92. package/dest/shared/submit-transactions.d.ts.map +1 -1
  93. package/dest/shared/uniswap_l1_l2.d.ts +5 -6
  94. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  95. package/dest/shared/uniswap_l1_l2.js +136 -90
  96. package/dest/simulators/lending_simulator.d.ts +5 -6
  97. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  98. package/dest/simulators/lending_simulator.js +11 -15
  99. package/dest/simulators/token_simulator.d.ts +2 -1
  100. package/dest/simulators/token_simulator.d.ts.map +1 -1
  101. package/dest/simulators/token_simulator.js +16 -13
  102. package/dest/spartan/setup_test_wallets.d.ts +8 -1
  103. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  104. package/dest/spartan/setup_test_wallets.js +108 -22
  105. package/dest/spartan/utils.d.ts +60 -307
  106. package/dest/spartan/utils.d.ts.map +1 -1
  107. package/dest/spartan/utils.js +200 -115
  108. package/package.json +60 -56
  109. package/src/bench/client_flows/benchmark.ts +341 -0
  110. package/src/bench/client_flows/client_flows_benchmark.ts +422 -0
  111. package/src/bench/client_flows/config.ts +61 -0
  112. package/src/bench/client_flows/data_extractor.ts +111 -0
  113. package/src/bench/utils.ts +26 -52
  114. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +60 -40
  115. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +47 -75
  116. package/src/e2e_deploy_contract/deploy_test.ts +11 -8
  117. package/src/e2e_epochs/epochs_test.ts +276 -54
  118. package/src/e2e_fees/bridging_race.notest.ts +75 -0
  119. package/src/e2e_fees/fees_test.ts +121 -108
  120. package/src/e2e_l1_publisher/write_json.ts +74 -0
  121. package/src/e2e_multi_validator/utils.ts +258 -0
  122. package/src/e2e_nested_contract/nested_contract_test.ts +22 -14
  123. package/src/e2e_p2p/inactivity_slash_test.ts +174 -0
  124. package/src/e2e_p2p/p2p_network.ts +212 -144
  125. package/src/e2e_p2p/shared.ts +234 -14
  126. package/src/e2e_token_contract/token_contract_test.ts +42 -38
  127. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  128. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +62 -69
  129. package/src/fixtures/fixtures.ts +4 -3
  130. package/src/fixtures/get_acvm_config.ts +2 -10
  131. package/src/fixtures/get_bb_config.ts +15 -11
  132. package/src/fixtures/l1_to_l2_messaging.ts +53 -23
  133. package/src/fixtures/setup_l1_contracts.ts +5 -6
  134. package/src/fixtures/setup_p2p_test.ts +112 -30
  135. package/src/fixtures/snapshot_manager.ts +150 -102
  136. package/src/fixtures/token_utils.ts +33 -8
  137. package/src/fixtures/utils.ts +530 -352
  138. package/src/fixtures/web3signer.ts +46 -0
  139. package/src/guides/up_quick_start.sh +4 -4
  140. package/src/shared/cross_chain_test_harness.ts +92 -52
  141. package/src/shared/gas_portal_test_harness.ts +47 -31
  142. package/src/shared/uniswap_l1_l2.ts +127 -124
  143. package/src/simulators/lending_simulator.ts +11 -15
  144. package/src/simulators/token_simulator.ts +17 -12
  145. package/src/spartan/DEVELOP.md +116 -0
  146. package/src/spartan/setup_test_wallets.ts +144 -29
  147. package/src/spartan/utils.ts +194 -116
  148. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  149. package/dest/sample-dapp/connect.js +0 -12
  150. package/dest/sample-dapp/contracts.js +0 -10
  151. package/dest/sample-dapp/deploy.js +0 -35
  152. package/dest/sample-dapp/index.js +0 -98
  153. package/src/sample-dapp/connect.mjs +0 -16
  154. package/src/sample-dapp/contracts.mjs +0 -14
  155. package/src/sample-dapp/deploy.mjs +0 -40
  156. package/src/sample-dapp/index.mjs +0 -128
@@ -0,0 +1,46 @@
1
+ import { sleep } from '@aztec/aztec.js';
2
+ import { randomBytes } from '@aztec/foundation/crypto';
3
+
4
+ import { mkdirSync } from 'node:fs';
5
+ import { writeFile } from 'node:fs/promises';
6
+ import { join } from 'node:path';
7
+
8
+ export async function createWeb3SignerKeystore(dir: string, ...privateKeys: string[]) {
9
+ const yaml = privateKeys
10
+ .map(
11
+ pk => `\
12
+ type: file-raw
13
+ keyType: SECP256K1
14
+ privateKey: ${pk}`,
15
+ )
16
+ .join('\n---\n');
17
+
18
+ // NOTE: nodejs stdlib can only create temp directories, not temp files!
19
+ // this write uses wx (write-exclusive) so it'll throw if the file already exists
20
+ const path = join(dir, `keystore-${randomBytes(4).toString('hex')}.yaml`);
21
+ await writeFile(path, yaml, { flag: 'wx' });
22
+ }
23
+
24
+ export async function refreshWeb3Signer(url: string) {
25
+ await fetch(new URL('reload', url), { method: 'POST' });
26
+ // give the service a chance to load up the new files
27
+ // 1s might not be enough if there are a lot of files to scan
28
+ await sleep(1000);
29
+ }
30
+
31
+ export function getWeb3SignerTestKeystoreDir(): string {
32
+ if (process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR) {
33
+ mkdirSync(process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR, { recursive: true });
34
+ return process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR;
35
+ } else {
36
+ throw new Error('Web3signer not running');
37
+ }
38
+ }
39
+
40
+ export function getWeb3SignerUrl(): string {
41
+ if (process.env.WEB3_SIGNER_URL) {
42
+ return process.env.WEB3_SIGNER_URL;
43
+ } else {
44
+ throw new Error('Web3signer not running');
45
+ }
46
+ }
@@ -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..."
@@ -30,7 +31,7 @@ echo "Deployed contract at $TOKEN_ADDRESS"
30
31
 
31
32
  # docs:start:mint-private
32
33
  MINT_AMOUNT=69
33
- aztec-wallet send mint_to_private -ca last --args accounts:test0 accounts:alice $MINT_AMOUNT -f test0
34
+ aztec-wallet send mint_to_private -ca last --args accounts:alice $MINT_AMOUNT -f test0
34
35
  # docs:end:mint-private
35
36
 
36
37
  # docs:start:get-balance
@@ -45,9 +46,8 @@ fi
45
46
  TRANSFER_AMOUNT=42
46
47
 
47
48
  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
49
 
50
- aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -f test0
50
+ aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -aw authwits:last -f test0
51
51
  # docs:end:transfer
52
52
 
53
53
  # Test end result
@@ -1,6 +1,7 @@
1
1
  // docs:start:cross_chain_test_harness
2
2
  import {
3
3
  type AccountWallet,
4
+ AuthWitness,
4
5
  type AztecAddress,
5
6
  type AztecNode,
6
7
  EthAddress,
@@ -15,10 +16,9 @@ import {
15
16
  type SiblingPath,
16
17
  type TxReceipt,
17
18
  type Wallet,
18
- deployL1Contract,
19
19
  retryUntil,
20
20
  } from '@aztec/aztec.js';
21
- import type { L1ContractAddresses, ViemPublicClient, ViemWalletClient } from '@aztec/ethereum';
21
+ import { type ExtendedViemWalletClient, type L1ContractAddresses, deployL1Contract } from '@aztec/ethereum';
22
22
  import { TestERC20Abi, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts';
23
23
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
24
24
  import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
@@ -40,8 +40,7 @@ import { mintTokensToPrivate } from '../fixtures/token_utils.js';
40
40
  */
41
41
  export async function deployAndInitializeTokenAndBridgeContracts(
42
42
  wallet: Wallet,
43
- walletClient: ViemWalletClient,
44
- publicClient: ViemPublicClient,
43
+ l1Client: ExtendedViemWalletClient,
45
44
  rollupRegistryAddress: EthAddress,
46
45
  owner: AztecAddress,
47
46
  underlyingERC20Address: EthAddress,
@@ -68,35 +67,34 @@ export async function deployAndInitializeTokenAndBridgeContracts(
68
67
  underlyingERC20: any;
69
68
  }> {
70
69
  // deploy the token portal
71
- const { address: tokenPortalAddress } = await deployL1Contract(
72
- walletClient,
73
- publicClient,
74
- TokenPortalAbi,
75
- TokenPortalBytecode,
76
- );
70
+ const { address: tokenPortalAddress } = await deployL1Contract(l1Client, TokenPortalAbi, TokenPortalBytecode);
77
71
  const tokenPortal = getContract({
78
72
  address: tokenPortalAddress.toString(),
79
73
  abi: TokenPortalAbi,
80
- client: walletClient,
74
+ client: l1Client,
81
75
  });
82
76
 
83
77
  // deploy l2 token
84
- const token = await TokenContract.deploy(wallet, owner, 'TokenName', 'TokenSymbol', 18).send().deployed();
78
+ const token = await TokenContract.deploy(wallet, owner, 'TokenName', 'TokenSymbol', 18)
79
+ .send({ from: owner })
80
+ .deployed();
85
81
 
86
82
  // deploy l2 token bridge and attach to the portal
87
- const bridge = await TokenBridgeContract.deploy(wallet, token.address, tokenPortalAddress).send().deployed();
83
+ const bridge = await TokenBridgeContract.deploy(wallet, token.address, tokenPortalAddress)
84
+ .send({ from: owner })
85
+ .deployed();
88
86
 
89
- if ((await token.methods.get_admin().simulate()) !== owner.toBigInt()) {
87
+ if ((await token.methods.get_admin().simulate({ from: owner })) !== owner.toBigInt()) {
90
88
  throw new Error(`Token admin is not ${owner}`);
91
89
  }
92
90
 
93
- if (!(await bridge.methods.get_config().simulate()).token.equals(token.address)) {
91
+ if (!(await bridge.methods.get_config().simulate({ from: owner })).token.equals(token.address)) {
94
92
  throw new Error(`Bridge token is not ${token.address}`);
95
93
  }
96
94
 
97
95
  // 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) {
96
+ await token.methods.set_minter(bridge.address, true).send({ from: owner }).wait();
97
+ if ((await token.methods.is_minter(bridge.address).simulate({ from: owner })) === 1n) {
100
98
  throw new Error(`Bridge is not a minter`);
101
99
  }
102
100
 
@@ -109,13 +107,24 @@ export async function deployAndInitializeTokenAndBridgeContracts(
109
107
  const underlyingERC20 = getContract({
110
108
  address: underlyingERC20Address.toString(),
111
109
  abi: TestERC20Abi,
112
- client: walletClient,
110
+ client: l1Client,
113
111
  });
114
112
 
115
113
  return { token, bridge, tokenPortalAddress, tokenPortal, underlyingERC20 };
116
114
  }
117
115
  // docs:end:deployAndInitializeTokenAndBridgeContracts
118
116
 
117
+ export type CrossChainContext = {
118
+ l2Token: AztecAddress;
119
+ l2Bridge: AztecAddress;
120
+ tokenPortal: EthAddress;
121
+ underlying: EthAddress;
122
+ ethAccount: EthAddress;
123
+ ownerAddress: AztecAddress;
124
+ inbox: EthAddress;
125
+ outbox: EthAddress;
126
+ };
127
+
119
128
  /**
120
129
  * A Class for testing cross chain interactions, contains common interactions
121
130
  * shared between cross chain tests.
@@ -124,21 +133,20 @@ export class CrossChainTestHarness {
124
133
  static async new(
125
134
  aztecNode: AztecNode,
126
135
  pxeService: PXE,
127
- publicClient: ViemPublicClient,
128
- walletClient: ViemWalletClient,
136
+ l1Client: ExtendedViemWalletClient,
129
137
  wallet: AccountWallet,
138
+ ownerAddress: AztecAddress,
130
139
  logger: Logger,
131
140
  underlyingERC20Address: EthAddress,
132
141
  ): Promise<CrossChainTestHarness> {
133
- const ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]);
142
+ const ethAccount = EthAddress.fromString((await l1Client.getAddresses())[0]);
134
143
  const l1ContractAddresses = (await pxeService.getNodeInfo()).l1ContractAddresses;
135
144
 
136
145
  // Deploy and initialize all required contracts
137
146
  logger.info('Deploying and initializing token, portal and its bridge...');
138
147
  const { token, bridge, tokenPortalAddress, underlyingERC20 } = await deployAndInitializeTokenAndBridgeContracts(
139
148
  wallet,
140
- walletClient,
141
- publicClient,
149
+ l1Client,
142
150
  l1ContractAddresses.registryAddress,
143
151
  wallet.getAddress(),
144
152
  underlyingERC20Address,
@@ -154,18 +162,16 @@ export class CrossChainTestHarness {
154
162
  ethAccount,
155
163
  tokenPortalAddress,
156
164
  underlyingERC20.address,
157
- publicClient,
158
- walletClient,
165
+ l1Client,
159
166
  l1ContractAddresses,
160
167
  wallet,
168
+ ownerAddress,
161
169
  );
162
170
  }
163
171
 
164
172
  private readonly l1TokenManager: L1TokenManager;
165
173
  private readonly l1TokenPortalManager: L1TokenPortalManager;
166
174
 
167
- public readonly ownerAddress: AztecAddress;
168
-
169
175
  constructor(
170
176
  /** Aztec node instance. */
171
177
  public aztecNode: AztecNode,
@@ -186,23 +192,24 @@ export class CrossChainTestHarness {
186
192
  public tokenPortalAddress: EthAddress,
187
193
  /** Underlying token for portal tests. */
188
194
  public underlyingERC20Address: EthAddress,
189
- /** Viem Public client instance. */
190
- public publicClient: ViemPublicClient,
191
- /** Viem Wallet Client instance. */
192
- public walletClient: ViemWalletClient,
195
+ /** Viem Extended client instance. */
196
+ public l1Client: ExtendedViemWalletClient,
193
197
 
194
198
  /** Deployment addresses for all L1 contracts */
195
199
  public readonly l1ContractAddresses: L1ContractAddresses,
196
200
 
197
201
  /** Wallet of the owner. */
198
202
  public readonly ownerWallet: AccountWallet,
203
+
204
+ /** Owner of the l2 token and bridge */
205
+ public readonly ownerAddress: AztecAddress,
199
206
  ) {
200
207
  this.l1TokenPortalManager = new L1TokenPortalManager(
201
208
  this.tokenPortalAddress,
202
209
  this.underlyingERC20Address,
210
+ this.l1ContractAddresses.feeAssetHandlerAddress,
203
211
  this.l1ContractAddresses.outboxAddress,
204
- this.publicClient,
205
- this.walletClient,
212
+ this.l1Client,
206
213
  this.logger,
207
214
  );
208
215
  this.l1TokenManager = this.l1TokenPortalManager.getTokenManager();
@@ -210,8 +217,15 @@ export class CrossChainTestHarness {
210
217
  }
211
218
 
212
219
  async mintTokensOnL1(amount: bigint) {
213
- await this.l1TokenManager.mint(amount, this.ethAccount.toString());
214
- expect(await this.l1TokenManager.getL1TokenBalance(this.ethAccount.toString())).toEqual(amount);
220
+ const contract = getContract({
221
+ abi: TestERC20Abi,
222
+ address: this.l1TokenManager.tokenAddress.toString(),
223
+ client: this.l1Client,
224
+ });
225
+ const balanceBefore = await this.l1TokenManager.getL1TokenBalance(this.ethAccount.toString());
226
+ const hash = await contract.write.mint([this.ethAccount.toString(), amount]);
227
+ await this.l1Client.waitForTransactionReceipt({ hash });
228
+ expect(await this.l1TokenManager.getL1TokenBalance(this.ethAccount.toString())).toEqual(balanceBefore + amount);
215
229
  }
216
230
 
217
231
  getL1BalanceOf(address: EthAddress) {
@@ -228,16 +242,19 @@ export class CrossChainTestHarness {
228
242
 
229
243
  async mintTokensPublicOnL2(amount: bigint) {
230
244
  this.logger.info('Minting tokens on L2 publicly');
231
- await this.l2Token.methods.mint_to_public(this.ownerAddress, amount).send().wait();
245
+ await this.l2Token.methods.mint_to_public(this.ownerAddress, amount).send({ from: this.ownerAddress }).wait();
232
246
  }
233
247
 
234
248
  async mintTokensPrivateOnL2(amount: bigint) {
235
- await mintTokensToPrivate(this.l2Token, this.ownerWallet, this.ownerAddress, amount);
249
+ await mintTokensToPrivate(this.l2Token, this.ownerAddress, this.ownerWallet, this.ownerAddress, amount);
236
250
  }
237
251
 
238
252
  async sendL2PublicTransfer(transferAmount: bigint, receiverAddress: AztecAddress) {
239
253
  // 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();
254
+ await this.l2Token.methods
255
+ .transfer_in_public(this.ownerAddress, receiverAddress, transferAmount, 0)
256
+ .send({ from: this.ownerAddress })
257
+ .wait();
241
258
  }
242
259
 
243
260
  async consumeMessageOnAztecAndMintPrivately(
@@ -247,7 +264,7 @@ export class CrossChainTestHarness {
247
264
  const { recipient, claimAmount, claimSecret: secretForL2MessageConsumption, messageLeafIndex } = claim;
248
265
  await this.l2Bridge.methods
249
266
  .claim_private(recipient, claimAmount, secretForL2MessageConsumption, messageLeafIndex)
250
- .send()
267
+ .send({ from: this.ownerAddress })
251
268
  .wait();
252
269
  }
253
270
 
@@ -258,23 +275,27 @@ export class CrossChainTestHarness {
258
275
  const { claimAmount, claimSecret, messageLeafIndex } = claim;
259
276
  await this.l2Bridge.methods
260
277
  .claim_public(this.ownerAddress, claimAmount, claimSecret, messageLeafIndex)
261
- .send()
278
+ .send({ from: this.ownerAddress })
262
279
  .wait();
263
280
  }
264
281
 
265
- async withdrawPrivateFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise<FieldsOf<TxReceipt>> {
282
+ async withdrawPrivateFromAztecToL1(
283
+ withdrawAmount: bigint,
284
+ authwitNonce: Fr = Fr.ZERO,
285
+ authWitness: AuthWitness,
286
+ ): Promise<FieldsOf<TxReceipt>> {
266
287
  const withdrawReceipt = await this.l2Bridge.methods
267
- .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce)
268
- .send()
288
+ .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, authwitNonce)
289
+ .send({ authWitnesses: [authWitness], from: this.ownerAddress })
269
290
  .wait();
270
291
 
271
292
  return withdrawReceipt;
272
293
  }
273
294
 
274
- async withdrawPublicFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO): Promise<FieldsOf<TxReceipt>> {
295
+ async withdrawPublicFromAztecToL1(withdrawAmount: bigint, authwitNonce: Fr = Fr.ZERO): Promise<FieldsOf<TxReceipt>> {
275
296
  const withdrawReceipt = await this.l2Bridge.methods
276
- .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce)
277
- .send()
297
+ .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, authwitNonce)
298
+ .send({ from: this.ownerAddress })
278
299
  .wait();
279
300
 
280
301
  return withdrawReceipt;
@@ -291,7 +312,7 @@ export class CrossChainTestHarness {
291
312
  }
292
313
 
293
314
  async getL2PublicBalanceOf(owner: AztecAddress) {
294
- return await this.l2Token.methods.balance_of_public(owner).simulate();
315
+ return await this.l2Token.methods.balance_of_public(owner).simulate({ from: this.ownerAddress });
295
316
  }
296
317
 
297
318
  async expectPublicBalanceOnL2(owner: AztecAddress, expectedBalance: bigint) {
@@ -299,8 +320,8 @@ export class CrossChainTestHarness {
299
320
  expect(balance).toBe(expectedBalance);
300
321
  }
301
322
 
302
- getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Fr {
303
- return this.l1TokenPortalManager.getL2ToL1MessageLeaf(
323
+ async getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Promise<Fr> {
324
+ return await this.l1TokenPortalManager.getL2ToL1MessageLeaf(
304
325
  withdrawAmount,
305
326
  this.ethAccount,
306
327
  this.l2Bridge.address,
@@ -325,12 +346,18 @@ export class CrossChainTestHarness {
325
346
 
326
347
  async transferToPrivateOnL2(shieldAmount: bigint) {
327
348
  this.logger.info('Transferring to private on L2');
328
- await this.l2Token.methods.transfer_to_private(this.ownerAddress, shieldAmount).send().wait();
349
+ await this.l2Token.methods
350
+ .transfer_to_private(this.ownerAddress, shieldAmount)
351
+ .send({ from: this.ownerAddress })
352
+ .wait();
329
353
  }
330
354
 
331
- async transferToPublicOnL2(amount: bigint, nonce = Fr.ZERO) {
355
+ async transferToPublicOnL2(amount: bigint, authwitNonce = Fr.ZERO) {
332
356
  this.logger.info('Transferring tokens to public');
333
- await this.l2Token.methods.transfer_to_public(this.ownerAddress, this.ownerAddress, amount, nonce).send().wait();
357
+ await this.l2Token.methods
358
+ .transfer_to_public(this.ownerAddress, this.ownerAddress, amount, authwitNonce)
359
+ .send({ from: this.ownerAddress })
360
+ .wait();
334
361
  }
335
362
 
336
363
  /**
@@ -348,5 +375,18 @@ export class CrossChainTestHarness {
348
375
  await this.mintTokensPublicOnL2(0n);
349
376
  await this.mintTokensPublicOnL2(0n);
350
377
  }
378
+
379
+ toCrossChainContext(): CrossChainContext {
380
+ return {
381
+ l2Token: this.l2Token.address,
382
+ l2Bridge: this.l2Bridge.address,
383
+ tokenPortal: this.tokenPortalAddress,
384
+ underlying: this.underlyingERC20Address,
385
+ ethAccount: this.ethAccount,
386
+ ownerAddress: this.ownerAddress,
387
+ inbox: this.l1ContractAddresses.inboxAddress,
388
+ outbox: this.l1ContractAddresses.outboxAddress,
389
+ };
390
+ }
351
391
  }
352
392
  // docs:end:cross_chain_test_harness
@@ -11,23 +11,24 @@ import {
11
11
  type Wallet,
12
12
  retryUntil,
13
13
  } from '@aztec/aztec.js';
14
- import type { ViemPublicClient, ViemWalletClient } from '@aztec/ethereum';
14
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum';
15
15
  import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice';
16
16
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
17
+ import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
17
18
 
18
19
  export interface IGasBridgingTestHarness {
19
20
  getL1FeeJuiceBalance(address: EthAddress): Promise<bigint>;
20
- prepareTokensOnL1(bridgeAmount: bigint, owner: AztecAddress): Promise<L2AmountClaim>;
21
- bridgeFromL1ToL2(bridgeAmount: bigint, owner: AztecAddress): Promise<void>;
21
+ prepareTokensOnL1(owner: AztecAddress): Promise<L2AmountClaim>;
22
+ bridgeFromL1ToL2(owner: AztecAddress, claimer: AztecAddress): Promise<void>;
22
23
  feeJuice: FeeJuiceContract;
23
24
  l1FeeJuiceAddress: EthAddress;
24
25
  }
25
26
 
26
27
  export interface FeeJuicePortalTestingHarnessFactoryConfig {
27
28
  aztecNode: AztecNode;
29
+ aztecNodeAdmin?: AztecNodeAdmin;
28
30
  pxeService: PXE;
29
- publicClient: ViemPublicClient;
30
- walletClient: ViemWalletClient;
31
+ l1Client: ExtendedViemWalletClient;
31
32
  wallet: Wallet;
32
33
  logger: Logger;
33
34
  mockL1?: boolean;
@@ -37,9 +38,9 @@ export class FeeJuicePortalTestingHarnessFactory {
37
38
  private constructor(private config: FeeJuicePortalTestingHarnessFactoryConfig) {}
38
39
 
39
40
  private async createReal() {
40
- const { aztecNode, pxeService, publicClient, walletClient, wallet, logger } = this.config;
41
+ const { aztecNode, aztecNodeAdmin, pxeService, l1Client, wallet, logger } = this.config;
41
42
 
42
- const ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]);
43
+ const ethAccount = EthAddress.fromString((await l1Client.getAddresses())[0]);
43
44
  const l1ContractAddresses = (await pxeService.getNodeInfo()).l1ContractAddresses;
44
45
 
45
46
  const feeJuiceAddress = l1ContractAddresses.feeJuiceAddress;
@@ -53,14 +54,15 @@ export class FeeJuicePortalTestingHarnessFactory {
53
54
 
54
55
  return new GasBridgingTestHarness(
55
56
  aztecNode,
57
+ aztecNodeAdmin,
56
58
  pxeService,
57
59
  logger,
58
60
  gasL2,
59
61
  ethAccount,
60
62
  feeJuicePortalAddress,
61
63
  feeJuiceAddress,
62
- publicClient,
63
- walletClient,
64
+ l1ContractAddresses.feeAssetHandlerAddress!,
65
+ l1Client,
64
66
  );
65
67
  }
66
68
 
@@ -81,6 +83,8 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness {
81
83
  constructor(
82
84
  /** Aztec node */
83
85
  public aztecNode: AztecNode,
86
+ /** Aztec node admin interface */
87
+ public aztecNodeAdmin: AztecNodeAdmin | undefined,
84
88
  /** Private eXecution Environment (PXE). */
85
89
  public pxeService: PXE,
86
90
  /** Logger. */
@@ -96,44 +100,45 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness {
96
100
  public feeJuicePortalAddress: EthAddress,
97
101
  /** Underlying token for portal tests. */
98
102
  public l1FeeJuiceAddress: EthAddress,
99
- /** Viem Public client instance. */
100
- public publicClient: ViemPublicClient,
101
- /** Viem Wallet Client instance. */
102
- public walletClient: ViemWalletClient,
103
+ /** Fee asset handler address. */
104
+ public feeAssetHandlerAddress: EthAddress,
105
+ /** Viem Extended client instance. */
106
+ public l1Client: ExtendedViemWalletClient,
103
107
  ) {
104
108
  this.feeJuicePortalManager = new L1FeeJuicePortalManager(
105
109
  this.feeJuicePortalAddress,
106
110
  this.l1FeeJuiceAddress,
107
- this.publicClient,
108
- this.walletClient,
111
+ this.feeAssetHandlerAddress,
112
+ this.l1Client,
109
113
  this.logger,
110
114
  );
111
115
 
112
116
  this.l1TokenManager = this.feeJuicePortalManager.getTokenManager();
113
117
  }
114
118
 
115
- async mintTokensOnL1(amount: bigint, to: EthAddress = this.ethAccount) {
116
- const balanceBefore = await this.l1TokenManager.getL1TokenBalance(to.toString());
117
- await this.l1TokenManager.mint(amount, to.toString());
118
- expect(await this.l1TokenManager.getL1TokenBalance(to.toString())).toEqual(balanceBefore + amount);
119
+ async mintTokensOnL1(to: EthAddress = this.ethAccount) {
120
+ // const balanceBefore = await this.l1TokenManager.getL1TokenBalance(to.toString());
121
+ await this.l1TokenManager.mint(to.toString());
122
+
123
+ // expect(await this.l1TokenManager.getL1TokenBalance(to.toString())).toEqual(balanceBefore + amount);
119
124
  }
120
125
 
121
126
  async getL1FeeJuiceBalance(address: EthAddress) {
122
127
  return await this.l1TokenManager.getL1TokenBalance(address.toString());
123
128
  }
124
129
 
125
- sendTokensToPortalPublic(bridgeAmount: bigint, l2Address: AztecAddress, mint = false) {
126
- return this.feeJuicePortalManager.bridgeTokensPublic(l2Address, bridgeAmount, mint);
130
+ sendTokensToPortalPublic(bridgeAmount: bigint, l2Address: AztecAddress) {
131
+ return this.feeJuicePortalManager.bridgeTokensPublic(l2Address, bridgeAmount, false);
127
132
  }
128
133
 
129
- async consumeMessageOnAztecAndClaimPrivately(owner: AztecAddress, claim: L2AmountClaim) {
134
+ async consumeMessageOnAztecAndClaimPrivately(owner: AztecAddress, claimer: AztecAddress, claim: L2AmountClaim) {
130
135
  this.logger.info('Consuming messages on L2 Privately');
131
136
  const { claimAmount, claimSecret, messageLeafIndex } = claim;
132
- await this.feeJuice.methods.claim(owner, claimAmount, claimSecret, messageLeafIndex).send().wait();
137
+ await this.feeJuice.methods.claim(owner, claimAmount, claimSecret, messageLeafIndex).send({ from: claimer }).wait();
133
138
  }
134
139
 
135
140
  async getL2PublicBalanceOf(owner: AztecAddress) {
136
- return await this.feeJuice.methods.balance_of_public(owner).simulate();
141
+ return await this.feeJuice.methods.balance_of_public(owner).simulate({ from: owner });
137
142
  }
138
143
 
139
144
  async expectPublicBalanceOnL2(owner: AztecAddress, expectedBalance: bigint) {
@@ -141,8 +146,10 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness {
141
146
  expect(balance).toBe(expectedBalance);
142
147
  }
143
148
 
144
- async prepareTokensOnL1(bridgeAmount: bigint, owner: AztecAddress) {
145
- const claim = await this.sendTokensToPortalPublic(bridgeAmount, owner, true);
149
+ async prepareTokensOnL1(owner: AztecAddress) {
150
+ const bridgeAmount = await this.l1TokenManager.getMintAmount();
151
+ await this.mintTokensOnL1();
152
+ const claim = await this.sendTokensToPortalPublic(bridgeAmount, owner);
146
153
 
147
154
  const isSynced = async () => await this.aztecNode.isL1ToL2MessageSynced(Fr.fromHexString(claim.messageHash));
148
155
  await retryUntil(isSynced, `message ${claim.messageHash} sync`, 24, 1);
@@ -154,19 +161,28 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness {
154
161
  return claim;
155
162
  }
156
163
 
157
- async bridgeFromL1ToL2(bridgeAmount: bigint, owner: AztecAddress) {
164
+ async bridgeFromL1ToL2(owner: AztecAddress, claimer: AztecAddress) {
158
165
  // Prepare the tokens on the L1 side
159
- const claim = await this.prepareTokensOnL1(bridgeAmount, owner);
166
+ const claim = await this.prepareTokensOnL1(owner);
160
167
 
161
168
  // Consume L1 -> L2 message and claim tokens privately on L2
162
- await this.consumeMessageOnAztecAndClaimPrivately(owner, claim);
163
- await this.expectPublicBalanceOnL2(owner, bridgeAmount);
169
+ await this.consumeMessageOnAztecAndClaimPrivately(owner, claimer, claim);
164
170
  }
165
171
 
166
172
  private async advanceL2Block() {
167
173
  const initialBlockNumber = await this.aztecNode.getBlockNumber();
168
- await this.aztecNode.flushTxs();
174
+
175
+ let minTxsPerBlock = undefined;
176
+ if (this.aztecNodeAdmin) {
177
+ ({ minTxsPerBlock } = await this.aztecNodeAdmin.getConfig());
178
+ await this.aztecNodeAdmin.setConfig({ minTxsPerBlock: 0 }); // Set to 0 to ensure we can advance the block
179
+ }
180
+
169
181
  await retryUntil(async () => (await this.aztecNode.getBlockNumber()) >= initialBlockNumber + 1);
182
+
183
+ if (this.aztecNodeAdmin && minTxsPerBlock !== undefined) {
184
+ await this.aztecNodeAdmin.setConfig({ minTxsPerBlock });
185
+ }
170
186
  }
171
187
  }
172
188
  // docs:end:cross_chain_test_harness