Skip to content

Commit

Permalink
Merge branch 'integration-tests-signed' into oleh-bairak-qa-681-accou…
Browse files Browse the repository at this point in the history
…nts-api-deposit-multitransfer-transfer
  • Loading branch information
olehbairak committed Mar 12, 2024
2 parents d03fe86 + 5467a5e commit 4e4f6db
Show file tree
Hide file tree
Showing 63 changed files with 1,216 additions and 830 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

- name: Install dependencies
run: |
npm ci --no-audit
npm ci
npx playwright install --with-deps chromium
- name: Log in to Docker Hub
uses: docker/login-action@v2
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"test": "lerna run test",
"test:ci": "lerna run test:ci",
"test:e2e": "lerna run test:e2e",
"test:integration:ui": "lerna run integration-test:ui",
"test:integration:api": "lerna run integration-test:api",
"test:integration:ui": "lerna run integration-tests:ui",
"test:integration:api": "lerna run integration-tests:api",
"dev": "lerna run dev",
"build": "lerna run build",
"start": "lerna run start",
Expand Down
4 changes: 2 additions & 2 deletions packages/app/tests/e2e/features/copying.feature

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ npm install
cp .env.example packages/integration-tests/src/playbook/.env
```

- Add your private wallet key to `WALLET_PRIVATE_KEY=` By default we use `richWalletPrivateKey` private key in `integration-tests/src/playbook/utils/getWallet.ts` from `integration-tests/src/entities.ts`.
- Add your private wallet key to `WALLET_PRIVATE_KEY={YOUR_PRIVATE_KEY}`. By default we use `richWalletPrivateKey` private key in `integration-tests/src/playbook/utils/getWallet.ts` from `integration-tests/src/constants.ts`.

## Preparing a local environment

Expand All @@ -42,13 +42,13 @@ npm run integration-test:ui
If you need to run the exact test or/and suite you can change
key-words from `it` to `fit` (for the test) and `describe` to `fdescribe` for suite.

If you need to exclude some specific test/suites, you can change keywords `it` to `xit` and/or
If you need to exclude some specific test/suite, you can change keywords `it` to `xit` and/or
`describe` to `xdescribe`.

The test solution contains two main folders: [src](./src) and [tests](./tests).
[src](./src) folder contains:
- essential [scenarios](./src/playbook/scenarios/)
- predefined [entities](./src/entities.ts) and [config](./src/config.ts) config files
- predefined [constants](./src/constants.ts) and [config](./src/config.ts) config files
- [contracts](./src/playbook/contracts/) folder with a set of contracts
- [deploy](./src/playbook/deploy/) folder with a set of deploy scripts
- [buffer](./src/playbook/buffer/) folder as a temporary storage of transaction hashes and addresses
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "integration-tests",
"version": "0.0.0",
"title": "Integration tests",
"description": "The test solution for transaction processing`",
"description": "The test solution for Block Explorer API and UI",
"repository": "https://github.com/matter-labs/block-explorer",
"private": true,
"author": "Matter Labs",
Expand Down
4 changes: 2 additions & 2 deletions packages/integration-tests/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Wallets } from "./entities";
import { Wallets } from "./constants";

