@aztec/aztec 0.0.1-commit.e588bc7e5 → 0.0.1-commit.e5a3663dd

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 (72) hide show
  1. package/dest/cli/aztec_start_action.d.ts +1 -1
  2. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  3. package/dest/cli/aztec_start_action.js +13 -4
  4. package/dest/cli/aztec_start_options.d.ts +2 -2
  5. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  6. package/dest/cli/aztec_start_options.js +13 -6
  7. package/dest/cli/cmds/compile.d.ts +1 -1
  8. package/dest/cli/cmds/compile.d.ts.map +1 -1
  9. package/dest/cli/cmds/compile.js +1 -14
  10. package/dest/cli/cmds/profile.d.ts +1 -1
  11. package/dest/cli/cmds/profile.d.ts.map +1 -1
  12. package/dest/cli/cmds/profile.js +1 -1
  13. package/dest/cli/cmds/profile_gates.d.ts +2 -2
  14. package/dest/cli/cmds/profile_gates.d.ts.map +1 -1
  15. package/dest/cli/cmds/profile_gates.js +21 -3
  16. package/dest/cli/cmds/standby.d.ts +1 -1
  17. package/dest/cli/cmds/standby.js +2 -2
  18. package/dest/cli/cmds/start_archiver.d.ts +1 -1
  19. package/dest/cli/cmds/start_archiver.d.ts.map +1 -1
  20. package/dest/cli/cmds/start_archiver.js +3 -1
  21. package/dest/cli/cmds/start_node.d.ts +1 -1
  22. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  23. package/dest/cli/cmds/start_node.js +3 -5
  24. package/dest/cli/cmds/start_prover_agent.js +2 -2
  25. package/dest/cli/cmds/start_prover_broker.js +2 -2
  26. package/dest/cli/cmds/start_txe.d.ts +2 -2
  27. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  28. package/dest/cli/cmds/start_txe.js +4 -3
  29. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +2 -2
  30. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -1
  31. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +33 -12
  32. package/dest/local-network/local-network.d.ts +3 -4
  33. package/dest/local-network/local-network.d.ts.map +1 -1
  34. package/dest/local-network/local-network.js +3 -3
  35. package/dest/testing/anvil_test_watcher.d.ts +7 -3
  36. package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
  37. package/dest/testing/anvil_test_watcher.js +39 -13
  38. package/dest/testing/cheat_codes.d.ts +11 -15
  39. package/dest/testing/cheat_codes.d.ts.map +1 -1
  40. package/dest/testing/cheat_codes.js +33 -31
  41. package/dest/testing/index.d.ts +2 -2
  42. package/dest/testing/index.d.ts.map +1 -1
  43. package/package.json +33 -33
  44. package/scripts/add_crate.sh +8 -58
  45. package/scripts/aztec.sh +5 -1
  46. package/scripts/init.sh +5 -5
  47. package/scripts/new.sh +2 -2
  48. package/scripts/setup_workspace.sh +3 -2
  49. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  50. package/scripts/templates/blank/contract/src/main.nr +10 -0
  51. package/scripts/templates/blank/test/Nargo.toml +7 -0
  52. package/scripts/templates/blank/test/src/lib.nr +11 -0
  53. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  54. package/scripts/templates/counter/contract/src/main.nr +48 -0
  55. package/scripts/templates/counter/test/Nargo.toml +7 -0
  56. package/scripts/templates/counter/test/src/lib.nr +32 -0
  57. package/src/cli/aztec_start_action.ts +7 -4
  58. package/src/cli/aztec_start_options.ts +20 -11
  59. package/src/cli/cmds/compile.ts +1 -17
  60. package/src/cli/cmds/profile.ts +2 -1
  61. package/src/cli/cmds/profile_gates.ts +20 -4
  62. package/src/cli/cmds/standby.ts +2 -2
  63. package/src/cli/cmds/start_archiver.ts +7 -1
  64. package/src/cli/cmds/start_node.ts +2 -4
  65. package/src/cli/cmds/start_prover_agent.ts +2 -2
  66. package/src/cli/cmds/start_prover_broker.ts +2 -2
  67. package/src/cli/cmds/start_txe.ts +5 -3
  68. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +35 -12
  69. package/src/local-network/local-network.ts +5 -5
  70. package/src/testing/anvil_test_watcher.ts +43 -12
  71. package/src/testing/cheat_codes.ts +41 -35
  72. package/src/testing/index.ts +1 -1
@@ -1,9 +1,8 @@
1
1
  import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
2
- import { BlockNumber } from '@aztec/foundation/branded-types';
3
- import { retryUntil } from '@aztec/foundation/retry';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { createLogger } from '@aztec/foundation/log';
4
4
  import type { DateProvider } from '@aztec/foundation/timer';
