Skip to content

Commit 86584f6

Browse files
committed
test: centralize test config defaults using constants
- Replace hardcoded values with imports from constants module - Use SUBGRAPH_ID constant to match local-network/.env SUBGRAPH value - Consolidate import statements for better organization - Remove duplicate env var lookup in test_subgraph_deployment - Maintain env variable override functionality while standardizing defaults
1 parent d8dfcf4 commit 86584f6

File tree

2 files changed

+38
-50
lines changed

2 files changed

+38
-50
lines changed

integration-tests/src/constants.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ pub const TAP_AGENT_METRICS_URL: &str = "http://localhost:7300/metrics";
1414
// Wallet
1515
// - Account 0 used by: EBO, admin actions (deploy contracts, transfer ETH/GRT), gateway sender for PaymentsEscrow
1616
// - Account 1 used by: Gateway signer for PaymentsEscrow
17-
// pub const MNEMONIC: &str = "test test test test test test test test test test test junk";
18-
// pub const ACCOUNT0_ADDRESS: &str = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
17+
pub const MNEMONIC: &str = "test test test test test test test test test test test junk";
18+
pub const ACCOUNT0_ADDRESS: &str = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
1919
pub const ACCOUNT0_SECRET: &str =
2020
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
21-
// pub const ACCOUNT1_ADDRESS: &str = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
22-
// pub const ACCOUNT1_SECRET: &str =
23-
// "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
21+
pub const ACCOUNT1_ADDRESS: &str = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
22+
pub const ACCOUNT1_SECRET: &str =
23+
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d";
2424

2525
// The deployed gateway and indexer
2626
// use this verifier contract
@@ -36,7 +36,9 @@ pub const TAP_VERIFIER_CONTRACT: &str = "0xC9a43158891282A2B1475592D5719c001986A
3636
pub const GRAPH_TALLY_COLLECTOR_CONTRACT: &str = "0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07";
3737
pub const CHAIN_ID: u64 = 1337;
3838

39-
pub const SUBGRAPH_ID: &str = "Qmc2CbqucMvaS4GFvt2QUZWvRwSZ3K5ipeGvbC6UUBf616";
39+
// pub const SUBGRAPH_ID: &str = "Qmc2CbqucMvaS4GFvt2QUZWvRwSZ3K5ipeGvbC6UUBf616";
40+
// This is in the SUBGRAPH constant in local-network/.env
41+
pub const SUBGRAPH_ID: &str = "BFr2mx7FgkJ36Y6pE5BiXs1KmNUmVDCnL82KUSdcLW1g";
4042
pub const TEST_SUBGRAPH_DEPLOYMENT: &str = "QmRcucmbxAXLaAZkkCR8Bdj1X7QGPLjfRmQ5H6tFhGqiHX";
4143

4244
pub const GRAPH_URL: &str = "http://localhost:8000/subgraphs/name/graph-network";

integration-tests/src/test_config.rs

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
// Copyright 2025-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::env;
5-
use std::fs;
6-
use std::path::Path;
4+
use std::{env, fs, path::Path};
75

86
use anyhow::Result;
97
use serde::Deserialize;
108

11-
use crate::constants::TEST_SUBGRAPH_DEPLOYMENT;
12-
use crate::env_loader::load_integration_env;
9+
use crate::{
10+
constants::{
11+
ACCOUNT0_ADDRESS, ACCOUNT0_SECRET, ACCOUNT1_ADDRESS, ACCOUNT1_SECRET, CHAIN_ID,
12+
GATEWAY_API_KEY, GATEWAY_URL, GRAPH_TALLY_COLLECTOR_CONTRACT, GRAPH_URL, INDEXER_URL,
13+
SUBGRAPH_ID, TAP_AGENT_METRICS_URL, TAP_VERIFIER_CONTRACT, TEST_DATA_SERVICE,
14+
TEST_SUBGRAPH_DEPLOYMENT,
15+
},
16+
env_loader::load_integration_env,
17+
};
1318

