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

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