Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zk_toolbox): add fees integration test to toolbox #2898

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
51381cf
feat: add fees integration test to toolbox
manuelmauro Sep 17, 2024
19b0976
ci: add CI step for fees integration test
manuelmauro Sep 17, 2024
533655b
Merge branch 'main' into manuel-add-ts-integration-fees-test-to-toolbox
manuelmauro Sep 17, 2024
4f586d5
ci: add CI step for fees integration test
manuelmauro Sep 17, 2024
0d01aa6
refactor: use a single constant for TS_INTEGRATION_PATH
manuelmauro Sep 17, 2024
f934384
style: lint
manuelmauro Sep 17, 2024
3028221
refactor: simplify code
manuelmauro Sep 17, 2024
ff58c82
Merge branch 'main' into manuel-add-ts-integration-fees-test-to-toolbox
manuelmauro Sep 17, 2024
4379a32
fix: restore contracts
manuelmauro Sep 17, 2024
732ab9d
feat: test fees on all chains
manuelmauro Sep 17, 2024
5b816e1
refactor: remove unused arg
manuelmauro Sep 18, 2024
c364c8e
ci: parallelize fees testing
manuelmauro Sep 18, 2024
c67a0f1
style: remove unused import
manuelmauro Sep 18, 2024
aeb9c50
fix: wrong args type
manuelmauro Sep 18, 2024
9b363d6
feat: add FEES_LOGS_DIR to GITHUB_ENV
manuelmauro Sep 18, 2024
8c87f51
fix: truly run fees testing
manuelmauro Sep 18, 2024
b270415
revert: temporarily revert to sequential fees testing
manuelmauro Sep 18, 2024
0b29ee4
fix: try to re-run servers before fees testing
manuelmauro Sep 18, 2024
2860b8f
revert: do not re-run servers
manuelmauro Sep 19, 2024
ebbe4c1
style: remove optional double dash
manuelmauro Sep 19, 2024
66c4f5f
refactor: use managed start/kill node
manuelmauro Sep 19, 2024
ffda3f7
style: format
manuelmauro Sep 19, 2024
6b7233b
fix: update config on the fly
manuelmauro Sep 20, 2024
7ab0b1c
feat: add L2 node PID to TestEnvironment
manuelmauro Sep 20, 2024
7f62481
fix: set right properties on the fly
manuelmauro Sep 20, 2024
539517b
style: lint
manuelmauro Sep 20, 2024
eacd4de
fix: kill server before running fees.test.ts
manuelmauro Sep 20, 2024
b36f2d1
fix: logs folder
manuelmauro Sep 20, 2024
72d92ce
Merge branch 'main' into manuel-add-ts-integration-fees-test-to-toolbox
manuelmauro Sep 20, 2024
e3e33ff
test: temporarily run fees tests only on era chain
manuelmauro Sep 20, 2024
7e3889b
style: use const case for env variable in CI
manuelmauro Sep 20, 2024
87a3d26
style: format code
manuelmauro Sep 20, 2024
1699dd4
fix: bring forward server start
manuelmauro Sep 20, 2024
2ffcd92
style: format
manuelmauro Sep 20, 2024
5ba3f36
fix: read test environment before killing the node
manuelmauro Sep 20, 2024
a12bf21
fix: fix operations in beforeAll step
manuelmauro Sep 20, 2024
285289d
Revert "style: format code"
manuelmauro Sep 20, 2024
fb75f04
fix: remove extra node restart
manuelmauro Sep 20, 2024
a936b04
refactor: remove unused code from tester
manuelmauro Sep 20, 2024
a5d2f8f
fix: unref node processes
manuelmauro Sep 22, 2024
19138a7
fix: unref only when needed
manuelmauro Sep 22, 2024
44f743b
refactor: simplify waiting
manuelmauro Sep 22, 2024
dd71070
Merge branch 'main' into manuel-add-ts-integration-fees-test-to-toolbox
Deniallugo Sep 24, 2024
1ce733b
Fix queries
Deniallugo Sep 24, 2024
790e1a5
Fix
Deniallugo Sep 24, 2024
f5cfc0d
fix
Deniallugo Sep 24, 2024
f70e7d8
Correct kill the process
Deniallugo Sep 25, 2024
df0a451
Reset pid
Deniallugo Sep 25, 2024
74e2951
Fix lints and increase timings
Deniallugo Sep 26, 2024
f02b261
Fix nits
Deniallugo Sep 27, 2024
fb31b2d
Fix logs place
Deniallugo Sep 27, 2024
1cec206
Run all fee tests
Deniallugo Sep 27, 2024
77e8814
Fix multiple chains for fees
Deniallugo Sep 27, 2024
1a47104
Merge branch 'main' into manuel-add-ts-integration-fees-test-to-toolbox
Deniallugo Sep 27, 2024
4028d35
Add no deps
Deniallugo Sep 27, 2024
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
34 changes: 29 additions & 5 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ jobs:
SNAPSHOT_RECOVERY_LOGS_DIR=logs/snapshot_recovery/
GENESIS_RECOVERY_LOGS_DIR=logs/genesis_recovery/
EXTERNAL_NODE_LOGS_DIR=logs/external_node
FEES_LOGS_DIR=logs/fees
REVERT_LOGS_DIR=logs/revert

