Skip to content

Commit

Permalink
feat: add integration test ci for zk_toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
aon committed May 31, 2024
1 parent 67f6080 commit 6bfb499
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 4 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/ci-zk-toolbox-reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Workflow template for CI jobs for Core Components
on:
workflow_call:

jobs:
lint:
name: lint
uses: ./.github/workflows/ci-core-lint-reusable.yml

build:
runs-on: [matterlabs-ci-runner]

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
with:
submodules: "recursive"
fetch-depth: 0

- name: Setup environment
run: |
echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV
echo $(pwd)/bin >> $GITHUB_PATH
echo IN_DOCKER=1 >> .env
- name: Start services
run: |
ci_localnet_up
- name: Build
run: |
ci_run bash -c "cd zk_toolbox && cargo build --release"
# Compress with tar to avoid permission loss
# https://github.com/actions/upload-artifact?tab=readme-ov-file#permission-loss
- name: Tar zk_toolbox binaries
run: |
tar -C ./zk_toolbox/target/release -cvf zk_toolbox.tar zk_inception zk_supervisor
- name: Upload zk_toolbox binaries
uses: actions/upload-artifact@v4
with:
name: zk_toolbox
path: zk_toolbox.tar
compression-level: 0

integration_test:
runs-on: [matterlabs-ci-runner]
needs: [build]

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
with:
submodules: "recursive"
fetch-depth: 0

- name: Download zk_toolbox binaries
uses: actions/download-artifact@v4
with:
name: zk_toolbox
path: .

- name: Extract zk_toolbox binaries
run: |
tar -xvf zk_toolbox.tar -C ./bin
- name: Setup environment
run: |
echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV
echo $(pwd)/bin >> $GITHUB_PATH
echo IN_DOCKER=1 >> .env
- name: Run tests
run: |
ci_run zk_inception ecosystem init --deploy-paymaster --deploy-erc20 \
--deploy-ecosystem --l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_era \
--prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--prover-db-name=zksync_prover_localhost_era
ci_run zk_inception server &
ci_run zk_supervisor integration-tests
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
outputs:
core: ${{ steps.changed-files.outputs.core_any_changed }}
prover: ${{ steps.changed-files.outputs.prover_any_changed }}
zk_toolbox: ${{ steps.changed-files.outputs.zk_toolbox_any_changed }}
docs: ${{ steps.changed-files.outputs.docs_any_changed }}
all: ${{ steps.changed-files.outputs.all_any_changed }}
steps:
Expand Down Expand Up @@ -60,6 +61,10 @@ jobs:
- '!**/*.md'
- '!**/*.MD'
- 'docker-compose.yml'
zk_toolbox:
- 'zk_toolbox/**'
- '!**/*.md'
- '!**/*.MD'
docs:
- '**/*.md'
- '**/*.MD'
Expand Down Expand Up @@ -91,6 +96,12 @@ jobs:
name: CI for Prover Components
uses: ./.github/workflows/ci-prover-reusable.yml

ci-for-zk-toolbox:
needs: changed_files
if: ${{ (needs.changed_files.outputs.zk_toolbox == 'true' || needs.changed_files.outputs.all == 'true') && !contains(github.ref_name, 'release-please--branches') }}
name: CI for zk_toolbox
uses: ./.github/workflows/ci-zk-toolbox-reusable.yml