1419
#[derive(Clone)]
1520
pub struct TestConfig {
@@ -96,43 +101,25 @@ impl TestConfig {
96101
let get_s = |k: &str, d: &str| -> String { env::var(k).unwrap_or_else(|_| d.to_string()) };
97102

98103
// Derive URLs from ports when present, allow explicit URL overrides
99-
let indexer_url = env::var("INDEXER_URL")
100-
.unwrap_or_else(|_| format!("http://localhost:{}", get_u16("INDEXER_SERVICE", 7601)));
101-
let gateway_url = env::var("GATEWAY_URL")
102-
.unwrap_or_else(|_| format!("http://localhost:{}", get_u16("GATEWAY", 7700)));
103-
let graph_url = env::var("GRAPH_URL").unwrap_or_else(|_| {
104-
format!(
105-
"http://localhost:{}/subgraphs/name/graph-network",
106-
get_u16("GRAPH_NODE_GRAPHQL", 8000)
107-
)
108-
});
109-
110-
let tap_agent_metrics_url = get_s("TAP_AGENT_METRICS_URL", "http://localhost:7300/metrics");
111-
112-
let chain_id = get_u64("CHAIN_ID", 1337);
113-
let gateway_api_key = get_s("GATEWAY_API_KEY", "deadbeefdeadbeefdeadbeefdeadbeef");
114-
115-
let account0_address = get_s(
116-
"ACCOUNT0_ADDRESS",
117-
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
118-
);
119-
let account0_secret = get_s(
120-
"ACCOUNT0_SECRET",
121-
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
122-
);
123-
let account1_address = get_s(
124-
"ACCOUNT1_ADDRESS",
125-
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
126-
);
127-
let account1_secret = get_s(
128-
"ACCOUNT1_SECRET",
129-
"0x59c6995e998f97a5a0044966f0945389e86dae88c7a8412f4603b6b78690d",
130-
);
131-
132-
let mut tap_verifier_contract = "0xC9a43158891282A2B1475592D5719c001986Aaec".to_string();
133-
let mut graph_tally_collector_contract =
134-
"0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07".to_string();
135-
let mut test_data_service = "0xf4ef6650e48d099a4972ea5b414dab86e1998bd3".to_string();
104+
let indexer_url = env::var("INDEXER_URL").unwrap_or_else(|_| INDEXER_URL.to_string());
105+
let gateway_url = env::var("GATEWAY_URL").unwrap_or_else(|_| GATEWAY_URL.to_string());
106+
107+
let graph_url = env::var("GRAPH_URL").unwrap_or_else(|_| GRAPH_URL.to_string());
108+
109+
let tap_agent_metrics_url = get_s("TAP_AGENT_METRICS_URL", TAP_AGENT_METRICS_URL);
110+
111+
let chain_id = get_u64("CHAIN_ID", CHAIN_ID);
112+
let gateway_api_key = get_s("GATEWAY_API_KEY", GATEWAY_API_KEY);
113+
114+
// TODO: default values from constants or load contrib/local-network/.env
115+
let account0_address = get_s("ACCOUNT0_ADDRESS", ACCOUNT0_ADDRESS);
116+
let account0_secret = get_s("ACCOUNT0_SECRET", ACCOUNT0_SECRET);
117+
let account1_address = get_s("ACCOUNT1_ADDRESS", ACCOUNT1_ADDRESS);
118+
let account1_secret = get_s("ACCOUNT1_SECRET", ACCOUNT1_SECRET);
119+
120+
let mut tap_verifier_contract = TAP_VERIFIER_CONTRACT.to_string();
121+
let mut graph_tally_collector_contract = GRAPH_TALLY_COLLECTOR_CONTRACT.to_string();
122+
let mut test_data_service = TEST_DATA_SERVICE.to_string();
136123

137124
// Load JSONs from contrib when available. Path is relative to integration-tests/ CWD.
138125
read_tap_verifier_json("../contrib/local-network/tap-contracts.json")
@@ -146,10 +133,9 @@ impl TestConfig {
146133
.ok();
147134

148135
// Subgraph identifiers
149-
let subgraph_id = get_s("SUBGRAPH", "Qmc2CbqucMvaS4GFvt2QUZWvRwSZ3K5ipeGvbC6UUBf616");
136+
let subgraph_id = get_s("SUBGRAPH", SUBGRAPH_ID);
150137
// Allow env override; also accept alias SUBGRAPH_DEPLOYMENT. Fallback to constants::TEST_SUBGRAPH_DEPLOYMENT.
151138
let test_subgraph_deployment = env::var("TEST_SUBGRAPH_DEPLOYMENT")
152-
.or_else(|_| env::var("TEST_SUBGRAPH_DEPLOYMENT"))
153139
.unwrap_or_else(|_| TEST_SUBGRAPH_DEPLOYMENT.to_string());
154140

155141
Ok(Self {

0 commit comments

Comments
 (0)