Skip to content

Commit

Permalink
Merge pull request #1492 from matter-labs/feat/update-integration-tests
Browse files Browse the repository at this point in the history
feat(kl-factory): update integration tests
  • Loading branch information
kelemeno committed Apr 9, 2024
2 parents 3b280b4 + f971469 commit 20574f7
Show file tree
Hide file tree
Showing 16 changed files with 336 additions and 538 deletions.
2 changes: 1 addition & 1 deletion core/lib/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ async fn add_state_keeper_to_task_futures(
.context("failed to build miniblock_sealer_pool")?;
let (persistence, miniblock_sealer) = StateKeeperPersistence::new(
miniblock_sealer_pool,
contracts_config.l2_erc20_bridge_addr.unwrap(),
contracts_config.l2_shared_bridge_addr,
state_keeper_config.miniblock_seal_queue_capacity,
);
task_futures.push(tokio::spawn(miniblock_sealer.run()));
Expand Down
34 changes: 28 additions & 6 deletions core/tests/ts-integration/src/context-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class TestContextOwner {
const l2ETHAmountToDeposit = await this.ensureBalances(accountsAmount);
const l2ERC20AmountToDeposit = ERC20_PER_ACCOUNT.mul(accountsAmount);
const wallets = this.createTestWallets(suites);
await this.distributeL1BaseToken(l2ERC20AmountToDeposit);
await this.distributeL1BaseToken(wallets, l2ERC20AmountToDeposit);
await this.cancelAllowances();
await this.distributeL1Tokens(wallets, l2ETHAmountToDeposit, l2ERC20AmountToDeposit);
await this.distributeL2Tokens(wallets);
Expand Down Expand Up @@ -271,7 +271,7 @@ export class TestContextOwner {
* Sends L1 tokens to the test wallet accounts.
* Additionally, deposits L1 tokens to the main account for further distribution on L2 (if required).
*/
private async distributeL1BaseToken(l2erc20DepositAmount: ethers.BigNumber) {
private async distributeL1BaseToken(wallets: TestWallets, l2erc20DepositAmount: ethers.BigNumber) {
this.reporter.startAction(`Distributing base tokens on L1`);
const baseTokenAddress = process.env.CONTRACTS_BASE_TOKEN_ADDR!;
if (baseTokenAddress != zksync.utils.ETH_ADDRESS_IN_CONTRACTS) {
Expand Down Expand Up @@ -329,9 +329,24 @@ export class TestContextOwner {
.then((tx) => {
// Note: there is an `approve` tx, not listed here.
this.reporter.debug(`Sent ERC20 deposit transaction. Hash: ${tx.hash}, tx nonce: ${tx.nonce}`);
return tx.wait();
tx.wait();

nonce = nonce + 1 + (ethIsBaseToken ? 0 : 1) + (baseIsTransferred ? 0 : 1);

if (!ethIsBaseToken) {
// Send base token on L1.
const baseTokenTransfers = sendTransfers(
baseTokenAddress,
this.mainEthersWallet,
wallets,
ERC20_PER_ACCOUNT,
nonce,
gasPrice,
this.reporter
);
return baseTokenTransfers;
}
});
nonce = nonce + 1 + (ethIsBaseToken ? 0 : 1) + (baseIsTransferred ? 0 : 1);
l1TxPromises.push(baseDepositPromise);

this.reporter.debug(`Sent ${l1TxPromises.length} base token initial transactions on L1`);
Expand Down Expand Up @@ -367,7 +382,7 @@ export class TestContextOwner {
if (!l2ETHAmountToDeposit.isZero()) {
// Given that we've already sent a number of transactions,
// we have to correctly send nonce.
await this.mainSyncWallet
const depositHandle = this.mainSyncWallet
.deposit({
token: zksync.utils.ETH_ADDRESS,
approveBaseERC20: true,
Expand All @@ -382,11 +397,18 @@ export class TestContextOwner {
gasPrice
}
})
.then((op) => op.waitL1Commit());
.then((tx) => {
const amount = ethers.utils.formatEther(l2ETHAmountToDeposit);
this.reporter.debug(`Sent ETH deposit. Nonce ${tx.nonce}, amount: ${amount}, hash: ${tx.hash}`);
tx.wait();
});
nonce = nonce + 1 + (ethIsBaseToken ? 0 : 1);
this.reporter.debug(
`Nonce changed by ${1 + (ethIsBaseToken ? 0 : 1)} for ETH deposit, new nonce: ${nonce}`
);
// Add this promise to the list of L1 tx promises.
// l1TxPromises.push(depositHandle);
await depositHandle;
}
// Define values for handling ERC20 transfers/deposits.
const erc20Token = this.env.erc20Token.l1Address;
Expand Down
12 changes: 12 additions & 0 deletions core/tests/ts-integration/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as ethers from 'ethers';
import * as zksync from 'zksync-ethers';
import { TestEnvironment } from './types';
import { Reporter } from './reporter';
import { L2_ETH_TOKEN_ADDRESS } from 'zksync-ethers/build/src/utils';

/**
* Attempts to connect to server.
Expand Down Expand Up @@ -49,6 +50,7 @@ export async function waitForServer() {
*/
export async function loadTestEnvironment(): Promise<TestEnvironment> {
const network = process.env.CHAIN_ETH_NETWORK || 'localhost';
let baseTokenAddress = process.env.CONTRACTS_BASE_TOKEN_ADDR!;

let mainWalletPK;
if (network == 'localhost') {
Expand Down Expand Up @@ -81,6 +83,7 @@ export async function loadTestEnvironment(): Promise<TestEnvironment> {
token = tokens[0];
}
const weth = tokens.find((token: { symbol: string }) => token.symbol == 'WETH')!;
const baseToken = tokens.find((token: { address: string }) => token.address == baseTokenAddress)!;

// `waitForServer` is expected to be executed. Otherwise this call may throw.
const l2TokenAddress = await new zksync.Wallet(
Expand All @@ -95,6 +98,8 @@ export async function loadTestEnvironment(): Promise<TestEnvironment> {
ethers.getDefaultProvider(l1NodeUrl)
).l2TokenAddress(weth.address);

const baseTokenAddressL2 = L2_ETH_TOKEN_ADDRESS;

return {
network,
mainWalletPK,
Expand All @@ -115,6 +120,13 @@ export async function loadTestEnvironment(): Promise<TestEnvironment> {
decimals: weth.decimals,
l1Address: weth.address,
l2Address: l2WethAddress
},
baseToken: {
name: baseToken?.name || token.name,
symbol: baseToken?.symbol || token.symbol,
decimals: baseToken?.decimals || token.decimals,
l1Address: baseToken?.address || token.address,
l2Address: baseTokenAddressL2
}
};
}
Expand Down
124 changes: 0 additions & 124 deletions core/tests/ts-integration/src/system.ts

This file was deleted.

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 @@ -49,6 +49,10 @@ export interface TestEnvironment {
* Description of the WETH token used in the tests.
*/
wethToken: Token;
/**
* Description of the "base" ERC20 token used in the tests.
*/
baseToken: Token;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion core/tests/ts-integration/tests/api/web3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,10 @@ describe('web3 API compatibility tests', () => {
});

test('Should test L1 transaction details', async () => {
if (testMaster.isFastMode()) {
// ToDo: remove when server is fixed
const baseTokenAddress = process.env.CONTRACTS_BASE_TOKEN_ADDR!;
const isETHBasedChain = baseTokenAddress == zksync.utils.ETH_ADDRESS_IN_CONTRACTS;
if (testMaster.isFastMode() || !isETHBasedChain) {
return;
}
let amount = 1;
Expand Down
Loading

0 comments on commit 20574f7

Please sign in to comment.