Skip to content

Commit 67536ce

Browse files
committed
test(integration-tests): fix routing in tests
Signed-off-by: Joseph Livesey <[email protected]>
1 parent 9da93bc commit 67536ce

File tree

5 files changed

+117
-16
lines changed

5 files changed

+117
-16
lines changed

integration-tests/src/constants.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//! Constants used in the integration tests for the TAP RAV generation
66
//! their value is taken from local-network .env variable
77
8-
pub const INDEXER_URL: &str = "http://localhost:7601";
8+
// Keep for backwards compatibility if needed
9+
// pub const INDEXER_URL: &str = "http://localhost:7601";
910

1011
pub const GATEWAY_API_KEY: &str = "deadbeefdeadbeefdeadbeefdeadbeef";
1112
pub const GATEWAY_URL: &str = "http://localhost:7700";
@@ -24,8 +25,12 @@ pub const ACCOUNT0_SECRET: &str =
2425
"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
2526
pub const CHAIN_ID: u64 = 1337;
2627

28+
// Use the test subgraph ID for TAP receipt generation testing
2729
pub const SUBGRAPH_ID: &str = "QmRcucmbxAXLaAZkkCR8Bdj1X7QGPLjfRmQ5H6tFhGqiHX";
2830

31+
// Network subgraph ID - used by gateway for network information
32+
pub const NETWORK_SUBGRAPH_ID: &str = "Qmc2CbqucMvaS4GFvt2QUZWvRwSZ3K5ipeGvbC6UUBf616";
33+
2934
pub const GRAPH_URL: &str = "http://localhost:8000/subgraphs/name/graph-network";
3035

3136
pub const GRT_DECIMALS: u8 = 18;

integration-tests/src/load_test.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use tokio::{sync::Semaphore, task, time::Instant};
1111

1212
use crate::{
1313
constants::{
14-
ACCOUNT0_SECRET, CHAIN_ID, GRAPH_URL, INDEXER_URL, MAX_RECEIPT_VALUE, SUBGRAPH_ID,
15-
TAP_VERIFIER_CONTRACT,
14+
ACCOUNT0_SECRET, CHAIN_ID, GATEWAY_API_KEY, GATEWAY_URL, GRAPH_URL, MAX_RECEIPT_VALUE,
15+
SUBGRAPH_ID, TAP_VERIFIER_CONTRACT,
1616
},
1717
utils::{
18-
create_request, create_tap_receipt, create_tap_receipt_v2, encode_v2_receipt,
18+
create_request_with_api_key, create_tap_receipt, create_tap_receipt_v2, encode_v2_receipt,
1919
find_allocation,
2020
},
2121
};
@@ -109,13 +109,14 @@ async fn create_and_send_receipts(
109109
)?;
110110

111111
let receipt_json = serde_json::to_string(&receipt).unwrap();
112-
let response = create_request(
112+
let response = create_request_with_api_key(
113113
&http_client,
114-
format!("{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}").as_str(),
114+
format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}").as_str(),
115115
&receipt_json,
116116
&json!({
117117
"query": "{ _meta { block { number } } }"
118118
}),
119+
GATEWAY_API_KEY,
119120
)
120121
.send()
121122
.await?;
@@ -225,13 +226,14 @@ async fn create_and_send_receipts_v2(
225226
)?;
226227

227228
let receipt_encoded = encode_v2_receipt(&receipt)?;
228-
let response = create_request(
229+
let response = create_request_with_api_key(
229230
&http_client,
230-
format!("{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}").as_str(),
231+
format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}").as_str(),
231232
&receipt_encoded,
232233
&json!({
233234
"query": "{ _meta { block { number } } }"
234235
}),
236+
GATEWAY_API_KEY,
235237
)
236238
.send()
237239
.await?;

integration-tests/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ enum Commands {
4343

4444
#[clap(name = "debug")]
4545
Debug,
46+
47+
#[clap(name = "verify")]
48+
VerifyGateway,
4649
}
4750

4851
#[tokio::main]
@@ -73,6 +76,10 @@ async fn main() -> Result<()> {
7376
Commands::Debug => {
7477
signature_test::test_v2_signature_recovery().await?;
7578
}
79+
// cargo run -- verify
80+
Commands::VerifyGateway => {
81+
utils::verify_gateway_routing().await?;
82+
}
7683
}
7784

7885
Ok(())

