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

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 (174) 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 +334 -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 +19 -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 +50 -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 +59 -18
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +226 -44
  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 +21 -10
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +103 -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 +139 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +275 -23
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +184 -131
  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 +63 -0
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +104 -105
  58. package/dest/fixtures/fixtures.d.ts +6 -7
  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 +2 -2
  62. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  63. package/dest/fixtures/get_acvm_config.js +2 -14
  64. package/dest/fixtures/get_bb_config.d.ts +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 +9 -6
  69. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  70. package/dest/fixtures/l1_to_l2_messaging.js +44 -18
  71. package/dest/fixtures/logging.d.ts +1 -1
  72. package/dest/fixtures/setup_l1_contracts.d.ts +476 -5
  73. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  74. package/dest/fixtures/setup_l1_contracts.js +4 -4
  75. package/dest/fixtures/setup_p2p_test.d.ts +15 -14
  76. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  77. package/dest/fixtures/setup_p2p_test.js +81 -21
  78. package/dest/fixtures/snapshot_manager.d.ts +17 -9
  79. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  80. package/dest/fixtures/snapshot_manager.js +147 -121
  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 +28 -12
  84. package/dest/fixtures/utils.d.ts +524 -40
  85. package/dest/fixtures/utils.d.ts.map +1 -1
  86. package/dest/fixtures/utils.js +464 -369
  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 +1 -1
  91. package/dest/index.d.ts +1 -1
  92. package/dest/quality_of_service/alert_checker.d.ts +2 -2
  93. package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
  94. package/dest/shared/cross_chain_test_harness.d.ts +39 -34
  95. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  96. package/dest/shared/cross_chain_test_harness.js +104 -50
  97. package/dest/shared/gas_portal_test_harness.d.ts +29 -31
  98. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  99. package/dest/shared/gas_portal_test_harness.js +51 -30
  100. package/dest/shared/index.d.ts +1 -1
  101. package/dest/shared/jest_setup.d.ts +1 -1
  102. package/dest/shared/jest_setup.js +1 -1
  103. package/dest/shared/submit-transactions.d.ts +6 -4
  104. package/dest/shared/submit-transactions.d.ts.map +1 -1
  105. package/dest/shared/submit-transactions.js +8 -7
  106. package/dest/shared/uniswap_l1_l2.d.ts +14 -12
  107. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  108. package/dest/shared/uniswap_l1_l2.js +146 -116
  109. package/dest/simulators/index.d.ts +1 -1
  110. package/dest/simulators/lending_simulator.d.ts +7 -11
  111. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  112. package/dest/simulators/lending_simulator.js +15 -16
  113. package/dest/simulators/token_simulator.d.ts +6 -3
  114. package/dest/simulators/token_simulator.d.ts.map +1 -1
  115. package/dest/simulators/token_simulator.js +16 -13
  116. package/dest/spartan/setup_test_wallets.d.ts +26 -11
  117. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  118. package/dest/spartan/setup_test_wallets.js +201 -58
  119. package/dest/spartan/utils.d.ts +118 -313
  120. package/dest/spartan/utils.d.ts.map +1 -1
  121. package/dest/spartan/utils.js +472 -135
  122. package/package.json +65 -58
  123. package/src/bench/client_flows/benchmark.ts +341 -0
  124. package/src/bench/client_flows/client_flows_benchmark.ts +447 -0
  125. package/src/bench/client_flows/config.ts +61 -0
  126. package/src/bench/client_flows/data_extractor.ts +89 -0
  127. package/src/bench/utils.ts +22 -76
  128. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
  129. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +65 -106
  130. package/src/e2e_deploy_contract/deploy_test.ts +24 -39
  131. package/src/e2e_epochs/epochs_test.ts +276 -55
  132. package/src/e2e_fees/bridging_race.notest.ts +80 -0
  133. package/src/e2e_fees/fees_test.ts +142 -138
  134. package/src/e2e_l1_publisher/write_json.ts +77 -0
  135. package/src/e2e_multi_validator/utils.ts +258 -0
  136. package/src/e2e_nested_contract/nested_contract_test.ts +29 -19
  137. package/src/e2e_p2p/inactivity_slash_test.ts +182 -0
  138. package/src/e2e_p2p/p2p_network.ts +279 -169
  139. package/src/e2e_p2p/shared.ts +247 -29
  140. package/src/e2e_token_contract/token_contract_test.ts +43 -39
  141. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  142. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +107 -152
  143. package/src/fixtures/fixtures.ts +4 -3
  144. package/src/fixtures/get_acvm_config.ts +3 -11
  145. package/src/fixtures/get_bb_config.ts +18 -13
  146. package/src/fixtures/l1_to_l2_messaging.ts +53 -23
  147. package/src/fixtures/setup_l1_contracts.ts +6 -7
  148. package/src/fixtures/setup_p2p_test.ts +126 -38
  149. package/src/fixtures/snapshot_manager.ts +187 -139
  150. package/src/fixtures/token_utils.ts +32 -15
  151. package/src/fixtures/utils.ts +580 -434
  152. package/src/fixtures/web3signer.ts +63 -0
  153. package/src/guides/up_quick_start.sh +7 -15
  154. package/src/quality_of_service/alert_checker.ts +1 -1
  155. package/src/shared/cross_chain_test_harness.ts +108 -79
  156. package/src/shared/gas_portal_test_harness.ts +59 -50
  157. package/src/shared/jest_setup.ts +1 -1
  158. package/src/shared/submit-transactions.ts +12 -8
  159. package/src/shared/uniswap_l1_l2.ts +181 -184
  160. package/src/simulators/lending_simulator.ts +14 -15
  161. package/src/simulators/token_simulator.ts +21 -13
  162. package/src/spartan/DEVELOP.md +121 -0
  163. package/src/spartan/setup_test_wallets.ts +251 -93
  164. package/src/spartan/utils.ts +536 -136
  165. package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
  166. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  167. package/dest/sample-dapp/connect.js +0 -12
  168. package/dest/sample-dapp/contracts.js +0 -10
  169. package/dest/sample-dapp/deploy.js +0 -35
  170. package/dest/sample-dapp/index.js +0 -98
  171. package/src/sample-dapp/connect.mjs +0 -16
  172. package/src/sample-dapp/contracts.mjs +0 -14
  173. package/src/sample-dapp/deploy.mjs +0 -40
  174. package/src/sample-dapp/index.mjs +0 -128
