@@ -15,6 +15,7 @@ import { GSEContract } from './contracts/gse.js';
1515import { RegistryContract } from './contracts/registry.js' ;
1616import { RollupContract } from './contracts/rollup.js' ;
1717import { type DeployL1ContractsArgs , type Operator , deployL1Contracts } from './deploy_l1_contracts.js' ;
18+ import { EthCheatCodes } from './test/eth_cheat_codes.js' ;
1819import { startAnvil } from './test/start_anvil.js' ;
1920import type { ExtendedViemWalletClient } from './types.js' ;
2021
@@ -26,13 +27,16 @@ describe('deploy_l1_contracts', () => {
2627 let protocolContractTreeRoot : Fr ;
2728 let genesisArchiveRoot : Fr ;
2829 let initialValidators : Operator [ ] ;
30+ let timeout : NodeJS . Timeout ;
2931
3032 // Use these environment variables to run against a live node. Eg to test against spartan's eth-devnet:
3133 // BLOCK_TIME=1 spartan/aztec-network/eth-devnet/run-locally.sh
3234 // LOG_LEVEL=verbose L1_RPC_URL=http://localhost:8545 L1_CHAIN_ID=1337 yarn test deploy_l1_contracts
3335 const chainId = process . env . L1_CHAIN_ID ? parseInt ( process . env . L1_CHAIN_ID , 10 ) : 31337 ;
36+
3437 let rpcUrl = process . env . L1_RPC_URL ;
3538 let client : ExtendedViemWalletClient ;
39+ let cheat : EthCheatCodes ;
3640 let stop : ( ) => Promise < void > = ( ) => Promise . resolve ( ) ;
3741
3842 beforeAll ( async ( ) => {
@@ -53,9 +57,14 @@ describe('deploy_l1_contracts', () => {
5357 }
5458
5559 client = createExtendedL1Client ( [ rpcUrl ] , privateKey , createEthereumChain ( [ rpcUrl ] , chainId ) . chainInfo ) ;
60+ cheat = new EthCheatCodes ( [ rpcUrl ] ) ;
5661 } ) ;
5762
5863 afterAll ( async ( ) => {
64+ if ( timeout ) {
65+ clearTimeout ( timeout ) ;
66+ }
67+
5968 if ( stop ) {
6069 try {
6170 await stop ( ) ;
@@ -65,17 +74,26 @@ describe('deploy_l1_contracts', () => {
6574 }
6675 } ) ;
6776
68- const deploy = ( args : Partial < DeployL1ContractsArgs > = { } ) =>
69- deployL1Contracts ( [ rpcUrl ! ] , privateKey , createEthereumChain ( [ rpcUrl ! ] , chainId ) . chainInfo , logger , {
70- ...DefaultL1ContractsConfig ,
71- salt : undefined ,
72- vkTreeRoot,
73- protocolContractTreeRoot,
74- genesisArchiveRoot,
75- l1TxConfig : { checkIntervalMs : 100 } ,
76- realVerifier : false ,
77- ...args ,
78- } ) ;
77+ const deploy = ( args : Partial < DeployL1ContractsArgs > & { flushEntryQueue ?: boolean } = { } ) =>
78+ deployL1Contracts (
79+ [ rpcUrl ! ] ,
80+ privateKey ,
81+ createEthereumChain ( [ rpcUrl ! ] , chainId ) . chainInfo ,
82+ logger ,
83+ {
84+ ...DefaultL1ContractsConfig ,
85+ salt : undefined ,
86+ vkTreeRoot,
87+ protocolContractTreeRoot,
88+ genesisArchiveRoot,
89+ l1TxConfig : { checkIntervalMs : 100 } ,
90+ realVerifier : false ,
91+ ...args ,
92+ } ,
93+ undefined ,
94+ false ,
95+ args . flushEntryQueue ?? true ,
96+ ) ;
7997
8098 const getRollup = ( deployed : Awaited < ReturnType < typeof deploy > > ) =>
8199 new RollupContract ( deployed . l1Client , deployed . l1ContractAddresses . rollupAddress ) ;
@@ -147,22 +165,48 @@ describe('deploy_l1_contracts', () => {
147165 } ) ;
148166
149167 it ( 'deploys and adds 48 initialValidators' , async ( ) => {
150- // Adds 48 validators.
151- // Note, that not all 48 validators is necessarily added in the active set, some might be in the entry queue
152-
168+ // Adds 48 validators. Note, that not all 48 validators is necessarily added in the active set, some might be in the entry queue
153169 const initialValidators = times ( 48 , ( ) => {
154170 const addr = EthAddress . random ( ) ;
155171 const bn254SecretKey = new SecretValue ( Fr . random ( ) . toBigInt ( ) ) ;
156172 return { attester : addr , withdrawer : addr , bn254SecretKey } ;
157173 } ) ;
158- const info = await deploy ( { initialValidators, aztecTargetCommitteeSize : initialValidators . length } ) ;
159- const rollup = new RollupContract ( client , info . l1ContractAddresses . rollupAddress ) ;
160174
175+ const info = await deploy ( {
176+ initialValidators,
177+ aztecTargetCommitteeSize : initialValidators . length ,
178+ flushEntryQueue : false ,
179+ } ) ;
180+
181+ const rollup = new RollupContract ( client , info . l1ContractAddresses . rollupAddress ) ;
161182 expect ( ( await rollup . getActiveAttesterCount ( ) ) + ( await rollup . getEntryQueueLength ( ) ) ) . toEqual (
162183 BigInt ( initialValidators . length ) ,
163184 ) ;
164185 } ) ;
165186
187+ it ( 'deploys and flushes 48 initialValidators' , async ( ) => {
188+ // Adds 48 validators. This time we flush the entry queue so we can verify that the flushing logic works as expected.
189+ const initialValidators = times ( 48 , ( ) => {
190+ const addr = EthAddress . random ( ) ;
191+ const bn254SecretKey = new SecretValue ( Fr . random ( ) . toBigInt ( ) ) ;
192+ return { attester : addr , withdrawer : addr , bn254SecretKey } ;
193+ } ) ;
194+
195+ // Set an interval to advance the chain, otherwise we get stuck in "Waiting for next flushable epoch"
196+ let timestamp = await client . getBlock ( { includeTransactions : false } ) . then ( b => b . timestamp ) ;
197+ timeout = setInterval ( ( ) => void cheat . warp ( ( timestamp += 60n * 60n ) ) , 1000 ) ;
198+
199+ const info = await deploy ( {
200+ initialValidators,
201+ aztecTargetCommitteeSize : initialValidators . length ,
202+ flushEntryQueue : true ,
203+ } ) ;
204+ const rollup = new RollupContract ( client , info . l1ContractAddresses . rollupAddress ) ;
205+
206+ expect ( await rollup . getEntryQueueLength ( ) ) . toEqual ( 0n ) ;
207+ expect ( await rollup . getActiveAttesterCount ( ) ) . toEqual ( BigInt ( initialValidators . length ) ) ;
208+ } ) ;
209+
166210 it ( 'ensure governance is the owner' , async ( ) => {
167211 // Runs the deployment script and checks if we have handed over things correctly to the governance.
168212
0 commit comments