mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 09:50:01 +00:00
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 <gonzamontiel@users.noreply.github.com>
This commit is contained in:
parent
ba1cc63cb0
commit
53d209bbae
5 changed files with 37 additions and 5 deletions
1
.github/workflows/task-e2e.yml
vendored
1
.github/workflows/task-e2e.yml
vendored
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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**:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<void>) | 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...");
|
||||
|
|
|
|||
Loading…
Reference in a new issue