Skip to content

Commit fe5904b

Browse files
authored
Merge pull request #4577 from matter-labs/sma/medium-interop-fixes
chore: polishing
2 parents d239cb8 + e0f544a commit fe5904b

File tree

15 files changed

+168
-81
lines changed

15 files changed

+168
-81
lines changed

.github/workflows/ci-core-reusable.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ jobs:
239239
run: |
240240
ci_run zkstack chain create \
241241
--chain-name gateway \
242-
--chain-id 505 \
242+
--chain-id 506 \
243243
--prover-mode no-proofs \
244244
--wallet-creation localhost \
245245
--l1-batch-commit-data-generator-mode rollup \

core/tests/gateway-migration-test/tests/migration.test.ts

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

309337
async function checkedRandomTransfer(sender: zksync.Wallet, amount: bigint): Promise<zksync.types.TransactionResponse> {

core/tests/gateway-migration-test/tests/tester.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ export class Tester {
1111
public ethWallet: ethers.Wallet,
1212
public syncWallet: zksync.Wallet,
1313
public web3Provider: zksync.Provider,
14+
public gwProvider: zksync.Provider,
1415
public token: L1Token
1516
) {
1617
this.runningFee = new Map();
1718
}
1819

1920
// prettier-ignore
20-
static async init(ethProviderAddress: string, web3JsonRpc: string) {
21+
static async init(ethProviderAddress: string, web3JsonRpc: string, gatewayRpcUrl: string) {
2122
const pathToHome = path.join(__dirname, '../../../..');
2223

2324
const ethProvider = new ethers.JsonRpcProvider(ethProviderAddress);
@@ -28,6 +29,8 @@ export class Tester {
2829
ethWallet = ethWallet.connect(ethProvider);
2930
const web3Provider = new zksync.Provider(web3JsonRpc);
3031
web3Provider.pollingInterval = 100; // It's OK to keep it low even on stage.
32+
const gwProvider = new zksync.Provider(gatewayRpcUrl);
33+
gwProvider.pollingInterval = 100;
3134
const syncWallet = new zksync.Wallet(ethWallet.privateKey, web3Provider, ethProvider);
3235

3336

@@ -54,7 +57,7 @@ export class Tester {
5457

5558
const { token, } = getToken(pathToHome, baseTokenAddress);
5659

57-
return new Tester(ethProvider, ethWallet, syncWallet, web3Provider, token);
60+
return new Tester(ethProvider, ethWallet, syncWallet, web3Provider, gwProvider, token);
5861
}
5962

6063
emptyWallet() {

core/tests/ts-integration/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from 'fs';
33
export const REQUIRED_L2_GAS_PRICE_PER_PUBDATA = 800;
44

55
export const SYSTEM_UPGRADE_L2_TX_TYPE = 254;
6-
export const GATEWAY_CHAIN_ID = 505;
6+
export const GATEWAY_CHAIN_ID = 506;
77
export const ADDRESS_ONE = '0x0000000000000000000000000000000000000001';
88
export const ETH_ADDRESS_IN_CONTRACTS = ADDRESS_ONE;
99
export const L1_TO_L2_ALIAS_OFFSET = '0x1111000000000000000000000000000000001111';

core/tests/ts-integration/src/env.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ async function loadTestEnvironmentFromFile(
171171
const l1BatchCommitDataGeneratorMode = genesisConfig.l1_batch_commit_data_generator_mode as DataAvailabityMode;
172172
const minimalL2GasPrice = BigInt(generalConfig.state_keeper.minimal_l2_gas_price);
173173

174+
let baseTokenSecondChain;
175+
if (secondChainFileConfig) {
176+
const l2ProviderSecondChain = new zksync.Provider(l2NodeUrlSecondChain);
177+
const baseTokenAddressSecondChain = await l2ProviderSecondChain.getBaseTokenContractAddress();
178+
const { token: _tokenSecondChain, baseToken: _baseTokenSecondChain } = getToken(
179+
pathToHome,
180+
baseTokenAddressSecondChain
181+
);
182+
baseTokenSecondChain = {
183+
name: _baseTokenSecondChain?.name || _tokenSecondChain.name,
184+
symbol: _baseTokenSecondChain?.symbol || _tokenSecondChain.symbol,
185+
decimals: _baseTokenSecondChain?.decimals || _tokenSecondChain.decimals,
186+
l1Address: _baseTokenSecondChain?.address || _tokenSecondChain.address,
187+
l2Address: baseTokenAddressL2
188+
};
189+
}
190+
174191
const validationComputationalGasLimit = parseInt(generalConfig.state_keeper.validation_computational_gas_limit);
175192
// TODO set it properly
176193
const priorityTxMaxGasLimit = 72000000n;
@@ -214,6 +231,7 @@ async function loadTestEnvironmentFromFile(
214231
l1Address: baseToken?.address || token.address,
215232
l2Address: baseTokenAddressL2
216233
},
234+
baseTokenSecondChain,
217235
timestampAsserterAddress,
218236
timestampAsserterMinTimeTillEndSec,
219237
l2WETHAddress

core/tests/ts-integration/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export interface TestEnvironment {
110110
* Description of the "base" ERC20 token used in the tests.
111111
*/
112112
baseToken: Token;
113+
baseTokenSecondChain: Token | undefined;
113114
healthcheckPort: string;
114115
timestampAsserterAddress: string;
115116
timestampAsserterMinTimeTillEndSec: number;

0 commit comments

Comments
 (0)