11import { TestCircuitVerifier } from '@aztec/bb-prover' ;
22import { EpochCache } from '@aztec/epoch-cache' ;
33import type { RollupContract } from '@aztec/ethereum/contracts' ;
4- import { BlockNumber } from '@aztec/foundation/branded-types' ;
4+ import { BlockNumber , CheckpointNumber , EpochNumber , SlotNumber } from '@aztec/foundation/branded-types' ;
55import { Fr } from '@aztec/foundation/curves/bn254' ;
66import { EthAddress } from '@aztec/foundation/eth-address' ;
77import { BadRequestError } from '@aztec/foundation/json-rpc' ;
@@ -16,7 +16,8 @@ import { computeFeePayerBalanceLeafSlot } from '@aztec/protocol-contracts/fee-ju
1616import type { GlobalVariableBuilder , SequencerClient } from '@aztec/sequencer-client' ;
1717import type { SlasherClientInterface } from '@aztec/slasher' ;
1818import { AztecAddress } from '@aztec/stdlib/aztec-address' ;
19- import { BlockHash , L2Block , type L2BlockSource } from '@aztec/stdlib/block' ;
19+ import { BlockHash , CheckpointedL2Block , L2Block , type L2BlockSource } from '@aztec/stdlib/block' ;
20+ import { L1PublishedData } from '@aztec/stdlib/checkpoint' ;
2021import type { ContractDataSource } from '@aztec/stdlib/contract' ;
2122import { EmptyL1RollupConstants } from '@aztec/stdlib/epoch-helpers' ;
2223import { GasFees } from '@aztec/stdlib/gas' ;
@@ -35,6 +36,7 @@ import {
3536 TX_ERROR_INVALID_EXPIRATION_TIMESTAMP ,
3637 TX_ERROR_SIZE_ABOVE_LIMIT ,
3738 Tx ,
39+ TxEffect ,
3840} from '@aztec/stdlib/tx' ;
3941import { getPackageVersion } from '@aztec/stdlib/update-checker' ;
4042import type { ValidatorClient } from '@aztec/validator-client' ;
@@ -810,4 +812,54 @@ describe('aztec node', () => {
810812 } ) ;
811813 } ) ;
812814 } ) ;
815+
816+ describe ( 'getL2ToL1Messages' , ( ) => {
817+ const makeCheckpointedBlock = ( slotNumber : number , l2ToL1MsgsByTx : Fr [ ] [ ] ) : CheckpointedL2Block => {
818+ const block = L2Block . empty (
819+ BlockHeader . empty ( {
820+ globalVariables : GlobalVariables . empty ( { slotNumber : SlotNumber ( slotNumber ) } ) ,
821+ } ) ,
822+ ) ;
823+ // Override the body's txEffects with our custom l2ToL1Msgs
824+ unfreeze ( block . body ) . txEffects = l2ToL1MsgsByTx . map ( msgs => ( { l2ToL1Msgs : msgs } ) as TxEffect ) ;
825+ return new CheckpointedL2Block ( CheckpointNumber ( 0 ) , block , new L1PublishedData ( 0n , 0n , '0x0' ) , [ ] ) ;
826+ } ;
827+
828+ it ( 'groups blocks by slot number into checkpoints' , async ( ) => {
829+ const msg1 = Fr . random ( ) ;
830+ const msg2 = Fr . random ( ) ;
831+ const msg3 = Fr . random ( ) ;
832+
833+ // Two blocks in slot 1, one block in slot 2
834+ const blocks = [
835+ makeCheckpointedBlock ( 1 , [ [ msg1 ] ] ) ,
836+ makeCheckpointedBlock ( 1 , [ [ msg2 ] ] ) ,
837+ makeCheckpointedBlock ( 2 , [ [ msg3 ] ] ) ,
838+ ] ;
839+
840+ l2BlockSource . getCheckpointedBlocksForEpoch . mockResolvedValue ( blocks ) ;
841+
842+ const result = await node . getL2ToL1Messages ( EpochNumber ( 0 ) ) ;
843+
844+ // First checkpoint (slot 1): 2 blocks, each with 1 tx with 1 message
845+ // Second checkpoint (slot 2): 1 block with 1 tx with 1 message
846+ expect ( result ) . toEqual ( [ [ [ [ msg1 ] ] , [ [ msg2 ] ] ] , [ [ [ msg3 ] ] ] ] ) ;
847+ } ) ;
848+
849+ it ( 'correctly includes blocks in slot zero' , async ( ) => {
850+ const msg1 = Fr . random ( ) ;
851+ const msg2 = Fr . random ( ) ;
852+
853+ // Block in slot 0, block in slot 1
854+ const blocks = [ makeCheckpointedBlock ( 0 , [ [ msg1 ] ] ) , makeCheckpointedBlock ( 1 , [ [ msg2 ] ] ) ] ;
855+
856+ l2BlockSource . getCheckpointedBlocksForEpoch . mockResolvedValue ( blocks ) ;
857+
858+ const result = await node . getL2ToL1Messages ( EpochNumber ( 0 ) ) ;
859+
860+ // First checkpoint (slot 0): 1 block with 1 tx with 1 message
861+ // Second checkpoint (slot 1): 1 block with 1 tx with 1 message
862+ expect ( result ) . toEqual ( [ [ [ [ msg1 ] ] ] , [ [ [ msg2 ] ] ] ] ) ;
863+ } ) ;
864+ } ) ;
813865} ) ;
0 commit comments