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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +60 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +261 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +69 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.js +315 -0
  7. package/dest/bench/client_flows/config.d.ts +14 -0
  8. package/dest/bench/client_flows/config.d.ts.map +1 -0
  9. package/dest/bench/client_flows/config.js +106 -0
  10. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  12. package/dest/bench/client_flows/data_extractor.js +99 -0
  13. package/dest/bench/utils.d.ts +10 -27
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +27 -43
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +15 -7
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +66 -38
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +10 -18
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +34 -53
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -2
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +9 -6
  25. package/dest/e2e_epochs/epochs_test.d.ts +56 -17
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +222 -42
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  29. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  30. package/dest/e2e_fees/bridging_race.notest.js +60 -0
  31. package/dest/e2e_fees/fees_test.d.ts +16 -5
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +87 -88
  34. package/dest/e2e_l1_publisher/write_json.d.ts +8 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +57 -0
  37. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  38. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  39. package/dest/e2e_multi_validator/utils.js +214 -0
  40. package/dest/e2e_nested_contract/nested_contract_test.d.ts +5 -5
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +19 -14
  43. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.js +132 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +56 -21
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +154 -125
  49. package/dest/e2e_p2p/shared.d.ts +41 -3
  50. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  51. package/dest/e2e_p2p/shared.js +146 -6
  52. package/dest/e2e_token_contract/token_contract_test.d.ts +10 -5
  53. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  54. package/dest/e2e_token_contract/token_contract_test.js +51 -24
  55. package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +7 -4
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +67 -62
  58. package/dest/fixtures/fixtures.d.ts +5 -6
  59. package/dest/fixtures/fixtures.d.ts.map +1 -1
  60. package/dest/fixtures/fixtures.js +4 -3
  61. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  62. package/dest/fixtures/get_acvm_config.js +2 -14
  63. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  64. package/dest/fixtures/get_bb_config.js +8 -15
  65. package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
  66. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  67. package/dest/fixtures/l1_to_l2_messaging.js +44 -18
  68. package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
  69. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  70. package/dest/fixtures/setup_l1_contracts.js +3 -3
  71. package/dest/fixtures/setup_p2p_test.d.ts +14 -6
  72. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  73. package/dest/fixtures/setup_p2p_test.js +73 -21
  74. package/dest/fixtures/snapshot_manager.d.ts +8 -3
  75. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  76. package/dest/fixtures/snapshot_manager.js +120 -104
  77. package/dest/fixtures/token_utils.d.ts +4 -3
  78. package/dest/fixtures/token_utils.d.ts.map +1 -1
  79. package/dest/fixtures/token_utils.js +24 -7
  80. package/dest/fixtures/utils.d.ts +65 -22
  81. package/dest/fixtures/utils.d.ts.map +1 -1
  82. package/dest/fixtures/utils.js +439 -318
  83. package/dest/fixtures/web3signer.d.ts +5 -0
  84. package/dest/fixtures/web3signer.d.ts.map +1 -0
  85. package/dest/fixtures/web3signer.js +42 -0
  86. package/dest/shared/cross_chain_test_harness.d.ts +28 -18
  87. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  88. package/dest/shared/cross_chain_test_harness.js +97 -41
  89. package/dest/shared/gas_portal_test_harness.d.ts +23 -18
  90. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  91. package/dest/shared/gas_portal_test_harness.js +43 -25
  92. package/dest/shared/submit-transactions.d.ts.map +1 -1
  93. package/dest/shared/uniswap_l1_l2.d.ts +5 -6
  94. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  95. package/dest/shared/uniswap_l1_l2.js +136 -90
  96. package/dest/simulators/lending_simulator.d.ts +5 -6
  97. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  98. package/dest/simulators/lending_simulator.js +11 -15
  99. package/dest/simulators/token_simulator.d.ts +2 -1
  100. package/dest/simulators/token_simulator.d.ts.map +1 -1
  101. package/dest/simulators/token_simulator.js +16 -13
  102. package/dest/spartan/setup_test_wallets.d.ts +8 -1
  103. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  104. package/dest/spartan/setup_test_wallets.js +108 -22
  105. package/dest/spartan/utils.d.ts +60 -307
  106. package/dest/spartan/utils.d.ts.map +1 -1
  107. package/dest/spartan/utils.js +200 -115
  108. package/package.json +60 -56
  109. package/src/bench/client_flows/benchmark.ts +341 -0
  110. package/src/bench/client_flows/client_flows_benchmark.ts +422 -0
  111. package/src/bench/client_flows/config.ts +61 -0
  112. package/src/bench/client_flows/data_extractor.ts +111 -0
  113. package/src/bench/utils.ts +26 -52
  114. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +60 -40
  115. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +47 -75
  116. package/src/e2e_deploy_contract/deploy_test.ts +11 -8
  117. package/src/e2e_epochs/epochs_test.ts +276 -54
  118. package/src/e2e_fees/bridging_race.notest.ts +75 -0
  119. package/src/e2e_fees/fees_test.ts +121 -108
  120. package/src/e2e_l1_publisher/write_json.ts +74 -0
  121. package/src/e2e_multi_validator/utils.ts +258 -0
  122. package/src/e2e_nested_contract/nested_contract_test.ts +22 -14
  123. package/src/e2e_p2p/inactivity_slash_test.ts +174 -0
  124. package/src/e2e_p2p/p2p_network.ts +212 -144
  125. package/src/e2e_p2p/shared.ts +234 -14
  126. package/src/e2e_token_contract/token_contract_test.ts +42 -38
  127. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  128. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +62 -69
  129. package/src/fixtures/fixtures.ts +4 -3
  130. package/src/fixtures/get_acvm_config.ts +2 -10
  131. package/src/fixtures/get_bb_config.ts +15 -11
  132. package/src/fixtures/l1_to_l2_messaging.ts +53 -23
  133. package/src/fixtures/setup_l1_contracts.ts +5 -6
  134. package/src/fixtures/setup_p2p_test.ts +112 -30
  135. package/src/fixtures/snapshot_manager.ts +150 -102
  136. package/src/fixtures/token_utils.ts +33 -8
  137. package/src/fixtures/utils.ts +530 -352
  138. package/src/fixtures/web3signer.ts +46 -0
  139. package/src/guides/up_quick_start.sh +4 -4
  140. package/src/shared/cross_chain_test_harness.ts +92 -52
  141. package/src/shared/gas_portal_test_harness.ts +47 -31
  142. package/src/shared/uniswap_l1_l2.ts +127 -124
  143. package/src/simulators/lending_simulator.ts +11 -15
  144. package/src/simulators/token_simulator.ts +17 -12
  145. package/src/spartan/DEVELOP.md +116 -0
  146. package/src/spartan/setup_test_wallets.ts +144 -29
  147. package/src/spartan/utils.ts +194 -116
  148. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  149. package/dest/sample-dapp/connect.js +0 -12
  150. package/dest/sample-dapp/contracts.js +0 -10
  151. package/dest/sample-dapp/deploy.js +0 -35
  152. package/dest/sample-dapp/index.js +0 -98
  153. package/src/sample-dapp/connect.mjs +0 -16
  154. package/src/sample-dapp/contracts.mjs +0 -14
  155. package/src/sample-dapp/deploy.mjs +0 -40
  156. package/src/sample-dapp/index.mjs +0 -128
