Skip to content

Commit e6b89e2

Browse files
committed
fix: add dotenv and zod to package.json and package-lock.json; create env.ts for environment variable validation
1 parent 93167f9 commit e6b89e2

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

config/env.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'dotenv/config';
2+
import { z } from 'zod';
3+
4+
const envSchema = z.object({
5+
NETWORK_NAME: z.string().min(1, 'NETWORK_NAME is required').default('bellecour'),
6+
7+
GRAPHNODE_URL: z
8+
.string()
9+
.url('GRAPHNODE_URL must be a valid URL')
10+
.default('http://localhost:8020'),
11+
12+
IPFS_URL: z.string().url('IPFS_URL must be a valid URL').default('http://localhost:5001'),
13+
14+
VERSION_LABEL: z.string().min(1, 'VERSION_LABEL is required').default('bellecour/poco-v5'),
15+
});
16+
17+
export const env = envSchema.parse(process.env);

package-lock.json

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build": "rm -rf generated && rm -rf build && npm run generate:typechain && graph codegen && graph build --network ${NETWORK_NAME:-bellecour}",
1111
"test": "npm run test:unit && npm run test:e2e",
1212
"test:unit": "graph test",
13-
"test:e2e": "NETWORK_NAME=${NETWORK_NAME:-bellecour} mocha",
13+
"test:e2e": "mocha",
1414
"coverage": "graph test -- -c",
1515
"create": "graph create ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020}",
1616
"deploy": "graph deploy ${NETWORK_NAME:-bellecour}/poco --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --version-label ${VERSION_LABEL:-bellecour/poco-v5}",
@@ -39,6 +39,7 @@
3939
"@graphprotocol/graph-ts": "^0.38.0",
4040
"@typechain/ethers-v6": "^0.5.1",
4141
"@types/mocha": "^10.0.9",
42+
"dotenv": "^16.5.0",
4243
"ethers": "^6.13.5",
4344
"husky": "^9.1.6",
4445
"lint-staged": "^15.2.10",
@@ -48,7 +49,8 @@
4849
"prettier-plugin-organize-imports": "^4.1.0",
4950
"testcontainers": "^10.13.2",
5051
"ts-node": "^10.9.2",
51-
"tsx": "^4.19.3"
52+
"tsx": "^4.19.3",
53+
"zod": "^3.24.3"
5254
},
5355
"dependencies": {
5456
"@iexec/poco": "^5.5.0",

tests/e2e/integration.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { InMemoryCache } from '@apollo/client/cache';
22
import { ApolloClient, gql } from '@apollo/client/core';
33
import { equal } from 'assert';
44
import { JsonRpcProvider, Wallet, ZeroHash } from 'ethers';
5+
import { env } from '../../config/env';
56
import { AppRegistry__factory, IexecInterfaceToken__factory } from '../../generated/typechain';
67
import config from '../../networks.json' with { type: 'json' };
78

8-
const APIURL = `http://localhost:8000/subgraphs/name/${process.env.NETWORK_NAME}/poco`;
9+
const APIURL = `http://localhost:8000/subgraphs/name/${env.NETWORK_NAME}/poco`;
910
const client = new ApolloClient({
1011
uri: APIURL,
1112
cache: new InMemoryCache(),
1213
});
13-
const networkName = process.env.NETWORK_NAME!;
14+
const networkName = env.NETWORK_NAME!;
1415
const iexecProxyAddress = (config as any)[networkName].ERC1538.address;
1516

1617
describe('Integration tests', () => {

0 commit comments

Comments
 (0)