mkdir -p $SERVER_LOGS_DIR
Expand All @@ -193,6 +194,7 @@ jobs:
mkdir -p $SNAPSHOT_RECOVERY_LOGS_DIR
mkdir -p $GENESIS_RECOVERY_LOGS_DIR
mkdir -p $EXTERNAL_NODE_LOGS_DIR
mkdir -p $FEES_LOGS_DIR
manuelmauro marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $REVERT_LOGS_DIR

echo "SERVER_LOGS_DIR=$SERVER_LOGS_DIR" >> $GITHUB_ENV
Expand All @@ -201,6 +203,7 @@ jobs:
echo "SNAPSHOT_RECOVERY_LOGS_DIR=$SNAPSHOT_RECOVERY_LOGS_DIR" >> $GITHUB_ENV
echo "GENESIS_RECOVERY_LOGS_DIR=$GENESIS_RECOVERY_LOGS_DIR" >> $GITHUB_ENV
echo "EXTERNAL_NODE_LOGS_DIR=$EXTERNAL_NODE_LOGS_DIR" >> $GITHUB_ENV
echo "FEES_LOGS_DIR=$FEES_LOGS_DIR" >> $GITHUB_ENV
echo "REVERT_LOGS_DIR=$REVERT_LOGS_DIR" >> $GITHUB_ENV

- name: Initialize ecosystem
Expand All @@ -220,9 +223,9 @@ jobs:

