Skip to content

Commit

Permalink
Merge branch 'integration-tests-signed' into oleh-bairak-qa-653-token…
Browse files Browse the repository at this point in the history
…sapi-accounts-api-automate-test-cases-for-contracts-api
  • Loading branch information
olehbairak committed Mar 7, 2024
2 parents 78a146c + 0ccaf8f commit 9ff2fd0
Show file tree
Hide file tree
Showing 55 changed files with 575 additions and 644 deletions.
4 changes: 2 additions & 2 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={YOUR_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 Down Expand Up @@ -48,7 +48,7 @@ If you need to exclude some specific test/suite, you can change keywords `it` to
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/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Wallets } from "./entities";
import { Wallets } from "./constants";

export const localConfig = {
gasLimit: { gasLimit: 10000000 },
Expand Down
86 changes: 86 additions & 0 deletions packages/integration-tests/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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 {
// CUST_Address = "0x0928008B245A76E105E02C522b5d309c0887ecA5",// probably unused
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",
}
83 changes: 0 additions & 83 deletions packages/integration-tests/src/entities.ts

This file was deleted.

31 changes: 17 additions & 14 deletions packages/integration-tests/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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 { environment, localConfig } from "./config";
import { Logger } from "./entities";
import { Logger } from "./constants";

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,23 +22,26 @@ 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);
reject(error);
} else {
console.log(`> Run NPM Script "${script}":\n`, stdout);
resolve(stdout);
}
});
});
}

async getStringFromFile(fileName: string) {
const absoluteRoute = path.join(__dirname, "..", fileName);
async readFile(filePath: string, fileName: string) {
const absoluteRoute = path.join(filePath + fileName);

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

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

import { localConfig } from "../../config";
import { Buffer } from "../../entities";
import { Buffer } from "../../constants";
import getWallet from "../utils/getWallet";

import type { HardhatRuntimeEnvironment } from "hardhat/types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ethers from "ethers";
import { promises as fs } from "fs";
import { Wallet } from "zksync-web3";

import { Buffer, Wallets } from "../../entities";
import { Buffer, Wallets } from "../../constants";

import type { HardhatRuntimeEnvironment } from "hardhat/types";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { promises as fs } from "fs";
import { ethers } from "hardhat";

import { localConfig } from "../../config";
import { Buffer, Wallets } from "../../entities";
import { Buffer, Wallets } from "../../constants";

async function main() {
const [deployer] = await ethers.getSigners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { promises as fs } from "fs";

import { localConfig } from "../../config";
import { Buffer } from "../../entities";
import { Buffer } from "../../constants";
import getWallet from "../utils/getWallet";

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

import { Buffer, Wallets } from "../../entities";
import { Buffer, Wallets } from "../../constants";
import verify from "../utils/displayVerificationInfo";
import getWallet from "../utils/getWallet";

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

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

Expand All @@ -10,15 +10,14 @@ import type { HardhatRuntimeEnvironment } from "hardhat/types";
export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the contract`);
const helper = new Helper();
const playbookRoot = "src/playbook/";
const wallet = await getWallet(hre);

// Create deployer object and load the artifact of the contract we want to deploy.
const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("GCaller");

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
const addressContractMiddle = await helper.getStringFromFile(playbookRoot + Buffer.addressMultiCallMiddle);
const addressContractMiddle = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.addressMultiCallMiddle);
const contractConstructorArguments = [addressContractMiddle];
console.log(`Arguments for the contract constructor: ${JSON.stringify(contractConstructorArguments)}`);
const deployedContract = await deployer.deploy(artifact, contractConstructorArguments);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { promises as fs } from "fs";

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

Expand All @@ -11,15 +11,14 @@ export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Running deploy script for the contract`);

const helper = new Helper();
const playbookRoot = "src/playbook/";
const wallet = await getWallet(hre);

// Create deployer object and load the artifact of the contract we want to deploy.
const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("Middle");

// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
const addressContractRoot = await helper.getStringFromFile(playbookRoot + Buffer.addressMultiCallRoot);
const addressContractRoot = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.addressMultiCallRoot);
const contractConstructorArguments = [addressContractRoot];
console.log(`Arguments for the contract constructor: ${JSON.stringify(contractConstructorArguments)}`);
const deployedContract = await deployer.deploy(artifact, contractConstructorArguments);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { promises as fs } from "fs";

import { Buffer } from "../../entities";
import { Buffer } from "../../constants";
import getWallet from "../utils/getWallet";

import type { HardhatRuntimeEnvironment } from "hardhat/types";
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/src/playbook/deploy/nftToL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { promises as fs } from "fs";
import { ethers } from "hardhat";
import * as hardhatConfig from "hardhat";

import { Buffer, Wallets } from "../../entities";
import { Buffer, Wallets } from "../../constants";

import type { HardhatRuntimeEnvironment } from "hardhat/types";

Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/src/playbook/deploy/nftToL2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { promises as fs } from "fs";

import { Buffer, Wallets } from "../../entities";
import { Buffer, Wallets } from "../../constants";
import displayVerificationInfo from "../utils/displayVerificationInfo";
import getWallet from "../utils/getWallet";

Expand Down
6 changes: 3 additions & 3 deletions packages/integration-tests/src/playbook/deploy/use-greeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { promises as fs } from "fs";
import { Provider, Wallet } from "zksync-web3";

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

import type { HardhatRuntimeEnvironment } from "hardhat/types";
Expand All @@ -14,7 +14,7 @@ export default async function (hre: HardhatRuntimeEnvironment) {
const helper = new Helper();
let contract: any; // eslint-disable-line

const greeterContractAddress = await helper.getStringFromFile(bufferRoute + Buffer.greeterL2);
const greeterContractAddress = await helper.readFile(bufferRoute + Buffer.greeterL2);

const provider = new Provider(localConfig.L2Network);
const wallet = new Wallet(Wallets.richWalletPrivateKey, provider);
Expand Down
Loading

0 comments on commit 9ff2fd0

Please sign in to comment.