@aztec/end-to-end 0.0.0-test.0 → 0.0.1-commit.023c3e5

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 (240) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +62 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +281 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +79 -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 +321 -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 +79 -0
  13. package/dest/bench/utils.d.ts +16 -41
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +41 -72
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +26 -19
  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 +114 -102
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +32 -32
  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 +104 -104
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +19 -10
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +26 -27
  25. package/dest/e2e_epochs/epochs_test.d.ts +71 -22
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +260 -54
  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 +61 -0
  31. package/dest/e2e_fees/fees_test.d.ts +38 -23
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +162 -183
  34. package/dest/e2e_l1_publisher/write_json.d.ts +11 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +56 -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 +15 -15
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +37 -41
  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 +136 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +281 -27
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +237 -175
  49. package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
  50. package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
  51. package/dest/e2e_p2p/reqresp/utils.js +153 -0
  52. package/dest/e2e_p2p/shared.d.ts +44 -8
  53. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  54. package/dest/e2e_p2p/shared.js +165 -27
  55. package/dest/e2e_token_contract/token_contract_test.d.ts +27 -14
  56. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  57. package/dest/e2e_token_contract/token_contract_test.js +96 -74
  58. package/dest/fixtures/e2e_prover_test.d.ts +55 -0
  59. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  60. package/dest/fixtures/e2e_prover_test.js +278 -0
  61. package/dest/fixtures/fixtures.d.ts +6 -8
  62. package/dest/fixtures/fixtures.d.ts.map +1 -1
  63. package/dest/fixtures/fixtures.js +5 -5
  64. package/dest/fixtures/get_acvm_config.d.ts +2 -2
  65. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  66. package/dest/fixtures/get_acvm_config.js +3 -15
  67. package/dest/fixtures/get_bb_config.d.ts +2 -2
  68. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  69. package/dest/fixtures/get_bb_config.js +10 -17
  70. package/dest/fixtures/index.d.ts +1 -1
  71. package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
  72. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  73. package/dest/fixtures/l1_to_l2_messaging.js +45 -19
  74. package/dest/fixtures/logging.d.ts +1 -1
  75. package/dest/fixtures/setup.d.ts +218 -0
  76. package/dest/fixtures/setup.d.ts.map +1 -0
  77. package/dest/fixtures/setup.js +695 -0
  78. package/dest/fixtures/setup_p2p_test.d.ts +15 -15
  79. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  80. package/dest/fixtures/setup_p2p_test.js +96 -31
  81. package/dest/fixtures/token_utils.d.ts +10 -4
  82. package/dest/fixtures/token_utils.d.ts.map +1 -1
  83. package/dest/fixtures/token_utils.js +31 -12
  84. package/dest/fixtures/utils.d.ts +5 -153
  85. package/dest/fixtures/utils.d.ts.map +1 -1
  86. package/dest/fixtures/utils.js +4 -552
  87. package/dest/fixtures/web3signer.d.ts +5 -0
  88. package/dest/fixtures/web3signer.d.ts.map +1 -0
  89. package/dest/fixtures/web3signer.js +53 -0
  90. package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
  91. package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
  92. package/dest/fixtures/with_telemetry_utils.js +2 -2
  93. package/dest/index.d.ts +1 -1
  94. package/dest/quality_of_service/grafana_client.d.ts +41 -0
  95. package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
  96. package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
  97. package/dest/quality_of_service/prometheus_client.d.ts +38 -0
  98. package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
  99. package/dest/quality_of_service/prometheus_client.js +67 -0
  100. package/dest/shared/cross_chain_test_harness.d.ts +44 -27
  101. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  102. package/dest/shared/cross_chain_test_harness.js +105 -51
  103. package/dest/shared/gas_portal_test_harness.d.ts +33 -25
  104. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  105. package/dest/shared/gas_portal_test_harness.js +51 -30
  106. package/dest/shared/index.d.ts +2 -2
  107. package/dest/shared/index.d.ts.map +1 -1
  108. package/dest/shared/jest_setup.d.ts +1 -1
  109. package/dest/shared/jest_setup.js +1 -1
  110. package/dest/shared/submit-transactions.d.ts +6 -4
  111. package/dest/shared/submit-transactions.d.ts.map +1 -1
  112. package/dest/shared/submit-transactions.js +15 -16
  113. package/dest/shared/uniswap_l1_l2.d.ts +3 -25
  114. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  115. package/dest/shared/uniswap_l1_l2.js +176 -126
  116. package/dest/simulators/index.d.ts +1 -1
  117. package/dest/simulators/lending_simulator.d.ts +7 -7
  118. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  119. package/dest/simulators/lending_simulator.js +17 -18
  120. package/dest/simulators/token_simulator.d.ts +6 -3
  121. package/dest/simulators/token_simulator.d.ts.map +1 -1
  122. package/dest/simulators/token_simulator.js +16 -13
  123. package/dest/spartan/setup_test_wallets.d.ts +27 -11
  124. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  125. package/dest/spartan/setup_test_wallets.js +233 -62
  126. package/dest/spartan/tx_metrics.d.ts +88 -0
  127. package/dest/spartan/tx_metrics.d.ts.map +1 -0
  128. package/dest/spartan/tx_metrics.js +422 -0
  129. package/dest/spartan/utils/bot.d.ts +27 -0
  130. package/dest/spartan/utils/bot.d.ts.map +1 -0
  131. package/dest/spartan/utils/bot.js +141 -0
  132. package/dest/spartan/utils/chaos.d.ts +79 -0
  133. package/dest/spartan/utils/chaos.d.ts.map +1 -0
  134. package/dest/spartan/utils/chaos.js +142 -0
  135. package/dest/spartan/utils/clients.d.ts +39 -0
  136. package/dest/spartan/utils/clients.d.ts.map +1 -0
  137. package/dest/spartan/utils/clients.js +90 -0
  138. package/dest/spartan/utils/config.d.ts +36 -0
  139. package/dest/spartan/utils/config.d.ts.map +1 -0
  140. package/dest/spartan/utils/config.js +20 -0
  141. package/dest/spartan/utils/health.d.ts +63 -0
  142. package/dest/spartan/utils/health.d.ts.map +1 -0
  143. package/dest/spartan/utils/health.js +202 -0
  144. package/dest/spartan/utils/helm.d.ts +15 -0
  145. package/dest/spartan/utils/helm.d.ts.map +1 -0
  146. package/dest/spartan/utils/helm.js +47 -0
  147. package/dest/spartan/utils/index.d.ts +9 -0
  148. package/dest/spartan/utils/index.d.ts.map +1 -0
  149. package/dest/spartan/utils/index.js +18 -0
  150. package/dest/spartan/utils/k8s.d.ts +126 -0
  151. package/dest/spartan/utils/k8s.d.ts.map +1 -0
  152. package/dest/spartan/utils/k8s.js +375 -0
  153. package/dest/spartan/utils/nodes.d.ts +41 -0
  154. package/dest/spartan/utils/nodes.d.ts.map +1 -0
  155. package/dest/spartan/utils/nodes.js +461 -0
  156. package/dest/spartan/utils/scripts.d.ts +16 -0
  157. package/dest/spartan/utils/scripts.d.ts.map +1 -0
  158. package/dest/spartan/utils/scripts.js +66 -0
  159. package/dest/spartan/utils.d.ts +2 -415
  160. package/dest/spartan/utils.d.ts.map +1 -1
  161. package/dest/spartan/utils.js +1 -445
  162. package/package.json +66 -58
  163. package/src/bench/client_flows/benchmark.ts +363 -0
  164. package/src/bench/client_flows/client_flows_benchmark.ts +384 -0
  165. package/src/bench/client_flows/config.ts +61 -0
  166. package/src/bench/client_flows/data_extractor.ts +89 -0
  167. package/src/bench/utils.ts +41 -85
  168. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +134 -169
  169. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +156 -182
  170. package/src/e2e_deploy_contract/deploy_test.ts +40 -48
  171. package/src/e2e_epochs/epochs_test.ts +341 -81
  172. package/src/e2e_fees/bridging_race.notest.ts +74 -0
  173. package/src/e2e_fees/fees_test.ts +220 -258
  174. package/src/e2e_l1_publisher/write_json.ts +77 -0
  175. package/src/e2e_multi_validator/utils.ts +258 -0
  176. package/src/e2e_nested_contract/nested_contract_test.ts +46 -59
  177. package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
  178. package/src/e2e_p2p/p2p_network.ts +341 -234
  179. package/src/e2e_p2p/reqresp/utils.ts +207 -0
  180. package/src/e2e_p2p/shared.ts +260 -39
  181. package/src/e2e_token_contract/token_contract_test.ts +115 -126
  182. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  183. package/src/fixtures/e2e_prover_test.ts +336 -0
  184. package/src/fixtures/fixtures.ts +5 -7
  185. package/src/fixtures/get_acvm_config.ts +4 -12
  186. package/src/fixtures/get_bb_config.ts +18 -13
  187. package/src/fixtures/l1_to_l2_messaging.ts +56 -24
  188. package/src/fixtures/setup.ts +1017 -0
  189. package/src/fixtures/setup_p2p_test.ts +133 -50
  190. package/src/fixtures/token_utils.ts +33 -15
  191. package/src/fixtures/utils.ts +27 -820
  192. package/src/fixtures/web3signer.ts +63 -0
  193. package/src/fixtures/with_telemetry_utils.ts +2 -2
  194. package/src/guides/up_quick_start.sh +7 -15
  195. package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
  196. package/src/quality_of_service/prometheus_client.ts +113 -0
  197. package/src/shared/cross_chain_test_harness.ts +103 -91
  198. package/src/shared/gas_portal_test_harness.ts +59 -50
  199. package/src/shared/index.ts +1 -1
  200. package/src/shared/jest_setup.ts +1 -1
  201. package/src/shared/submit-transactions.ts +18 -20
  202. package/src/shared/uniswap_l1_l2.ts +197 -221
  203. package/src/simulators/lending_simulator.ts +16 -17
  204. package/src/simulators/token_simulator.ts +21 -13
  205. package/src/spartan/DEVELOP.md +128 -0
  206. package/src/spartan/setup_test_wallets.ts +308 -95
  207. package/src/spartan/tx_metrics.ts +376 -0
  208. package/src/spartan/utils/bot.ts +185 -0
  209. package/src/spartan/utils/chaos.ts +253 -0
  210. package/src/spartan/utils/clients.ts +100 -0
  211. package/src/spartan/utils/config.ts +26 -0
  212. package/src/spartan/utils/health.ts +255 -0
  213. package/src/spartan/utils/helm.ts +84 -0
  214. package/src/spartan/utils/index.ts +64 -0
  215. package/src/spartan/utils/k8s.ts +527 -0
  216. package/src/spartan/utils/nodes.ts +538 -0
  217. package/src/spartan/utils/scripts.ts +63 -0
  218. package/src/spartan/utils.ts +1 -582
  219. package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
  220. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  221. package/dest/e2e_prover/e2e_prover_test.js +0 -291
  222. package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
  223. package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
  224. package/dest/fixtures/setup_l1_contracts.js +0 -17
  225. package/dest/fixtures/snapshot_manager.d.ts +0 -87
  226. package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
  227. package/dest/fixtures/snapshot_manager.js +0 -479
  228. package/dest/quality_of_service/alert_checker.d.ts +0 -41
  229. package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
  230. package/dest/sample-dapp/connect.js +0 -12
  231. package/dest/sample-dapp/contracts.js +0 -10
  232. package/dest/sample-dapp/deploy.js +0 -35
  233. package/dest/sample-dapp/index.js +0 -98
  234. package/src/e2e_prover/e2e_prover_test.ts +0 -418
  235. package/src/fixtures/setup_l1_contracts.ts +0 -27
  236. package/src/fixtures/snapshot_manager.ts +0 -617
  237. package/src/sample-dapp/connect.mjs +0 -16
  238. package/src/sample-dapp/contracts.mjs +0 -14
  239. package/src/sample-dapp/deploy.mjs +0 -40
  240. package/src/sample-dapp/index.mjs +0 -128