- name: Read Custom Token address and set as environment variable
run: |
address=$(awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /DAI:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' ./configs/erc20.yaml)
echo "address=$address"
echo "address=$address" >> $GITHUB_ENV
CUSTOM_TOKEN_ADDRESS=$(awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /DAI:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' ./configs/erc20.yaml)
echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS"
echo "CUSTOM_TOKEN_ADDRESS=$CUSTOM_TOKEN_ADDRESS" >> $GITHUB_ENV

- name: Create and initialize Validium chain
run: |
Expand Down Expand Up @@ -256,7 +259,7 @@ jobs:
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
--base-token-address ${{ env.address }} \
--base-token-address ${{ env.CUSTOM_TOKEN_ADDRESS }} \
--base-token-price-nominator 3 \
--base-token-price-denominator 2 \
--set-as-default false \
Expand Down Expand Up @@ -315,7 +318,7 @@ jobs:
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode validium \
--base-token-address ${{ env.address }} \
--base-token-address ${{ env.CUSTOM_TOKEN_ADDRESS }} \
--base-token-price-nominator 3 \
--base-token-price-denominator 2 \
--set-as-default false \
Expand Down Expand Up @@ -458,6 +461,27 @@ jobs:
wait $PID3
wait $PID4

- name: Fee projection tests
run: |
ci_run killall -INT zksync_server || true

ci_run zk_supervisor test fees --no-deps --no-kill --chain era &> ${{ env.FEES_LOGS_DIR }}/era.log &
PID1=$!

ci_run zk_supervisor test fees --no-deps --no-kill --chain validium &> ${{ env.FEES_LOGS_DIR }}/validium.log &
PID2=$!

ci_run zk_supervisor test fees --no-deps --no-kill --chain custom_token &> ${{ env.FEES_LOGS_DIR }}/custom_token.log &
PID3=$!

ci_run zk_supervisor test fees --no-deps --no-kill --chain consensus &> ${{ env.FEES_LOGS_DIR }}/consensus.log &
PID4=$!

wait $PID1
wait $PID2
wait $PID3
wait $PID4

- name: Run revert tests
run: |
ci_run killall -INT zksync_server || true
Expand Down
10 changes: 10 additions & 0 deletions core/tests/ts-integration/src/context-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { lookupPrerequisites } from './prerequisites';
import { Reporter } from './reporter';
import { scaledGasPrice } from './helpers';
import { RetryProvider } from './retry-provider';
import { killPidWithAllChilds } from 'utils/build/kill';

// These amounts of ETH would be provided to each test suite through its "main" account.
// It is assumed to be enough to run a set of "normal" transactions.
Expand Down Expand Up @@ -624,6 +625,11 @@ export class TestContextOwner {
// Then propagate the exception.
throw error;
}
if (this.env.l2NodePid !== undefined) {
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
this.reporter.startAction(`Terminating L2 node process`);
await killPidWithAllChilds(this.env.l2NodePid, 9);
this.reporter.finishAction();
}
}

/**
Expand All @@ -648,6 +654,10 @@ export class TestContextOwner {
// into account. If the same wallet would be reused (e.g. on stage), it'll just have to
// deposit less next time.
}

setL2NodePid(newPid: number) {
this.env.l2NodePid = newPid;
}
}

/**
Expand Down
52 changes: 45 additions & 7 deletions core/tests/ts-integration/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ import { DataAvailabityMode, NodeMode, TestEnvironment } from './types';
import { Reporter } from './reporter';
import * as yaml from 'yaml';
import { L2_BASE_TOKEN_ADDRESS } from 'zksync-ethers/build/utils';
import { loadConfig, loadEcosystem, shouldLoadConfigFromFile } from 'utils/build/file-configs';
import { FileConfig, loadConfig, loadEcosystem, shouldLoadConfigFromFile } from 'utils/build/file-configs';
import { NodeSpawner } from './utils';
import { logsTestPath } from 'utils/build/logs';
import * as nodefs from 'node:fs/promises';
import { exec } from 'utils';

const enableConsensus = process.env.ENABLE_CONSENSUS === 'true';

async function logsPath(chain: string, name: string): Promise<string> {
return await logsTestPath(chain, 'logs/server/', name);
}

/**
* Attempts to connect to server.
Expand Down Expand Up @@ -60,8 +70,10 @@ function getMainWalletPk(pathToHome: string): string {
/*
Loads the environment for file based configs.
*/
async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironment> {
async function loadTestEnvironmentFromFile(fileConfig: FileConfig): Promise<TestEnvironment> {
let chain = fileConfig.chain!;
const pathToHome = path.join(__dirname, '../../../..');
let spawnNode = process.env.SPAWN_NODE;
let nodeMode;
if (process.env.EXTERNAL_NODE == 'true') {
nodeMode = NodeMode.External;
Expand All @@ -75,18 +87,42 @@ async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironme
let configsFolderSuffix = nodeMode == NodeMode.External ? 'external_node' : undefined;
let generalConfig = loadConfig({ pathToHome, chain, config: 'general.yaml', configsFolderSuffix });
let secretsConfig = loadConfig({ pathToHome, chain, config: 'secrets.yaml', configsFolderSuffix });
let contracts = loadConfig({ pathToHome, chain, config: 'contracts.yaml', configsFolderSuffix });

const network = ecosystem.l1_network.toLowerCase();
let mainWalletPK = getMainWalletPk(pathToHome);

const l2NodeUrl = generalConfig.api.web3_json_rpc.http_url;

await waitForServer(l2NodeUrl);
const l1NodeUrl = secretsConfig.l1.l1_rpc_url;

const pathToMainLogs = await logsPath(fileConfig.chain!, 'server.log');
let mainLogs = await nodefs.open(pathToMainLogs, 'a');
let l2Node;
if (spawnNode) {
// Before starting any actual logic, we need to ensure that the server is running (it may not
// be the case, for example, right after deployment on stage).
const autoKill: boolean = process.env.NO_KILL !== 'true';
if (autoKill) {
try {
await exec(`killall -KILL zksync_server`);
} catch (err) {
console.log(`ignored error: ${err}`);
}
}
let mainNodeSpawner = new NodeSpawner(pathToHome, mainLogs, fileConfig, {
enableConsensus,
ethClientWeb3Url: l1NodeUrl,
apiWeb3JsonRpcHttpUrl: l2NodeUrl,
baseTokenAddress: contracts.l1.base_token_addr
});

l2Node = await mainNodeSpawner.spawnMainNode();
}

const l2Provider = new zksync.Provider(l2NodeUrl);
const baseTokenAddress = await l2Provider.getBaseTokenContractAddress();

const l1NodeUrl = secretsConfig.l1.l1_rpc_url;
const wsL2NodeUrl = generalConfig.api.web3_json_rpc.ws_url;

const contractVerificationUrl = generalConfig.contract_verifier.url;
Expand Down Expand Up @@ -141,6 +177,7 @@ async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironme
network,
mainWalletPK,
l2NodeUrl,
l2NodePid: l2Node ? l2Node.proc.pid : undefined,
l1NodeUrl,
wsL2NodeUrl,
contractVerificationUrl,
Expand All @@ -163,10 +200,10 @@ async function loadTestEnvironmentFromFile(chain: string): Promise<TestEnvironme
}

export async function loadTestEnvironment(): Promise<TestEnvironment> {
const { loadFromFile, chain } = shouldLoadConfigFromFile();
const fileConfig = shouldLoadConfigFromFile();

if (loadFromFile) {
return await loadTestEnvironmentFromFile(chain);
if (fileConfig.loadFromFile) {
return await loadTestEnvironmentFromFile(fileConfig);
}
return await loadTestEnvironmentFromEnv();
}
Expand Down Expand Up @@ -257,6 +294,7 @@ export async function loadTestEnvironmentFromEnv(): Promise<TestEnvironment> {
network,
mainWalletPK,
l2NodeUrl,
l2NodePid: undefined,
l1NodeUrl,
wsL2NodeUrl,
healthcheckPort,
Expand Down
5 changes: 1 addition & 4 deletions core/tests/ts-integration/src/jest-setup/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ async function performSetup(_globalConfig: any, _projectConfig: any) {
console.log('');
globalThis.rawWriteToConsole = console.log;

// Before starting any actual logic, we need to ensure that the server is running (it may not
// be the case, for example, right after deployment on stage).

const testEnvironment = await loadTestEnvironment();
let testEnvironment = await loadTestEnvironment();
const testContextOwner = new TestContextOwner(testEnvironment);
const testContext = await testContextOwner.setupContext();

Expand Down
4 changes: 4 additions & 0 deletions core/tests/ts-integration/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export interface TestEnvironment {
* Mode of the l2 node
*/
nodeMode: NodeMode;
/*
* L2 node PID
*/
l2NodePid: number | undefined;
/**
* Plaintext name of the L1 network name (i.e. `localhost` or `goerli`).
*/
Expand Down
Loading
Loading