From aeb2cfc5182b21dd52d4f414ba02808ebafed8e9 Mon Sep 17 00:00:00 2001 From: Kristin Kirkov Date: Mon, 5 Aug 2024 16:01:03 +0300 Subject: [PATCH] refactor(env): Remove `getRootDir` func and use `rootDir` everywhere --- .../cosmos/verifier/typescript/verifier-make-update.ts | 3 +-- libs/typescript/cosmos-utils/cosmos-utils.ts | 3 +-- libs/typescript/ts-utils/common-utils.ts | 10 ++-------- .../test-nim-light-client-in-cosmos.ts | 6 +----- .../cosmosLightClient/test-verifier-in-cosmos-relay.ts | 4 +--- tests/eosLightClient/test-verifier-in-EOS-relay.ts | 3 +-- tests/eosLightClient/test-verifier-in-EOS.ts | 3 +-- tests/helpers/helpers.ts | 3 +-- tests/verify_proof/verify_given_proof_test.ts | 4 +--- 9 files changed, 10 insertions(+), 29 deletions(-) diff --git a/contracts/cosmos/verifier/typescript/verifier-make-update.ts b/contracts/cosmos/verifier/typescript/verifier-make-update.ts index 779f314d8..16f156bc9 100644 --- a/contracts/cosmos/verifier/typescript/verifier-make-update.ts +++ b/contracts/cosmos/verifier/typescript/verifier-make-update.ts @@ -3,7 +3,7 @@ import { exec as exec_ } from 'node:child_process'; import { calculateFee, GasPrice } from '@cosmjs/stargate'; import { CosmosClientWithWallet } from '@dendreth/utils/cosmos-utils/cosmos-utils'; -import { getRootDir } from '@dendreth/utils/ts-utils/common-utils'; +import { rootDir } from '@dendreth/utils/ts-utils/common-utils'; const exec = promisify(exec_); @@ -14,7 +14,6 @@ export async function updateVerifierContract( updateFile: string, target: string, ) { - const rootDir = await getRootDir(); const contractDir = rootDir + `/contracts/cosmos/verifier/` + target; const pathToVerifyUtils = diff --git a/libs/typescript/cosmos-utils/cosmos-utils.ts b/libs/typescript/cosmos-utils/cosmos-utils.ts index 6dc688d7d..6fa2d076c 100644 --- a/libs/typescript/cosmos-utils/cosmos-utils.ts +++ b/libs/typescript/cosmos-utils/cosmos-utils.ts @@ -1,10 +1,9 @@ import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'; import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; import { GasPrice } from '@cosmjs/stargate'; -import { getRootDir } from '../ts-utils/common-utils'; +import { rootDir } from '../ts-utils/common-utils'; export async function getCosmosContractArtifacts(contract: string) { - const rootDir = await getRootDir(); var contractDir; if (contract == 'light-client') { contractDir = `${rootDir}/contracts/cosmos/${contract}`; diff --git a/libs/typescript/ts-utils/common-utils.ts b/libs/typescript/ts-utils/common-utils.ts index 4f07cff07..1b7d4880e 100644 --- a/libs/typescript/ts-utils/common-utils.ts +++ b/libs/typescript/ts-utils/common-utils.ts @@ -6,6 +6,8 @@ import { assert } from 'console'; const exec = promisify(exec_); +export const rootDir = getEnvString('GIT_ROOT'); + export function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -127,13 +129,6 @@ export function appendJsonFile(filePath: string, data: any) { fs.writeFileSync(filePath, JSON.stringify(fileData, null, 2)); } -export async function getRootDir() { - return (await exec('git rev-parse --show-toplevel')).stdout.replace( - /\s/g, - '', - ); -} - export function assertNotNull( value: T | null | undefined, errorMessage?: string, @@ -174,7 +169,6 @@ export function getSecretEnvString(varName: string) { return ''; } else { let path = process.env[varName]; - const rootDir = getEnvString('GIT_ROOT'); return fs.readFileSync(rootDir + path, 'ascii').trim(); } } diff --git a/tests/cosmosLightClient/test-nim-light-client-in-cosmos.ts b/tests/cosmosLightClient/test-nim-light-client-in-cosmos.ts index eaa486018..ada88764b 100644 --- a/tests/cosmosLightClient/test-nim-light-client-in-cosmos.ts +++ b/tests/cosmosLightClient/test-nim-light-client-in-cosmos.ts @@ -15,7 +15,7 @@ import { compileNimFileToWasm } from '@dendreth/utils/ts-utils/compile-nim-to-wa import { byteArrayToNumber, appendJsonFile, - getRootDir, + rootDir, } from '@dendreth/utils/ts-utils/common-utils'; import { setUpCosmosTestnet, @@ -25,8 +25,6 @@ import { gasUsed } from '../helpers/helpers'; const exec = promisify(exec_); -let rootDir; - describe('Light Client In Cosmos', () => { let gasArrayLightClient: gasUsed[] = []; let client: SigningCosmWasmClient; @@ -42,8 +40,6 @@ describe('Light Client In Cosmos', () => { const gasUsageFile = 'tests/cosmosLightClient/gasLightClient.json'; beforeAll(async () => { - rootDir = await getRootDir(); - let contractDirLightClient = rootDir + `/contracts/cosmos/light-client`; let nimFilePathLightClient = contractDirLightClient + `/lib/nim/light_client_cosmos_wrapper.nim`; diff --git a/tests/cosmosLightClient/test-verifier-in-cosmos-relay.ts b/tests/cosmosLightClient/test-verifier-in-cosmos-relay.ts index 62cbe2330..22f2551ff 100644 --- a/tests/cosmosLightClient/test-verifier-in-cosmos-relay.ts +++ b/tests/cosmosLightClient/test-verifier-in-cosmos-relay.ts @@ -12,7 +12,7 @@ import { } from '@dendreth/utils/cosmos-utils/testnet-setup'; import { CosmosContract } from '@dendreth/relay/implementations/cosmos-contract'; import { bytesToHex } from '@dendreth/utils/ts-utils/bls'; -import { getRootDir } from '@dendreth/utils/ts-utils/common-utils'; +import { rootDir } from '@dendreth/utils/ts-utils/common-utils'; import { compileContractMain } from '../../contracts/cosmos/verifier/typescript/verifier-compile-contract-and-tools'; import { @@ -40,8 +40,6 @@ describe('Light Client Verifier In Cosmos', () => { 'economy stock theory fatal elder harbor betray wasp final emotion task crumble siren bottom lizard educate guess current outdoor pair theory focus wife stone'; beforeAll(async () => { - const rootDir = await getRootDir(); - contractDirVerifier = rootDir + `/contracts/cosmos/verifier/verifier-bncurve`; parseDataTool = `${contractDirVerifier}/nimcache/verifier_parse_data`; diff --git a/tests/eosLightClient/test-verifier-in-EOS-relay.ts b/tests/eosLightClient/test-verifier-in-EOS-relay.ts index 11949adda..28c1663c5 100644 --- a/tests/eosLightClient/test-verifier-in-EOS-relay.ts +++ b/tests/eosLightClient/test-verifier-in-EOS-relay.ts @@ -8,7 +8,7 @@ import { compileVerifierParseDataTool, replaceInTextProof, } from '../helpers/helpers'; -import { getRootDir, sleep } from '@dendreth/utils/ts-utils/common-utils'; +import { rootDir, sleep } from '@dendreth/utils/ts-utils/common-utils'; import { EOSContract } from '@dendreth/relay/implementations/eos-contract'; import { bytesToHex } from '@dendreth/utils/ts-utils/bls'; @@ -34,7 +34,6 @@ describe('Verifier in EOS', () => { const defaultDomain = '0x07000000628941ef21d1fe8c7134720add10bb91e3b02c007e0046d2472c6695'; beforeAll(async () => { - const rootDir = await getRootDir(); parseDataTool = await compileVerifierParseDataTool( 'eos', 'verifier', diff --git a/tests/eosLightClient/test-verifier-in-EOS.ts b/tests/eosLightClient/test-verifier-in-EOS.ts index 92feb8b78..812b90e15 100644 --- a/tests/eosLightClient/test-verifier-in-EOS.ts +++ b/tests/eosLightClient/test-verifier-in-EOS.ts @@ -8,7 +8,7 @@ import { compileVerifierParseDataTool, replaceInTextProof, } from '../helpers/helpers'; -import { getRootDir, sleep } from '@dendreth/utils/ts-utils/common-utils'; +import { rootDir, sleep } from '@dendreth/utils/ts-utils/common-utils'; import { getDataFromPrintHeaderResult } from '@dendreth/utils/cosmos-utils/cosmos-utils'; const exec = promisify(exec_); @@ -27,7 +27,6 @@ describe('Verifier in EOS', () => { const defaultDomain = '0x07000000628941ef21d1fe8c7134720add10bb91e3b02c007e0046d2472c6695'; beforeAll(async () => { - const rootDir = await getRootDir(); parseDataTool = await compileVerifierParseDataTool( 'eos', 'verifier', diff --git a/tests/helpers/helpers.ts b/tests/helpers/helpers.ts index f8480ce28..4819cab39 100644 --- a/tests/helpers/helpers.ts +++ b/tests/helpers/helpers.ts @@ -1,6 +1,6 @@ import { promisify } from 'node:util'; import { exec as exec_ } from 'node:child_process'; -import { getRootDir } from '@dendreth/utils/ts-utils/common-utils'; +import { rootDir } from '@dendreth/utils/ts-utils/common-utils'; const exec = promisify(exec_); @@ -26,7 +26,6 @@ async function getDirs( protocol: 'cosmos' | 'eos', contract: 'verifier' | 'light-client', ) { - const rootDir = await getRootDir(); const contractDir = `${rootDir}/contracts/${protocol}/${contract}`; return { rootDir, contractDir }; } diff --git a/tests/verify_proof/verify_given_proof_test.ts b/tests/verify_proof/verify_given_proof_test.ts index 850d17450..86eaf7cb3 100644 --- a/tests/verify_proof/verify_given_proof_test.ts +++ b/tests/verify_proof/verify_given_proof_test.ts @@ -1,7 +1,7 @@ import { beforeAll, describe, expect, test } from '@jest/globals'; import { VerifyFromPaths } from '@dendreth/utils/verify-utils/verify-given-proof-ffjavascript'; -import { getRootDir } from '@dendreth/utils/ts-utils/common-utils'; +import { rootDir } from '@dendreth/utils/ts-utils/common-utils'; describe('Check verifier build on ffjavascript', () => { let keyPath: string; @@ -10,8 +10,6 @@ describe('Check verifier build on ffjavascript', () => { let updatePath: string; beforeAll(async () => { - const rootDir = await getRootDir(); - keyPath = rootDir + '/vendor/eth2-light-client-updates/prater/capella-updates-94/vk.json';