-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk_toolbox): add test upgrade subcommand to zk_toolbox (#2515)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> Add upgrade tests to zk_supervisor ## 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. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --------- Signed-off-by: Danil <deniallugo@gmail.com> Co-authored-by: Danil <deniallugo@gmail.com>
- Loading branch information
1 parent
c8c8334
commit 1a12f5f
Showing
9 changed files
with
339 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { ethers } from 'ethers'; | ||
import * as fs from 'fs'; | ||
import { background } from 'utils'; | ||
import { getConfigPath } from 'utils/build/file-configs'; | ||
|
||
export function runServerInBackground({ | ||
components, | ||
stdio, | ||
cwd, | ||
useZkInception | ||
}: { | ||
components?: string[]; | ||
stdio: any; | ||
cwd?: Parameters<typeof background>[0]['cwd']; | ||
useZkInception?: boolean; | ||
}) { | ||
let command = useZkInception | ||
? 'zk_inception server' | ||
: 'cd $ZKSYNC_HOME && cargo run --bin zksync_server --release --'; | ||
if (components && components.length > 0) { | ||
command += ` --components=${components.join(',')}`; | ||
} | ||
background({ command, stdio, cwd }); | ||
} | ||
|
||
export function setEthSenderSenderAggregatedBlockCommitDeadline(pathToHome: string, fileConfig: any, value: number) { | ||
setPropertyInGeneralConfig(pathToHome, fileConfig, 'aggregated_block_commit_deadline', value); | ||
} | ||
|
||
export function setAggregatedBlockProveDeadline(pathToHome: string, fileConfig: any, value: number) { | ||
setPropertyInGeneralConfig(pathToHome, fileConfig, 'aggregated_block_prove_deadline', value); | ||
} | ||
|
||
export function setAggregatedBlockExecuteDeadline(pathToHome: string, fileConfig: any, value: number) { | ||
setPropertyInGeneralConfig(pathToHome, fileConfig, 'aggregated_block_execute_deadline', value); | ||
} | ||
|
||
export function setBlockCommitDeadlineMs(pathToHome: string, fileConfig: any, value: number) { | ||
setPropertyInGeneralConfig(pathToHome, fileConfig, 'block_commit_deadline_ms', value); | ||
} | ||
|
||
function setPropertyInGeneralConfig(pathToHome: string, fileConfig: any, property: string, value: number) { | ||
const generalConfigPath = getConfigPath({ | ||
pathToHome, | ||
chain: fileConfig.chain, | ||
configsFolder: 'configs', | ||
config: 'general.yaml' | ||
}); | ||
const generalConfig = fs.readFileSync(generalConfigPath, 'utf8'); | ||
const regex = new RegExp(`\\b${property}:\\s*\\d+`, 'g'); | ||
const newGeneralConfig = generalConfig.replace(regex, `${property}: ${value}`); | ||
|
||
fs.writeFileSync(generalConfigPath, newGeneralConfig, 'utf8'); | ||
} | ||
|
||
export interface Contracts { | ||
l1DefaultUpgradeAbi: any; | ||
governanceAbi: any; | ||
adminFacetAbi: any; | ||
chainAdminAbi: any; | ||
l2ForceDeployUpgraderAbi: any; | ||
complexUpgraderAbi: any; | ||
counterBytecode: any; | ||
stateTransitonManager: any; | ||
} | ||
|
||
export function initContracts(pathToHome: string, zkToolbox: boolean): Contracts { | ||
if (zkToolbox) { | ||
const CONTRACTS_FOLDER = `${pathToHome}/contracts`; | ||
return { | ||
l1DefaultUpgradeAbi: new ethers.Interface( | ||
require(`${CONTRACTS_FOLDER}/l1-contracts/out/DefaultUpgrade.sol/DefaultUpgrade.json`).abi | ||
), | ||
governanceAbi: new ethers.Interface( | ||
require(`${CONTRACTS_FOLDER}/l1-contracts/out/Governance.sol/Governance.json`).abi | ||
), | ||
adminFacetAbi: new ethers.Interface( | ||
require(`${CONTRACTS_FOLDER}/l1-contracts/out/IAdmin.sol/IAdmin.json`).abi | ||
), | ||
chainAdminAbi: new ethers.Interface( | ||
require(`${CONTRACTS_FOLDER}/l1-contracts/out/ChainAdmin.sol/ChainAdmin.json`).abi | ||
), | ||
l2ForceDeployUpgraderAbi: new ethers.Interface( | ||
require(`${CONTRACTS_FOLDER}/l2-contracts/artifacts-zk/contracts/ForceDeployUpgrader.sol/ForceDeployUpgrader.json`).abi | ||
), | ||
complexUpgraderAbi: new ethers.Interface( | ||
require(`${CONTRACTS_FOLDER}/system-contracts/artifacts-zk/contracts-preprocessed/ComplexUpgrader.sol/ComplexUpgrader.json`).abi | ||
), | ||
counterBytecode: | ||
require(`${pathToHome}/core/tests/ts-integration/artifacts-zk/contracts/counter/counter.sol/Counter.json`) | ||
.deployedBytecode, | ||
stateTransitonManager: new ethers.Interface( | ||
require(`${CONTRACTS_FOLDER}/l1-contracts/out/StateTransitionManager.sol/StateTransitionManager.json`).abi | ||
) | ||
}; | ||
} else { | ||
const L1_CONTRACTS_FOLDER = `${pathToHome}/contracts/l1-contracts/artifacts/contracts`; | ||
return { | ||
l1DefaultUpgradeAbi: new ethers.Interface( | ||
require(`${L1_CONTRACTS_FOLDER}/upgrades/DefaultUpgrade.sol/DefaultUpgrade.json`).abi | ||
), | ||
governanceAbi: new ethers.Interface( | ||
require(`${L1_CONTRACTS_FOLDER}/governance/Governance.sol/Governance.json`).abi | ||
), | ||
adminFacetAbi: new ethers.Interface( | ||
require(`${L1_CONTRACTS_FOLDER}/state-transition/chain-interfaces/IAdmin.sol/IAdmin.json`).abi | ||
), | ||
chainAdminAbi: new ethers.Interface( | ||
require(`${L1_CONTRACTS_FOLDER}/governance/ChainAdmin.sol/ChainAdmin.json`).abi | ||
), | ||
l2ForceDeployUpgraderAbi: new ethers.Interface( | ||
require(`${pathToHome}/contracts/l2-contracts/artifacts-zk/contracts/ForceDeployUpgrader.sol/ForceDeployUpgrader.json`).abi | ||
), | ||
complexUpgraderAbi: new ethers.Interface( | ||
require(`${pathToHome}/contracts/system-contracts/artifacts-zk/contracts-preprocessed/ComplexUpgrader.sol/ComplexUpgrader.json`).abi | ||
), | ||
counterBytecode: | ||
require(`${pathToHome}/core/tests/ts-integration/artifacts-zk/contracts/counter/counter.sol/Counter.json`) | ||
.deployedBytecode, | ||
stateTransitonManager: new ethers.Interface( | ||
require(`${L1_CONTRACTS_FOLDER}/state-transition/StateTransitionManager.sol/StateTransitionManager.json`).abi | ||
) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
zk_toolbox/crates/zk_supervisor/src/commands/test/upgrade.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use common::{cmd::Cmd, logger, spinner::Spinner}; | ||
use config::EcosystemConfig; | ||
use xshell::{cmd, Shell}; | ||
|
||
use crate::messages::{ | ||
MSG_UPGRADE_TEST_INSTALLING_DEPENDENCIES, MSG_UPGRADE_TEST_RUN_INFO, | ||
MSG_UPGRADE_TEST_RUN_SUCCESS, | ||
}; | ||
|
||
const UPGRADE_TESTS_PATH: &str = "core/tests/upgrade-test"; | ||
|
||
pub fn run(shell: &Shell) -> anyhow::Result<()> { | ||
let ecosystem_config = EcosystemConfig::from_file(shell)?; | ||
shell.change_dir(ecosystem_config.link_to_code.join(UPGRADE_TESTS_PATH)); | ||
|
||
logger::info(MSG_UPGRADE_TEST_RUN_INFO); | ||
install_and_build_dependencies(shell, &ecosystem_config)?; | ||
run_test(shell, &ecosystem_config)?; | ||
logger::outro(MSG_UPGRADE_TEST_RUN_SUCCESS); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn install_and_build_dependencies( | ||
shell: &Shell, | ||
ecosystem_config: &EcosystemConfig, | ||
) -> anyhow::Result<()> { | ||
let _dir_guard = shell.push_dir(&ecosystem_config.link_to_code); | ||
let spinner = Spinner::new(MSG_UPGRADE_TEST_INSTALLING_DEPENDENCIES); | ||
Cmd::new(cmd!(shell, "yarn install")).run()?; | ||
Cmd::new(cmd!(shell, "yarn utils build")).run()?; | ||
|
||
spinner.finish(); | ||
Ok(()) | ||
} | ||
|
||
fn run_test(shell: &Shell, ecosystem_config: &EcosystemConfig) -> anyhow::Result<()> { | ||
Spinner::new(MSG_UPGRADE_TEST_RUN_INFO).freeze(); | ||
let cmd = Cmd::new(cmd!(shell, "yarn mocha tests/upgrade.test.ts")) | ||
.env("CHAIN_NAME", &ecosystem_config.default_chain); | ||
cmd.with_force_run().run()?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters