@@ -8,12 +8,22 @@ use std::str::FromStr;
88use  std:: sync:: Arc ; 
99use  std:: time:: Duration ; 
1010use  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} ; 
1214use  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+ 
1727const  GATEWAY_URL :  & str  = "http://localhost:7700" ; 
1828const  SUBGRAPH_ID :  & str  = "BFr2mx7FgkJ36Y6pE5BiXs1KmNUmVDCnL82KUSdcLW1g" ; 
1929const  GATEWAY_API_KEY :  & str  = "deadbeefdeadbeefdeadbeefdeadbeef" ; 
@@ -30,42 +40,20 @@ const NUM_RECEIPTS: u32 = 3;
3040const  BATCHES :  u32  = 2 ; 
3141const  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 
3449pub  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