Skip to content

Commit

Permalink
test: refactoring path and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
pcheremu committed Mar 7, 2024
1 parent 0ccaf8f commit b0a38a0
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 126 deletions.
5 changes: 2 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,18 +3,17 @@ import { promises as fs } from "fs";
import { Provider, Wallet } from "zksync-web3";

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

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

export default async function (hre: HardhatRuntimeEnvironment) {
const bufferRoute = "src/playbook/";
const helper = new Helper();
let contract: any; // eslint-disable-line

const greeterContractAddress = await helper.readFile(bufferRoute + Buffer.greeterL2);
const greeterContractAddress = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.greeterL2);

const provider = new Provider(localConfig.L2Network);
const wallet = new Wallet(Wallets.richWalletPrivateKey, provider);
Expand Down
10 changes: 4 additions & 6 deletions packages/integration-tests/src/playbook/deploy/use-paymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import { promises as fs } from "fs";
import { Provider, utils, Wallet } from "zksync-web3";

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

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

export default async function (hre: HardhatRuntimeEnvironment) {
const bufferRoute = "src/playbook/";

const PAYMASTER_ADDRESS = await helper.readFile(bufferRoute + Buffer.paymaster);
const TOKEN_ADDRESS = await helper.readFile(bufferRoute + Buffer.customToken);
const EMPTY_WALLET_PRIVATE_KEY = await helper.readFile(bufferRoute + Buffer.emptyWalletPrivateKey);
const PAYMASTER_ADDRESS = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.paymaster);
const TOKEN_ADDRESS = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.customToken);
const EMPTY_WALLET_PRIVATE_KEY = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.emptyWalletPrivateKey);

