Skip to content

Commit

Permalink
feat: integration tests setup (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters authored and pcheremu committed Aug 22, 2024
1 parent 0633916 commit b2a1cc4
Show file tree
Hide file tree
Showing 26 changed files with 4,399 additions and 357 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ lerna-debug.log*
!.vscode/extensions.json

# Allure
**allure-results/
#Allure results and artifacts
**/allure-results/
**/e2e/artifacts/
**/playbook/artifacts*
**/playbook/cache*
**/buffer/*.txt

# App hyperchain config
hyperchain.config.json
2,888 changes: 2,594 additions & 294 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions packages/integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ Based on Jest.io/TypeScript/TDD.
npm install
```

## Setting up env variables

- Create `.env` file in the `integration-tests/src/playbook/` package folder and copy paste `.env.example` content in there.
```
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`.

## Preparing a local environment

Make sure you have `Docker` installed. Before running the tests you need to spin up a local environment (use `docker-compose.yaml` from the root directory):
Expand Down
1 change: 0 additions & 1 deletion packages/integration-tests/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"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",
"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: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: 10000000 },
l2GasLimit: 10000000,
gasLimit: { gasLimit: 8000000 },
l2GasLimit: 8000000,
L1Network: "http://localhost:8545",
L2Network: "http://localhost:3050",
privateKey: Wallets.richWalletPrivateKey,
Expand Down
7 changes: 0 additions & 7 deletions packages/integration-tests/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export enum Buffer {
L2 = "./buffer/L2.txt",
L2deposited = "./buffer/L2deposited.txt",
paymaster = "./buffer/paymaster.txt",
paymasterDeployTx = "./buffer/paymasterDeployTx.txt",
paymasterTx = "./buffer/paymasterTx.txt",
addressMultiTransferETH = "./buffer/multiTransferETH.txt",
txMultiTransferETH = "./buffer/txMultiTransferETH.txt",
Expand All @@ -20,12 +19,6 @@ 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
Expand Up @@ -31,7 +31,6 @@ export default async function (hre: HardhatRuntimeEnvironment) {

const deployTransaction = await paymaster.deployTransaction;
console.log(`Paymaster deploy transaction: ${deployTransaction.hash}`);
await fs.writeFile(Buffer.paymasterDeployTx, deployTransaction.hash);

await (
await deployer.zkWallet.sendTransaction({
Expand Down
1 change: 0 additions & 1 deletion packages/integration-tests/src/playbook/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require("dotenv").config({ path: __dirname + "/.env" });
import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
import "@nomiclabs/hardhat-ethers";

import { localConfig } from "../config";

import type { HardhatUserConfig } from "hardhat/types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

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

export const transferERC20 = async function (sum: string, tokenAddress: string, tokenName?: string /*, units = 18*/) {
Expand All @@ -12,8 +11,6 @@ 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 @@ -24,7 +21,6 @@ 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,9 +1,8 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

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

export const transferEth = async function (sum = "0.000009", address: string = Wallets.mainWalletPrivateKey) {
Expand All @@ -12,8 +11,6 @@ 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 @@ -23,7 +20,6 @@ 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,9 +1,8 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

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

export const transferFailedState = async function (tokenAddress: string, tokenName?: string) {
Expand All @@ -12,8 +11,6 @@ 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 @@ -24,7 +21,6 @@ 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,9 +1,8 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

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

export const withdrawERC20 = async function (tokenAddress: string, sum = "0.2") {
Expand All @@ -12,8 +11,6 @@ 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 @@ -24,7 +21,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 @@ -37,7 +34,6 @@ 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,9 +1,8 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

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

export const withdrawERC20toOtherAddress = async function (tokenAddress: string, sum = "0.2") {
Expand All @@ -12,8 +11,6 @@ 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 @@ -37,7 +34,6 @@ 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,18 +1,15 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Buffer, Logger } from "../../../entities";
import { 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 @@ -23,7 +20,6 @@ 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,18 +1,15 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import * as zksync from "zksync-web3";

import { localConfig } from "../../../config";
import { Buffer, Logger, Wallets } from "../../../entities";
import { 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 @@ -24,7 +21,6 @@ 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;
};
9 changes: 5 additions & 4 deletions packages/integration-tests/src/playbook/utils/getWallet.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { getDefaultProvider, utils } from "ethers";
import { Provider, Wallet } from "zksync-web3";

import { Wallets } from "../../entities";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default async function (hre: any) {
const syncProvider = new Provider(hre.config.networks.zkSyncLocal.url);
const ethProvider = getDefaultProvider(hre.config.networks.zkSyncLocal.ethNetwork);
const walletPrivateKey = process.env.WALLET_PRIVATE_KEY || Wallets.richWalletPrivateKey;

if (!process.env.WALLET_PRIVATE_KEY) {
throw new Error("WALLET_PRIVATE_KEY env variable is not set");
}

// Initialize the wallet.
const wallet = new Wallet(walletPrivateKey as string, syncProvider, ethProvider);
const wallet = new Wallet(process.env.WALLET_PRIVATE_KEY as string, syncProvider, ethProvider);
console.log(`Deploying using wallet: ${wallet.address}`);

// Wallet ETH balance
Expand Down
31 changes: 31 additions & 0 deletions packages/integration-tests/tests/api/before-all/deposit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { localConfig } from "../../../src/config";
import { Buffer } from "../../../src/entities";
import { Logger } from "../../../src/entities";
import { Helper } from "../../../src/helper";
import { Playbook } from "../../../src/playbook/playbook";

describe("Deposit", () => {
const playbook = new Playbook();
const helper = new Helper();
const bufferRoute = "src/playbook/";

let result: string;
let token: string;
jest.setTimeout(localConfig.extendedTimeout);

//@id633
it("Make a deposit with 0.0000001 ETH ", async () => {
result = await playbook.depositETH("0.0000001");
await expect(result).not.toBeUndefined();
await expect(result.includes(Logger.txHashStartsWith)).toBe(true);
});

//@id638
it("Make a deposit with the Custom token ", async () => {
const bufferFile = bufferRoute + Buffer.L1;
token = await helper.getStringFromFile(bufferFile);
result = await playbook.depositERC20("100", token, 18);
await expect(result).not.toBeUndefined();
await expect(result.includes(Logger.txHashStartsWith)).toBe(true);
});
});
Loading

0 comments on commit b2a1cc4

Please sign in to comment.