@aztec/sequencer-client 3.0.0-nightly.20251223 → 3.0.0-nightly.20251225

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.
@@ -0,0 +1,137 @@
1
+ import { Body } from '@aztec/aztec.js/block';
2
+ import { CheckpointNumber } from '@aztec/foundation/branded-types';
3
+ import { times } from '@aztec/foundation/collection';
4
+ import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
6
+ import type { EthAddress } from '@aztec/foundation/eth-address';
7
+ import { Signature } from '@aztec/foundation/eth-signature';
8
+ import type { P2P } from '@aztec/p2p';
9
+ import { PublicDataWrite } from '@aztec/stdlib/avm';
10
+ import { CommitteeAttestation, L2BlockNew } from '@aztec/stdlib/block';
11
+ import { BlockAttestation, BlockProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
12
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
13
+ import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
14
+ import {
15
+ BlockHeader,
16
+ ContentCommitment,
17
+ GlobalVariables,
18
+ type Tx,
19
+ makeProcessedTxFromPrivateOnlyTx,
20
+ } from '@aztec/stdlib/tx';
21
+
22
+ import type { MockProxy } from 'jest-mock-extended';
23
+
24
+ // Re-export mock classes from their dedicated file
25
+ export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
26
+
27
+ /**
28
+ * Creates a mock transaction with a specific seed for deterministic testing
29
+ */
30
+ export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
31
+ const tx = await mockTxForRollup(seed);
32
+ if (chainId) {
33
+ tx.data.constants.txContext.chainId = chainId;
34
+ }
35
+ return tx;
36
+ }
37
+
38
+ /**
39
+ * Creates an L2BlockNew from transactions and global variables
40
+ */
41
+ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2BlockNew> {
42
+ const processedTxs = await Promise.all(
43
+ txs.map(tx =>
44
+ makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
45
+ ),
46
+ );
47
+ const body = new Body(processedTxs.map(tx => tx.txEffect));
48
+ const header = BlockHeader.empty({ globalVariables });
49
+ const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
50
+ return new L2BlockNew(archive, header, body, CheckpointNumber(globalVariables.blockNumber), 0);
51
+ }
52
+
53
+ /**
54
+ * Mocks the P2P client to return specific pending transactions
55
+ */
56
+ export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
57
+ p2p.getPendingTxCount.mockResolvedValue(txs.length);
58
+ p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
59
+ }
60
+
61
+ /**
62
+ * Creates an async iterator for transactions
63
+ */
64
+ export async function* mockTxIterator(txs: Promise<Tx[]>): AsyncIterableIterator<Tx> {
65
+ for (const tx of await txs) {
66
+ yield tx;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Creates mock committee attestations from a signer
72
+ */
73
+ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestation[] {
74
+ const mockedSig = Signature.random();
75
+ return [new CommitteeAttestation(signer.address, mockedSig)];
76
+ }
77
+
78
+ /**
79
+ * Creates a CheckpointHeader from an L2BlockNew for testing purposes.
80
+ * Uses mock values for contentCommitment and blockHeadersHash since
81
+ * L2BlockNew doesn't have these fields.
82
+ */
83
+ function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
84
+ const gv = block.header.globalVariables;
85
+ return new CheckpointHeader(
86
+ block.header.lastArchive.root,
87
+ Fr.random(), // blockHeadersHash - mock value for testing
88
+ ContentCommitment.empty(), // contentCommitment - mock value for testing
89
+ gv.slotNumber,
90
+ gv.timestamp,
91
+ gv.coinbase,
92
+ gv.feeRecipient,
93
+ gv.gasFees,
94
+ block.header.totalManaUsed,
95
+ );
96
+ }
97
+
98
+ /**
99
+ * Creates a block proposal from a block and signature
100
+ */
101
+ export function createBlockProposal(block: L2BlockNew, signature: Signature): BlockProposal {
102
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
103
+ const consensusPayload = new ConsensusPayload(checkpointHeader, block.archive.root);
104
+ const txHashes = block.body.txEffects.map(tx => tx.txHash);
105
+ return new BlockProposal(consensusPayload, signature, txHashes);
106
+ }
107
+
108
+ /**
109
+ * Creates a block attestation from a block and signature.
110
+ * Note: We manually set the sender since we use random signatures in tests.
111
+ * In production, the sender is recovered from the signature.
112
+ */
113
+ export function createBlockAttestation(block: L2BlockNew, signature: Signature, sender: EthAddress): BlockAttestation {
114
+ const checkpointHeader = createCheckpointHeaderFromBlock(block);
115
+ const consensusPayload = new ConsensusPayload(checkpointHeader, block.archive.root);
116
+ const attestation = new BlockAttestation(consensusPayload, signature, signature);
117
+ // Set sender directly for testing (bypasses signature recovery)
118
+
119
+ (attestation as any).sender = sender;
120
+ return attestation;
121
+ }
122
+
123
+ /**
124
+ * Creates transactions and a block, and mocks P2P to return them.
125
+ * Helper for tests that need to set up a block with transactions.
126
+ */
127
+ export async function setupTxsAndBlock(
128
+ p2p: MockProxy<P2P>,
129
+ globalVariables: GlobalVariables,
130
+ txCount: number,
131
+ chainId: Fr,
132
+ ): Promise<{ txs: Tx[]; block: L2BlockNew }> {
133
+ const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
134
+ const block = await makeBlock(txs, globalVariables);
135
+ mockPendingTxs(p2p, txs);
136
+ return { txs, block };
137
+ }