Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ jobs:
run: |
ci_run zkstack chain create \
--chain-name gateway \
--chain-id 505 \
--chain-id 506 \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
Expand Down
58 changes: 43 additions & 15 deletions core/tests/gateway-migration-test/tests/migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Migration From/To gateway test', function () {
// The diamond proxy contract on the settlement layer.
let l1MainContract: ethers.Contract;
let gwMainContract: ethers.Contract;
let chainGatewayContract: ethers.Contract;

let gatewayChain: string;
let logs: fs.FileHandle;
Expand Down Expand Up @@ -70,6 +71,11 @@ describe('Migration From/To gateway test', function () {
chain: fileConfig.chain,
config: 'contracts.yaml'
});
const chainGatewayConfig = loadConfig({
pathToHome,
chain: fileConfig.chain,
config: 'gateway_chain.yaml'
});
const secretsConfig = loadConfig({
pathToHome,
chain: fileConfig.chain,
Expand All @@ -85,19 +91,30 @@ describe('Migration From/To gateway test', function () {
baseTokenAddress: contractsConfig.l1.base_token_addr
});

tester = await Tester.init(ethProviderAddress!, web3JsonRpc!);
await mainNodeSpawner.killAndSpawnMainNode();

const gatewayRpcUrl = secretsConfig.l1.gateway_rpc_url;
tester = await Tester.init(ethProviderAddress!, web3JsonRpc!, gatewayRpcUrl!);
alice = tester.emptyWallet();

l1MainContract = new ethers.Contract(
contractsConfig.l1.diamond_proxy_addr,
ZK_CHAIN_INTERFACE,
tester.syncWallet.providerL1
);

let gatewayInfo = getGatewayInfo(pathToHome, fileConfig.chain!);
let gwMainContractsAddress = await gatewayInfo?.gatewayProvider.getMainContractAddress()!;
gwMainContract = new ethers.Contract(gwMainContractsAddress, ZK_CHAIN_INTERFACE, tester.syncWallet.providerL1);

chainGatewayContract = new ethers.Contract(
chainGatewayConfig.diamond_proxy_addr,
ZK_CHAIN_INTERFACE,
tester.gwProvider
);
});