@@ -1,16 +1,30 @@
1
- import { getSchnorrAccount } from '@aztec/accounts/schnorr';
2
1
  import type { InitialAccountData } from '@aztec/accounts/testing';
3
2
  import type { AztecNodeService } from '@aztec/aztec-node';
4
- import { type Logger, type SentTx, TxStatus } from '@aztec/aztec.js';
5
- import type { SpamContract } from '@aztec/noir-contracts.js/Spam';
6
- import { createPXEService, getPXEServiceConfig as getRpcConfig } from '@aztec/pxe/server';
3
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
4
+ import { type SentTx, getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
5
+ import { Fr } from '@aztec/aztec.js/fields';
6
+ import type { Logger } from '@aztec/aztec.js/log';
7
+ import { Tx, TxStatus } from '@aztec/aztec.js/tx';
8
+ import type { RollupCheatCodes } from '@aztec/aztec/testing';
9
+ import type { EmpireSlashingProposerContract, RollupContract, TallySlashingProposerContract } from '@aztec/ethereum';
10
+ import { EpochNumber } from '@aztec/foundation/branded-types';
11
+ import { timesAsync, unique } from '@aztec/foundation/collection';
12
+ import { retryUntil } from '@aztec/foundation/retry';
13
+ import { pluralize } from '@aztec/foundation/string';
14
+ import type { SpamContract } from '@aztec/noir-test-contracts.js/Spam';
15
+ import { TestContract, TestContractArtifact } from '@aztec/noir-test-contracts.js/Test';
16
+ import { getPXEConfig, getPXEConfig as getRpcConfig } from '@aztec/pxe/server';
17
+ import { getRoundForOffense } from '@aztec/slasher';
18
+ import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
19
+ import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
20
+ import { TestWallet, proveInteraction } from '@aztec/test-wallet/server';
7
21
 
8
- import type { NodeContext } from '../fixtures/setup_p2p_test.js';
9
22
  import { submitTxsTo } from '../shared/submit-transactions.js';
10
23
 
11
24
  // submits a set of transactions to the provided Private eXecution Environment (PXE)
12
25
  export const submitComplexTxsTo = async (
13
26
  logger: Logger,
27
+ from: AztecAddress,
14
28
  spamContract: SpamContract,
15
29
  numTxs: number,
16
30
  opts: { callPublic?: boolean } = {},
@@ -20,12 +34,10 @@ export const submitComplexTxsTo = async (
20
34
  const seed = 1234n;
21
35
  const spamCount = 15;
22
36
  for (let i = 0; i < numTxs; i++) {
23
- const tx = spamContract.methods
24
- .spam(seed + BigInt(i * spamCount), spamCount, !!opts.callPublic)
25
- .send({ skipPublicSimulation: true });
37
+ const tx = spamContract.methods.spam(seed + BigInt(i * spamCount), spamCount, !!opts.callPublic).send({ from });
26
38
  const txHash = await tx.getTxHash();
27
39
 
28
- logger.info(`Tx sent with hash ${txHash}`);
40
+ logger.info(`Tx sent with hash ${txHash.toString()}`);
29
41
  const receipt = await tx.getReceipt();
30
42
  expect(receipt).toEqual(
31
43
  expect.objectContaining({
@@ -33,35 +45,241 @@ export const submitComplexTxsTo = async (
33
45
  error: '',
34
46
  }),
35
47
  );
36
- logger.info(`Receipt received for ${txHash}`);
48
+ logger.info(`Receipt received for ${txHash.toString()}`);
37
49
  txs.push(tx);
38
50
  }
39
51
  return txs;
40
52
  };
41
53
 
42
- // creates an instance of the PXE and submit a given number of transactions to it.
43
- export const createPXEServiceAndSubmitTransactions = async (
54
+ // creates a wallet and submit a given number of transactions through it.
55
+ export const submitTransactions = async (
44
56
  logger: Logger,
45
57
  node: AztecNodeService,
46
58
  numTxs: number,
47
59
  fundedAccount: InitialAccountData,
48
- ): Promise<NodeContext> => {
60
+ ): Promise<SentTx[]> => {
49
61
  const rpcConfig = getRpcConfig();
50
- const pxeService = await createPXEService(node, rpcConfig, true);
62
+ rpcConfig.proverEnabled = false;
63
+ const wallet = await TestWallet.create(node, { ...getPXEConfig(), proverEnabled: false }, { useLogSuffix: true });
64
+ const fundedAccountManager = await wallet.createSchnorrAccount(fundedAccount.secret, fundedAccount.salt);
65
+ return submitTxsTo(wallet, fundedAccountManager.address, numTxs, logger);
66
+ };
67
+
68
+ export async function prepareTransactions(
69
+ logger: Logger,
70
+ node: AztecNodeService,
71
+ numTxs: number,
72
+ fundedAccount: InitialAccountData,
73
+ ): Promise<Tx[]> {
74
+ const rpcConfig = getRpcConfig();
75
+ rpcConfig.proverEnabled = false;
76
+
77
+ const wallet = await TestWallet.create(node, { ...getPXEConfig(), proverEnabled: false }, { useLogSuffix: true });
78
+ const fundedAccountManager = await wallet.createSchnorrAccount(fundedAccount.secret, fundedAccount.salt);
79
+
80
+ const testContractInstance = await getContractInstanceFromInstantiationParams(TestContractArtifact, {
81
+ salt: Fr.random(),
82
+ });
83
+ await wallet.registerContract(testContractInstance, TestContractArtifact);
84
+ const contract = TestContract.at(testContractInstance.address, wallet);
85
+
86
+ return timesAsync(numTxs, async () => {
87
+ const tx = await proveInteraction(wallet, contract.methods.emit_nullifier(Fr.random()), {
88
+ from: fundedAccountManager.address,
89
+ });
90
+ const txHash = tx.getTxHash();
91
+ logger.info(`Tx prepared with hash ${txHash}`);
92
+ return tx;
93
+ });
94
+ }
51
95
 
52
- const account = await getSchnorrAccount(
53
- pxeService,
54
- fundedAccount.secret,
55
- fundedAccount.signingKey,
56
- fundedAccount.salt,
96
+ export function awaitProposalExecution(
97
+ slashingProposer: EmpireSlashingProposerContract | TallySlashingProposerContract,
98
+ timeoutSeconds: number,
99
+ logger: Logger,
100
+ ): Promise<bigint> {
101
+ return new Promise<bigint>((resolve, reject) => {
102
+ const timeout = setTimeout(() => {
103
+ logger.warn(`Timed out waiting for proposal execution`);
104
+ reject(new Error(`Timeout waiting for proposal execution after ${timeoutSeconds}s`));
105
+ }, timeoutSeconds * 1000);
106
+
107
+ if (slashingProposer.type === 'empire') {
108
+ const unwatch = slashingProposer.listenToPayloadSubmitted(args => {
109
+ logger.warn(`Proposal ${args.payload} from round ${args.round} executed`);
110
+ clearTimeout(timeout);
111
+ unwatch();
112
+ resolve(args.round);
113
+ });
114
+ } else if (slashingProposer.type === 'tally') {
115
+ const unwatch = slashingProposer.listenToRoundExecuted(args => {
116
+ logger.warn(`Slash from round ${args.round} executed`);
117
+ clearTimeout(timeout);
118
+ unwatch();
119
+ resolve(args.round);
120
+ });
121
+ } else {
122
+ clearTimeout(timeout);
123
+ reject(new Error(`Unknown slashing proposer type: ${(slashingProposer as any).type}`));
124
+ }
125
+ });
126
+ }
127
+
128
+ export async function awaitCommitteeExists({
129
+ rollup,
130
+ logger,
131
+ }: {
132
+ rollup: RollupContract;
133
+ logger: Logger;
134
+ }): Promise<readonly `0x${string}`[]> {
135
+ logger.info(`Waiting for committee to be set`);
136
+ let committee: readonly `0x${string}`[] | undefined;
137
+ await retryUntil(
138
+ async () => {
139
+ committee = await rollup.getCurrentEpochCommittee();
140
+ return committee && committee.length > 0;
141
+ },
142
+ 'non-empty committee',
143
+ 60,
57
144
  );
58
- await account.register();
59
- const wallet = await account.getWallet();
60
-
61
- const txs = await submitTxsTo(pxeService, numTxs, wallet, logger);
62
- return {
63
- txs,
64
- pxeService,
65
- node,
66
- };
67
- };
145
+ return committee!;
146
+ }
147
+
148
+ export async function awaitOffenseDetected({
149
+ logger,
150
+ nodeAdmin,
151
+ slashingRoundSize,
152
+ epochDuration,
153
+ waitUntilOffenseCount,
154
+ timeoutSeconds = 120,
155
+ }: {
156
+ nodeAdmin: AztecNodeAdmin;
157
+ logger: Logger;
158
+ slashingRoundSize: number;
159
+ epochDuration: number;
160
+ waitUntilOffenseCount?: number;
161
+ timeoutSeconds?: number;
162
+ }) {
163
+ const targetOffenseCount = waitUntilOffenseCount ?? 1;
164
+ logger.warn(`Waiting for ${pluralize('offense', targetOffenseCount)} to be detected`);
165
+ const offenses = await retryUntil(
166
+ async () => {
167
+ const offenses = await nodeAdmin.getSlashOffenses('all');
168
+ if (offenses.length >= targetOffenseCount) {
169
+ return offenses;
170
+ }
171
+ },
172
+ 'non-empty offenses',
173
+ timeoutSeconds,
174
+ );
175
+ logger.info(
176
+ `Hit ${offenses.length} offenses on rounds ${unique(offenses.map(o => getRoundForOffense(o, { slashingRoundSize, epochDuration })))}`,
177
+ { offenses },
178
+ );
179
+ return offenses;
180
+ }
181
+
182
+ /**
183
+ * Await the committee to be slashed out of the validator set.
184
+ * Currently assumes that the committee is the same size as the validator set.
185
+ */
186
+ export async function awaitCommitteeKicked({
187
+ rollup,
188
+ cheatCodes,
189
+ committee,
190
+ slashFactory,
191
+ slashingProposer,
192
+ slashingRoundSize,
193
+ aztecSlotDuration,
194
+ aztecEpochDuration,
195
+ logger,
196
+ offenseEpoch,
197
+ }: {
198
+ rollup: RollupContract;
199
+ cheatCodes: RollupCheatCodes;
200
+ committee: readonly `0x${string}`[];
201
+ slashFactory: SlashFactoryContract;
202
+ slashingProposer: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
203
+ slashingRoundSize: number;
204
+ aztecSlotDuration: number;
205
+ aztecEpochDuration: number;
206
+ logger: Logger;
207
+ offenseEpoch: number;
208
+ }) {
209
+ if (!slashingProposer) {
210
+ throw new Error('No slashing proposer configured. Cannot test slashing.');
211
+ }
212
+
213
+ await cheatCodes.debugRollup();
214
+
215
+ if (slashingProposer.type === 'empire') {
216
+ // Await for the slash payload to be created if empire (no payload is created on tally until execution time)
217
+ const targetEpoch = BigInt(await cheatCodes.getEpoch()) + (await rollup.getLagInEpochsForValidatorSet()) + 1n;
218
+ logger.info(`Advancing to epoch ${targetEpoch} so we start slashing`);
219
+ await cheatCodes.advanceToEpoch(EpochNumber.fromBigInt(targetEpoch));
220
+
221
+ const slashPayloadEvents = await retryUntil(
222
+ async () => {
223
+ const events = await slashFactory.getSlashPayloadCreatedEvents();
224
+ return events.length > 0 ? events : undefined;
225
+ },
226
+ 'slash payload created',
227
+ 120,
228
+ 1,
229
+ );
230
+ expect(slashPayloadEvents.length).toBe(1);
231
+ // The uniqueness check is needed since a validator may be slashed more than once on the same round (eg because they let two epochs be pruned)
232
+ expect(unique(slashPayloadEvents[0].slashes.map(slash => slash.validator.toString()))).toHaveLength(
233
+ committee.length,
234
+ );
235
+ } else {
236
+ // Use the slash offset to ensure we are in the right epoch for tally
237
+ const slashOffsetInRounds = await slashingProposer.getSlashOffsetInRounds();
238
+ const slashingRoundSizeInEpochs = slashingRoundSize / aztecEpochDuration;
239
+ const slashingOffsetInEpochs = Number(slashOffsetInRounds) * slashingRoundSizeInEpochs;
240
+ const firstEpochInOffenseRound = offenseEpoch - (offenseEpoch % slashingRoundSizeInEpochs);
241
+ const targetEpoch = firstEpochInOffenseRound + slashingOffsetInEpochs;
242
+ logger.info(`Advancing to epoch ${targetEpoch} so we start slashing`);
243
+ await cheatCodes.advanceToEpoch(EpochNumber(targetEpoch), { offset: -aztecSlotDuration / 2 });
244
+ }
245
+
246
+ const attestersPre = await rollup.getAttesters();
247
+ expect(attestersPre.length).toBe(committee.length);
248
+
249
+ for (const attester of attestersPre) {
250
+ const attesterInfo = await rollup.getAttesterView(attester);
251
+ expect(attesterInfo.status).toEqual(1); // Validating
252
+ }
253
+
254
+ const timeout = slashingRoundSize * 2 * aztecSlotDuration + 30;
255
+ logger.info(`Waiting for slash to be executed (timeout ${timeout}s)`);
256
+ await awaitProposalExecution(slashingProposer, timeout, logger);
257
+
258
+ // The attesters should still form the committee but they should be reduced to the "living" status
259
+ await cheatCodes.debugRollup();
260
+ const committeePostSlashing = await rollup.getCurrentEpochCommittee();
261
+ expect(committeePostSlashing?.length).toBe(attestersPre.length);
262
+
263
+ const attestersPostSlashing = await rollup.getAttesters();
264
+ expect(attestersPostSlashing.length).toBe(0);
265
+
266
+ for (const attester of attestersPre) {
267
+ const attesterInfo = await rollup.getAttesterView(attester);
268
+ expect(attesterInfo.status).toEqual(2); // Living
269
+ }
270
+
271
+ logger.info(`Advancing to check current committee`);
272
+ await cheatCodes.debugRollup();
273
+ await cheatCodes.advanceToEpoch(
274
+ EpochNumber.fromBigInt(BigInt(await cheatCodes.getEpoch()) + (await rollup.getLagInEpochsForValidatorSet()) + 1n),
275
+ );
276
+ await cheatCodes.debugRollup();
277
+
278
+ const committeeNextEpoch = await rollup.getCurrentEpochCommittee();
279
+ // The committee should be undefined, since the validator set is empty
280
+ // and the tests currently using this helper always set a target committee size.
281
+ expect(committeeNextEpoch).toBeUndefined();
282
+
283
+ const attestersNextEpoch = await rollup.getAttesters();
284
+ expect(attestersNextEpoch.length).toBe(0);
285
+ }
@@ -1,7 +1,9 @@
1
- import { getSchnorrWallet } from '@aztec/accounts/schnorr';
2
- import { type AccountWallet, type CompleteAddress, type Logger, createLogger } from '@aztec/aztec.js';
3
- import { DocsExampleContract } from '@aztec/noir-contracts.js/DocsExample';
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { type Logger, createLogger } from '@aztec/aztec.js/log';
3
+ import type { AztecNode } from '@aztec/aztec.js/node';
4
4
  import { TokenContract } from '@aztec/noir-contracts.js/Token';
5
+ import { InvalidAccountContract } from '@aztec/noir-test-contracts.js/InvalidAccount';
6
+ import type { TestWallet } from '@aztec/test-wallet/server';
5
7
 
6
8
  import { jest } from '@jest/globals';
7
9
 
@@ -23,11 +25,15 @@ export class TokenContractTest {
23
25
  static TOKEN_DECIMALS = 18n;
24
26
  private snapshotManager: ISnapshotManager;
25
27
  logger: Logger;
26
- wallets: AccountWallet[] = [];
27
- accounts: CompleteAddress[] = [];
28
28
  asset!: TokenContract;
29
29
  tokenSim!: TokenSimulator;
30
- badAccount!: DocsExampleContract;
30
+ node!: AztecNode;
31
+
32
+ badAccount!: InvalidAccountContract;
33
+ wallet!: TestWallet;
34
+ adminAddress!: AztecAddress;
35
+ account1Address!: AztecAddress;
36
+ account2Address!: AztecAddress;
31
37
 
32
38
  constructor(testName: string) {
33
39
  this.logger = createLogger(`e2e:e2e_token_contract:${testName}`);
@@ -48,9 +54,11 @@ export class TokenContractTest {
48
54
  await this.snapshotManager.snapshot(
49
55
  '3_accounts',
50
56
  deployAccounts(3, this.logger),
51
- async ({ deployedAccounts }, { pxe }) => {
52
- this.wallets = await Promise.all(deployedAccounts.map(a => getSchnorrWallet(pxe, a.address, a.signingKey)));
53
- this.accounts = this.wallets.map(w => w.getCompleteAddress());
57
+ ({ deployedAccounts }, { wallet, aztecNode }) => {
58
+ this.node = aztecNode;
59
+ this.wallet = wallet;
60
+ [this.adminAddress, this.account1Address, this.account2Address] = deployedAccounts.map(acc => acc.address);
61
+ return Promise.resolve();
54
62
  },
55
63
  );
56
64
 
@@ -60,42 +68,42 @@ export class TokenContractTest {
60
68
  // Create the token contract state.
61
69
  // Move this account thing to addAccounts above?
62
70
  this.logger.verbose(`Public deploy accounts...`);
63
- await publicDeployAccounts(this.wallets[0], this.accounts.slice(0, 2));
71
+ await publicDeployAccounts(this.wallet, [this.adminAddress, this.account1Address]);
64
72
 
65
73
  this.logger.verbose(`Deploying TokenContract...`);
66
74
  const asset = await TokenContract.deploy(
67
- this.wallets[0],
68
- this.accounts[0],
75
+ this.wallet,
76
+ this.adminAddress,
69
77
  TokenContractTest.TOKEN_NAME,
70
78
  TokenContractTest.TOKEN_SYMBOL,
71
79
  TokenContractTest.TOKEN_DECIMALS,
72
80
  )
73
- .send()
81
+ .send({ from: this.adminAddress })
74
82
  .deployed();
75
83
  this.logger.verbose(`Token deployed to ${asset.address}`);
76
84
 
77
85
  this.logger.verbose(`Deploying bad account...`);
78
- this.badAccount = await DocsExampleContract.deploy(this.wallets[0]).send().deployed();
86
+ this.badAccount = await InvalidAccountContract.deploy(this.wallet).send({ from: this.adminAddress }).deployed();
79
87
  this.logger.verbose(`Deployed to ${this.badAccount.address}.`);
80
88
 
81
89
  return { tokenContractAddress: asset.address, badAccountAddress: this.badAccount.address };
82
90
  },
83
91
  async ({ tokenContractAddress, badAccountAddress }) => {
84
92
  // Restore the token contract state.
85
- this.asset = await TokenContract.at(tokenContractAddress, this.wallets[0]);
93
+ this.asset = TokenContract.at(tokenContractAddress, this.wallet);
86
94
  this.logger.verbose(`Token contract address: ${this.asset.address}`);
87
95
 
88
- this.tokenSim = new TokenSimulator(
89
- this.asset,
90
- this.wallets[0],
91
- this.logger,
92
- this.accounts.map(a => a.address),
93
- );
96
+ this.tokenSim = new TokenSimulator(this.asset, this.wallet, this.adminAddress, this.logger, [
97
+ this.adminAddress,
98
+ this.account1Address,
99
+ ]);
94
100
 
95
- this.badAccount = await DocsExampleContract.at(badAccountAddress, this.wallets[0]);
101
+ this.badAccount = InvalidAccountContract.at(badAccountAddress, this.wallet);
96
102
  this.logger.verbose(`Bad account address: ${this.badAccount.address}`);
97
103
 
98
- expect(await this.asset.methods.get_admin().simulate()).toBe(this.accounts[0].address.toBigInt());
104
+ expect(await this.asset.methods.get_admin().simulate({ from: this.adminAddress })).toBe(
105
+ this.adminAddress.toBigInt(),
106
+ );
99
107
  },
100
108
  );
101
109
 
@@ -123,36 +131,32 @@ export class TokenContractTest {
123
131
  await this.snapshotManager.snapshot(
124
132
  'mint',
125
133
  async () => {
126
- const { asset, wallets } = this;
134
+ const { asset, adminAddress } = this;
127
135
  const amount = 10000n;
128
136
 
129
137
  this.logger.verbose(`Minting ${amount} publicly...`);
130
- await asset.methods.mint_to_public(wallets[0].getAddress(), amount).send().wait();
138
+ await asset.methods.mint_to_public(adminAddress, amount).send({ from: adminAddress }).wait();
131
139
 
132
140
  this.logger.verbose(`Minting ${amount} privately...`);
133
- await mintTokensToPrivate(asset, wallets[0], wallets[0].getAddress(), amount);
141
+ await mintTokensToPrivate(asset, adminAddress, adminAddress, amount);
134
142
  this.logger.verbose(`Minting complete.`);
135
143
 
136
144
  return { amount };
137
145
  },
138
146
  async ({ amount }) => {
139
- const {
140
- asset,
141
- accounts: [{ address }],
142
- tokenSim,
143
- } = this;
144
- tokenSim.mintPublic(address, amount);
145
-
146
- const publicBalance = await asset.methods.balance_of_public(address).simulate();
147
+ const { asset, adminAddress, tokenSim } = this;
148
+ tokenSim.mintPublic(adminAddress, amount);
149
+
150
+ const publicBalance = await asset.methods.balance_of_public(adminAddress).simulate({ from: adminAddress });
147
151
  this.logger.verbose(`Public balance of wallet 0: ${publicBalance}`);
148
- expect(publicBalance).toEqual(this.tokenSim.balanceOfPublic(address));
152
+ expect(publicBalance).toEqual(this.tokenSim.balanceOfPublic(adminAddress));
149
153
 
150
- tokenSim.mintPrivate(address, amount);
151
- const privateBalance = await asset.methods.balance_of_private(address).simulate();
154
+ tokenSim.mintPrivate(adminAddress, amount);
155
+ const privateBalance = await asset.methods.balance_of_private(adminAddress).simulate({ from: adminAddress });
152
156
  this.logger.verbose(`Private balance of wallet 0: ${privateBalance}`);
153
- expect(privateBalance).toEqual(tokenSim.balanceOfPrivate(address));
157
+ expect(privateBalance).toEqual(tokenSim.balanceOfPrivate(adminAddress));
154
158
 
155
- const totalSupply = await asset.methods.total_supply().simulate();
159
+ const totalSupply = await asset.methods.total_supply().simulate({ from: adminAddress });
156
160
  this.logger.verbose(`Total supply: ${totalSupply}`);
157
161
  expect(totalSupply).toEqual(tokenSim.totalSupply);
158
162