1- import { CheckpointNumber } from '@aztec/foundation/branded-types' ;
21import { Fr } from '@aztec/foundation/curves/bn254' ;
32import type { BlockData } from '@aztec/stdlib/block' ;
43import type { AztecNode } from '@aztec/stdlib/interfaces/client' ;
@@ -8,44 +7,45 @@ import { type MockProxy, mock } from 'jest-mock-extended';
87import { isL1ToL2MessageReady } from './cross_chain.js' ;
98
109describe ( 'isL1ToL2MessageReady' , ( ) => {
11- let node : MockProxy < Pick < AztecNode , 'getBlockData' | 'getL1ToL2MessageCheckpoint ' > > ;
10+ let node : MockProxy < Pick < AztecNode , 'getBlockData' | 'getL1ToL2MessageIndex ' > > ;
1211 let messageHash : Fr ;
1312
14- const blockAtCheckpoint = ( checkpointNumber : number ) =>
15- ( { checkpointNumber : CheckpointNumber ( checkpointNumber ) } ) as BlockData ;
13+ /** A block whose L1-to-L2 message tree holds `leafCount` leaves, i.e. leaf indices 0..leafCount-1. */
14+ const blockWithMessageLeaves = ( leafCount : number ) =>
15+ ( { header : { state : { l1ToL2MessageTree : { nextAvailableLeafIndex : leafCount } } } } ) as BlockData ;
1616
1717 beforeEach ( ( ) => {
1818 node = mock ( ) ;
1919 messageHash = Fr . random ( ) ;
2020 } ) ;
2121
22- it ( 'returns false when the message is not yet in any checkpoint ' , async ( ) => {
23- node . getL1ToL2MessageCheckpoint . mockResolvedValue ( undefined ) ;
22+ it ( 'returns false when the node has not seen the message yet ' , async ( ) => {
23+ node . getL1ToL2MessageIndex . mockResolvedValue ( undefined ) ;
2424
2525 expect ( await isL1ToL2MessageReady ( node , messageHash ) ) . toBe ( false ) ;
2626 expect ( node . getBlockData ) . not . toHaveBeenCalled ( ) ;
2727 } ) ;
2828
2929 describe ( 'latest fallback (no chain tip)' , ( ) => {
3030 beforeEach ( ( ) => {
31- node . getL1ToL2MessageCheckpoint . mockResolvedValue ( CheckpointNumber ( 5 ) ) ;
31+ node . getL1ToL2MessageIndex . mockResolvedValue ( 5n ) ;
3232 } ) ;
3333
34- it ( 'checks readiness against the latest block' , async ( ) => {
35- node . getBlockData . mockResolvedValue ( blockAtCheckpoint ( 5 ) ) ;
34+ it ( 'returns true once the latest block has consumed the message leaf ' , async ( ) => {
35+ node . getBlockData . mockResolvedValue ( blockWithMessageLeaves ( 6 ) ) ;
3636
3737 expect ( await isL1ToL2MessageReady ( node , messageHash ) ) . toBe ( true ) ;
3838 expect ( node . getBlockData ) . toHaveBeenCalledWith ( 'latest' ) ;
3939 } ) ;
4040
41- it ( 'returns true once the latest block reaches the message checkpoint ' , async ( ) => {
42- node . getBlockData . mockResolvedValue ( blockAtCheckpoint ( 6 ) ) ;
41+ it ( 'returns false when the latest block stops exactly at the message leaf ' , async ( ) => {
42+ node . getBlockData . mockResolvedValue ( blockWithMessageLeaves ( 5 ) ) ;
4343
44- expect ( await isL1ToL2MessageReady ( node , messageHash ) ) . toBe ( true ) ;
44+ expect ( await isL1ToL2MessageReady ( node , messageHash ) ) . toBe ( false ) ;
4545 } ) ;
4646
47- it ( 'returns false when the latest block is behind the message checkpoint ' , async ( ) => {
48- node . getBlockData . mockResolvedValue ( blockAtCheckpoint ( 4 ) ) ;
47+ it ( 'returns false when the latest block is behind the message leaf ' , async ( ) => {
48+ node . getBlockData . mockResolvedValue ( blockWithMessageLeaves ( 4 ) ) ;
4949
5050 expect ( await isL1ToL2MessageReady ( node , messageHash ) ) . toBe ( false ) ;
5151 } ) ;
@@ -59,23 +59,23 @@ describe('isL1ToL2MessageReady', () => {
5959
6060 describe ( 'with an explicit chain tip' , ( ) => {
6161 beforeEach ( ( ) => {
62- node . getL1ToL2MessageCheckpoint . mockResolvedValue ( CheckpointNumber ( 5 ) ) ;
62+ node . getL1ToL2MessageIndex . mockResolvedValue ( 5n ) ;
6363 } ) ;
6464
6565 it ( 'compares against the requested tip instead of latest' , async ( ) => {
66- // The proven tip lags behind latest: the message is in checkpoint 5 but proven is only at 4 .
66+ // The proven tip lags behind latest: latest consumed the message leaf, proven has not .
6767 node . getBlockData . mockImplementation ( param =>
68- Promise . resolve ( param === 'proven' ? blockAtCheckpoint ( 4 ) : blockAtCheckpoint ( 6 ) ) ,
68+ Promise . resolve ( param === 'proven' ? blockWithMessageLeaves ( 5 ) : blockWithMessageLeaves ( 7 ) ) ,
6969 ) ;
7070
7171 expect ( await isL1ToL2MessageReady ( node , messageHash , 'latest' ) ) . toBe ( true ) ;
7272 expect ( await isL1ToL2MessageReady ( node , messageHash , 'proven' ) ) . toBe ( false ) ;
7373 expect ( node . getBlockData ) . toHaveBeenLastCalledWith ( 'proven' ) ;
7474 } ) ;
7575
76- it ( 'returns true once the requested tip reaches the message checkpoint ' , async ( ) => {
76+ it ( 'returns true once the requested tip has consumed the message leaf ' , async ( ) => {
7777 node . getBlockData . mockImplementation ( param =>
78- Promise . resolve ( param === 'proven' ? blockAtCheckpoint ( 5 ) : blockAtCheckpoint ( 7 ) ) ,
78+ Promise . resolve ( param === 'proven' ? blockWithMessageLeaves ( 6 ) : blockWithMessageLeaves ( 8 ) ) ,
7979 ) ;
8080
8181 expect ( await isL1ToL2MessageReady ( node , messageHash , 'proven' ) ) . toBe ( true ) ;
0 commit comments