step('Run server and execute some transactions', async () => {
await mainNodeSpawner.killAndSpawnMainNode();

let blocksCommitted = await l1MainContract.getTotalBatchesCommitted();

const initialL1BatchNumber = await tester.web3Provider.getL1BatchNumber();
Expand Down Expand Up @@ -159,17 +176,18 @@ describe('Migration From/To gateway test', function () {
tryCount += 1;
await utils.sleep(1);
}
});

// Additionally wait until the priority queue is empty if we are migrating to gateway
if (direction == 'TO') {
let priorityQueueSize = await l1MainContract.getPriorityQueueSize();
let tryCount = 0;
while (priorityQueueSize > 0 && tryCount < 30) {
priorityQueueSize = await l1MainContract.getPriorityQueueSize();
tryCount += 1;
await utils.sleep(1);
}
step('Pause deposits before initiating migration', async () => {
await utils.spawn(`zkstack chain pause-deposits --chain ${fileConfig.chain}`);

// Wait until the priority queue is empty
let tryCount = 0;
while ((await getPriorityQueueSize()) > 0 && tryCount < 100) {
tryCount += 1;
await utils.sleep(1);
}
console.error('tryCount', tryCount);
});

step('Migrate to/from gateway', async () => {
Expand All @@ -185,6 +203,7 @@ describe('Migration From/To gateway test', function () {
// where there is an inflight transaction before the migration is complete.
// If you encounter an error, such as a failed transaction, after the migration,
// this area might be worth revisiting to wait for unconfirmed transactions on the server.
await utils.sleep(30);

if (direction == 'TO') {
await utils.spawn(
Expand All @@ -208,9 +227,6 @@ describe('Migration From/To gateway test', function () {
gatewayInfo?.gatewayProvider
);

let gwMainContractsAddress = await gatewayInfo?.gatewayProvider.getMainContractAddress()!;
gwMainContract = new ethers.Contract(gwMainContractsAddress, ZK_CHAIN_INTERFACE, tester.syncWallet.providerL1);

let slAddressl1 = await l1MainContract.getSettlementLayer();
let slAddressGW = await slMainContract.getSettlementLayer();
if (direction == 'TO') {
Expand All @@ -229,6 +245,10 @@ describe('Migration From/To gateway test', function () {
await txHandle.waitFinalize();
});

step('Unpause deposits', async () => {
await utils.spawn(`zkstack chain unpause-deposits --chain ${fileConfig.chain}`);
});

step('Migrate token balances', async () => {
if (direction == 'TO') {
await utils.spawn(
Expand Down Expand Up @@ -304,6 +324,14 @@ describe('Migration From/To gateway test', function () {
mainNodeSpawner.mainNode?.terminate();
} catch (_) {}
});

async function getPriorityQueueSize() {
if (direction == 'TO') {
return await l1MainContract.getPriorityQueueSize();
} else {
return await chainGatewayContract.getPriorityQueueSize();
}
}
});

async function checkedRandomTransfer(sender: zksync.Wallet, amount: bigint): Promise<zksync.types.TransactionResponse> {
Expand Down
7 changes: 5 additions & 2 deletions core/tests/gateway-migration-test/tests/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export class Tester {
public ethWallet: ethers.Wallet,
public syncWallet: zksync.Wallet,
public web3Provider: zksync.Provider,
public gwProvider: zksync.Provider,
public token: L1Token
) {
this.runningFee = new Map();
}

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

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


Expand All @@ -54,7 +57,7 @@ export class Tester {

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

return new Tester(ethProvider, ethWallet, syncWallet, web3Provider, token);
return new Tester(ethProvider, ethWallet, syncWallet, web3Provider, gwProvider, token);
}

emptyWallet() {
Expand Down
2 changes: 1 addition & 1 deletion core/tests/ts-integration/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';
export const REQUIRED_L2_GAS_PRICE_PER_PUBDATA = 800;

export const SYSTEM_UPGRADE_L2_TX_TYPE = 254;
export const GATEWAY_CHAIN_ID = 505;
export const GATEWAY_CHAIN_ID = 506;
export const ADDRESS_ONE = '0x0000000000000000000000000000000000000001';
export const ETH_ADDRESS_IN_CONTRACTS = ADDRESS_ONE;
export const L1_TO_L2_ALIAS_OFFSET = '0x1111000000000000000000000000000000001111';
Expand Down
18 changes: 18 additions & 0 deletions core/tests/ts-integration/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ async function loadTestEnvironmentFromFile(
const l1BatchCommitDataGeneratorMode = genesisConfig.l1_batch_commit_data_generator_mode as DataAvailabityMode;
const minimalL2GasPrice = BigInt(generalConfig.state_keeper.minimal_l2_gas_price);

let baseTokenSecondChain;
if (secondChainFileConfig) {
const l2ProviderSecondChain = new zksync.Provider(l2NodeUrlSecondChain);
const baseTokenAddressSecondChain = await l2ProviderSecondChain.getBaseTokenContractAddress();
const { token: _tokenSecondChain, baseToken: _baseTokenSecondChain } = getToken(
pathToHome,
baseTokenAddressSecondChain
);
baseTokenSecondChain = {
name: _baseTokenSecondChain?.name || _tokenSecondChain.name,
symbol: _baseTokenSecondChain?.symbol || _tokenSecondChain.symbol,
decimals: _baseTokenSecondChain?.decimals || _tokenSecondChain.decimals,
l1Address: _baseTokenSecondChain?.address || _tokenSecondChain.address,
l2Address: baseTokenAddressL2
};
}

const validationComputationalGasLimit = parseInt(generalConfig.state_keeper.validation_computational_gas_limit);
// TODO set it properly
const priorityTxMaxGasLimit = 72000000n;
Expand Down Expand Up @@ -214,6 +231,7 @@ async function loadTestEnvironmentFromFile(
l1Address: baseToken?.address || token.address,
l2Address: baseTokenAddressL2
},
baseTokenSecondChain,
timestampAsserterAddress,
timestampAsserterMinTimeTillEndSec,
l2WETHAddress
Expand Down
1 change: 1 addition & 0 deletions core/tests/ts-integration/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export interface TestEnvironment {
* Description of the "base" ERC20 token used in the tests.
*/
baseToken: Token;
baseTokenSecondChain: Token | undefined;
healthcheckPort: string;
timestampAsserterAddress: string;
timestampAsserterMinTimeTillEndSec: number;
Expand Down
Loading
Loading