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

chore: Fix ext node test #1691

Merged
merged 8 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
5 changes: 2 additions & 3 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,8 @@ jobs:
ci_run zk external-node $EXT_NODE_FLAGS &>>ext-node.log &
ci_run sleep 30

- name: Integration tests - DISABLED (EVM-559)
run: ls
# ci_run zk test i server --testPathIgnorePatterns 'contract-verification|snapshots-creator'
- name: Integration tests
run: ci_run zk test i server --testPathIgnorePatterns 'contract-verification|snapshots-creator'

- name: Run revert test - DISABLED (EVM-539)
run: |
Expand Down
14 changes: 13 additions & 1 deletion core/lib/zksync_core/src/consistency_checker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ impl LocalL1BatchCommitData {
.map_or(true, |version| version.is_pre_boojum())
}

fn is_pre_shared_bridge(&self) -> bool {
self.l1_batch
.header
.protocol_version
.map_or(true, |version| version.is_pre_shared_bridge())
}

/// All returned errors are validation errors.
fn verify_commitment(&self, reference: &ethabi::Token) -> anyhow::Result<()> {
let protocol_version = self
Expand Down Expand Up @@ -415,11 +422,16 @@ impl ConsistencyChecker {
// TODO: Add support for post shared bridge commits
let commit_function = if local.is_pre_boojum() {
&*PRE_BOOJUM_COMMIT_FUNCTION
} else {
} else if local.is_pre_shared_bridge() {
self.contract
.function("commitBatches")
.context("L1 contract does not have `commitBatches` function")
.map_err(CheckError::Internal)?
} else {
self.contract
.function("commitBatchesSharedBridge")
.context("L1 contract does not have `commitBatches` function")
.map_err(CheckError::Internal)?
};

let commitment =
Expand Down
42 changes: 27 additions & 15 deletions core/lib/zksync_core/src/consistency_checker/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) fn create_l1_batch_with_metadata(number: u32) -> L1BatchWithMetadata
const PRE_BOOJUM_PROTOCOL_VERSION: ProtocolVersionId = ProtocolVersionId::Version10;
const DIAMOND_PROXY_ADDR: Address = Address::repeat_byte(1);
const VALIDATOR_TIMELOCK_ADDR: Address = Address::repeat_byte(23);
const CHAIN_ID: u32 = 270;
StanislavBreadless marked this conversation as resolved.
Show resolved Hide resolved

pub(crate) fn create_pre_boojum_l1_batch_with_metadata(number: u32) -> L1BatchWithMetadata {
let mut l1_batch = L1BatchWithMetadata {
Expand All @@ -56,24 +57,35 @@ pub(crate) fn build_commit_tx_input_data(
) -> Vec<u8> {
let pubdata_da = PubdataDA::Calldata;

let is_pre_boojum = batches[0].header.protocol_version.unwrap().is_pre_boojum();
let contract;
let commit_function = if is_pre_boojum {
&*PRE_BOOJUM_COMMIT_FUNCTION
} else {
contract = zksync_contracts::state_transition_chain_contract();
contract.function("commitBatches").unwrap()
};
let protocol_version = batches[0].header.protocol_version.unwrap();
let contract = zksync_contracts::state_transition_chain_contract();

let mut encoded = vec![];
encoded.extend_from_slice(&commit_function.short_signature());
// Mock an additional argument used in real `commitBlocks` / `commitBatches`. In real transactions,
// it's taken from the L1 batch previous to `batches[0]`, but since this argument is not checked,
// it's OK to use `batches[0]`.
encoded.extend_from_slice(&ethabi::encode(
&l1_batch_commit_data_generator.l1_commit_batches(&batches[0], batches, &pubdata_da),
));
encoded
let tokens =
l1_batch_commit_data_generator.l1_commit_batches(&batches[0], batches, &pubdata_da);

if protocol_version.is_pre_boojum() {
PRE_BOOJUM_COMMIT_FUNCTION.encode_input(&tokens).unwrap()
} else if protocol_version.is_pre_shared_bridge() {
contract
.function("commitBatches")
.unwrap()
.encode_input(&tokens)
.unwrap()
} else {
// Post shared bridge transactions also require chain id
let tokens: Vec<_> = vec![Token::Uint(CHAIN_ID.into())]
.into_iter()
.chain(tokens)
.collect();
contract
.function("commitBatchesSharedBridge")
.unwrap()
.encode_input(&tokens)
.unwrap()
}
}

pub(crate) fn create_mock_checker(
Expand Down Expand Up @@ -133,7 +145,7 @@ fn build_commit_tx_input_data_is_correct(deployment_mode: DeploymentMode) {
};

let contract = zksync_contracts::state_transition_chain_contract();
let commit_function = contract.function("commitBatches").unwrap();
let commit_function = contract.function("commitBatchesSharedBridge").unwrap();
let batches = vec![
create_l1_batch_with_metadata(1),
create_l1_batch_with_metadata(2),
Expand Down
21 changes: 13 additions & 8 deletions core/tests/ts-integration/src/context-owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ export class TestContextOwner {
const l2ETHAmountToDeposit = await this.ensureBalances(accountsAmount);
const l2ERC20AmountToDeposit = ERC20_PER_ACCOUNT.mul(accountsAmount);
const wallets = this.createTestWallets(suites);
await this.distributeL1BaseToken(wallets, l2ERC20AmountToDeposit);
const baseTokenAddress = await this.mainSyncWallet.provider.getBaseTokenContractAddress();
await this.distributeL1BaseToken(wallets, l2ERC20AmountToDeposit, baseTokenAddress);
await this.cancelAllowances();
await this.distributeL1Tokens(wallets, l2ETHAmountToDeposit, l2ERC20AmountToDeposit);
await this.distributeL1Tokens(wallets, l2ETHAmountToDeposit, l2ERC20AmountToDeposit, baseTokenAddress);
await this.distributeL2Tokens(wallets);

this.reporter.finishAction();
Expand Down Expand Up @@ -271,9 +272,12 @@ 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(wallets: TestWallets, l2erc20DepositAmount: ethers.BigNumber) {
private async distributeL1BaseToken(
wallets: TestWallets,
l2erc20DepositAmount: ethers.BigNumber,
baseTokenAddress: zksync.types.Address
) {
this.reporter.startAction(`Distributing base tokens on L1`);
const baseTokenAddress = process.env.CONTRACTS_BASE_TOKEN_ADDR!;
if (baseTokenAddress != zksync.utils.ETH_ADDRESS_IN_CONTRACTS) {
const chainId = process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID!;
const l1startNonce = await this.mainEthersWallet.getTransactionCount();
Expand Down Expand Up @@ -362,7 +366,8 @@ export class TestContextOwner {
private async distributeL1Tokens(
wallets: TestWallets,
l2ETHAmountToDeposit: ethers.BigNumber,
l2erc20DepositAmount: ethers.BigNumber
l2erc20DepositAmount: ethers.BigNumber,
baseTokenAddress: zksync.types.Address
) {
const chainId = process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID!;
this.reporter.startAction(`Distributing tokens on L1`);
Expand Down Expand Up @@ -486,8 +491,8 @@ export class TestContextOwner {

nonce += erc20Transfers.length;
// Send ERC20 base token on L1.
const BaseErc20Transfers = await sendTransfers(
process.env.CONTRACTS_BASE_TOKEN_ADDR!,
const baseErc20Transfers = await sendTransfers(
baseTokenAddress,
this.mainEthersWallet,
wallets,
ERC20_PER_ACCOUNT,
Expand All @@ -499,7 +504,7 @@ export class TestContextOwner {
l1TxPromises.push(erc20DepositPromise);
l1TxPromises.push(...ethTransfers);
l1TxPromises.push(...erc20Transfers);
l1TxPromises.push(...BaseErc20Transfers);
l1TxPromises.push(...baseErc20Transfers);

this.reporter.debug(`Sent ${l1TxPromises.length} initial transactions on L1`);
await Promise.all(l1TxPromises);
Expand Down
12 changes: 8 additions & 4 deletions core/tests/ts-integration/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ 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 All @@ -65,6 +64,9 @@ export async function loadTestEnvironment(): Promise<TestEnvironment> {
process.env.ZKSYNC_WEB3_API_URL || process.env.API_WEB3_JSON_RPC_HTTP_URL,
'L2 node URL'
);
const l2Provider = new zksync.Provider(l2NodeUrl);
const baseTokenAddress = await l2Provider.getBaseTokenContractAddress();

const l1NodeUrl = ensureVariable(process.env.L1_RPC_ADDRESS || process.env.ETH_CLIENT_WEB3_URL, 'L1 node URL');
const wsL2NodeUrl = ensureVariable(
process.env.ZKSYNC_WEB3_WS_API_URL || process.env.API_WEB3_JSON_RPC_WS_URL,
Expand All @@ -83,18 +85,20 @@ 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)!;
const baseToken = tokens.find((token: { address: string }) =>
zksync.utils.isAddressEq(token.address, baseTokenAddress)
)!;

// `waitForServer` is expected to be executed. Otherwise this call may throw.
const l2TokenAddress = await new zksync.Wallet(
mainWalletPK,
new zksync.Provider(l2NodeUrl),
l2Provider,
ethers.getDefaultProvider(l1NodeUrl)
).l2TokenAddress(token.address);

const l2WethAddress = await new zksync.Wallet(
mainWalletPK,
new zksync.Provider(l2NodeUrl),
l2Provider,
ethers.getDefaultProvider(l1NodeUrl)
).l2TokenAddress(weth.address);

Expand Down
3 changes: 2 additions & 1 deletion core/tests/ts-integration/tests/base-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe('base ERC20 contract checks', () => {
bob = testMaster.newEmptyAccount();

baseTokenDetails = testMaster.environment().baseToken;
isETHBasedChain = process.env.CONTRACTS_BASE_TOKEN_ADDR! == zksync.utils.ETH_ADDRESS_IN_CONTRACTS;
const baseToken = await alice.provider.getBaseTokenContractAddress();
isETHBasedChain = baseToken == zksync.utils.ETH_ADDRESS_IN_CONTRACTS;
StanislavBreadless marked this conversation as resolved.
Show resolved Hide resolved
});

test('Can perform a deposit', async () => {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11792,7 +11792,7 @@ yocto-queue@^1.0.0:

"zksync-ethers@https://github.com/zksync-sdk/zksync-ethers#ethers-v5-feat/bridgehub":
version "5.1.0"
resolved "https://github.com/zksync-sdk/zksync-ethers#6a2908fe909488abf1c8bb8afc616d5eadf6816e"
resolved "https://github.com/zksync-sdk/zksync-ethers#7e5e8edc57c848aabdb4b018de8270addc82aa6e"
dependencies:
ethers "~5.7.0"

Expand Down
Loading