export const localConfig = {
gasLimit: { gasLimit: 10000000 },
l1GasLimit: { gasLimit: 10000000 },
l2GasLimit: 10000000,
L1Network: "http://localhost:8545",
L2Network: "http://localhost:3050",
Expand Down
85 changes: 85 additions & 0 deletions packages/integration-tests/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as path from "path";

export enum Buffer {
greeterL2 = "greeterL2.txt",
executeGreeterTx = "executeGreeterTx.txt",
NFTtoL1 = "NFTtoL1.txt",
NFTtoL2 = "NFTtoL2.txt",
L1 = "L1.txt",
L2 = "L2.txt",
L2deposited = "L2deposited.txt",
paymaster = "paymaster.txt",
paymasterDeployTx = "paymasterDeployTx.txt",
paymasterTx = "paymasterTx.txt",
addressMultiTransferETH = "multiTransferETH.txt",
txMultiTransferETH = "txMultiTransferETH.txt",
txMultiTransferCustomTokenI = "txMultiTransferCustomTokenI.txt",
txMultiTransferCustomTokenII = "txMultiTransferCustomTokenII.txt",
addressMultiCallMiddle = "multiCallMiddle.txt",
addressMultiCallCaller = "multiCallCaller.txt",
addressMultiCallRoot = "multiCallRoot.txt",
txMultiCallMiddle = "txMultiCallMiddle.txt",
txMultiCallCaller = "txMultiCallCaller.txt",
txMultiCallRoot = "txmultiCallRoot.txt",
txUseMultiCallContracts = "txUseMultiCallContracts.txt",
txEthTransfer = "txEthTransfer.txt",
txERC20Withdraw = "txERC20Withdraw.txt",
txERC20WithdrawOtherAddress = "txERC20WithdrawOtherAddress.txt",
txEthWithdraw = "txEthWithdraw.txt",
txEthWithdrawOtherAddress = "txEthWithdrawOtherAddress.txt",
txERC20Transfer = "txERC20Transfer.txt",
emptyWalletPrivateKey = "emptyWalletPrivateKey.txt",
emptyWalletAddress = "emptyWalletAddress.txt",
failedState = "failedState.txt",
customToken = "customToken.txt",
txEthDeposit = "txEthDeposit.txt",
txERC20Deposit = "txERC20Deposit.txt",
}

export const Path = {
playbookRoot: path.join("src", "playbook"),
absolutePathToBufferFiles: path.join(__dirname, "..", "src", "playbook", "buffer"),
};

export enum Logger {
deposit = "DEPOSIT",
withdraw = "WITHDRAW",
transfer = "TRANSFER",
txHashStartsWith = "0x",
textSeparator = "======================= ",
txFailedState = "FAILED STATE",
}

export enum Token {
customL2TokenName = "L2 ERC20 token",
customL2TokenSymbol = "L2",
customL2TokenDecimals = 18,
pullAddressETH = "0x0000000000000000000000000000000000008001",
addressETH = "0x0000000000000000000000000000000000000000",
ERC20AddressETH = "0x000000000000000000000000000000000000800A",
}

export enum TransactionsType {
fee = "fee",
transfer = "transfer",
refund = "refund",
withdrawal = "withdrawal",
}

export enum TransactionStatus {
failed = "failed",
}

export enum Wallets {
mainWalletAddress = "0x586607935E1462ab762F438E0A7b2968A4158975",
secondaryWalletAddress = "0x26A4c5Dfe2cA3c9E7E8C417B689F41b6b5745C37",
richWalletAddress = "0x36615Cf349d7F6344891B1e7CA7C72883F5dc049",
mainWalletPrivateKey = "0x06ac1584dd1cf69f97a784b2b7812cd0c65a867ec997add028cdf56483c1c299",
secondaryWalletPrivateKey = "e14e6e0b3b610411cf15c3a5aa3252cac9e0a40a9bbe67ceb3b5d506f56576fd",
richWalletPrivateKey = "0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110",
}

export enum BlockExplorer {
baseUrl = "http://localhost:3010",
localNetwork = "/?network=local",
}
87 changes: 0 additions & 87 deletions packages/integration-tests/src/entities.ts

This file was deleted.

53 changes: 29 additions & 24 deletions packages/integration-tests/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { execSync } from "child_process";
import { exec } from "child_process";
import { ethers } from "ethers";
import { promises as fs } from "fs";
import * as path from "path";
import * as request from "supertest";
import { Provider } from "zksync-web3";
import { setTimeout } from "timers/promises";

import { environment, localConfig } from "./config";
import { Logger } from "./entities";
import { Logger } from "./constants";
import { getProviderForL1, getProviderForL2 } from "./provider";

import type { BaseProvider } from "@ethersproject/providers/src.ts/base-provider";

export class Helper {
async txHashLogger(txType: string, txValue: string, tokenName?: string) {
async logTransaction(txType: string, txValue: string, tokenName?: string) {
const logMessage = `TxHash for ${txType} ${Logger.textSeparator} ${txValue}`;

if (tokenName === undefined) {
Expand All @@ -22,46 +23,50 @@ export class Helper {
}

async executeScript(script: string) {
const output = execSync(script, { encoding: "utf-8" });

try {
console.log(`> Run NPM Script "${script}":\n`, output);
return output;
} catch (e) {
console.log(e);
}
return new Promise((resolve, reject) => {
exec(script, { encoding: "utf-8" }, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing script "${script}":`, error);
console.error(`stderr executing script "${script}":`, stderr);
reject(error);
} else {
console.log(`> Run NPM Script "${script}":\n`, stdout);
resolve(stdout);
}
});
});
}

async getStringFromFile(fileName: string) {
const absoluteRoute = path.join(__dirname, "..", fileName);
async writeFile(filePath: string, fileName: string, data: string) {
const absoluteRoute = path.join(filePath, fileName);
await fs.writeFile(absoluteRoute, data);
}

try {
return await fs.readFile(absoluteRoute, { encoding: "utf-8" });
} catch {
console.log(`There is no the expected file: ${fileName}`);
}
async readFile(filePath: string, fileName: string) {
const absoluteRoute = path.join(filePath, fileName);
return await fs.readFile(absoluteRoute, { encoding: "utf-8" });
}

async getBalanceETH(walletAddress: string, layer: string) {
let network: string;
let provider: BaseProvider;
if (layer == "L1") {
network = localConfig.L1Network;
provider = ethers.getDefaultProvider(network);
provider = getProviderForL1(network);
} else if (layer == "L2") {
network = localConfig.L2Network;
provider = new Provider(network);
provider = getProviderForL2(network);
} else {
console.log(`Wrong layer: ${layer}`);
}
return ethers.utils.formatUnits(await provider.getBalance(walletAddress), "wei");
}

async delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
await setTimeout(ms);
}

async performGETrequest(apiRoute: string) {
async performBlockExplorerApiGetRequest(apiRoute: string) {
return request(environment.blockExplorerAPI).get(apiRoute);
}

Expand All @@ -73,7 +78,7 @@ export class Helper {
* with a delay between attempts (localConfig.intervalAPIretries).
* Throws an error if the action consistently fails after all retries.
*/
async retryTestAction(action) {
async runRetriableTestAction(action) {
for (let i = 0; i < localConfig.maxAPIretries; i++) {
try {
await action();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: Unlicense
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IGreeter2 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: Unlicense
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IGreeter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { promises as fs } from "fs";

import { localConfig } from "../../config";
import { Buffer } from "../../entities";
import { Buffer, Path } from "../../constants";
import { Helper } from "../../helper";
import getWallet from "../utils/getWallet";

import type { HardhatRuntimeEnvironment } from "hardhat/types";
const helper = new Helper();

export default async function (hre: HardhatRuntimeEnvironment) {
const wallet = await getWallet(hre);

const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("Greeter");
const contract = await deployer.deploy(artifact, [], localConfig.gasLimit);
const contract = await deployer.deploy(artifact, [], localConfig.l1GasLimit);
const contractAddress = contract.address;
console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
await fs.writeFile(Buffer.greeterL2, contractAddress);
await helper.writeFile(Path.absolutePathToBufferFiles, Buffer.greeterL2, contractAddress);
}
Loading

0 comments on commit 4e4f6db

Please sign in to comment.