From aa893c030ed20651f366f1b895a1f7277676b952 Mon Sep 17 00:00:00 2001 From: pcheremu Date: Thu, 7 Mar 2024 12:35:36 +0100 Subject: [PATCH] test: update executeScript function to exec() method --- packages/integration-tests/src/helper.ts | 30 +++++++++++++------ .../scenarios/deposit/depositERC20.ts | 2 +- .../playbook/scenarios/deposit/depositETH.ts | 2 +- .../scenarios/transfers/transferERC20.ts | 2 +- .../scenarios/transfers/transferETH.ts | 2 +- .../transfers/transferFailedState.ts | 2 +- .../scenarios/withdrawal/withdrawERC20.ts | 2 +- .../withdrawal/withdrawERC20toOtherAddress.ts | 2 +- .../scenarios/withdrawal/withdrawETH.ts | 2 +- .../withdrawal/withdrawETHtoOtherAddress.ts | 2 +- 10 files changed, 30 insertions(+), 18 deletions(-) diff --git a/packages/integration-tests/src/helper.ts b/packages/integration-tests/src/helper.ts index 6342a76f86..d18ad051ff 100644 --- a/packages/integration-tests/src/helper.ts +++ b/packages/integration-tests/src/helper.ts @@ -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"; @@ -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) { @@ -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) { diff --git a/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts b/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts index ab36021949..98d1f1701d 100644 --- a/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts +++ b/packages/integration-tests/src/playbook/scenarios/deposit/depositERC20.ts @@ -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); diff --git a/packages/integration-tests/src/playbook/scenarios/deposit/depositETH.ts b/packages/integration-tests/src/playbook/scenarios/deposit/depositETH.ts index c5d966adc7..98d99f8aa1 100644 --- a/packages/integration-tests/src/playbook/scenarios/deposit/depositETH.ts +++ b/packages/integration-tests/src/playbook/scenarios/deposit/depositETH.ts @@ -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; diff --git a/packages/integration-tests/src/playbook/scenarios/transfers/transferERC20.ts b/packages/integration-tests/src/playbook/scenarios/transfers/transferERC20.ts index 8b8e524694..3ab4e41e36 100644 --- a/packages/integration-tests/src/playbook/scenarios/transfers/transferERC20.ts +++ b/packages/integration-tests/src/playbook/scenarios/transfers/transferERC20.ts @@ -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; diff --git a/packages/integration-tests/src/playbook/scenarios/transfers/transferETH.ts b/packages/integration-tests/src/playbook/scenarios/transfers/transferETH.ts index 6367b87a3a..e616a84c44 100644 --- a/packages/integration-tests/src/playbook/scenarios/transfers/transferETH.ts +++ b/packages/integration-tests/src/playbook/scenarios/transfers/transferETH.ts @@ -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; diff --git a/packages/integration-tests/src/playbook/scenarios/transfers/transferFailedState.ts b/packages/integration-tests/src/playbook/scenarios/transfers/transferFailedState.ts index 29ae716d39..6a90a2241e 100644 --- a/packages/integration-tests/src/playbook/scenarios/transfers/transferFailedState.ts +++ b/packages/integration-tests/src/playbook/scenarios/transfers/transferFailedState.ts @@ -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; diff --git a/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawERC20.ts b/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawERC20.ts index ecd33fe152..08be5788a9 100644 --- a/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawERC20.ts +++ b/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawERC20.ts @@ -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; diff --git a/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawERC20toOtherAddress.ts b/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawERC20toOtherAddress.ts index 66de2badc9..9d93e74dc1 100644 --- a/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawERC20toOtherAddress.ts +++ b/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawERC20toOtherAddress.ts @@ -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; diff --git a/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawETH.ts b/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawETH.ts index 4bd76049ab..d2faa8ffab 100644 --- a/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawETH.ts +++ b/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawETH.ts @@ -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; diff --git a/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawETHtoOtherAddress.ts b/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawETHtoOtherAddress.ts index f4ed657ae0..847ebafd87 100644 --- a/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawETHtoOtherAddress.ts +++ b/packages/integration-tests/src/playbook/scenarios/withdrawal/withdrawETHtoOtherAddress.ts @@ -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;