const provider = new Provider(localConfig.L2Network);
const emptyWallet = new Wallet(EMPTY_WALLET_PRIVATE_KEY, provider);
Expand Down
3 changes: 1 addition & 2 deletions packages/integration-tests/tests/api/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe("API module: Account", () => {
jest.setTimeout(localConfig.standardTimeout);

const helper = new Helper();
const bufferFile = "src/playbook/";
let apiRoute: string;
let response;
const playbook = new Playbook();
Expand Down Expand Up @@ -215,7 +214,7 @@ describe("API module: Account", () => {
await helper.runRetriableTestAction(async () => {
const blocks = await request(environment.blockExplorerAPI).get("/blocks");
const blockNumber = blocks.body.items[0].number;
const nftAddress = await helper.readFile(bufferFile + Buffer.NFTtoL2);
const nftAddress = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.NFTtoL2);
apiRoute = `/api?module=account&action=tokennfttx&page=1&offset=10&sort=desc&endblock=${blockNumber}&startblock=0&contractaddress=${nftAddress}&address=${nftAddress}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand Down
33 changes: 16 additions & 17 deletions packages/integration-tests/tests/api/addresses.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { localConfig } from "../../src/config";
import { Buffer, Token, Wallets } from "../../src/constants";
import { Buffer, Path, Token, Wallets } from "../../src/constants";
import { Helper } from "../../src/helper";
import { Playbook } from "../../src/playbook/playbook";

Expand All @@ -8,7 +8,6 @@ describe("Address", () => {

const helper = new Helper();
const playbook = new Playbook();
const bufferFile = "src/playbook/";
let apiRoute: string;
let contract: string;
let token: string;
Expand All @@ -29,7 +28,7 @@ describe("Address", () => {
//@id1457
it("Verify deployed to L2 NFT via /address/{address}", async () => {
await helper.runRetriableTestAction(async () => {
token = await helper.readFile(bufferFile + Buffer.NFTtoL2);
token = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.NFTtoL2);
apiRoute = `/address/${token}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand All @@ -52,8 +51,8 @@ describe("Address", () => {
//@id1464
it("Verify the deployed Root contract via /address/{address}", async () => {
await helper.runRetriableTestAction(async () => {
contract = await helper.readFile(bufferFile + Buffer.addressMultiCallRoot);
txHash = await helper.readFile(bufferFile + Buffer.txMultiCallRoot);
contract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.addressMultiCallRoot);
txHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txMultiCallRoot);
apiRoute = `/address/${contract}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand All @@ -69,8 +68,8 @@ describe("Address", () => {
//@id1465
it("Verify the deployed Middle contract via /address/{address}", async () => {
await helper.runRetriableTestAction(async () => {
contract = await helper.readFile(bufferFile + Buffer.addressMultiCallMiddle);
txHash = await helper.readFile(bufferFile + Buffer.txMultiCallMiddle);
contract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.addressMultiCallMiddle);
txHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txMultiCallMiddle);
apiRoute = `/address/${contract}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand All @@ -86,8 +85,8 @@ describe("Address", () => {
//@id1466
it("Verify the deployed Caller contract via /address/{address}", async () => {
await helper.runRetriableTestAction(async () => {
contract = await helper.readFile(bufferFile + Buffer.addressMultiCallCaller);
txHash = await helper.readFile(bufferFile + Buffer.txMultiCallCaller);
contract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.addressMultiCallCaller);
txHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txMultiCallCaller);
apiRoute = `/address/${contract}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand All @@ -103,7 +102,7 @@ describe("Address", () => {
//@id1476
it("Verify the deployed multitransfer contract via /address/{address}", async () => {
await helper.runRetriableTestAction(async () => {
contract = await helper.readFile(bufferFile + Buffer.addressMultiTransferETH);
contract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.addressMultiTransferETH);
apiRoute = `/address/${contract}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand All @@ -116,7 +115,7 @@ describe("Address", () => {
//@id1449
it("Verify the deployed Greeter contract via /address/{address}", async () => {
await helper.runRetriableTestAction(async () => {
contract = await helper.readFile(bufferFile + Buffer.greeterL2);
contract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.greeterL2);
apiRoute = `/address/${contract}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand All @@ -135,8 +134,8 @@ describe("Address", () => {
//@id1510
it("Verify the transaction via /address/{address}/logs", async () => {
await helper.runRetriableTestAction(async () => {
contract = await helper.readFile(bufferFile + Buffer.greeterL2);
txHash = await helper.readFile(bufferFile + Buffer.executeGreeterTx);
contract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.greeterL2);
txHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.executeGreeterTx);
apiRoute = `/address/${contract}/logs`;
const decapitalizedAddress = apiRoute.slice(1).toLowerCase();
response = await helper.performBlockExplorerApiGetRequest(apiRoute);
Expand Down Expand Up @@ -176,10 +175,10 @@ describe("Address", () => {
//@id1509
it("Verify the transaction via /address/{address}/transfers", async () => {
await helper.runRetriableTestAction(async () => {
contract = await helper.readFile(bufferFile + Buffer.paymaster);
const emptyWallet = await helper.readFile(bufferFile + Buffer.emptyWalletAddress);
txHash = await helper.readFile(bufferFile + Buffer.paymasterTx);
const customTokenAddress = await helper.readFile(bufferFile + Buffer.customToken);
contract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.paymaster);
const emptyWallet = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.emptyWalletAddress);
txHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.paymasterTx);
const customTokenAddress = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.customToken);
apiRoute = `/address/${contract}/transfers`;
const decapitalizedAddress = apiRoute.slice(1).toLowerCase();
response = await helper.performBlockExplorerApiGetRequest(apiRoute);
Expand Down
11 changes: 5 additions & 6 deletions packages/integration-tests/tests/api/contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { localConfig } from "../../src/config";
import { Buffer, Wallets } from "../../src/constants";
import { Buffer, Path, Wallets } from "../../src/constants";
import { Helper } from "../../src/helper";
import { Playbook } from "../../src/playbook/playbook";

Expand All @@ -8,7 +8,6 @@ describe("API module: Contract", () => {

const helper = new Helper();
const playbook = new Playbook();
const bufferFile = "src/playbook/";
let apiRoute: string;
let paymasterContract: string;
let paymasterTx: string;
Expand All @@ -25,10 +24,10 @@ describe("API module: Contract", () => {
//@id1696
it("Verify /api?module=contract&action=getcontractcreation&contractaddresses={address1},{address2} response", async () => {
await helper.runRetriableTestAction(async () => {
paymasterContract = await helper.readFile(bufferFile + Buffer.paymaster);
paymasterTx = await helper.readFile(bufferFile + Buffer.paymasterDeployTx);
multicallCallerContract = await helper.readFile(bufferFile + Buffer.addressMultiCallCaller);
multicallCallerTx = await helper.readFile(bufferFile + Buffer.txMultiCallCaller);
paymasterContract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.paymaster);
paymasterTx = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.paymasterDeployTx);
multicallCallerContract = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.addressMultiCallCaller);
multicallCallerTx = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.txMultiCallCaller);
apiRoute = `/api?module=contract&action=getcontractcreation&contractaddresses=${paymasterContract},${multicallCallerContract}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand Down
7 changes: 3 additions & 4 deletions packages/integration-tests/tests/api/logs.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { localConfig } from "../../src/config";
import { Buffer } from "../../src/constants";
import { Buffer, Path } from "../../src/constants";
import { Helper } from "../../src/helper";
import { Playbook } from "../../src/playbook/playbook";

describe("API module: Logs", () => {
jest.setTimeout(localConfig.standardTimeout); //works unstable without timeout

const helper = new Helper();
const bufferFile = "src/playbook/";
const playbook = new Playbook();
let apiRoute: string;
let contractAddress: string;
Expand All @@ -23,8 +22,8 @@ describe("API module: Logs", () => {
//@id1808
it("Verify /api?module=logs&action=getLogs&page={page}&offset={offset}0&toBlock={toBlock}&fromBlock={fromBlock}&address={address} response", async () => {
await helper.runRetriableTestAction(async () => {
contractAddress = await helper.readFile(bufferFile + Buffer.greeterL2);
txHash = await helper.readFile(bufferFile + Buffer.executeGreeterTx);
contractAddress = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.greeterL2);
txHash = await helper.readFile(Path.absolutePathToBufferFiles, Buffer.executeGreeterTx);
apiRoute = `/api?module=logs&action=getLogs&page=1&offset=10&toBlock=10000&fromBlock=1&address=${contractAddress}`;
response = await helper.performBlockExplorerApiGetRequest(apiRoute);

Expand Down
Loading

0 comments on commit b0a38a0

Please sign in to comment.