@@ -41,6 +41,7 @@ describe('Migration From/To gateway test', function () {
4141 // The diamond proxy contract on the settlement layer.
4242 let l1MainContract : ethers . Contract ;
4343 let gwMainContract : ethers . Contract ;
44+ let chainGatewayContract : ethers . Contract ;
4445
4546 let gatewayChain : string ;
4647 let logs : fs . FileHandle ;
@@ -70,6 +71,11 @@ describe('Migration From/To gateway test', function () {
7071 chain : fileConfig . chain ,
7172 config : 'contracts.yaml'
7273 } ) ;
74+ const chainGatewayConfig = loadConfig ( {
75+ pathToHome,
76+ chain : fileConfig . chain ,
77+ config : 'gateway_chain.yaml'
78+ } ) ;
7379 const secretsConfig = loadConfig ( {
7480 pathToHome,
7581 chain : fileConfig . chain ,
@@ -85,19 +91,30 @@ describe('Migration From/To gateway test', function () {
8591 baseTokenAddress : contractsConfig . l1 . base_token_addr
8692 } ) ;
8793
88- tester = await Tester . init ( ethProviderAddress ! , web3JsonRpc ! ) ;
94+ await mainNodeSpawner . killAndSpawnMainNode ( ) ;
95+
96+ const gatewayRpcUrl = secretsConfig . l1 . gateway_rpc_url ;
97+ tester = await Tester . init ( ethProviderAddress ! , web3JsonRpc ! , gatewayRpcUrl ! ) ;
8998 alice = tester . emptyWallet ( ) ;
9099
91100 l1MainContract = new ethers . Contract (
92101 contractsConfig . l1 . diamond_proxy_addr ,
93102 ZK_CHAIN_INTERFACE ,
94103 tester . syncWallet . providerL1
95104 ) ;
105+
106+ let gatewayInfo = getGatewayInfo ( pathToHome , fileConfig . chain ! ) ;
107+ let gwMainContractsAddress = await gatewayInfo ?. gatewayProvider . getMainContractAddress ( ) ! ;
108+ gwMainContract = new ethers . Contract ( gwMainContractsAddress , ZK_CHAIN_INTERFACE , tester . syncWallet . providerL1 ) ;
109+
110+ chainGatewayContract = new ethers . Contract (
111+ chainGatewayConfig . diamond_proxy_addr ,
112+ ZK_CHAIN_INTERFACE ,
113+ tester . gwProvider
114+ ) ;
96115 } ) ;
97116
98117 step ( 'Run server and execute some transactions' , async ( ) => {
99- await mainNodeSpawner . killAndSpawnMainNode ( ) ;
100-
101118 let blocksCommitted = await l1MainContract . getTotalBatchesCommitted ( ) ;
102119
103120 const initialL1BatchNumber = await tester . web3Provider . getL1BatchNumber ( ) ;
@@ -159,17 +176,18 @@ describe('Migration From/To gateway test', function () {
159176 tryCount += 1 ;
160177 await utils . sleep ( 1 ) ;
161178 }
179+ } ) ;
162180
163- // Additionally wait until the priority queue is empty if we are migrating to gateway
164- if ( direction == 'TO' ) {
165- let priorityQueueSize = await l1MainContract . getPriorityQueueSize ( ) ;
166- let tryCount = 0 ;
167- while ( priorityQueueSize > 0 && tryCount < 30 ) {
168- priorityQueueSize = await l1MainContract . getPriorityQueueSize ( ) ;
169- tryCount += 1 ;
170- await utils . sleep ( 1 ) ;
171- }
181+ step ( 'Pause deposits before initiating migration' , async ( ) => {
182+ await utils . spawn ( `zkstack chain pause-deposits --chain ${ fileConfig . chain } ` ) ;
183+
184+ // Wait until the priority queue is empty
185+ let tryCount = 0 ;
186+ while ( ( await getPriorityQueueSize ( ) ) > 0 && tryCount < 100 ) {
187+ tryCount += 1 ;
188+ await utils . sleep ( 1 ) ;
172189 }
190+ console . error ( 'tryCount' , tryCount ) ;
173191 } ) ;
174192
175193 step ( 'Migrate to/from gateway' , async ( ) => {
@@ -185,6 +203,7 @@ describe('Migration From/To gateway test', function () {
185203 // where there is an inflight transaction before the migration is complete.
186204 // If you encounter an error, such as a failed transaction, after the migration,
187205 // this area might be worth revisiting to wait for unconfirmed transactions on the server.
206+ await utils . sleep ( 30 ) ;
188207
189208 if ( direction == 'TO' ) {
190209 await utils . spawn (
@@ -208,9 +227,6 @@ describe('Migration From/To gateway test', function () {
208227 gatewayInfo ?. gatewayProvider
209228 ) ;
210229
211- let gwMainContractsAddress = await gatewayInfo ?. gatewayProvider . getMainContractAddress ( ) ! ;
212- gwMainContract = new ethers . Contract ( gwMainContractsAddress , ZK_CHAIN_INTERFACE , tester . syncWallet . providerL1 ) ;
213-
214230 let slAddressl1 = await l1MainContract . getSettlementLayer ( ) ;
215231 let slAddressGW = await slMainContract . getSettlementLayer ( ) ;
216232 if ( direction == 'TO' ) {
@@ -229,6 +245,10 @@ describe('Migration From/To gateway test', function () {
229245 await txHandle . waitFinalize ( ) ;
230246 } ) ;
231247
248+ step ( 'Unpause deposits' , async ( ) => {
249+ await utils . spawn ( `zkstack chain unpause-deposits --chain ${ fileConfig . chain } ` ) ;
250+ } ) ;
251+
232252 step ( 'Migrate token balances' , async ( ) => {
233253 if ( direction == 'TO' ) {
234254 await utils . spawn (
@@ -304,6 +324,14 @@ describe('Migration From/To gateway test', function () {
304324 mainNodeSpawner . mainNode ?. terminate ( ) ;
305325 } catch ( _ ) { }
306326 } ) ;
327+
328+ async function getPriorityQueueSize ( ) {
329+ if ( direction == 'TO' ) {
330+ return await l1MainContract . getPriorityQueueSize ( ) ;
331+ } else {
332+ return await chainGatewayContract . getPriorityQueueSize ( ) ;
333+ }
334+ }
307335} ) ;
308336
309337async function checkedRandomTransfer ( sender : zksync . Wallet , amount : bigint ) : Promise < zksync . types . TransactionResponse > {
0 commit comments