From 155b91252fc52aa618c6e7bc0bd92a6c57f998a5 Mon Sep 17 00:00:00 2001 From: Jan Nanista Date: Tue, 12 Dec 2023 15:39:11 -0800 Subject: [PATCH] chore: Simplify the exposed network setup --- README.md | 14 ++++++++++++-- docker-compose.yaml | 12 ++++++++++++ package.json | 2 ++ .../hardhat.config.ts | 18 ++++++++++-------- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1245d1a1a..807faf08c 100644 --- a/README.md +++ b/README.md @@ -79,10 +79,20 @@ This allows you to monitor logs coming from e.g. the `hardhat` nodes It is possible to expose the test networks defined in `docker-compose.yaml` on your host machine. To do this, you can run: ```bash -docker compose -f docker-compose.yaml -f docker-compose.local.yaml up network-britney network-vengaboys +yarn start ``` -You can then adjust your `hardhat.config.ts` to point to `http://localhost:{10001,10002}` for access to `britney`/`vengaboys` networks. You will need to use the `MNEMONIC` defined in `docker-compose.templates.yaml` if you require funded accounts. +You will need to use the `MNEMONIC` defined in `docker-compose.templates.yaml` if you require funded accounts: + +```bash +export MNEMONIC='test test test test test test test test test test test junk' +``` + +To stop the network containers, just run: + +```bash +yarn stop +``` **Don't forget that the state of the local networks disappears after they are stopped and any deployment files created in one session will be invalid in the next one.** diff --git a/docker-compose.yaml b/docker-compose.yaml index 17f414e8a..71d121997 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -41,6 +41,18 @@ services: condition: service_healthy logging: driver: none + # The default containerized setup will specify the network URLs + # for the internal networks + # + # This works in conjunction with hardhat configs in the test projects. + # + # If these environment variables are not specified, the exposed networks are used + # that need to be started using docker compose up: + # + # docker compose -f docker-compose.yaml -f docker-compose.local.yaml up network-britney network-vengaboys + environment: + - NETWORK_URL_BRITNEY=http://network-britney:8545 + - NETWORK_URL_VENGABOYS=http://network-vengaboys:8545 volumes: - ./node_modules/.cache/turbo:/app/node_modules/.cache/turbo - ./packages:/app/packages diff --git a/package.json b/package.json index 21053d8e5..f64072edd 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ "dev": "npx turbo run dev", "lint": "npx turbo run lint", "prepare": "husky install", + "start": "docker compose -f docker-compose.yaml -f docker-compose.local.yaml up network-britney network-vengaboys", + "stop": "docker compose down", "test": "docker compose run --rm $DOCKER_COMPOSE_RUN_TESTS_ARGS tests" }, "lint-staged": { diff --git a/packages/ua-utils-evm-hardhat-test/hardhat.config.ts b/packages/ua-utils-evm-hardhat-test/hardhat.config.ts index 17648ddf5..689ef45ce 100644 --- a/packages/ua-utils-evm-hardhat-test/hardhat.config.ts +++ b/packages/ua-utils-evm-hardhat-test/hardhat.config.ts @@ -22,24 +22,26 @@ const config: HardhatUserConfig = { networks: { vengaboys: { eid: EndpointId.ETHEREUM_MAINNET, - url: 'http://network-vengaboys:8545', - // For exposed networks + // Containerized setup defines these environment variables + // to point the networks to the internal ones // - // See root README.md for information on how to use exposed networks + // If these are not specified, exposed networks are used // - // url: 'http://localhost:10001', + // See root README.md for usage with exposed network + url: process.env.NETWORK_URL_VENGABOYS ?? 'http://localhost:10001', accounts: { mnemonic: MNEMONIC, }, }, britney: { eid: EndpointId.AVALANCHE_MAINNET, - url: 'http://network-britney:8545', - // For exposed networks + // Containerized setup defines these environment variables + // to point the networks to the internal ones // - // See root README.md for information on how to use exposed networks + // If these are not specified, exposed networks are used // - // url: 'http://localhost:10002', + // See root README.md for usage with exposed network + url: process.env.NETWORK_URL_BRITNEY ?? 'http://localhost:10002', accounts: { mnemonic: MNEMONIC, },