Skip to content

Commit 19d6ccd

Browse files
committed
test(integration-tests): fix routing in tests
Signed-off-by: Joseph Livesey <[email protected]>
1 parent 8a9292c commit 19d6ccd

File tree

5 files changed

+124
-58
lines changed

5 files changed

+124
-58
lines changed

integration-tests/src/constants.rs

Lines changed: 7 additions & 2 deletions
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,7 +25,11 @@ pub const ACCOUNT0_SECRET: &str =
2425
"ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
2526
pub const CHAIN_ID: u64 = 1337;
2627

27-
pub const SUBGRAPH_ID: &str = "Qmc2CbqucMvaS4GFvt2QUZWvRwSZ3K5ipeGvbC6UUBf616";
28+
// Use the test subgraph ID for TAP receipt generation testing
29+
pub const SUBGRAPH_ID: &str = "QmRcucmbxAXLaAZkkCR8Bdj1X7QGPLjfRmQ5H6tFhGqiHX";
30+
31+
// Network subgraph ID - used by gateway for network information
32+
pub const NETWORK_SUBGRAPH_ID: &str = "Qmc2CbqucMvaS4GFvt2QUZWvRwSZ3K5ipeGvbC6UUBf616";
2833

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

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: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +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_TALLY_COLLECTOR_CONTRACT,
14-
GRAPH_URL, INDEXER_URL, MAX_RECEIPT_VALUE, SUBGRAPH_ID, TAP_AGENT_METRICS_URL,
15-
TAP_VERIFIER_CONTRACT,
16-
},
17-
utils::{
18-
create_request, create_tap_receipt, create_tap_receipt_v2, encode_v2_receipt,
19-
find_allocation,
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,
2015
},
16+
utils::{create_request_with_api_key, create_tap_receipt, find_allocation},
2117
MetricsChecker,
2218
};
2319

@@ -68,7 +64,7 @@ pub async fn test_tap_rav_v1() -> Result<()> {
6864

6965
for i in 0..NUM_RECEIPTS {
7066
let response = http_client
71-
.post(format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}"))
67+
.post(format!("{GATEWAY_URL}/api/deployments/id/{SUBGRAPH_ID}"))
7268
.header("Content-Type", "application/json")
7369
.header("Authorization", format!("Bearer {GATEWAY_API_KEY}"))
7470
.json(&json!({
@@ -115,7 +111,7 @@ pub async fn test_tap_rav_v1() -> Result<()> {
115111
println!("Sending trigger query {}/{}...", i + 1, MAX_TRIGGERS);
116112

117113
let response = http_client
118-
.post(format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}"))
114+
.post(format!("{GATEWAY_URL}/api/deployments/id/{SUBGRAPH_ID}"))
119115
.header("Content-Type", "application/json")
120116
.header("Authorization", format!("Bearer {GATEWAY_API_KEY}"))
121117
.json(&json!({
@@ -194,13 +190,14 @@ pub async fn test_invalid_chain_id() -> Result<()> {
194190
)?;
195191

196192
let receipt_json = serde_json::to_string(&receipt).unwrap();
197-
let response = create_request(
193+
let response = create_request_with_api_key(
198194
&http_client,
199-
format!("{INDEXER_URL}/subgraphs/id/{SUBGRAPH_ID}").as_str(),
195+
format!("{GATEWAY_URL}/api/deployments/id/{SUBGRAPH_ID}").as_str(),
200196
&receipt_json,
201197
&json!({
202198
"query": "{ _meta { block { number } } }"
203199
}),
200+
GATEWAY_API_KEY,
204201
)
205202
.send()
206203
.await?;
@@ -217,16 +214,11 @@ pub async fn test_invalid_chain_id() -> Result<()> {
217214
pub async fn test_tap_rav_v2() -> Result<()> {
218215
// Setup HTTP client
219216
let http_client = Arc::new(Client::new());
220-
let wallet: PrivateKeySigner = ACCOUNT0_SECRET.parse().unwrap();
221217

222218
// Query the network subgraph to find active allocations
223219
let allocation_id = find_allocation(http_client.clone(), GRAPH_URL).await?;
224220
let allocation_id = Address::from_str(&allocation_id)?;
225221

226-
// For V2, we need payer and service provider addresses
227-
let payer = wallet.address();
228-
let service_provider = allocation_id; // Using allocation_id as service provider for simplicity
229-
230222
// Create a metrics checker
231223
let metrics_checker =
232224
MetricsChecker::new(http_client.clone(), TAP_AGENT_METRICS_URL.to_string());
@@ -261,24 +253,11 @@ pub async fn test_tap_rav_v2() -> Result<()> {
261253
println!("Sending V2 batch {batch} of {BATCHES} with {NUM_RECEIPTS} receipts each...",);
262254

263255
for i in 0..NUM_RECEIPTS {
264-
// Create V2 receipt
265-
let receipt = create_tap_receipt_v2(
266-
MAX_RECEIPT_VALUE,
267-
&allocation_id,
268-
GRAPH_TALLY_COLLECTOR_CONTRACT,
269-
CHAIN_ID,
270-
&wallet,
271-
&payer,
272-
&service_provider,
273-
)?;
274-
275-
let receipt_encoded = encode_v2_receipt(&receipt)?;
276-
256+
// Send plain GraphQL query to gateway - let gateway generate V2 receipt
277257
let response = http_client
278-
.post(format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}"))
258+
.post(format!("{GATEWAY_URL}/api/deployments/id/{SUBGRAPH_ID}"))
279259
.header("Content-Type", "application/json")
280260
.header("Authorization", format!("Bearer {GATEWAY_API_KEY}"))
281-
.header("Tap-Receipt", receipt_encoded)
282261
.json(&json!({
283262
"query": "{ _meta { block { number } } }"
284263
}))
@@ -333,24 +312,11 @@ pub async fn test_tap_rav_v2() -> Result<()> {
333312
for i in 0..MAX_TRIGGERS {
334313
println!("Sending V2 trigger query {}/{}...", i + 1, MAX_TRIGGERS);
335314

336-
// Create V2 receipt
337-
let receipt = create_tap_receipt_v2(
338-
MAX_RECEIPT_VALUE / 10, // Smaller value for trigger receipts
339-
&allocation_id,
340-
GRAPH_TALLY_COLLECTOR_CONTRACT,
341-
CHAIN_ID,
342-
&wallet,
343-
&payer,
344-
&service_provider,
345-
)?;
346-
347-
let receipt_encoded = encode_v2_receipt(&receipt)?;
348-
315+
// Send plain GraphQL query to gateway - let gateway generate V2 receipt
349316
let response = http_client
350-
.post(format!("{GATEWAY_URL}/api/subgraphs/id/{SUBGRAPH_ID}"))
317+
.post(format!("{GATEWAY_URL}/api/deployments/id/{SUBGRAPH_ID}"))
351318
.header("Content-Type", "application/json")
352319
.header("Authorization", format!("Bearer {GATEWAY_API_KEY}"))
353-
.header("Tap-Receipt", receipt_encoded)
354320
.json(&json!({
355321
"query": "{ _meta { block { number } } }"
356322
}))

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,
@@ -122,7 +124,8 @@ pub fn encode_v2_receipt(receipt: &Eip712SignedMessage<tap_graph::v2::Receipt>)
122124
Ok(base64_encoded)
123125
}
124126

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

0 commit comments

Comments
 (0)