Skip to content

Commit 4b37edf

Browse files
committed
refactor: use utils module and add new but simple test
1 parent 78b209d commit 4b37edf

File tree

2 files changed

+62
-35
lines changed

2 files changed

+62
-35
lines changed

integration-tests/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use anyhow::Result;
5-
use rav_tests::test_tap_rav_v1;
5+
use rav_tests::{test_invalid_chain_id, test_tap_rav_v1};
66

77
mod metrics;
88
mod rav_tests;
9-
mod receipt;
9+
mod utils;
10+
1011
use metrics::MetricsChecker;
11-
use receipt::create_tap_receipt;
1212

1313
#[tokio::main]
1414
async fn main() -> Result<()> {
1515
// Run the TAP receipt test
16+
test_invalid_chain_id().await?;
1617
test_tap_rav_v1().await
1718
}

integration-tests/src/rav_tests.rs

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ use std::str::FromStr;
88
use std::sync::Arc;
99
use std::time::Duration;
1010
use thegraph_core::alloy::primitives::Address;
11+
use thegraph_core::alloy::signers::local::PrivateKeySigner;
1112

13+
use crate::utils::{create_request, create_tap_receipt, find_allocation};
1214
use crate::MetricsChecker;
1315

14-
// TODO: Would be nice to read this values from:
15-
// contrib/tap-agent/config.toml
16-
// and contrib/local-network/.env
16+
const INDEXER_URL: &str = "http://localhost:7601";
17+
// Taken from .env
18+
// this is the key gateway uses
19+
const ACCOUNT0_SECRET: &str = "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
20+
21+
// The deployed gateway and indexer
22+
// use this verifier contract
23+
// which must be part of the eip712 domain
24+
const TAP_VERIFIER_CONTRACT: &str = "0x8198f5d8F8CfFE8f9C413d98a0A55aEB8ab9FbB7";
25+
const CHAIN_ID: u64 = 1337;
26+
1727
const GATEWAY_URL: &str = "http://localhost:7700";
1828
const SUBGRAPH_ID: &str = "BFr2mx7FgkJ36Y6pE5BiXs1KmNUmVDCnL82KUSdcLW1g";
1929
const GATEWAY_API_KEY: &str = "deadbeefdeadbeefdeadbeefdeadbeef";
@@ -30,42 +40,20 @@ const NUM_RECEIPTS: u32 = 3;
3040
const BATCHES: u32 = 2;
3141
const MAX_TRIGGERS: usize = 100;
3242

43+
const GRT_DECIMALS: u8 = 18;
44+
const GRT_BASE: u128 = 10u128.pow(GRT_DECIMALS as u32);
45+
46+
const MAX_RECEIPT_VALUE: u128 = GRT_BASE / 10_000;
47+
3348
// Function to test the tap RAV generation
3449
pub async fn test_tap_rav_v1() -> Result<()> {
3550
// Setup HTTP client
3651
let http_client = Arc::new(Client::new());
3752

3853
// Query the network subgraph to find active allocations
39-
println!("Querying for active allocations...");
40-
let response = http_client
41-
.post(GRAPH_URL)
42-
.json(&json!({
43-
"query": "{ allocations(where: { status: Active }) { id indexer { id } subgraphDeployment { id } } }"
44-
}))
45-
.send()
46-
.await?;
47-
48-
if !response.status().is_success() {
49-
return Err(anyhow::anyhow!(
50-
"Network subgraph request failed with status: {}",
51-
response.status()
52-
));
53-
}
54-
55-
// Try to find a valid allocation
56-
let response_text = response.text().await?;
57-
58-
let json_value = serde_json::from_str::<serde_json::Value>(&response_text)?;
59-
let allocation_id = json_value
60-
.get("data")
61-
.and_then(|d| d.get("allocations"))
62-
.and_then(|a| a.as_array())
63-
.filter(|arr| !arr.is_empty())
64-
.and_then(|arr| arr[0].get("id"))
65-
.and_then(|id| id.as_str())
66-
.ok_or_else(|| anyhow::anyhow!("No valid allocation ID found"))?;
54+
let allocation_id = find_allocation(http_client.clone(), GRAPH_URL).await?;
6755

68-
let allocation_id = Address::from_str(allocation_id)?;
56+
let allocation_id = Address::from_str(&allocation_id)?;
6957

7058
// Create a metrics checker
7159
let metrics_checker =
@@ -205,3 +193,41 @@ pub async fn test_tap_rav_v1() -> Result<()> {
205193
println!("❌ TEST FAILED: No RAV generation detected");
206194
Err(anyhow::anyhow!("Failed to detect RAV generation"))
207195
}
196+
197+
pub async fn test_invalid_chain_id() -> Result<()> {
198+
let wallet: PrivateKeySigner = ACCOUNT0_SECRET.parse().unwrap();
199+
200+
let http_client = Arc::new(Client::new());
201+
202+
let allocation_id = find_allocation(http_client.clone(), GRAPH_URL).await?;
203+
204+
let allocation_id = Address::from_str(&allocation_id)?;
205+
println!("Found allocation ID: {}", allocation_id);
206+
207+
let receipt = create_tap_receipt(
208+
MAX_RECEIPT_VALUE,
209+
&allocation_id,
210+
TAP_VERIFIER_CONTRACT,
211+
CHAIN_ID + 18,
212+
&wallet,
213+
)?;
214+
215+
let receipt_json = serde_json::to_string(&receipt).unwrap();
216+
let response = create_request(
217+
&http_client,
218+
format!("{}/subgraphs/id/{}", INDEXER_URL, SUBGRAPH_ID).as_str(),
219+
&receipt_json,
220+
&json!({
221+
"query": "{ _meta { block { number } } }"
222+
}),
223+
)
224+
.send()
225+
.await?;
226+
227+
assert!(
228+
response.status().is_client_error(),
229+
"Failed to send receipt"
230+
);
231+
232+
Ok(())
233+
}

0 commit comments

Comments
 (0)