5
- import type { SequencerClient } from '@aztec/sequencer-client';
6
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
+ import type { AztecNode, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
7
6
 
8
7
  /**
9
8
  * A class that provides utility functions for interacting with the chain.
@@ -12,6 +11,8 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
12
11
  * codes, please consider whether it makes sense to just introduce new utils in your tests instead.
13
12
  */
14
13
  export class CheatCodes {
14
+ private logger = createLogger('aztecjs:cheat_codes');
15
+
15
16
  constructor(
16
17
  /** Cheat codes for L1.*/
17
18
  public eth: EthCheatCodes,
@@ -30,50 +31,55 @@ export class CheatCodes {
30
31
 
31
32
  /**
32
33
  * Warps the L1 timestamp to a target timestamp and mines an L2 block that advances the L2 timestamp to at least
33
- * the target timestamp. L2 timestamp is not advanced exactly to the target timestamp because it is determined
34
- * by the slot number, which advances in fixed intervals.
35
- * This is useful for testing time-dependent contract behavior.
36
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
37
- * @param node - The Aztec node used to query if a new block has been mined.
34
+ * the target timestamp. If the target timestamp falls within the current L2 slot (which already has a block),
35
+ * the timestamp is automatically adjusted forward to the start of the next slot so that `mineBlock()` succeeds.
36
+ * @param node - The Aztec node used to force an empty block to be mined.
38
37
  * @param targetTimestamp - The target timestamp to warp to (in seconds)
39
38
  */
40
- async warpL2TimeAtLeastTo(sequencerClient: SequencerClient, node: AztecNode, targetTimestamp: bigint | number) {
41
- const currentL2BlockNumber: BlockNumber = await node.getBlockNumber();
39
+ async warpL2TimeAtLeastTo(node: AztecNodeDebug, targetTimestamp: bigint | number) {
40
+ const targetBigInt = BigInt(targetTimestamp);
41
+ const currentTimestamp = BigInt(await this.eth.lastBlockTimestamp());
42
42
 
43
- // We warp the L1 timestamp
44
- await this.eth.warp(targetTimestamp, { resetBlockInterval: true });
43
+ if (targetBigInt <= currentTimestamp) {
44
+ throw new Error(
45
+ `warpL2TimeAtLeastTo: target timestamp ${targetBigInt} is not in the future (current L1 timestamp is ${currentTimestamp}).`,
46
+ );
47
+ }
45
48
 
46
- // Wait until an L2 block is mined
47
- const sequencer = sequencerClient.getSequencer();
48
- const minTxsPerBlock = sequencer.getConfig().minTxsPerBlock;
49
- sequencer.updateConfig({ minTxsPerBlock: 0 });
49
+ const currentSlot = await this.rollup.getSlot();
50
+ const targetSlot = await this.rollup.getSlotAt(targetBigInt);
50
51
 
51
- await retryUntil(
52
- async () => {
53
- const newL2BlockNumber: BlockNumber = await node.getBlockNumber();
54
- return newL2BlockNumber > currentL2BlockNumber;
55
- },
56
- 'new block after warping L2 time',
57
- 36,
58
- 1,
59
- );
52
+ let effectiveTimestamp = targetBigInt;
60
53
 
61
- // Restore original minTxsPerBlock
62
- sequencer.updateConfig({ minTxsPerBlock });
54
+ if (targetSlot <= currentSlot) {
55
+ // Target lands in the same (or earlier) slot — auto-adjust to the next slot's start.
56
+ const nextSlot = SlotNumber(currentSlot + 1);
57
+ const nextSlotTimestamp = await this.rollup.getTimestampForSlot(nextSlot);
58
+ this.logger.warn(
59
+ `warpL2TimeAtLeastTo: target timestamp ${targetBigInt} falls in current slot ${currentSlot}. ` +
60
+ `Auto-adjusting to start of slot ${nextSlot} at timestamp ${nextSlotTimestamp}.`,
61
+ );
62
+ effectiveTimestamp = nextSlotTimestamp;
63
+ }
64
+
65
+ await this.eth.warp(effectiveTimestamp, { resetBlockInterval: true });
66
+ await node.mineBlock();
63
67
  }
64
68
 
65
69
  /**
66
70
  * Warps the L1 timestamp forward by a specified duration and mines an L2 block that advances the L2 timestamp at
67
- * least by the duration. L2 timestamp is not advanced exactly by the duration because it is determined by the slot
68
- * number, which advances in fixed intervals.
69
- * This is useful for testing time-dependent contract behavior.
70
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
71
- * @param node - The Aztec node used to query if a new block has been mined.
71
+ * least by the duration. If the duration is too short to cross an L2 slot boundary, the warp is automatically
72
+ * extended to the start of the next slot so that `mineBlock()` succeeds.
73
+ * @param node - The Aztec node used to force an empty block to be mined.
72
74
  * @param duration - The duration to advance time by (in seconds)
73
75
  */
74
- async warpL2TimeAtLeastBy(sequencerClient: SequencerClient, node: AztecNode, duration: bigint | number) {
76
+ async warpL2TimeAtLeastBy(node: AztecNodeDebug, duration: bigint | number) {
77
+ if (BigInt(duration) <= 0n) {
78
+ throw new Error(`warpL2TimeAtLeastBy: duration must be positive, got ${duration} seconds.`);
79
+ }
80
+
75
81
  const currentTimestamp = await this.eth.lastBlockTimestamp();
76
82
  const targetTimestamp = BigInt(currentTimestamp) + BigInt(duration);
77
- await this.warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp);
83
+ await this.warpL2TimeAtLeastTo(node, targetTimestamp);
78
84
  }
79
85
  }
@@ -1,4 +1,4 @@
1
- export { AnvilTestWatcher } from './anvil_test_watcher.js';
1
+ export { AnvilTestWatcher, type AnvilTestWatcherOpts } from './anvil_test_watcher.js';
2
2
  export { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
3
3
  export { CheatCodes } from './cheat_codes.js';
4
4
  export { EpochTestSettler } from './epoch_test_settler.js';