From 53d209bbae941a7a3f9023cf85735bcf24936ced Mon Sep 17 00:00:00 2001 From: undercover-cactus Date: Mon, 24 Nov 2025 12:07:36 +0100 Subject: [PATCH] test: only inject contracts in e2e tests if INJECT_CONTRACTS env is 'true' (#315) In this PR we add an environment variable `INJECT_CONTRACTS`. This environment variable specify if the contracts should be injected in the e2e tests. By default it is false. The environment variable is set to `true` in the CI job that run the e2e tests. We are using a environment variable because `bun test` doesn't allow for passing extra arguments. A note about the new variable has been added in the documentation to inform about the new behavior. --------- Co-authored-by: Gonza Montiel --- .github/workflows/task-e2e.yml | 1 + README.md | 2 ++ test/README.md | 1 + test/docs/E2E_FRAMEWORK_OVERVIEW.md | 3 +++ test/launcher/network/index.ts | 35 ++++++++++++++++++++++++----- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.github/workflows/task-e2e.yml b/.github/workflows/task-e2e.yml index a53224c9..92e5bcc6 100644 --- a/.github/workflows/task-e2e.yml +++ b/.github/workflows/task-e2e.yml @@ -33,6 +33,7 @@ env: KURTOSIS_CORE_IMAGE: ghcr.io/stiiifff/kurtosis/kurtosis-core KURTOSIS_ENGINE_IMAGE: ghcr.io/stiiifff/kurtosis/kurtosis-engine KURTOSIS_VERSION: 1.11.1 + INJECT_CONTRACTS: true jobs: kurtosis: diff --git a/README.md b/README.md index 953f3b33..264cb027 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,8 @@ bun test:e2e # Run all integration tests bun test:e2e:parallel # Run with limited concurrency ``` +NOTES: Adding the environment variable `INJECT_CONTRACTS=true` will inject the contracts when starting the tests to speed up setup. + ### Development Workflows **Smart Contract Development**: diff --git a/test/README.md b/test/README.md index 982da22c..e401093d 100644 --- a/test/README.md +++ b/test/README.md @@ -55,6 +55,7 @@ bun test:e2e:parallel bun test suites/some-test.test.ts ``` +NOTES: Adding the environment variable `INJECT_CONTRACTS=true` will inject the contracts when starting the tests to speed up setup. ## Generating Ethereum state diff --git a/test/docs/E2E_FRAMEWORK_OVERVIEW.md b/test/docs/E2E_FRAMEWORK_OVERVIEW.md index eae34074..0f63105b 100644 --- a/test/docs/E2E_FRAMEWORK_OVERVIEW.md +++ b/test/docs/E2E_FRAMEWORK_OVERVIEW.md @@ -138,6 +138,9 @@ bun fmt:fix bun typecheck ``` +NOTES: Adding the environment variable `INJECT_CONTRACTS=true` will inject the contracts when starting the tests to speed up setup. + + ## Network Configuration ### Default Test Network diff --git a/test/launcher/network/index.ts b/test/launcher/network/index.ts index 89073a8a..18e8c3ea 100644 --- a/test/launcher/network/index.ts +++ b/test/launcher/network/index.ts @@ -1,7 +1,8 @@ import { $ } from "bun"; -import { getContainersMatchingImage, logger } from "utils"; +import { getContainersMatchingImage, getPortFromKurtosis, logger } from "utils"; import { ParameterCollection } from "utils/parameters"; import { updateParameters } from "../../scripts/deploy-contracts"; +import { deployContracts } from "../contracts"; import { launchLocalDataHavenSolochain } from "../datahaven"; import { getRunningKurtosisEnclaves, launchKurtosisNetwork } from "../kurtosis"; import { setDataHavenParameters } from "../parameters"; @@ -145,6 +146,12 @@ export const launchNetwork = async ( const networkId = options.networkId; const launchedNetwork = new LaunchedNetwork(); launchedNetwork.networkName = networkId; + let injectContracts = false; + + // Using env to check + if (process.env.INJECT_CONTRACTS === "true") { + injectContracts = true; + } let cleanup: (() => Promise) | undefined; @@ -187,13 +194,29 @@ export const launchNetwork = async ( blockscout: options.blockscout ?? false, slotTime: options.slotTime || 2, kurtosisNetworkArgs: options.kurtosisNetworkArgs, - injectContracts: true // Forcing it to be true to run e2e tests + injectContracts }, launchedNetwork ); // 3. Deploy contracts - logger.info("📄 Smart contracts injected."); + if (injectContracts) { + logger.info("📄 Smart contracts injected."); + } else { + logger.info("📄 Deploying smart contracts..."); + let blockscoutBackendUrl: string | undefined; + if (options.blockscout) { + const blockscoutPort = await getPortFromKurtosis("blockscout", "http", kurtosisEnclaveName); + blockscoutBackendUrl = `http://127.0.0.1:${blockscoutPort}`; + } + + await deployContracts({ + rpcUrl: launchedNetwork.elRpcUrl, + verified: options.verified ?? false, + blockscoutBackendUrl, + parameterCollection + }); + } if (!launchedNetwork.elRpcUrl) { throw new Error("Ethereum RPC URL not available"); @@ -211,8 +234,10 @@ export const launchNetwork = async ( rpcUrl: launchedNetwork.elRpcUrl }); - // We are injecting contracts but we still need the addresses - await updateParameters(parameterCollection); + if (injectContracts) { + // We are injecting contracts but we still need the addresses + await updateParameters(parameterCollection); + } // 6. Set DataHaven runtime parameters logger.info("⚙️ Setting DataHaven parameters...");