Skip to content

Commit

Permalink
test: update executeScript function to exec() method
Browse files Browse the repository at this point in the history
  • Loading branch information
pcheremu committed Mar 7, 2024
1 parent d589cc0 commit aa893c0
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
30 changes: 21 additions & 9 deletions packages/integration-tests/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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";
Expand All @@ -11,7 +11,7 @@ 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,14 +22,26 @@ export class Helper {
}

async executeScript(script: string) {
const output = execSync(script, { encoding: "utf-8" });
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);
}
});
});

try {
console.log(`> Run NPM Script "${script}":\n`, output);
return output;
} catch (e) {
console.log(e);
}
// const output = execSync(script, { encoding: "utf-8" });

// try {
// console.log(`> Run NPM Script "${script}":\n`, output);
// return output;
// } catch (e) {
// console.log(e);
// }
}

async getStringFromFile(fileName: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const depositERC20 = async function (sum = "0.5", tokenAddress: string, u
const l2TokenAddress = await syncProvider.l2TokenAddress(tokenAddress);
console.log("L2 token address ", l2TokenAddress);
const txHash = await deposit.waitFinalize();
await helper.txHashLogger(Logger.deposit, txHash.transactionHash, "ERC20 token");
await helper.logTransaction(Logger.deposit, txHash.transactionHash, "ERC20 token");
await fs.writeFile(bufferAddressL2DepositedFile, l2TokenAddress);
await fs.writeFile(bufferTxErc20DepositFile, txHash.transactionHash);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const depositEth = async function (sum = "0.000009") {
});
await deposit.wait(1);
const txHash = await deposit.waitFinalize();
await helper.txHashLogger(Logger.deposit, txHash.transactionHash, "ETH");
await helper.logTransaction(Logger.deposit, txHash.transactionHash, "ETH");
await fs.writeFile(bufferFile, txHash.transactionHash);

return txHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const transferERC20 = async function (sum: string, tokenAddress: string,
});

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

return txHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const transferEth = async function (sum = "0.000009", address: string = W
});

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

return txHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const transferFailedState = async function (tokenAddress: string, tokenNa
});

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

return txHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 helper.logTransaction(Logger.withdraw, txHash, "Custom token");
await fs.writeFile(bufferFile, txHash);

return txHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const withdrawERC20toOtherAddress = async function (tokenAddress: string,

console.log(`Your balance is ${balanceAfter.toString()}`);

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

return txHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const withdrawETH = async function (sum = "0.000009") {
const txHash = withdrawL2.hash;

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

return txHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const withdrawETHtoOtherAddress = async function (sum = "0.000009") {
const txHash = withdrawL2.hash;

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

return txHash;
Expand Down

0 comments on commit aa893c0

Please sign in to comment.