Skip to content

Commit 982d670

Browse files
authored
chore(common): extend getRequiredEnvVar method to check empty values (#2156)
* hore(common): extend getRequiredEnvVar method to check empty values * refactor(common): implement same empty values check for the library solidity * fix(test-suite): adjust blank environment variables
1 parent 4ef47dc commit 982d670

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

gateway-contracts/tasks/utils/loadVariables.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import path from "path";
55
import { ADDRESSES_DIR, GATEWAY_ADDRESSES_ENV_FILE_NAME } from "../../hardhat.config";
66
import { pascalCaseToAddressEnvVar } from "../utils";
77

8-
// Get the required environment variable, throw an error if it's not set
9-
// We only check if the variable is set, not if it's empty
8+
// Get the required environment variable, throw an error if it's not set or empty
109
export function getRequiredEnvVar(name: string): string {
1110
if (!(name in process.env)) {
1211
throw new Error(`"${name}" env variable is not set`);
1312
}
14-
return process.env[name]!;
13+
const value = process.env[name]!;
14+
if (value.trim() === "") {
15+
throw new Error(`"${name}" env variable is set but empty`);
16+
}
17+
return value;
1518
}
1619

17-
// Get the required address from the environment variable, throw an error if it's not set
18-
// We only check if the variable is set, not if it's empty
20+
// Get the required address from the environment variable, throw an error if it's not set or empty
1921
export function getRequiredAddressEnvVar(name: string): string {
2022
const addressEnvVarName = pascalCaseToAddressEnvVar(name);
2123
return getRequiredEnvVar(addressEnvVarName);

host-contracts/tasks/utils/loadVariables.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import path from 'path';
44

55
import { ADDRESSES_DIR, HOST_ADDRESSES_ENV_FILE_NAME } from '../../hardhat.config';
66

7-
// Get the required environment variable, throw an error if it's not set
8-
// We only check if the variable is set, not if it's empty
7+
// Get the required environment variable, throw an error if it's not set or empty
98
export function getRequiredEnvVar(name: string): string {
109
if (!(name in process.env)) {
1110
throw new Error(`"${name}" env variable is not set`);
1211
}
13-
return process.env[name]!;
12+
const value = process.env[name]!;
13+
if (value.trim() === '') {
14+
throw new Error(`"${name}" env variable is set but empty`);
15+
}
16+
return value;
1417
}
1518

1619
// Load the addresses as environment variables from the env file

library-solidity/tasks/utils/loadVariables.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import path from 'path';
55
const ADDRESSES_DIR = path.resolve(__dirname, '../../fhevmTemp/addresses');
66
const HOST_ADDRESSES_ENV_FILE_NAME = '.env.host';
77

8-
// Get the required environment variable, throw an error if it's not set
9-
// We only check if the variable is set, not if it's empty
8+
// Get the required environment variable, throw an error if it's not set or empty
109
export function getRequiredEnvVar(name: string): string {
1110
if (!(name in process.env)) {
1211
throw new Error(`"${name}" env variable is not set`);
1312
}
14-
return process.env[name]!;
13+
const value = process.env[name]!;
14+
if (value.trim() === '') {
15+
throw new Error(`"${name}" env variable is set but empty`);
16+
}
17+
return value;
1518
}
1619

1720
// Load the addresses as environment variables from the env file

test-suite/fhevm/env/staging/.env.gateway-sc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ DEPLOYER_PRIVATE_KEY=0xe746bc71f6bee141a954e6a49bc9384d334e393a7ea1e70b50241cb2e
3232
# =============================================================================
3333
# PROTOCOL CONFIGURATION
3434
# =============================================================================
35-
PROTOCOL_NAME=
36-
PROTOCOL_WEBSITE=
35+
PROTOCOL_NAME="Test Protocol"
36+
PROTOCOL_WEBSITE="https://test-protocol.com"
3737

3838
# =============================================================================
3939
# KMS CONFIGURATION
@@ -55,7 +55,7 @@ NUM_KMS_NODES=1
5555
# KMS Node 1 (accounts[0] - Gateway)
5656
KMS_TX_SENDER_ADDRESS_0=0x31de9c8ac5ecd5eaceddddee531e9bad8ac9c2a5
5757
KMS_SIGNER_ADDRESS_0=0x0Ea5BA6Bdb66553ED882CDB7cc78630340e0F031
58-
KMS_NODE_IP_ADDRESS_0=
58+
KMS_NODE_IP_ADDRESS_0="127.0.0.1"
5959
KMS_NODE_STORAGE_URL_0=http://minio:9000/kms-public
6060

6161
# =============================================================================
@@ -89,8 +89,8 @@ NUM_HOST_CHAINS=1
8989
HOST_CHAIN_CHAIN_ID_0=12345
9090
HOST_CHAIN_FHEVM_EXECUTOR_ADDRESS_0=0xcCAe95fF1d11656358E782570dF0418F59fA40e1
9191
HOST_CHAIN_ACL_ADDRESS_0=0x05fD9B5EFE0a996095f42Ed7e77c390810CF660c
92-
HOST_CHAIN_NAME_0=
93-
HOST_CHAIN_WEBSITE_0=
92+
HOST_CHAIN_NAME_0="Host chain 0"
93+
HOST_CHAIN_WEBSITE_0="https://host-chain-0.com"
9494

9595
# =============================================================================
9696
# PAUSERS

0 commit comments

Comments
 (0)