ci-for-docs:
needs: changed_files
if: needs.changed_files.outputs.docs == 'true'
Expand Down
6 changes: 5 additions & 1 deletion core/tests/ts-integration/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironme
// wBTC is chosen because it has decimals different from ETH (8 instead of 18).
// Using this token will help us to detect decimals-related errors.
// but if it's not available, we'll use the first token from the list.
let token = tokens.tokens['wBTC'];
let token = tokens.tokens['WBTC'];
if (token === undefined) {
token = Object.values(tokens.tokens)[0];
if (token.symbol == 'WETH') {
token = Object.values(tokens.tokens)[1];
}
}
const weth = tokens.tokens['WETH'];
let baseToken;
Expand Down Expand Up @@ -352,6 +355,7 @@ function loadEcosystem(pathToHome: string): any {
function loadConfig(pathToHome: string, chainName: string, config: string): any {
const configPath = path.join(pathToHome, `/chains/${chainName}/configs/${config}`);
if (!fs.existsSync(configPath)) {
console.log('no existe pa');
return [];
}
return yaml.parse(
Expand Down
1 change: 1 addition & 0 deletions zk_toolbox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eco
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ impl Default for Erc20DeploymentConfig {
implementation: String::from("TestnetERC20Token.sol"),
mint: 10000000000,
},
Erc20DeploymentTokensConfig {
name: String::from("WBTC"),
symbol: String::from("WBTC"),
decimals: 8,
implementation: String::from("TestnetERC20Token.sol"),
mint: 10000000000,
},
Erc20DeploymentTokensConfig {
name: String::from("Wrapped Ether"),
symbol: String::from("WETH"),
Expand Down
25 changes: 25 additions & 0 deletions zk_toolbox/crates/zk_supervisor/src/commands/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use common::{cmd::Cmd, logger};
use config::EcosystemConfig;
use xshell::{cmd, Shell};

use crate::messages::{MSG_INTEGRATION_TESTS_RUN_INFO, MSG_INTEGRATION_TESTS_RUN_SUCCESS};

const TS_INTEGRATION_PATH: &str = "core/tests/ts-integration";

pub fn run(shell: &Shell) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let _dir_guard = shell.push_dir(ecosystem_config.link_to_code.join(TS_INTEGRATION_PATH));

logger::info(MSG_INTEGRATION_TESTS_RUN_INFO);

Cmd::new(
cmd!(shell, "yarn jest --forceExit --testTimeout 60000")
.env("CHAIN_NAME", ecosystem_config.default_chain),
)
.with_force_run()
.run()?;

logger::outro(MSG_INTEGRATION_TESTS_RUN_SUCCESS);

Ok(())
}
1 change: 1 addition & 0 deletions zk_toolbox/crates/zk_supervisor/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod database;
pub mod integration_tests;
11 changes: 8 additions & 3 deletions zk_toolbox/crates/zk_supervisor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use common::{
init_prompt_theme, logger,
};
use config::EcosystemConfig;
use messages::msg_global_chain_does_not_exist;
use messages::{
msg_global_chain_does_not_exist, MSG_SUBCOMMAND_DATABASE_ABOUT,
MSG_SUBCOMMAND_INTEGRATION_TESTS_ABOUT,
};
use xshell::Shell;

mod commands;
Expand All @@ -24,9 +27,10 @@ struct Supervisor {

#[derive(Subcommand, Debug)]
enum SupervisorSubcommands {
/// Database related commands
#[command(subcommand)]
#[command(subcommand, about = MSG_SUBCOMMAND_DATABASE_ABOUT)]
Database(DatabaseCommands),
#[command(about = MSG_SUBCOMMAND_INTEGRATION_TESTS_ABOUT)]
IntegrationTests,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -89,6 +93,7 @@ async fn main() -> anyhow::Result<()> {
async fn run_subcommand(args: Supervisor, shell: &Shell) -> anyhow::Result<()> {
match args.command {
SupervisorSubcommands::Database(command) => commands::database::run(shell, command).await?,
SupervisorSubcommands::IntegrationTests => commands::integration_tests::run(shell)?,
}
Ok(())
}
Expand Down
9 changes: 9 additions & 0 deletions zk_toolbox/crates/zk_supervisor/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pub(super) fn msg_global_chain_does_not_exist(chain: &str, available_chains: &st
format!("Chain with name {chain} doesnt exist, please choose one of: {available_chains}")
}

// Subcommands help
pub(super) const MSG_SUBCOMMAND_DATABASE_ABOUT: &str = "Database related commands";
pub(super) const MSG_SUBCOMMAND_INTEGRATION_TESTS_ABOUT: &str = "Run integration tests";

// Database related messages
pub(super) const MSG_NO_DATABASES_SELECTED: &str = "No databases selected";
pub(super) fn msg_database_info(gerund_verb: &str) -> String {
Expand Down Expand Up @@ -57,3 +61,8 @@ pub(super) fn msg_database_new_migration_loading(dal: &str) -> String {
format!("Creating new database migration for dal {}...", dal)
}
pub(super) const MSG_DATABASE_NEW_MIGRATION_SUCCESS: &str = "Migration created successfully";

// Integration tests related messages
pub(super) const MSG_INTEGRATION_TESTS_RUN_ABOUT: &str = "Run integration tests";
pub(super) const MSG_INTEGRATION_TESTS_RUN_INFO: &str = "Running integration tests";
pub(super) const MSG_INTEGRATION_TESTS_RUN_SUCCESS: &str = "Integration tests ran successfully";

0 comments on commit 6bfb499

Please sign in to comment.