Skip to content

Commit

Permalink
refactor(env): Remove getRootDir func and use rootDir everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
kkirkov committed Aug 6, 2024
1 parent b99fe84 commit efaabed
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 29 deletions.
3 changes: 1 addition & 2 deletions contracts/cosmos/verifier/typescript/verifier-make-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

Expand All @@ -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 =
Expand Down
3 changes: 1 addition & 2 deletions libs/typescript/cosmos-utils/cosmos-utils.ts
Original file line number Diff line number Diff line change
@@ -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}`;
Expand Down
10 changes: 2 additions & 8 deletions libs/typescript/ts-utils/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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<T>(
value: T | null | undefined,
errorMessage?: string,
Expand Down Expand Up @@ -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();
}
}
Expand Down
6 changes: 1 addition & 5 deletions tests/cosmosLightClient/test-nim-light-client-in-cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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`;
Expand Down
4 changes: 1 addition & 3 deletions tests/cosmosLightClient/test-verifier-in-cosmos-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`;
Expand Down
3 changes: 1 addition & 2 deletions tests/eosLightClient/test-verifier-in-EOS-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -34,7 +34,6 @@ describe('Verifier in EOS', () => {
const defaultDomain =
'0x07000000628941ef21d1fe8c7134720add10bb91e3b02c007e0046d2472c6695';
beforeAll(async () => {
const rootDir = await getRootDir();
parseDataTool = await compileVerifierParseDataTool(
'eos',
'verifier',
Expand Down
3 changes: 1 addition & 2 deletions tests/eosLightClient/test-verifier-in-EOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -27,7 +27,6 @@ describe('Verifier in EOS', () => {
const defaultDomain =
'0x07000000628941ef21d1fe8c7134720add10bb91e3b02c007e0046d2472c6695';
beforeAll(async () => {
const rootDir = await getRootDir();
parseDataTool = await compileVerifierParseDataTool(
'eos',
'verifier',
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -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_);

Expand All @@ -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 };
}
Expand Down
4 changes: 1 addition & 3 deletions tests/verify_proof/verify_given_proof_test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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';
Expand Down

0 comments on commit efaabed

Please sign in to comment.