11use std:: marker:: PhantomData ;
2- use std:: process:: Command ;
32use std:: str:: FromStr ;
43use std:: sync:: atomic:: { self , AtomicBool } ;
54use std:: sync:: Arc ;
@@ -13,93 +12,24 @@ use graph::data::subgraph::schema::{SubgraphError, SubgraphHealth};
1312use graph:: data:: value:: Word ;
1413use graph:: data_source:: CausalityRegion ;
1514use graph:: env:: { EnvVars , TEST_WITH_NO_REORG } ;
16- use graph:: ipfs;
1715use graph:: ipfs:: test_utils:: add_files_to_local_ipfs_node_for_testing;
1816use graph:: object;
1917use graph:: prelude:: ethabi:: ethereum_types:: H256 ;
2018use graph:: prelude:: web3:: types:: Address ;
21- use graph:: prelude:: {
22- hex, CheapClone , DeploymentHash , SubgraphAssignmentProvider , SubgraphName , SubgraphStore ,
23- } ;
19+ use graph:: prelude:: { hex, CheapClone , SubgraphAssignmentProvider , SubgraphName , SubgraphStore } ;
2420use graph_tests:: fixture:: ethereum:: {
2521 chain, empty_block, generate_empty_blocks_for_range, genesis, push_test_command, push_test_log,
2622 push_test_polling_trigger,
2723} ;
2824
2925use graph_tests:: fixture:: substreams:: chain as substreams_chain;
3026use graph_tests:: fixture:: {
31- self , stores , test_ptr, test_ptr_reorged, MockAdapterSelector , NoopAdapterSelector , Stores ,
32- TestChainTrait , TestContext , TestInfo ,
27+ self , test_ptr, test_ptr_reorged, MockAdapterSelector , NoopAdapterSelector , TestChainTrait ,
28+ TestContext , TestInfo ,
3329} ;
34- use graph_tests:: helpers :: run_cmd ;
30+ use graph_tests:: recipe :: { build_subgraph_with_yarn_cmd_and_arg , RunnerTestRecipe } ;
3531use slog:: { o, Discard , Logger } ;
3632
37- struct RunnerTestRecipe {
38- pub stores : Stores ,
39- pub test_info : TestInfo ,
40- }
41-
42- impl RunnerTestRecipe {
43- async fn new ( test_name : & str , subgraph_name : & str ) -> Self {
44- let subgraph_name = SubgraphName :: new ( subgraph_name) . unwrap ( ) ;
45- let test_dir = format ! ( "./runner-tests/{}" , subgraph_name) ;
46-
47- let ( stores, hash) = tokio:: join!(
48- stores( test_name, "./runner-tests/config.simple.toml" ) ,
49- build_subgraph( & test_dir, None )
50- ) ;
51-
52- Self {
53- stores,
54- test_info : TestInfo {
55- test_dir,
56- test_name : test_name. to_string ( ) ,
57- subgraph_name,
58- hash,
59- } ,
60- }
61- }
62-
63- /// Builds a new test subgraph with a custom deploy command.
64- async fn new_with_custom_cmd ( name : & str , subgraph_name : & str , deploy_cmd : & str ) -> Self {
65- let subgraph_name = SubgraphName :: new ( subgraph_name) . unwrap ( ) ;
66- let test_dir = format ! ( "./runner-tests/{}" , subgraph_name) ;
67-
68- let ( stores, hash) = tokio:: join!(
69- stores( name, "./runner-tests/config.simple.toml" ) ,
70- build_subgraph( & test_dir, Some ( deploy_cmd) )
71- ) ;
72-
73- Self {
74- stores,
75- test_info : TestInfo {
76- test_dir,
77- test_name : name. to_string ( ) ,
78- subgraph_name,
79- hash,
80- } ,
81- }
82- }
83-
84- async fn new_with_file_link_resolver ( name : & str , subgraph_name : & str , manifest : & str ) -> Self {
85- let subgraph_name = SubgraphName :: new ( subgraph_name) . unwrap ( ) ;
86- let test_dir = format ! ( "./runner-tests/{}" , subgraph_name) ;
87-
88- let stores = stores ( name, "./runner-tests/config.simple.toml" ) . await ;
89- build_subgraph ( & test_dir, None ) . await ;
90- let hash = DeploymentHash :: new ( manifest) . unwrap ( ) ;
91- Self {
92- stores,
93- test_info : TestInfo {
94- test_dir,
95- test_name : name. to_string ( ) ,
96- subgraph_name,
97- hash,
98- } ,
99- }
100- }
101- }
102-
10333fn assert_eq_ignore_backtrace ( err : & SubgraphError , expected : & SubgraphError ) {
10434 let equal = {
10535 if err. subgraph_id != expected. subgraph_id
@@ -1170,58 +1100,6 @@ async fn retry_create_ds() {
11701100 assert_eq ! ( runner. context( ) . hosts_len( ) , 2 ) ;
11711101}
11721102
1173- #[ tokio:: test]
1174- async fn file_link_resolver ( ) -> anyhow:: Result < ( ) > {
1175- let RunnerTestRecipe { stores, test_info } = RunnerTestRecipe :: new_with_file_link_resolver (
1176- "file_link_resolver" ,
1177- "file-link-resolver" ,
1178- "subgraph.yaml" ,
1179- )
1180- . await ;
1181-
1182- let blocks = {
1183- let block_0 = genesis ( ) ;
1184- let block_1 = empty_block ( block_0. ptr ( ) , test_ptr ( 1 ) ) ;
1185- let block_2 = empty_block ( block_1. ptr ( ) , test_ptr ( 2 ) ) ;
1186- let block_3 = empty_block ( block_2. ptr ( ) , test_ptr ( 3 ) ) ;
1187-
1188- vec ! [ block_0, block_1, block_2, block_3]
1189- } ;
1190-
1191- let chain = chain ( & test_info. test_name , blocks, & stores, None ) . await ;
1192-
1193- let ctx = fixture:: setup_with_file_link_resolver ( & test_info, & stores, & chain, None , None ) . await ;
1194- ctx. start_and_sync_to ( test_ptr ( 3 ) ) . await ;
1195- let query = r#"{ blocks(first: 4, orderBy: number) { id, hash } }"# ;
1196- let query_res = ctx. query ( query) . await . unwrap ( ) ;
1197-
1198- assert_eq ! (
1199- query_res,
1200- Some ( object! {
1201- blocks: vec![
1202- object! {
1203- id: test_ptr( 0 ) . number. to_string( ) ,
1204- hash: format!( "0x{}" , test_ptr( 0 ) . hash_hex( ) ) ,
1205- } ,
1206- object! {
1207- id: test_ptr( 1 ) . number. to_string( ) ,
1208- hash: format!( "0x{}" , test_ptr( 1 ) . hash_hex( ) ) ,
1209- } ,
1210- object! {
1211- id: test_ptr( 2 ) . number. to_string( ) ,
1212- hash: format!( "0x{}" , test_ptr( 2 ) . hash_hex( ) ) ,
1213- } ,
1214- object! {
1215- id: test_ptr( 3 ) . number. to_string( ) ,
1216- hash: format!( "0x{}" , test_ptr( 3 ) . hash_hex( ) ) ,
1217- } ,
1218- ]
1219- } )
1220- ) ;
1221-
1222- Ok ( ( ) )
1223- }
1224-
12251103#[ tokio:: test]
12261104async fn fatal_error ( ) -> anyhow:: Result < ( ) > {
12271105 let RunnerTestRecipe { stores, test_info } =
@@ -1348,60 +1226,3 @@ async fn arweave_file_data_sources() {
13481226 Some ( object! { file: object!{ id: id, content: content. clone( ) } } )
13491227 ) ;
13501228}
1351-
1352- /// deploy_cmd is the command to run to deploy the subgraph. If it is None, the
1353- /// default `yarn deploy:test` is used.
1354- async fn build_subgraph ( dir : & str , deploy_cmd : Option < & str > ) -> DeploymentHash {
1355- build_subgraph_with_yarn_cmd ( dir, deploy_cmd. unwrap_or ( "deploy:test" ) ) . await
1356- }
1357-
1358- async fn build_subgraph_with_yarn_cmd ( dir : & str , yarn_cmd : & str ) -> DeploymentHash {
1359- build_subgraph_with_yarn_cmd_and_arg ( dir, yarn_cmd, None ) . await
1360- }
1361-
1362- async fn build_subgraph_with_yarn_cmd_and_arg (
1363- dir : & str ,
1364- yarn_cmd : & str ,
1365- arg : Option < & str > ,
1366- ) -> DeploymentHash {
1367- // Test that IPFS is up.
1368- ipfs:: IpfsRpcClient :: new ( ipfs:: ServerAddress :: local_rpc_api ( ) , & graph:: log:: discard ( ) )
1369- . await
1370- . expect ( "Could not connect to IPFS, make sure it's running at port 5001" ) ;
1371-
1372- // Make sure dependencies are present.
1373-
1374- run_cmd (
1375- Command :: new ( "yarn" )
1376- . arg ( "install" )
1377- . arg ( "--mutex" )
1378- . arg ( "file:.yarn-mutex" )
1379- . current_dir ( "./runner-tests/" ) ,
1380- ) ;
1381-
1382- // Run codegen.
1383- run_cmd ( Command :: new ( "yarn" ) . arg ( "codegen" ) . current_dir ( dir) ) ;
1384-
1385- let mut args = vec ! [ yarn_cmd] ;
1386- args. extend ( arg) ;
1387-
1388- // Run `deploy` for the side effect of uploading to IPFS, the graph node url
1389- // is fake and the actual deploy call is meant to fail.
1390- let deploy_output = run_cmd (
1391- Command :: new ( "yarn" )
1392- . args ( & args)
1393- . env ( "IPFS_URI" , "http://127.0.0.1:5001" )
1394- . env ( "GRAPH_NODE_ADMIN_URI" , "http://localhost:0" )
1395- . current_dir ( dir) ,
1396- ) ;
1397-
1398- // Hack to extract deployment id from `graph deploy` output.
1399- const ID_PREFIX : & str = "Build completed: " ;
1400- let Some ( mut line) = deploy_output. lines ( ) . find ( |line| line. contains ( ID_PREFIX ) ) else {
1401- panic ! ( "No deployment id found, graph deploy probably had an error" )
1402- } ;
1403- if !line. starts_with ( ID_PREFIX ) {
1404- line = & line[ 5 ..line. len ( ) - 5 ] ; // workaround for colored output
1405- }
1406- DeploymentHash :: new ( line. trim_start_matches ( ID_PREFIX ) ) . unwrap ( )
1407- }
0 commit comments