@@ -1,20 +1,42 @@
1
- import { AztecNodeService } from '@aztec/aztec-node';
2
- import { Fr, type Logger, getTimestampRangeForEpoch, retryUntil, sleep } from '@aztec/aztec.js';
3
- import { ChainMonitor } from '@aztec/aztec.js/ethereum';
1
+ import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
2
+ import { getTimestampRangeForEpoch } from '@aztec/aztec.js/block';
3
+ import { getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
4
+ import { Fr } from '@aztec/aztec.js/fields';
5
+ import type { Logger } from '@aztec/aztec.js/log';
6
+ import { MerkleTreeId } from '@aztec/aztec.js/trees';
7
+ import type { Wallet } from '@aztec/aztec.js/wallet';
8
+ import { EpochCache } from '@aztec/epoch-cache';
9
+ import { createExtendedL1Client } from '@aztec/ethereum/client';
10
+ import { DefaultL1ContractsConfig } from '@aztec/ethereum/config';
4
11
  import { RollupContract } from '@aztec/ethereum/contracts';
5
- import { DelayedTxUtils, type Delayer, waitUntilL1Timestamp } from '@aztec/ethereum/test';
6
- import { randomBytes } from '@aztec/foundation/crypto';
7
- import { withLogNameSuffix } from '@aztec/foundation/log';
8
- import { ProverNode, ProverNodePublisher } from '@aztec/prover-node';
12
+ import { ChainMonitor, DelayedTxUtils, type Delayer, waitUntilL1Timestamp, withDelayer } from '@aztec/ethereum/test';
13
+ import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
14
+ import { BlockNumber, CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
15
+ import { SecretValue } from '@aztec/foundation/config';
16
+ import { randomBytes } from '@aztec/foundation/crypto/random';
17
+ import { withLoggerBindings } from '@aztec/foundation/log/server';
18
+ import { retryUntil } from '@aztec/foundation/retry';
19
+ import { sleep } from '@aztec/foundation/sleep';
20
+ import { SpamContract } from '@aztec/noir-test-contracts.js/Spam';
21
+ import { TestContract } from '@aztec/noir-test-contracts.js/Test';
22
+ import { getMockPubSubP2PServiceFactory } from '@aztec/p2p/test-helpers';
23
+ import { ProverNode, type ProverNodeConfig, ProverNodePublisher } from '@aztec/prover-node';
9
24
  import type { TestProverNode } from '@aztec/prover-node/test';
10
- import type { SequencerPublisher } from '@aztec/sequencer-client';
25
+ import type { PXEConfig } from '@aztec/pxe/config';
26
+ import {
27
+ type SequencerClient,
28
+ type SequencerEvents,
29
+ type SequencerPublisher,
30
+ SequencerState,
31
+ } from '@aztec/sequencer-client';
11
32
  import type { TestSequencerClient } from '@aztec/sequencer-client/test';
12
- import type { L2BlockNumber } from '@aztec/stdlib/block';
13
- import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
14
- import { MerkleTreeId } from '@aztec/stdlib/trees';
33
+ import { type BlockParameter, EthAddress } from '@aztec/stdlib/block';
34
+ import { type L1RollupConstants, getProofSubmissionDeadlineTimestamp } from '@aztec/stdlib/epoch-helpers';
35
+ import { tryStop } from '@aztec/stdlib/interfaces/server';
15
36
 
16
37
  import { join } from 'path';
17
- import type { Hex, PublicClient } from 'viem';
38
+ import type { Hex } from 'viem';
39
+ import { privateKeyToAccount } from 'viem/accounts';
18
40
 
19
41
  import {
20
42
  type EndToEndContext,
@@ -24,15 +46,24 @@ import {
24
46
  setup,
25
47
  } from '../fixtures/utils.js';
26
48
 
27
- // This can be lowered to as much as 2s in non-CI
28
- export const L1_BLOCK_TIME_IN_S = process.env.L1_BLOCK_TIME ? parseInt(process.env.L1_BLOCK_TIME) : 8;
29
- export const EPOCH_DURATION_IN_L2_SLOTS = 4;
30
- export const L2_SLOT_DURATION_IN_L1_SLOTS = 2;
31
49
  export const WORLD_STATE_BLOCK_HISTORY = 2;
32
50
  export const WORLD_STATE_BLOCK_CHECK_INTERVAL = 50;
33
51
  export const ARCHIVER_POLL_INTERVAL = 50;
52
+ export const DEFAULT_L1_BLOCK_TIME = process.env.CI ? 12 : 8;
53
+
54
+ export type EpochsTestOpts = Partial<SetupOptions> & {
55
+ numberOfAccounts?: number;
56
+ pxeOpts?: Partial<PXEConfig>;
57
+ aztecSlotDurationInL1Slots?: number;
58
+ };
34
59
 
35
- export type EpochsTestOpts = Partial<Pick<SetupOptions, 'startProverNode'>>;
60
+ export type TrackedSequencerEvent = {
61
+ [K in keyof SequencerEvents]: Parameters<SequencerEvents[K]>[0] & {
62
+ type: K;
63
+ sequencerIndex: number;
64
+ validator: EthAddress;
65
+ };
66
+ }[keyof SequencerEvents];
36
67
 
37
68
  /**
38
69
  * Tests building of epochs using fast block times and short epochs.
@@ -41,79 +72,128 @@ export type EpochsTestOpts = Partial<Pick<SetupOptions, 'startProverNode'>>;
41
72
  */
42
73
  export class EpochsTestContext {
43
74
  public context!: EndToEndContext;
44
- public l1Client!: PublicClient;
75
+ public l1Client!: ExtendedViemWalletClient;
45
76
  public rollup!: RollupContract;
46
77
  public constants!: L1RollupConstants;
47
78
  public logger!: Logger;
48
79
  public monitor!: ChainMonitor;
80
+ public epochCache!: EpochCache;
49
81
  public proverDelayer!: Delayer;
50
82
  public sequencerDelayer!: Delayer;
51
83
 
52
84
  public proverNodes: ProverNode[] = [];
53
85
  public nodes: AztecNodeService[] = [];
54
86
 
87
+ public epochDuration!: number;
88
+
89
+ public L1_BLOCK_TIME_IN_S!: number;
90
+ public L2_SLOT_DURATION_IN_S!: number;
91
+
55
92
  public static async setup(opts: EpochsTestOpts = {}) {
56
93
  const test = new EpochsTestContext();
57
94
  await test.setup(opts);
58
95
  return test;
59
96
  }
60
97
 
98
+ public static getSlotDurations(opts: EpochsTestOpts = {}) {
99
+ const envEthereumSlotDuration = process.env.L1_BLOCK_TIME
100
+ ? parseInt(process.env.L1_BLOCK_TIME)
101
+ : DEFAULT_L1_BLOCK_TIME;
102
+ const ethereumSlotDuration = opts.ethereumSlotDuration ?? envEthereumSlotDuration;
103
+ const aztecSlotDuration = opts.aztecSlotDuration ?? (opts.aztecSlotDurationInL1Slots ?? 2) * ethereumSlotDuration;
104
+ const aztecEpochDuration = opts.aztecEpochDuration ?? 6;
105
+ const aztecProofSubmissionEpochs = opts.aztecProofSubmissionEpochs ?? 1;
106
+ const l1PublishingTime = opts.l1PublishingTime ?? 1;
107
+ return {
108
+ l1PublishingTime,
109
+ ethereumSlotDuration,
110
+ aztecSlotDuration,
111
+ aztecEpochDuration,
112
+ aztecProofSubmissionEpochs,
113
+ };
114
+ }
115
+
61
116
  public async setup(opts: EpochsTestOpts = {}) {
117
+ const {
118
+ ethereumSlotDuration,
119
+ aztecSlotDuration,
120
+ aztecEpochDuration,
121
+ aztecProofSubmissionEpochs,
122
+ l1PublishingTime,
123
+ } = EpochsTestContext.getSlotDurations(opts);
124
+
125
+ this.L1_BLOCK_TIME_IN_S = ethereumSlotDuration;
126
+ this.L2_SLOT_DURATION_IN_S = aztecSlotDuration;
127
+
62
128
  // Set up system without any account nor protocol contracts
63
129
  // and with faster block times and shorter epochs.
64
- const context = await setup(0, {
65
- checkIntervalMs: 50,
66
- archiverPollingIntervalMS: ARCHIVER_POLL_INTERVAL,
67
- worldStateBlockCheckIntervalMS: WORLD_STATE_BLOCK_CHECK_INTERVAL,
68
- skipProtocolContracts: true,
69
- salt: 1,
70
- aztecEpochDuration: EPOCH_DURATION_IN_L2_SLOTS,
71
- aztecSlotDuration: L1_BLOCK_TIME_IN_S * L2_SLOT_DURATION_IN_L1_SLOTS,
72
- ethereumSlotDuration: L1_BLOCK_TIME_IN_S,
73
- aztecProofSubmissionWindow: EPOCH_DURATION_IN_L2_SLOTS * 2 - 1,
74
- minTxsPerBlock: 0,
75
- realProofs: false,
76
- startProverNode: true,
77
- // We use numeric incremental prover ids for simplicity, but we can switch to
78
- // using the prover's eth address if the proverId is used for something in the rollup contract
79
- proverId: Fr.fromString('1'),
80
- // This must be enough so that the tx from the prover is delayed properly,
81
- // but not so much to hang the sequencer and timeout the teardown
82
- txPropagationMaxQueryAttempts: 12,
83
- worldStateBlockHistory: WORLD_STATE_BLOCK_HISTORY,
84
- ...opts,
85
- });
130
+ const context = await setup(
131
+ opts.numberOfAccounts ?? 0,
132
+ {
133
+ automineL1Setup: true,
134
+ checkIntervalMs: 50,
135
+ archiverPollingIntervalMS: ARCHIVER_POLL_INTERVAL,
136
+ worldStateBlockCheckIntervalMS: WORLD_STATE_BLOCK_CHECK_INTERVAL,
137
+ aztecEpochDuration,
138
+ aztecSlotDuration,
139
+ ethereumSlotDuration,
140
+ aztecProofSubmissionEpochs,
141
+ aztecTargetCommitteeSize: opts.initialValidators?.length ?? 0,
142
+ minTxsPerBlock: 0,
143
+ realProofs: false,
144
+ startProverNode: true,
145
+ proverTestDelayMs: opts.proverTestDelayMs ?? 0,
146
+ // We use numeric incremental prover ids for simplicity, but we can switch to
147
+ // using the prover's eth address if the proverId is used for something in the rollup contract
148
+ // Use numeric EthAddress for deterministic prover id
149
+ proverId: EthAddress.fromNumber(1),
150
+ worldStateBlockHistory: WORLD_STATE_BLOCK_HISTORY,
151
+ exitDelaySeconds: DefaultL1ContractsConfig.exitDelaySeconds,
152
+ slasherFlavor: 'none',
153
+ l1PublishingTime,
154
+ ...opts,
155
+ },
156
+ // Use checkpointed chain tip for PXE by default to avoid issues with blocks being dropped due to pruned anchor blocks.
157
+ // Can be overridden via opts.pxeOpts.
158
+ { syncChainTip: 'checkpointed', ...opts.pxeOpts },
159
+ );
86
160
 
87
161
  this.context = context;
88
162
  this.proverNodes = context.proverNode ? [context.proverNode] : [];
89
163
  this.nodes = context.aztecNode ? [context.aztecNode as AztecNodeService] : [];
90
164
  this.logger = context.logger;
91
- this.l1Client = context.deployL1ContractsValues.publicClient;
165
+ this.l1Client = context.deployL1ContractsValues.l1Client;
92
166
  this.rollup = RollupContract.getFromConfig(context.config);
167
+ this.epochCache = await EpochCache.create(this.rollup, context.config, { dateProvider: context.dateProvider });
93
168
 
94
169
  // Loop that tracks L1 and L2 block numbers and logs whenever there's a new one.
95
- this.monitor = new ChainMonitor(this.rollup, this.logger).start();
170
+ this.monitor = new ChainMonitor(this.rollup, context.dateProvider, this.logger).start();
96
171
 
97
172
  // This is hideous.
98
173
  // We ought to have a definite reference to the l1TxUtils that we're using in both places, provided by the test context.
99
174
  this.proverDelayer = context.proverNode
100
175
  ? (((context.proverNode as TestProverNode).publisher as ProverNodePublisher).l1TxUtils as DelayedTxUtils).delayer!
101
176
  : undefined!;
102
- this.sequencerDelayer = (
103
- ((context.sequencer as TestSequencerClient).sequencer.publisher as SequencerPublisher).l1TxUtils as DelayedTxUtils
104
- ).delayer!;
177
+ this.sequencerDelayer = context.sequencer
178
+ ? (
179
+ ((context.sequencer as TestSequencerClient).sequencer.publisher as SequencerPublisher)
180
+ .l1TxUtils as DelayedTxUtils
181
+ ).delayer!
182
+ : undefined!;
105
183
 
106
- if ((context.proverNode && !this.proverDelayer) || !this.sequencerDelayer) {
184
+ if ((context.proverNode && !this.proverDelayer) || (context.sequencer && !this.sequencerDelayer)) {
107
185
  throw new Error(`Could not find prover or sequencer delayer`);
108
186
  }
109
187
 
110
188
  // Constants used for time calculation
189
+ this.epochDuration = aztecEpochDuration;
111
190
  this.constants = {
112
- epochDuration: EPOCH_DURATION_IN_L2_SLOTS,
113
- slotDuration: L1_BLOCK_TIME_IN_S * L2_SLOT_DURATION_IN_L1_SLOTS,
191
+ epochDuration: aztecEpochDuration,
192
+ slotDuration: aztecSlotDuration,
114
193
  l1StartBlock: await this.rollup.getL1StartBlock(),
115
194
  l1GenesisTime: await this.rollup.getL1GenesisTime(),
116
- ethereumSlotDuration: L1_BLOCK_TIME_IN_S,
195
+ ethereumSlotDuration,
196
+ proofSubmissionEpochs: Number(await this.rollup.getProofSubmissionEpochs()),
117
197
  };
118
198
 
119
199
  this.logger.info(
@@ -122,38 +202,99 @@ export class EpochsTestContext {
122
202
  }
123
203
 
124
204
  public async teardown() {
125
- this.monitor.stop();
126
- await Promise.all(this.proverNodes.map(node => node.stop()));
127
- await Promise.all(this.nodes.map(node => node.stop()));
205
+ await this.monitor.stop();
206
+ await Promise.all(this.proverNodes.map(node => tryStop(node, this.logger)));
207
+ await Promise.all(this.nodes.map(node => tryStop(node, this.logger)));
128
208
  await this.context.teardown();
129
209
  }
130
210
 
131
- public async createProverNode() {
211
+ public async createProverNode(opts: { dontStart?: boolean } & Partial<ProverNodeConfig> = {}) {
132
212
  this.logger.warn('Creating and syncing a simulated prover node...');
133
213
  const proverNodePrivateKey = this.getNextPrivateKey();
134
- const suffix = (this.proverNodes.length + 1).toString();
135
- const proverNode = await withLogNameSuffix(suffix, () =>
214
+ const proverIndex = this.proverNodes.length + 1;
215
+ const proverNode = await withLoggerBindings({ actor: `prover-${proverIndex}` }, () =>
136
216
  createAndSyncProverNode(
137
217
  proverNodePrivateKey,
138
- { ...this.context.config, proverId: Fr.fromString(suffix) },
218
+ { ...this.context.config },
219
+ {
220
+ dataDirectory: join(this.context.config.dataDirectory!, randomBytes(8).toString('hex')),
221
+ proverId: EthAddress.fromNumber(proverIndex),
222
+ dontStart: opts.dontStart,
223
+ ...opts,
224
+ },
139
225
  this.context.aztecNode,
140
- join(this.context.config.dataDirectory!, randomBytes(8).toString('hex')),
226
+ this.context.prefilledPublicData ?? [],
227
+ { dateProvider: this.context.dateProvider },
141
228
  ),
142
229
  );
143
230
  this.proverNodes.push(proverNode);
144
231
  return proverNode;
145
232
  }
146
233
 
147
- public async createNonValidatorNode() {
234
+ public createNonValidatorNode(opts: Partial<AztecNodeConfig> = {}) {
148
235
  this.logger.warn('Creating and syncing a node without a validator...');
149
- const suffix = (this.nodes.length + 1).toString();
150
- const node = await withLogNameSuffix(suffix, () =>
151
- AztecNodeService.createAndSync({
152
- ...this.context.config,
153
- disableValidator: true,
154
- dataDirectory: join(this.context.config.dataDirectory!, randomBytes(8).toString('hex')),
155
- }),
236
+ return this.createNode({ ...opts, disableValidator: true });
237
+ }
238
+
239
+ public createValidatorNode(
240
+ privateKeys: `0x${string}`[],
241
+ opts: Partial<AztecNodeConfig> & { txDelayerMaxInclusionTimeIntoSlot?: number; dontStartSequencer?: boolean } = {},
242
+ ) {
243
+ this.logger.warn('Creating and syncing a validator node...');
244
+ return this.createNode({ ...opts, disableValidator: false, validatorPrivateKeys: new SecretValue(privateKeys) });
245
+ }
246
+
247
+ private async createNode(
248
+ opts: Partial<AztecNodeConfig> & { txDelayerMaxInclusionTimeIntoSlot?: number; dontStartSequencer?: boolean } = {},
249
+ ) {
250
+ const nodeIndex = this.nodes.length + 1;
251
+ const actorPrefix = opts.disableValidator ? 'node' : 'validator';
252
+ const { mockGossipSubNetwork } = this.context;
253
+ const resolvedConfig = { ...this.context.config, ...opts };
254
+ const p2pEnabled = resolvedConfig.p2pEnabled || mockGossipSubNetwork !== undefined;
255
+ const p2pIp = resolvedConfig.p2pIp ?? (p2pEnabled ? '127.0.0.1' : undefined);
256
+ const node = await withLoggerBindings({ actor: `${actorPrefix}-${nodeIndex}` }, () =>
257
+ AztecNodeService.createAndSync(
258
+ {
259
+ ...resolvedConfig,
260
+ dataDirectory: join(this.context.config.dataDirectory!, randomBytes(8).toString('hex')),
261
+ validatorPrivateKeys: opts.validatorPrivateKeys ?? new SecretValue([]),
262
+ p2pEnabled,
263
+ p2pIp,
264
+ },
265
+ {
266
+ dateProvider: this.context.dateProvider,
267
+ p2pClientDeps: {
268
+ p2pServiceFactory: mockGossipSubNetwork ? getMockPubSubP2PServiceFactory(mockGossipSubNetwork) : undefined,
269
+ },
270
+ },
271
+ {
272
+ prefilledPublicData: this.context.prefilledPublicData,
273
+ ...opts,
274
+ },
275
+ ),
156
276
  );
277
+
278
+ // REFACTOR: We're getting too much into the internals of the sequencer here.
279
+ // We should have a single method for constructing an aztec node that returns a TestAztecNodeService
280
+ // which directly exposes the delayer and sets any test config.
281
+ if (opts.txDelayerMaxInclusionTimeIntoSlot !== undefined) {
282
+ this.logger.info(
283
+ `Setting tx delayer max inclusion time into slot to ${opts.txDelayerMaxInclusionTimeIntoSlot} seconds`,
284
+ );
285
+ // Here we reach into the sequencer and hook in a tx delayer. The problem is that the sequencer's l1 utils only uses a public client, not a wallet.
286
+ // The delayer needs a wallet (a client that can sign), so we have to create one here.
287
+ const l1Client = createExtendedL1Client(
288
+ resolvedConfig.l1RpcUrls!,
289
+ resolvedConfig.publisherPrivateKeys![0]!.getValue(),
290
+ );
291
+ const sequencer = node.getSequencer() as TestSequencerClient;
292
+ const publisher = sequencer.sequencer.publisher;
293
+ const delayed = DelayedTxUtils.fromL1TxUtils(publisher.l1TxUtils, this.L1_BLOCK_TIME_IN_S, l1Client);
294
+ delayed.delayer!.setMaxInclusionTimeIntoSlot(opts.txDelayerMaxInclusionTimeIntoSlot);
295
+ publisher.l1TxUtils = delayed;
296
+ }
297
+
157
298
  this.nodes.push(node);
158
299
  return node;
159
300
  }
@@ -165,53 +306,172 @@ export class EpochsTestContext {
165
306
 
166
307
  /** Waits until the epoch begins (ie until the immediately previous L1 block is mined). */
167
308
  public async waitUntilEpochStarts(epoch: number) {
168
- const [start] = getTimestampRangeForEpoch(BigInt(epoch), this.constants);
309
+ const [start] = getTimestampRangeForEpoch(EpochNumber(epoch), this.constants);
169
310
  this.logger.info(`Waiting until L1 timestamp ${start} is reached as the start of epoch ${epoch}`);
170
- await waitUntilL1Timestamp(this.l1Client, start - BigInt(L1_BLOCK_TIME_IN_S));
311
+ await waitUntilL1Timestamp(
312
+ this.l1Client,
313
+ start - BigInt(this.L1_BLOCK_TIME_IN_S),
314
+ undefined,
315
+ 30 * this.epochDuration,
316
+ );
171
317
  return start;
172
318
  }
173
319
 
174
- /** Waits until the given L2 block number is mined. */
175
- public async waitUntilL2BlockNumber(target: number, timeout = 60) {
320
+ /** Waits until the given checkpoint number is mined. */
321
+ public async waitUntilCheckpointNumber(target: CheckpointNumber, timeout = 120) {
176
322
  await retryUntil(
177
- () => Promise.resolve(target === this.monitor.l2BlockNumber),
178
- `Wait until L2 block ${target}`,
323
+ () => Promise.resolve(target <= this.monitor.checkpointNumber),
324
+ `Wait until checkpoint ${target}`,
179
325
  timeout,
180
326
  0.1,
181
327
  );
182
328
  }
183
329
 
184
- /** Waits until the given L2 block number is marked as proven. */
185
- public async waitUntilProvenL2BlockNumber(t: number, timeout = 60) {
330
+ /** Waits until the given checkpoint number is marked as proven. */
331
+ public async waitUntilProvenCheckpointNumber(target: CheckpointNumber, timeout = 120) {
186
332
  await retryUntil(
187
- () => Promise.resolve(t === this.monitor.l2ProvenBlockNumber),
188
- `Wait proven L2 block ${t}`,
333
+ () => Promise.resolve(target <= this.monitor.provenCheckpointNumber),
334
+ `Wait proven checkpoint ${target}`,
189
335
  timeout,
190
336
  0.1,
191
337
  );
338
+ return this.monitor.provenCheckpointNumber;
339
+ }
340
+
341
+ /** Waits until the last slot of the proof submission window for a given epoch. */
342
+ public async waitUntilLastSlotOfProofSubmissionWindow(epochNumber: number | bigint) {
343
+ const deadline = getProofSubmissionDeadlineTimestamp(EpochNumber.fromBigInt(BigInt(epochNumber)), this.constants);
344
+ const oneSlotBefore = deadline - BigInt(this.constants.slotDuration);
345
+ const date = new Date(Number(oneSlotBefore) * 1000);
346
+ this.logger.info(`Waiting until last slot of submission window for epoch ${epochNumber} at ${date}`, {
347
+ oneSlotBefore,
348
+ });
349
+ await waitUntilL1Timestamp(this.l1Client, oneSlotBefore);
192
350
  }
193
351
 
194
352
  /** Waits for the aztec node to sync to the target block number. */
195
- public async waitForNodeToSync(blockNumber: number, type: 'finalised' | 'historic') {
353
+ public async waitForNodeToSync(blockNumber: BlockNumber, type: 'proven' | 'finalized' | 'historic') {
196
354
  const waitTime = ARCHIVER_POLL_INTERVAL + WORLD_STATE_BLOCK_CHECK_INTERVAL;
197
355
  let synched = false;
198
356
  while (!synched) {
199
357
  await sleep(waitTime);
200
- const syncState = await this.context.aztecNode.getWorldStateSyncStatus();
201
- if (type === 'finalised') {
202
- synched = syncState.finalisedBlockNumber >= blockNumber;
358
+ const [syncState, tips] = await Promise.all([
359
+ this.context.aztecNode.getWorldStateSyncStatus(),
360
+ await this.context.aztecNode.getL2Tips(),
361
+ ]);
362
+ this.logger.info(`Wait for node synch ${blockNumber} ${type}`, { blockNumber, type, syncState, tips });
363
+ if (type === 'proven') {
364
+ synched = tips.proven.block.number >= blockNumber && syncState.latestBlockNumber >= blockNumber;
365
+ } else if (type === 'finalized') {
366
+ synched = syncState.finalizedBlockNumber >= blockNumber;
203
367
  } else {
204
368
  synched = syncState.oldestHistoricBlockNumber >= blockNumber;
205
369
  }
206
370
  }
207
371
  }
208
372
 
373
+ /** Registers the SpamContract on the given wallet. */
374
+ public async registerSpamContract(wallet: Wallet, salt = Fr.ZERO) {
375
+ const instance = await getContractInstanceFromInstantiationParams(SpamContract.artifact, {
376
+ constructorArgs: [],
377
+ constructorArtifact: undefined,
378
+ salt,
379
+ publicKeys: undefined,
380
+ deployer: undefined,
381
+ });
382
+ await wallet.registerContract(instance, SpamContract.artifact);
383
+ return SpamContract.at(instance.address, wallet);
384
+ }
385
+
386
+ /** Registers the TestContract on the given wallet. */
387
+ public async registerTestContract(wallet: Wallet, salt = Fr.ZERO) {
388
+ const instance = await getContractInstanceFromInstantiationParams(TestContract.artifact, {
389
+ constructorArgs: [],
390
+ constructorArtifact: undefined,
391
+ salt,
392
+ publicKeys: undefined,
393
+ deployer: undefined,
394
+ });
395
+ await wallet.registerContract(instance, TestContract.artifact);
396
+ return TestContract.at(instance.address, wallet);
397
+ }
398
+
399
+ /** Creates an L1 client using a fresh account with funds from anvil, with a tx delayer already set up. */
400
+ public async createL1Client() {
401
+ const { client, delayer } = withDelayer(
402
+ createExtendedL1Client(
403
+ [...this.l1Client.chain.rpcUrls.default.http],
404
+ privateKeyToAccount(this.getNextPrivateKey()),
405
+ this.l1Client.chain,
406
+ ),
407
+ this.context.dateProvider!,
408
+ { ethereumSlotDuration: this.L1_BLOCK_TIME_IN_S },
409
+ );
410
+ expect(await client.getBalance({ address: client.account.address })).toBeGreaterThan(0n);
411
+ return { client, delayer };
412
+ }
413
+
209
414
  /** Verifies whether the given block number is found on the aztec node. */
210
- public async verifyHistoricBlock(blockNumber: L2BlockNumber, expectedSuccess: boolean) {
415
+ public async verifyHistoricBlock(blockNumber: BlockParameter, expectedSuccess: boolean) {
416
+ // We use `findLeavesIndexes` here, but could use any function that queries the world-state
417
+ // at a particular block, so we know whether that historic block is available or has been
418
+ // pruned. Note that `getBlock` would not work here, since it only hits the archiver.
211
419
  const result = await this.context.aztecNode
212
- .findBlockNumbersForIndexes(blockNumber, MerkleTreeId.NULLIFIER_TREE, [0n])
420
+ .findLeavesIndexes(blockNumber, MerkleTreeId.NULLIFIER_TREE, [Fr.ZERO])
213
421
  .then(_ => true)
214
422
  .catch(_ => false);
215
423
  expect(result).toBe(expectedSuccess);
216
424
  }
425
+
426
+ public watchSequencerEvents(
427
+ sequencers: SequencerClient[],
428
+ getMetadata: (i: number) => Record<string, any> = () => ({}),
429
+ ) {
430
+ const stateChanges: TrackedSequencerEvent[] = [];
431
+ const failEvents: TrackedSequencerEvent[] = [];
432
+
433
+ // Note we do not include the 'block-tx-count-check-failed' event here, since it is fine if we dont build
434
+ // due to lack of txs available.
435
+ const failEventsKeys: (keyof SequencerEvents)[] = [
436
+ 'block-build-failed',
437
+ 'checkpoint-publish-failed',
438
+ 'proposer-rollup-check-failed',
439
+ ];
440
+
441
+ const makeEvent = (
442
+ i: number,
443
+ eventName: keyof SequencerEvents,
444
+ args: Parameters<SequencerEvents[keyof SequencerEvents]>[0],
445
+ ) =>
446
+ ({
447
+ ...args,
448
+ type: eventName,
449
+ sequencerIndex: i + 2,
450
+ ...getMetadata(i),
451
+ }) as TrackedSequencerEvent;
452
+
453
+ sequencers.forEach((sequencer, i) => {
454
+ const sequencerIndex = i + 2;
455
+ sequencer.getSequencer().on('state-changed', (args: Parameters<SequencerEvents['state-changed']>[0]) => {
456
+ const noisyStates = [SequencerState.IDLE, SequencerState.PROPOSER_CHECK, SequencerState.SYNCHRONIZING];
457
+ if (!noisyStates.includes(args.newState)) {
458
+ const evt = makeEvent(i, 'state-changed', args);
459
+ stateChanges.push(evt);
460
+ this.logger.verbose(
461
+ `Sequencer ${sequencerIndex} transitioned from state ${args.oldState} to state ${args.newState}`,
462
+ evt,
463
+ );
464
+ }
465
+ });
466
+ failEventsKeys.forEach(eventName => {
467
+ sequencer.getSequencer().on(eventName, (args: Parameters<SequencerEvents[typeof eventName]>[0]) => {
468
+ const evt = makeEvent(i, eventName, args);
469
+ failEvents.push(evt);
470
+ this.logger.error(`Failed event ${eventName} from sequencer ${sequencerIndex}`, undefined, evt);
471
+ });
472
+ });
473
+ });
474
+
475
+ return { failEvents, stateChanges };
476
+ }
217
477
  }
@@ -0,0 +1,74 @@
1
+ import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
2
+ import { Fr } from '@aztec/aztec.js/fields';
3
+ import type { Logger } from '@aztec/aztec.js/log';
4
+ import { Fq } from '@aztec/foundation/curves/bn254';
5
+ import { sleep } from '@aztec/foundation/sleep';
6
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
7
+ import type { TestWallet } from '@aztec/test-wallet/server';
8
+
9
+ import { jest } from '@jest/globals';
10
+ import type { Hex } from 'viem';
11
+
12
+ import { FeesTest } from './fees_test.js';
13
+
14
+ jest.setTimeout(300_000);
15
+
16
+ // Regression for https://github.com/AztecProtocol/aztec-packages/issues/12366
17
+ // Similar to e2e_fees/account_init but with no automine
18
+ describe('e2e_fees bridging_race', () => {
19
+ const ETHEREUM_SLOT_DURATION = 4;
20
+ const AZTEC_SLOT_DURATION = ETHEREUM_SLOT_DURATION * 2;
21
+
22
+ const t = new FeesTest('bridging_race', 1, {
23
+ ethereumSlotDuration: ETHEREUM_SLOT_DURATION,
24
+ aztecSlotDuration: AZTEC_SLOT_DURATION,
25
+ minTxsPerBlock: 0,
26
+ });
27
+
28
+ beforeAll(async () => {
29
+ await t.setup();
30
+ ({ wallet, logger } = t);
31
+ });
32
+
33
+ afterAll(async () => {
34
+ await t.teardown();
35
+ });
36
+
37
+ let logger: Logger;
38
+ let bobsAddress: AztecAddress;
39
+ let wallet: TestWallet;
40
+
41
+ beforeEach(async () => {
42
+ const bobsSecretKey = Fr.random();
43
+ const bobsPrivateSigningKey = Fq.random();
44
+ const bobsSalt = Fr.random();
45
+ const bobsAccountManager = await wallet.createAccount({
46
+ secret: bobsSecretKey,
47
+ salt: bobsSalt,
48
+ contract: new SchnorrAccountContract(bobsPrivateSigningKey),
49
+ });
50
+ bobsAddress = bobsAccountManager.address;
51
+ });
52
+
53
+ it('Alice bridges funds to Bob', async () => {
54
+ // Tweak the token manager so the bridging happens immediately before the end of the current L2 slot
55
+ // This caused the message to be "not in state" when tried to be used
56
+ const l1TokenManager = t.feeJuiceBridgeTestHarness.l1TokenManager;
57
+ const origApprove = l1TokenManager.approve.bind(l1TokenManager);
58
+ l1TokenManager.approve = async (amount: bigint, address: Hex, addressName = '') => {
59
+ await origApprove(amount, address, addressName);
60
+ const sleepTime = (Number(t.chainMonitor.checkpointTimestamp) + AZTEC_SLOT_DURATION) * 1000 - Date.now() - 500;
61
+ logger.info(`Sleeping for ${sleepTime}ms until near end of L2 slot before sending L1 fee juice to L2 inbox`);
62
+ await sleep(sleepTime);
63
+ };
64
+
65
+ // Waiting for the archiver to sync the message _before_ waiting for the mandatory 2 L2 blocks to pass fixed it
66
+ // This was added everywhere we wait for two blocks, which is spread across three different places in the codebase
67
+ // Yes, we need to REFACTOR it at some point
68
+ const claim = await t.feeJuiceBridgeTestHarness.prepareTokensOnL1(bobsAddress);
69
+ const { claimSecret: secret, messageLeafIndex: index } = claim;
70
+ await t.feeJuiceContract.methods.claim(bobsAddress, claim.claimAmount, secret, index).send({ from: bobsAddress });
71
+ const [balance] = await t.getGasBalanceFn(bobsAddress);
72
+ expect(balance).toEqual(claim.claimAmount);
73
+ });
74
+ });