@@ -3,25 +3,24 @@ import {
3
3
  type AccountWallet,
4
4
  type AztecAddress,
5
5
  type AztecNode,
6
- ChainMonitor,
7
- CheatCodes,
8
6
  type Logger,
9
7
  type PXE,
10
8
  createLogger,
11
9
  sleep,
12
10
  } from '@aztec/aztec.js';
13
- import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants';
14
- import { type DeployL1ContractsArgs, RollupContract, createL1Clients } from '@aztec/ethereum';
11
+ import { CheatCodes } from '@aztec/aztec/testing';
12
+ import { type DeployL1ContractsArgs, RollupContract, createExtendedL1Client } from '@aztec/ethereum';
13
+ import { ChainMonitor } from '@aztec/ethereum/test';
15
14
  import { EthAddress } from '@aztec/foundation/eth-address';
16
- import { RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts';
15
+ import { TestERC20Abi } from '@aztec/l1-artifacts';
17
16
  import { AppSubscriptionContract } from '@aztec/noir-contracts.js/AppSubscription';
18
- import { CounterContract } from '@aztec/noir-contracts.js/Counter';
19
17
  import { FPCContract } from '@aztec/noir-contracts.js/FPC';
20
18
  import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice';
19
+ import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
21
20
  import { TokenContract as BananaCoin } from '@aztec/noir-contracts.js/Token';
21
+ import { CounterContract } from '@aztec/noir-test-contracts.js/Counter';
22
22
  import { ProtocolContractAddress } from '@aztec/protocol-contracts';
23
23
  import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
24
- import { computePartialAddress } from '@aztec/stdlib/contract';
25
24
  import { GasSettings } from '@aztec/stdlib/gas';
26
25
 
27
26
  import { getContract } from 'viem';
@@ -37,9 +36,9 @@ import { mintTokensToPrivate } from '../fixtures/token_utils.js';
37
36
  import {
38
37
  type BalancesFn,
39
38
  type SetupOptions,
40
- ensureAccountsPubliclyDeployed,
39
+ ensureAccountContractsPublished,
41
40
  getBalancesFn,
42
- setupCanonicalFeeJuice,
41
+ setupSponsoredFPC,
43
42
  } from '../fixtures/utils.js';
44
43
  import { FeeJuicePortalTestingHarnessFactory, type GasBridgingTestHarness } from '../shared/gas_portal_test_harness.js';
45
44
 
@@ -51,12 +50,14 @@ const { E2E_DATA_PATH: dataPath } = process.env;
51
50
  * PublicDeployAccounts: Deploys the accounts publicly.
52
51
  * DeployFeeJuice: Deploys the Fee Juice contract.
53
52
  * FPCSetup: Deploys BananaCoin and FPC contracts, and bridges gas from L1.
53
+ * SponsoredFPCSetup: Deploys Sponsored FPC contract, and bridges gas from L1.
54
54
  * FundAlice: Mints private and public bananas to Alice.
55
55
  * SetupSubscription: Deploys a counter contract and a subscription contract, and mints Fee Juice to the subscription contract.
56
56
  */
57
57
  export class FeesTest {
58
58
  private snapshotManager: ISnapshotManager;
59
59
  private wallets: AccountWallet[] = [];
60
+ private accounts: AztecAddress[] = [];
60
61
 
61
62
  public logger: Logger;
62
63
  public pxe!: PXE;
@@ -74,9 +75,12 @@ export class FeesTest {
74
75
 
75
76
  public gasSettings!: GasSettings;
76
77
 
78
+ public rollupContract!: RollupContract;
79
+
77
80
  public feeJuiceContract!: FeeJuiceContract;
78
81
  public bananaCoin!: BananaCoin;
79
82
  public bananaFPC!: FPCContract;
83
+ public sponsoredFPC!: SponsoredFPCContract;
80
84
  public counterContract!: CounterContract;
81
85
  public subscriptionContract!: AppSubscriptionContract;
82
86
  public feeJuiceBridgeTestHarness!: GasBridgingTestHarness;
@@ -103,6 +107,8 @@ export class FeesTest {
103
107
  if (!numberOfAccounts) {
104
108
  throw new Error('There must be at least 1 initial account.');
105
109
  }
110
+ setupOptions.coinbase ??= EthAddress.random();
111
+ this.coinbase = setupOptions.coinbase!;
106
112
  this.logger = createLogger(`e2e:e2e_fees:${testName}`);
107
113
  this.snapshotManager = createSnapshotManager(
108
114
  `e2e_fees/${testName}-${numberOfAccounts}`,
@@ -114,16 +120,15 @@ export class FeesTest {
114
120
 
115
121
  async setup() {
116
122
  const context = await this.snapshotManager.setup();
117
- await context.aztecNode.setConfig({ feeRecipient: this.sequencerAddress, coinbase: this.coinbase });
118
123
 
119
- const rollupContract = RollupContract.getFromConfig(context.aztecNodeConfig);
120
- this.chainMonitor = new ChainMonitor(rollupContract, this.logger, 200).start();
124
+ this.rollupContract = RollupContract.getFromConfig(context.aztecNodeConfig);
125
+ this.chainMonitor = new ChainMonitor(this.rollupContract, context.dateProvider, this.logger, 200).start();
121
126
 
122
127
  return this;
123
128
  }
124
129
 
125
130
  async teardown() {
126
- this.chainMonitor.stop();
131
+ await this.chainMonitor.stop();
127
132
  await this.snapshotManager.teardown();
128
133
  }
129
134
 
@@ -138,19 +143,41 @@ export class FeesTest {
138
143
  }
139
144
  }
140
145
 
141
- async mintAndBridgeFeeJuice(address: AztecAddress, amount: bigint) {
142
- const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(amount, address);
146
+ async getBlockRewards() {
147
+ const blockReward = await this.rollupContract.getBlockReward();
148
+ const rewardConfig = await this.rollupContract.getRewardConfig();
149
+
150
+ const balance = await this.feeJuiceBridgeTestHarness.getL1FeeJuiceBalance(
151
+ EthAddress.fromString(rewardConfig.rewardDistributor),
152
+ );
153
+
154
+ const toDistribute = balance > blockReward ? blockReward : balance;
155
+ const sequencerBlockRewards = (toDistribute * BigInt(rewardConfig.sequencerBps)) / 10000n;
156
+ const proverBlockRewards = toDistribute - sequencerBlockRewards;
157
+
158
+ return { sequencerBlockRewards, proverBlockRewards };
159
+ }
160
+
161
+ async mintAndBridgeFeeJuice(minter: AztecAddress, recipient: AztecAddress) {
162
+ const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(recipient);
143
163
  const { claimSecret: secret, messageLeafIndex: index } = claim;
144
- await this.feeJuiceContract.methods.claim(address, amount, secret, index).send().wait();
164
+ await this.feeJuiceContract.methods
165
+ .claim(recipient, claim.claimAmount, secret, index)
166
+ .send({ from: minter })
167
+ .wait();
145
168
  }
146
169
 
147
170
  /** Alice mints bananaCoin tokens privately to the target address and redeems them. */
148
171
  async mintPrivateBananas(amount: bigint, address: AztecAddress) {
149
- const balanceBefore = await this.bananaCoin.methods.balance_of_private(address).simulate();
172
+ const balanceBefore = await this.bananaCoin.methods
173
+ .balance_of_private(address)
174
+ .simulate({ from: this.aliceAddress });
150
175
 
151
- await mintTokensToPrivate(this.bananaCoin, this.aliceWallet, address, amount);
176
+ await mintTokensToPrivate(this.bananaCoin, this.aliceAddress, this.aliceWallet, address, amount);
152
177
 
153
- const balanceAfter = await this.bananaCoin.methods.balance_of_private(address).simulate();
178
+ const balanceAfter = await this.bananaCoin.methods
179
+ .balance_of_private(address)
180
+ .simulate({ from: this.aliceAddress });
154
181
  expect(balanceAfter).toEqual(balanceBefore + amount);
155
182
  }
156
183
 
@@ -167,63 +194,52 @@ export class FeesTest {
167
194
  deployAccounts(this.numberOfAccounts, this.logger),
168
195
  async ({ deployedAccounts }, { pxe, aztecNode, aztecNodeConfig }) => {
169
196
  this.pxe = pxe;
197
+
170
198
  this.aztecNode = aztecNode;
171
199
  this.gasSettings = GasSettings.default({ maxFeesPerGas: (await this.aztecNode.getCurrentBaseFees()).mul(2) });
172
200
  this.cheatCodes = await CheatCodes.create(aztecNodeConfig.l1RpcUrls, pxe);
173
201
  this.wallets = await Promise.all(deployedAccounts.map(a => getSchnorrWallet(pxe, a.address, a.signingKey)));
174
202
  this.wallets.forEach((w, i) => this.logger.verbose(`Wallet ${i} address: ${w.getAddress()}`));
203
+ this.accounts = this.wallets.map(w => w.getAddress());
175
204
  [this.aliceWallet, this.bobWallet] = this.wallets.slice(0, 2);
176
- [this.aliceAddress, this.bobAddress, this.sequencerAddress] = this.wallets.map(w => w.getAddress());
205
+ [this.aliceAddress, this.bobAddress, this.sequencerAddress] = this.accounts;
177
206
 
178
207
  // We set Alice as the FPC admin to avoid the need for deployment of another account.
179
208
  this.fpcAdmin = this.aliceAddress;
180
209
 
181
210
  const canonicalFeeJuice = await getCanonicalFeeJuice();
182
211
  this.feeJuiceContract = await FeeJuiceContract.at(canonicalFeeJuice.address, this.aliceWallet);
183
- if (this.numberOfAccounts > 1) {
184
- const bobInstance = (await this.bobWallet.getContractMetadata(this.bobAddress)).contractInstance;
185
- await this.aliceWallet.registerAccount(deployedAccounts[1].secret, await computePartialAddress(bobInstance!));
186
- }
187
- this.coinbase = EthAddress.random();
188
-
189
- const { publicClient, walletClient } = createL1Clients(aztecNodeConfig.l1RpcUrls, MNEMONIC);
190
- this.feeJuiceBridgeTestHarness = await FeeJuicePortalTestingHarnessFactory.create({
191
- aztecNode: aztecNode,
192
- pxeService: pxe,
193
- publicClient: publicClient,
194
- walletClient: walletClient,
195
- wallet: this.aliceWallet,
196
- logger: this.logger,
197
- });
198
212
  },
199
213
  );
200
214
  }
201
215
 
202
216
  async applyPublicDeployAccountsSnapshot() {
203
217
  await this.snapshotManager.snapshot('public_deploy_accounts', () =>
204
- ensureAccountsPubliclyDeployed(this.aliceWallet, this.wallets),
218
+ ensureAccountContractsPublished(this.aliceWallet, this.wallets),
205
219
  );
206
220
  }
207
221
 
208
222
  async applySetupFeeJuiceSnapshot() {
209
223
  await this.snapshotManager.snapshot(
210
224
  'setup_fee_juice',
211
- async context => {
212
- await setupCanonicalFeeJuice(context.pxe);
213
- },
225
+ async () => {},
214
226
  async (_data, context) => {
215
227
  this.context = context;
216
228
 
217
229
  this.feeJuiceContract = await FeeJuiceContract.at(ProtocolContractAddress.FeeJuice, this.aliceWallet);
218
230
 
219
- this.getGasBalanceFn = getBalancesFn('⛽', this.feeJuiceContract.methods.balance_of_public, this.logger);
231
+ this.getGasBalanceFn = getBalancesFn(
232
+ '⛽',
233
+ this.feeJuiceContract.methods.balance_of_public,
234
+ this.aliceAddress,
235
+ this.logger,
236
+ );
220
237
 
221
- const { publicClient, walletClient } = createL1Clients(context.aztecNodeConfig.l1RpcUrls, MNEMONIC);
222
238
  this.feeJuiceBridgeTestHarness = await FeeJuicePortalTestingHarnessFactory.create({
223
239
  aztecNode: context.aztecNode,
240
+ aztecNodeAdmin: context.aztecNode,
224
241
  pxeService: context.pxe,
225
- publicClient: publicClient,
226
- walletClient: walletClient,
242
+ l1Client: context.deployL1ContractsValues.l1Client,
227
243
  wallet: this.aliceWallet,
228
244
  logger: this.logger,
229
245
  });
@@ -236,13 +252,26 @@ export class FeesTest {
236
252
  'deploy_banana_token',
237
253
  async () => {
238
254
  const bananaCoin = await BananaCoin.deploy(this.aliceWallet, this.aliceAddress, 'BC', 'BC', 18n)
239
- .send()
255
+ .send({ from: this.aliceAddress })
240
256
  .deployed();
241
257
  this.logger.info(`BananaCoin deployed at ${bananaCoin.address}`);
242
258
  return { bananaCoinAddress: bananaCoin.address };
243
259
  },
244
260
  async ({ bananaCoinAddress }) => {
245
261
  this.bananaCoin = await BananaCoin.at(bananaCoinAddress, this.aliceWallet);
262
+ const logger = this.logger;
263
+ this.getBananaPublicBalanceFn = getBalancesFn(
264
+ '🍌.public',
265
+ this.bananaCoin.methods.balance_of_public,
266
+ this.aliceAddress,
267
+ logger,
268
+ );
269
+ this.getBananaPrivateBalanceFn = getBalancesFn(
270
+ '🍌.private',
271
+ this.bananaCoin.methods.balance_of_private,
272
+ this.aliceAddress,
273
+ logger,
274
+ );
246
275
  },
247
276
  );
248
277
  }
@@ -252,16 +281,16 @@ export class FeesTest {
252
281
  'fpc_setup',
253
282
  async context => {
254
283
  const feeJuiceContract = this.feeJuiceBridgeTestHarness.feeJuice;
255
- expect((await context.pxe.getContractMetadata(feeJuiceContract.address)).isContractPubliclyDeployed).toBe(true);
284
+ expect((await context.pxe.getContractMetadata(feeJuiceContract.address)).isContractPublished).toBe(true);
256
285
 
257
286
  const bananaCoin = this.bananaCoin;
258
287
  const bananaFPC = await FPCContract.deploy(this.aliceWallet, bananaCoin.address, this.fpcAdmin)
259
- .send()
288
+ .send({ from: this.aliceAddress })
260
289
  .deployed();
261
290
 
262
291
  this.logger.info(`BananaPay deployed at ${bananaFPC.address}`);
263
292
 
264
- await this.feeJuiceBridgeTestHarness.bridgeFromL1ToL2(FEE_FUNDING_FOR_TESTER_ACCOUNT, bananaFPC.address);
293
+ await this.feeJuiceBridgeTestHarness.bridgeFromL1ToL2(bananaFPC.address, this.aliceAddress);
265
294
 
266
295
  return {
267
296
  bananaFPCAddress: bananaFPC.address,
@@ -274,59 +303,76 @@ export class FeesTest {
274
303
  const bananaFPC = await FPCContract.at(data.bananaFPCAddress, this.aliceWallet);
275
304
  this.bananaFPC = bananaFPC;
276
305
 
277
- const logger = this.logger;
278
- this.getBananaPublicBalanceFn = getBalancesFn('🍌.public', this.bananaCoin.methods.balance_of_public, logger);
279
- this.getBananaPrivateBalanceFn = getBalancesFn(
280
- '🍌.private',
281
- this.bananaCoin.methods.balance_of_private,
282
- logger,
283
- );
284
-
285
306
  this.getCoinbaseBalance = async () => {
286
- const { walletClient } = createL1Clients(context.aztecNodeConfig.l1RpcUrls, MNEMONIC);
307
+ const l1Client = createExtendedL1Client(context.aztecNodeConfig.l1RpcUrls, MNEMONIC);
287
308
  const gasL1 = getContract({
288
309
  address: data.l1FeeJuiceAddress.toString(),
289
310
  abi: TestERC20Abi,
290
- client: walletClient,
311
+ client: l1Client,
291
312
  });
292
313
  return await gasL1.read.balanceOf([this.coinbase.toString()]);
293
314
  };
294
315
 
295
316
  this.getCoinbaseSequencerRewards = async () => {
296
- const { walletClient } = createL1Clients(context.aztecNodeConfig.l1RpcUrls, MNEMONIC);
297
- const rollup = getContract({
298
- address: data.rollupAddress.toString(),
299
- abi: RollupAbi,
300
- client: walletClient,
301
- });
302
-
303
- return await rollup.read.getSequencerRewards([this.coinbase.toString()]);
317
+ return await this.rollupContract.getSequencerRewards(this.coinbase);
304
318
  };
305
319
 
306
320
  this.getProverFee = async (blockNumber: number) => {
307
- const { walletClient } = createL1Clients(context.aztecNodeConfig.l1RpcUrls, MNEMONIC);
308
- const rollup = getContract({
309
- address: data.rollupAddress.toString(),
310
- abi: RollupAbi,
311
- client: walletClient,
312
- });
321
+ const block = await this.pxe.getBlock(blockNumber);
313
322
 
314
- const provingCostPerMana = await rollup.read.getProvingCostPerManaInFeeAsset();
323
+ // @todo @lherskind As we deal with #13601
324
+ // Right now the value is from `FeeLib.sol`
325
+ const L1_GAS_PER_EPOCH_VERIFIED = 1000000n;
326
+
327
+ // We round up
328
+ const mulDiv = (a: bigint, b: bigint, c: bigint) => (a * b) / c + ((a * b) % c > 0n ? 1n : 0n);
329
+
330
+ const { baseFee } = await this.rollupContract.getL1FeesAt(block!.header.globalVariables.timestamp);
331
+ const proverCost =
332
+ mulDiv(
333
+ mulDiv(L1_GAS_PER_EPOCH_VERIFIED, baseFee, await this.rollupContract.getEpochDuration()),
334
+ 1n,
335
+ await this.rollupContract.getManaTarget(),
336
+ ) + (await this.rollupContract.getProvingCostPerMana());
337
+
338
+ const price = await this.rollupContract.getFeeAssetPerEth();
315
339
 
316
- const block = await this.pxe.getBlock(blockNumber);
317
340
  const mana = block!.header.totalManaUsed.toBigInt();
318
- return mana * provingCostPerMana;
341
+ return mulDiv(mana * proverCost, price, 10n ** 9n);
319
342
  };
320
343
  },
321
344
  );
322
345
  }
323
346
 
347
+ public async applySponsoredFPCSetupSnapshot() {
348
+ await this.snapshotManager.snapshot(
349
+ 'sponsored_fpc_setup',
350
+ async context => {
351
+ const feeJuiceContract = this.feeJuiceBridgeTestHarness.feeJuice;
352
+ expect((await context.pxe.getContractMetadata(feeJuiceContract.address)).isContractPublished).toBe(true);
353
+
354
+ const sponsoredFPC = await setupSponsoredFPC(context.pxe);
355
+ this.logger.info(`SponsoredFPC at ${sponsoredFPC.address}`);
356
+
357
+ return {
358
+ sponsoredFPCAddress: sponsoredFPC.address,
359
+ };
360
+ },
361
+ async data => {
362
+ this.sponsoredFPC = await SponsoredFPCContract.at(data.sponsoredFPCAddress, this.aliceWallet);
363
+ },
364
+ );
365
+ }
366
+
324
367
  public async applyFundAliceWithBananas() {
325
368
  await this.snapshotManager.snapshot(
326
369
  'fund_alice',
327
370
  async () => {
328
371
  await this.mintPrivateBananas(this.ALICE_INITIAL_BANANAS, this.aliceAddress);
329
- await this.bananaCoin.methods.mint_to_public(this.aliceAddress, this.ALICE_INITIAL_BANANAS).send().wait();
372
+ await this.bananaCoin.methods
373
+ .mint_to_public(this.aliceAddress, this.ALICE_INITIAL_BANANAS)
374
+ .send({ from: this.aliceAddress })
375
+ .wait();
330
376
  },
331
377
  () => Promise.resolve(),
332
378
  );
@@ -341,37 +387,4 @@ export class FeesTest {
341
387
  () => Promise.resolve(),
342
388
  );
343
389
  }
344
-
345
- public async applySetupSubscription() {
346
- await this.snapshotManager.snapshot(
347
- 'setup_subscription',
348
- async () => {
349
- const counterContract = await CounterContract.deploy(this.bobWallet, 0, this.bobAddress).send().deployed();
350
-
351
- // Deploy subscription contract, that allows subscriptions for SUBSCRIPTION_AMOUNT of bananas
352
- const subscriptionContract = await AppSubscriptionContract.deploy(
353
- this.bobWallet,
354
- counterContract.address,
355
- this.bobAddress,
356
- this.bananaCoin.address,
357
- this.SUBSCRIPTION_AMOUNT,
358
- this.APP_SPONSORED_TX_GAS_LIMIT,
359
- )
360
- .send()
361
- .deployed();
362
-
363
- // Mint some Fee Juice to the subscription contract
364
- // Could also use bridgeFromL1ToL2 from the harness, but this is more direct
365
- await this.mintAndBridgeFeeJuice(subscriptionContract.address, FEE_FUNDING_FOR_TESTER_ACCOUNT);
366
- return {
367
- counterContractAddress: counterContract.address,
368
- subscriptionContractAddress: subscriptionContract.address,
369
- };
370
- },
371
- async ({ counterContractAddress, subscriptionContractAddress }) => {
372
- this.counterContract = await CounterContract.at(counterContractAddress, this.bobWallet);
373
- this.subscriptionContract = await AppSubscriptionContract.at(subscriptionContractAddress, this.bobWallet);
374
- },
375
- );
376
- }
377
390
  }
@@ -0,0 +1,74 @@
1
+ import { AztecAddress, Fr, type L2Block } from '@aztec/aztec.js';
2
+ import { BatchedBlob, Blob } from '@aztec/blob-lib';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+
5
+ import { writeFile } from 'fs/promises';
6
+
7
+ const AZTEC_GENERATE_TEST_DATA = !!process.env.AZTEC_GENERATE_TEST_DATA;
8
+
9
+ /**
10
+ * Creates a json object that can be used to test the solidity contract.
11
+ * The json object must be put into
12
+ */
13
+ export async function writeJson(
14
+ fileName: string,
15
+ block: L2Block,
16
+ l1ToL2Content: Fr[],
17
+ blobs: Blob[],
18
+ batchedBlob: BatchedBlob,
19
+ recipientAddress: AztecAddress,
20
+ deployerAddress: `0x${string}`,
21
+ ): Promise<void> {
22
+ if (!AZTEC_GENERATE_TEST_DATA) {
23
+ return;
24
+ }
25
+ // Path relative to the package.json in the end-to-end folder
26
+ const path = `../../l1-contracts/test/fixtures/${fileName}.json`;
27
+
28
+ const asHex = (value: Fr | Buffer | EthAddress | AztecAddress, size = 64) => {
29
+ const buffer = Buffer.isBuffer(value) ? value : value.toBuffer();
30
+ return `0x${buffer.toString('hex').padStart(size, '0')}`;
31
+ };
32
+
33
+ const jsonObject = {
34
+ populate: {
35
+ l1ToL2Content: l1ToL2Content.map(asHex),
36
+ recipient: asHex(recipientAddress.toField()),
37
+ sender: deployerAddress,
38
+ },
39
+ messages: {
40
+ l2ToL1Messages: block.body.txEffects.flatMap(txEffect => txEffect.l2ToL1Msgs).map(asHex),
41
+ },
42
+ block: {
43
+ // The json formatting in forge is a bit brittle, so we convert Fr to a number in the few values below.
44
+ // This should not be a problem for testing as long as the values are not larger than u32.
45
+ archive: asHex(block.archive.root),
46
+ blobCommitments: Blob.getPrefixedEthBlobCommitments(blobs),
47
+ batchedBlobInputs: batchedBlob.getEthBlobEvaluationInputs(),
48
+ blockNumber: block.number,
49
+ body: `0x${block.body.toBuffer().toString('hex')}`,
50
+ header: {
51
+ lastArchiveRoot: asHex(block.header.lastArchive.root),
52
+ contentCommitment: {
53
+ blobsHash: asHex(block.header.contentCommitment.blobsHash),
54
+ inHash: asHex(block.header.contentCommitment.inHash),
55
+ outHash: asHex(block.header.contentCommitment.outHash),
56
+ },
57
+ slotNumber: Number(block.header.globalVariables.slotNumber),
58
+ timestamp: Number(block.header.globalVariables.timestamp),
59
+ coinbase: asHex(block.header.globalVariables.coinbase, 40),
60
+ feeRecipient: asHex(block.header.globalVariables.feeRecipient),
61
+ gasFees: {
62
+ feePerDaGas: Number(block.header.globalVariables.gasFees.feePerDaGas),
63
+ feePerL2Gas: Number(block.header.globalVariables.gasFees.feePerL2Gas),
64
+ },
65
+ totalManaUsed: block.header.totalManaUsed.toNumber(),
66
+ },
67
+ headerHash: asHex(block.header.toPropose().hash()),
68
+ numTxs: block.body.txEffects.length,
69
+ },
70
+ };
71
+
72
+ const output = JSON.stringify(jsonObject, null, 2);
73
+ await writeFile(path, output, 'utf8');
74
+ }