integration-tests/src/rav_tests.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use thegraph_core::alloy::{primitives::Address, signers::local::PrivateKeySigner
1010

1111
use crate::{
1212
constants::{
13-
ACCOUNT0_SECRET, CHAIN_ID, GATEWAY_API_KEY, GATEWAY_URL, GRAPH_URL, INDEXER_URL,
14-
MAX_RECEIPT_VALUE, SUBGRAPH_ID, TAP_AGENT_METRICS_URL, TAP_VERIFIER_CONTRACT,
13+
ACCOUNT0_SECRET, CHAIN_ID, GATEWAY_API_KEY, GATEWAY_URL, GRAPH_URL, MAX_RECEIPT_VALUE,
14+
SUBGRAPH_ID, TAP_AGENT_METRICS_URL, TAP_VERIFIER_CONTRACT,
1515
},
16-
utils::{create_request, create_tap_receipt, find_allocation},
16+
utils::{create_request_with_api_key, create_tap_receipt, find_allocation},
1717
MetricsChecker,
1818
};
1919

@@ -190,13 +190,14 @@ pub async fn test_invalid_chain_id() -> Result<()> {
190190
)?;
191191

192192
let receipt_json = serde_json::to_string(&receipt).unwrap();
193-
let response = create_request(
193+
let response = create_request_with_api_key(
194194
&http_client,
195-
format!("{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}").as_str(),
195+
format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}").as_str(),
196196
&receipt_json,
197197
&json!({
198198
"query": "{ _meta { block { number } } }"
199199
}),
200+
GATEWAY_API_KEY,
200201
)
201202
.send()
202203
.await?;

integration-tests/src/utils.rs

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use tap_graph::Receipt;
1919
use thegraph_core::alloy::{primitives::Address, signers::local::PrivateKeySigner};
2020
use thegraph_core::CollectionId;
2121

22-
use crate::constants::{GRAPH_TALLY_COLLECTOR_CONTRACT, TEST_DATA_SERVICE};
22+
use crate::constants::{
23+
GATEWAY_API_KEY, GATEWAY_URL, GRAPH_TALLY_COLLECTOR_CONTRACT, SUBGRAPH_ID, TEST_DATA_SERVICE,
24+
};
2325

2426
pub fn create_tap_receipt(
2527
value: u128,
@@ -116,7 +118,8 @@ pub fn encode_v2_receipt(receipt: &Eip712SignedMessage<tap_graph::v2::Receipt>)
116118
Ok(base64_encoded)
117119
}
118120

119-
// Function to create a configured request
121+
// Function to create a configured request (currently unused - kept for compatibility)
122+
#[allow(dead_code)]
120123
pub fn create_request(
121124
client: &reqwest::Client,
122125
url: &str,
@@ -126,7 +129,24 @@ pub fn create_request(
126129
client
127130
.post(url)
128131
.header("Content-Type", "application/json")
129-
.header("Tap-Receipt", receipt_json)
132+
.header("tap-receipt", receipt_json)
133+
.json(query)
134+
.timeout(Duration::from_secs(10))
135+
}
136+
137+
// Function to create a configured request with gateway API key
138+
pub fn create_request_with_api_key(
139+
client: &reqwest::Client,
140+
url: &str,
141+
receipt_json: &str,
142+
query: &serde_json::Value,
143+
api_key: &str,
144+
) -> reqwest::RequestBuilder {
145+
client
146+
.post(url)
147+
.header("Content-Type", "application/json")
148+
.header("tap-receipt", receipt_json)
149+
.header("Authorization", format!("Bearer {api_key}"))
130150
.json(query)
131151
.timeout(Duration::from_secs(10))
132152
}
@@ -162,3 +182,69 @@ pub async fn find_allocation(http_client: Arc<Client>, url: &str) -> Result<Stri
162182
.map(|id| id.to_string())
163183
.ok_or_else(|| anyhow::anyhow!("No valid allocation ID found"))
164184
}
185+
186+
pub async fn verify_gateway_routing() -> Result<()> {
187+
println!("🔍 Verifying gateway routing configuration...");
188+
189+
let client = Arc::new(Client::new());
190+
191+
// Test 1: Verify gateway is responding
192+
println!("📡 Testing gateway availability...");
193+
let gateway_response = client
194+
.get(format!("{GATEWAY_URL}/health"))
195+
.timeout(Duration::from_secs(5))
196+
.send()
197+
.await;
198+
199+
match gateway_response {
200+
Ok(resp) => {
201+
if resp.status().is_success() {
202+
println!("✅ Gateway is responding at {GATEWAY_URL}");
203+
} else {
204+
println!("⚠️ Gateway responded with status: {}", resp.status());
205+
}
206+
}
207+
Err(e) => {
208+
println!("❌ Gateway not reachable: {e}");
209+
return Err(anyhow::anyhow!("Gateway not reachable: {}", e));
210+
}
211+
}
212+
213+
// Test 2: Try a simple GraphQL query through the gateway
214+
println!("📊 Testing subgraph query routing through gateway...");
215+
let query_response = client
216+
.post(format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}"))
217+
.header("Content-Type", "application/json")
218+
.header("Authorization", format!("Bearer {GATEWAY_API_KEY}"))
219+
.json(&json!({
220+
"query": "{ _meta { block { number } } }"
221+
}))
222+
.timeout(Duration::from_secs(10))
223+
.send()
224+
.await?;
225+
226+
let status = query_response.status();
227+
let response_text = query_response.text().await?;
228+
229+
println!("📋 Gateway response status: {status}");
230+
println!("📋 Gateway response body: {response_text}");
231+
232+
if status.is_success() {
233+
println!("✅ Gateway successfully routed query to subgraph {SUBGRAPH_ID}");
234+
} else if status == 404 && response_text.contains("subgraph not found") {
235+
println!(
236+
"❌ Gateway routing issue: Subgraph {SUBGRAPH_ID} not found in gateway's routing table"
237+
);
238+
println!(
239+
"💡 This confirms the root cause - gateway cannot route to the specified subgraph ID"
240+
);
241+
return Err(anyhow::anyhow!(
242+
"Gateway routing verification failed: subgraph not found"
243+
));
244+
} else {
245+
println!("⚠️ Unexpected gateway response: {status} - {response_text}");
246+
}
247+
248+
println!("🎯 Gateway routing verification complete!");
249+
Ok(())
250+
}

0 commit comments

Comments
 (0)