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

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