Skip to content

Commit

Permalink
Merge pull request #67 from matter-labs/QA-487-re-structure-tests
Browse files Browse the repository at this point in the history
test: re-stucturing API test suites/global hooks
  • Loading branch information
abilevych authored Nov 14, 2023
2 parents 5e62c42 + 37765e0 commit f7ddfe6
Show file tree
Hide file tree
Showing 30 changed files with 1,617 additions and 1,796 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/app-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ env:

jobs:
e2e:
runs-on: [self-hosted, ci-runner]
runs-on: [matterlabs-ci-runner]
permissions:
contents: read
defaults:
Expand Down Expand Up @@ -64,6 +64,12 @@ jobs:
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'

- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
deployBackendToStaging:
name: Deploy Block Explorer backend to staging
runs-on: [self-hosted, ci-runner]
runs-on: [matterlabs-ci-runner]
permissions:
contents: read
needs: createReleaseVersion
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ services:
- DATABASE_PASSWORD=postgres
- DATABASE_NAME=block-explorer
- BLOCKCHAIN_RPC_URL=http://zksync:3050
- BATCHES_PROCESSING_POLLING_INTERVAL=1000
ports:
- '3001:3001'
- '9229:9229'
Expand Down
1 change: 1 addition & 0 deletions packages/integration-tests/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"globalSetup": "<rootDir>/tests/hooks/global.ts",
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".test.ts$",
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 @@ -9,7 +9,7 @@
"license": "MIT",
"scripts": {
"postinstall": "cd src/playbook && npm install",
"integration-test:api": "jest --verbose --testPathPattern=tokens.test.ts && jest --verbose --testPathPattern=deposit.test.ts && jest --verbose --testPathPattern=common && jest --verbose --testPathPattern=transactions",
"integration-test:api": "jest --verbose",
"integration-test:ui": "npx playwright test",
"block-explorer:start": "docker-compose up",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-pattern 'repos' --ignore-pattern 'git add .'"
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,8 +1,8 @@
import { Wallets } from "./entities";

export const localConfig = {
gasLimit: { gasLimit: 8000000 },
l2GasLimit: 8000000,
gasLimit: { gasLimit: 10000000 },
l2GasLimit: 10000000,
L1Network: "http://localhost:8545",
L2Network: "http://localhost:3050",
privateKey: Wallets.richWalletPrivateKey,
Expand Down
6 changes: 6 additions & 0 deletions packages/integration-tests/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export enum Buffer {
txMultiCallCaller = "./buffer/txMultiCallCaller.txt",
txMultiCallRoot = "./buffer/txmultiCallRoot.txt",
txUseMultiCallContracts = "./buffer/txUseMultiCallContracts.txt",
txEthTransfer = "./buffer/txEthTransfer.txt",
txERC20Withdraw = "./buffer/txERC20Withdraw.txt",
txERC20WithdrawOtherAddress = "./buffer/txERC20WithdrawOtherAddress.txt",
txEthWithdraw = "./buffer/txEthWithdraw.txt",
txEthWithdrawOtherAddress = "./buffer/txEthWithdrawOtherAddress.txt",
txERC20Transfer = "./buffer/txERC20Transfer.txt",
emptyWalletPrivateKey = "./buffer/emptyWalletPrivateKey.txt",
emptyWalletAddress = "./buffer/emptyWalletAddress.txt",
failedState = "./buffer/failedState.txt",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Logger, Wallets } from "../../../entities";
import { Buffer, Logger, Wallets } from "../../../entities";
import { Helper } from "../../../helper";

export const transferERC20 = async function (sum: string, tokenAddress: string, tokenName?: string /*, units = 18*/) {
Expand All @@ -11,6 +12,8 @@ export const transferERC20 = async function (sum: string, tokenAddress: string,
const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const syncWallet2 = new zksync.Wallet(Wallets.secondWalletPrivateKey, syncProvider, ethProvider);
const playbookRoot = "src/playbook/";
const bufferFile = playbookRoot + Buffer.txEthTransfer;

const transfer = await syncWallet.transfer({
to: syncWallet2.address,
Expand All @@ -21,6 +24,7 @@ export const transferERC20 = async function (sum: string, tokenAddress: string,

const txHash = transfer.hash;
await helper.txHashLogger(Logger.transfer, txHash, tokenName);
await fs.writeFile(bufferFile, txHash);

return txHash;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Logger, Wallets } from "../../../entities";
import { Buffer, Logger, Wallets } from "../../../entities";
import { Helper } from "../../../helper";

export const transferEth = async function (sum = "0.000009", address: string = Wallets.mainWalletPrivateKey) {
Expand All @@ -11,6 +12,8 @@ export const transferEth = async function (sum = "0.000009", address: string = W
const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const syncWallet2 = new zksync.Wallet(address, syncProvider, ethProvider);
const playbookRoot = "src/playbook/";
const bufferFile = playbookRoot + Buffer.txEthTransfer;

const transfer = await syncWallet.transfer({
to: syncWallet2.address,
Expand All @@ -20,6 +23,7 @@ export const transferEth = async function (sum = "0.000009", address: string = W

const txHash = transfer.hash;
await helper.txHashLogger(Logger.transfer, txHash, "ETH");
await fs.writeFile(bufferFile, txHash);

return txHash;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Logger } from "../../../entities";
import { Buffer, Logger } from "../../../entities";
import { Helper } from "../../../helper";

export const transferFailedState = async function (tokenAddress: string, tokenName?: string) {
Expand All @@ -11,6 +12,8 @@ export const transferFailedState = async function (tokenAddress: string, tokenNa
const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const amount = ethers.utils.parseEther("1.0");
const playbookRoot = "src/playbook/";
const bufferFile = playbookRoot + Buffer.failedState;

const transfer = await syncWallet.transfer({
to: "0x0000000000000000000000000000000000000000",
Expand All @@ -21,6 +24,7 @@ export const transferFailedState = async function (tokenAddress: string, tokenNa

const txHash = transfer.hash;
await helper.txHashLogger(Logger.txFailedState, txHash, tokenName);
await fs.writeFile(bufferFile, txHash);

return txHash;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Logger, Wallets } from "../../../entities";
import { Buffer, Logger, Wallets } from "../../../entities";
import { Helper } from "../../../helper";

export const withdrawERC20 = async function (tokenAddress: string, sum = "0.2") {
Expand All @@ -11,6 +12,8 @@ export const withdrawERC20 = async function (tokenAddress: string, sum = "0.2")
const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const bridges = await syncProvider.getDefaultBridgeAddresses();
const playbookRoot = "src/playbook/";
const bufferFile = playbookRoot + Buffer.txERC20Withdraw;

const balance = await syncWallet.getBalance(tokenAddress);

Expand All @@ -21,7 +24,7 @@ export const withdrawERC20 = async function (tokenAddress: string, sum = "0.2")
amount: ethers.utils.parseEther(sum),
token: tokenAddress,
bridgeAddress: bridges.erc20L2,
overrides: localConfig.gasLimit,
// overrides: localConfig.gasLimit,
});

const txHash = withdrawL2.hash;
Expand All @@ -34,6 +37,7 @@ export const withdrawERC20 = async function (tokenAddress: string, sum = "0.2")
console.log(`Your balance is ${balanceAfter.toString()}`);

await helper.txHashLogger(Logger.withdraw, txHash, "Custom token");
await fs.writeFile(bufferFile, txHash);

return txHash;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Logger, Wallets } from "../../../entities";
import { Buffer, Logger, Wallets } from "../../../entities";
import { Helper } from "../../../helper";

export const withdrawERC20toOtherAddress = async function (tokenAddress: string, sum = "0.2") {
Expand All @@ -11,6 +12,8 @@ export const withdrawERC20toOtherAddress = async function (tokenAddress: string,
const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const bridges = await syncProvider.getDefaultBridgeAddresses();
const playbookRoot = "src/playbook/";
const bufferFile = playbookRoot + Buffer.txERC20WithdrawOtherAddress;

const balance = await syncWallet.getBalance(tokenAddress);

Expand All @@ -34,6 +37,7 @@ export const withdrawERC20toOtherAddress = async function (tokenAddress: string,
console.log(`Your balance is ${balanceAfter.toString()}`);

await helper.txHashLogger(Logger.withdraw, txHash, "Custom token");
await fs.writeFile(bufferFile, txHash);

return txHash;
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Logger } from "../../../entities";
import { Buffer, Logger } from "../../../entities";
import { Helper } from "../../../helper";

export const withdrawETH = async function (sum = "0.000009") {
const helper = new Helper();
const syncProvider = new zksync.Provider(localConfig.L2Network);
const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const playbookRoot = "src/playbook/";
const bufferFile = playbookRoot + Buffer.txEthWithdraw;

const withdrawL2 = await syncWallet.withdraw({
token: zksync.utils.ETH_ADDRESS,
Expand All @@ -20,6 +23,7 @@ export const withdrawETH = async function (sum = "0.000009") {

await withdrawL2.waitFinalize();
await helper.txHashLogger(Logger.withdraw, txHash, "ETH");
await fs.writeFile(bufferFile, txHash);

return txHash;
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Logger, Wallets } from "../../../entities";
import { Buffer, Logger, Wallets } from "../../../entities";
import { Helper } from "../../../helper";

export const withdrawETHtoOtherAddress = async function (sum = "0.000009") {
const helper = new Helper();
const syncProvider = new zksync.Provider(localConfig.L2Network);
const ethProvider = ethers.getDefaultProvider(localConfig.L1Network);
const syncWallet = new zksync.Wallet(localConfig.privateKey, syncProvider, ethProvider);
const playbookRoot = "src/playbook/";
const bufferFile = playbookRoot + Buffer.txEthWithdrawOtherAddress;

const withdrawL2 = await syncWallet.withdraw({
token: zksync.utils.ETH_ADDRESS,
Expand All @@ -21,6 +24,7 @@ export const withdrawETHtoOtherAddress = async function (sum = "0.000009") {

await withdrawL2.waitFinalize();
await helper.txHashLogger(Logger.withdraw, txHash, "ETH");
await fs.writeFile(bufferFile, txHash);

return txHash;
};
Loading

0 comments on commit f7ddfe6

Please sign in to comment.