Skip to content

Commit

Permalink
chore: Enable upgrade test (#1698)
Browse files Browse the repository at this point in the history
## What ❔

Enable upgrade test

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
StanislavBreadless authored Apr 17, 2024
1 parent 79d39c1 commit 2e334d5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ jobs:
- name: Server integration tests
run: ci_run zk test i server

- name: Snapshot recovery test - DISABLED (EVM-540)
- name: Snapshot recovery test
# We use `yarn` directly because the test launches `zk` commands in both server and EN envs.
# An empty topmost environment helps avoid a mess when redefining env vars shared between both envs
# (e.g., DATABASE_URL).
Expand All @@ -225,12 +225,11 @@ jobs:

# This test should be the last one as soon as it
# finished bootloader will be different
- name: Run upgrade test - DISABLED (EVM-558)
- name: Run upgrade test
run: |
ls
# ci_run pkill zksync_server || true
# ci_run sleep 10
# ci_run zk test i upgrade
ci_run pkill zksync_server || true
ci_run sleep 10
ci_run zk test i upgrade
- name: Show server.log logs
if: always()
Expand Down Expand Up @@ -330,11 +329,10 @@ jobs:
# ZKSYNC_ENV=ext-node-docker ci_run zk external-node $EXT_NODE_FLAGS &>>ext-node.log &
# ci_run sleep 30

- name: Run upgrade test - DISABLED (EVM-558)
- name: Run upgrade test
run: |
ls
# ci_run zk env docker
# CHECK_EN_URL="http://0.0.0.0:3060" ci_run zk test i upgrade
ci_run zk env docker
CHECK_EN_URL="http://0.0.0.0:3060" ci_run zk test i upgrade
- name: Show server.log logs
if: always()
Expand Down
31 changes: 26 additions & 5 deletions core/tests/upgrade-test/tests/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { hashBytecode } from 'zksync-web3/build/src/utils';
import fs from 'fs';
import { TransactionResponse } from 'zksync-web3/build/src/types';
import { BytesLike } from '@ethersproject/bytes';
import { isAddressEq } from 'zksync-ethers/build/src/utils';

const L1_CONTRACTS_FOLDER = `${process.env.ZKSYNC_HOME}/contracts/l1-contracts/artifacts/contracts`;
const L1_DEFAULT_UPGRADE_ABI = new ethers.utils.Interface(
Expand Down Expand Up @@ -87,6 +88,7 @@ describe('Upgrade test', function () {
if (!mainContract) {
throw new Error('Server did not start');
}

const stmAddr = await mainContract.getStateTransitionManager();
const stmContract = new ethers.Contract(stmAddr, STATE_TRANSITON_MANAGER, tester.syncWallet.providerL1);
const governanceAddr = await stmContract.owner();
Expand All @@ -95,8 +97,15 @@ describe('Upgrade test', function () {

const initialL1BatchNumber = await tester.web3Provider.getL1BatchNumber();

const baseToken = await tester.syncWallet.provider.getBaseTokenContractAddress();

if (!isAddressEq(baseToken, zkweb3.utils.ETH_ADDRESS_IN_CONTRACTS)) {
await (await tester.syncWallet.approveERC20(baseToken, ethers.constants.MaxUint256)).wait();
await mintToWallet(baseToken, tester.syncWallet, depositAmount.mul(10));
}

const firstDepositHandle = await tester.syncWallet.deposit({
token: zkweb3.utils.ETH_ADDRESS,
token: baseToken,
amount: depositAmount,
to: alice.address
});
Expand All @@ -106,7 +115,7 @@ describe('Upgrade test', function () {
}

const secondDepositHandle = await tester.syncWallet.deposit({
token: zkweb3.utils.ETH_ADDRESS,
token: baseToken,
amount: depositAmount,
to: alice.address
});
Expand All @@ -129,7 +138,7 @@ describe('Upgrade test', function () {
// Wait for at least one new committed block
let newBlocksCommitted = await mainContract.getTotalBatchesCommitted();
let tryCount = 0;
while (blocksCommitted.eq(newBlocksCommitted) && tryCount < 10) {
while (blocksCommitted.eq(newBlocksCommitted) && tryCount < 30) {
newBlocksCommitted = await mainContract.getTotalBatchesCommitted();
tryCount += 1;
await utils.sleep(1);
Expand Down Expand Up @@ -225,7 +234,7 @@ describe('Upgrade test', function () {

let lastBatchExecuted = await mainContract.getTotalBatchesExecuted();
let tryCount = 0;
while (lastBatchExecuted < l1BatchNumber && tryCount < 10) {
while (lastBatchExecuted < l1BatchNumber && tryCount < 40) {
lastBatchExecuted = await mainContract.getTotalBatchesExecuted();
tryCount += 1;
await utils.sleep(2);
Expand Down Expand Up @@ -272,7 +281,7 @@ describe('Upgrade test', function () {

// Run again.
utils.background(
'cd $ZKSYNC_HOME && cargo run --bin zksync_server --release -- --components=api,tree,eth,state_keeper,commitment_generator &> upgrade.log',
'cd $ZKSYNC_HOME && zk f cargo run --bin zksync_server --release -- --components=api,tree,eth,state_keeper,commitment_generator &> upgrade.log',
[null, logs, logs]
);
await utils.sleep(5);
Expand Down Expand Up @@ -416,6 +425,8 @@ async function prepareUpgradeCalldata(
const stmUpgradeCalldata = STATE_TRANSITON_MANAGER.encodeFunctionData('setNewVersionUpgrade', [
upgradeParam,
oldProtocolVersion,
// The protocol version will not have any deadline in this upgrade
ethers.constants.MaxUint256,
newProtocolVersion
]);

Expand Down Expand Up @@ -451,3 +462,13 @@ async function prepareUpgradeCalldata(
finalizeOperation
};
}

async function mintToWallet(
baseTokenAddress: zkweb3.types.Address,
ethersWallet: ethers.Wallet,
amountToMint: ethers.BigNumber
) {
const l1Erc20ABI = ['function mint(address to, uint256 amount)'];
const l1Erc20Contract = new ethers.Contract(baseTokenAddress, l1Erc20ABI, ethersWallet);
await (await l1Erc20Contract.mint(ethersWallet.address, amountToMint)).wait();
}
1 change: 0 additions & 1 deletion etc/env/base/contracts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ SNARK_WRAPPER_VK_HASH = "0x063c6fb5c70404c2867f413a8e35563ad3d040b1ad8c11786231b
SHARED_BRIDGE_UPGRADE_STORAGE_SWITCH = 0
ERA_CHAIN_ID = 9
ERA_DIAMOND_PROXY_ADDR = "0x0000000000000000000000000000000000000000"
DEV_PROTOCOL_VERSION = 1
[contracts.test]
dummy_verifier = true
easy_priority_mode = false

0 comments on commit 2e334d5

Please sign in to comment.