@@ -143,10 +143,10 @@ async fn data_source_revert() -> anyhow::Result<()> {
143143
144144 // Test grafted version
145145 let subgraph_name = SubgraphName :: new ( "data-source-revert-grafted" ) . unwrap ( ) ;
146- let hash = build_subgraph_with_yarn_cmd_and_arg (
146+ let hash = build_subgraph_with_yarn_cmd_and_args (
147147 "./runner-tests/data-source-revert" ,
148148 "deploy:test-grafted" ,
149- Some ( & test_info. hash ) ,
149+ vec ! [ & test_info. hash] ,
150150 )
151151 . await ;
152152 let test_info = TestInfo {
@@ -1261,20 +1261,102 @@ async fn arweave_file_data_sources() {
12611261 ) ;
12621262}
12631263
1264+ #[ tokio:: test]
1265+ async fn auto_graft_sync ( ) -> anyhow:: Result < ( ) > {
1266+ let stores = fixture:: stores (
1267+ "auto_graft_sync" ,
1268+ "./runner-tests/auto-graft-sync/config.toml" ,
1269+ )
1270+ . await ;
1271+
1272+ let test_name = "auto_graft_sync" ;
1273+
1274+ let blocks = {
1275+ let block0 = genesis ( ) ;
1276+ let block1 = empty_block ( block0. ptr ( ) , test_ptr ( 1 ) ) ;
1277+ let block1_reorged_ptr = BlockPtr {
1278+ number : 1 ,
1279+ hash : H256 :: from_low_u64_be ( 12 ) . into ( ) ,
1280+ } ;
1281+ let block1_reorged = empty_block ( block0. ptr ( ) , block1_reorged_ptr. clone ( ) ) ;
1282+ let block2 = empty_block ( block1_reorged_ptr, test_ptr ( 2 ) ) ;
1283+ let block3 = empty_block ( block2. ptr ( ) , test_ptr ( 3 ) ) ;
1284+ let block4 = empty_block ( block3. ptr ( ) , test_ptr ( 4 ) ) ;
1285+ vec ! [ block0, block1, block1_reorged, block2, block3, block4]
1286+ } ;
1287+
1288+ let chain = chain ( & test_name, blocks. clone ( ) , & stores, None ) . await ;
1289+
1290+ // Root graft
1291+ // only build the subgraph and create it, but don't deploy it to be assigned
1292+ let root_deployment_hash = build_subgraph_with_yarn_cmd_and_args (
1293+ "./runner-tests/auto-graft-sync" ,
1294+ "build-graft-root" ,
1295+ vec ! [ ] ,
1296+ )
1297+ . await ;
1298+
1299+ let mut prev_hash = root_deployment_hash. clone ( ) ;
1300+ for i in ( 0 ..10 ) . rev ( ) {
1301+ let outfile = format ! ( "auto-graft-sync-{}.yaml" , i) ;
1302+ // Test grafted version
1303+ let hash = build_subgraph_with_yarn_cmd_and_args (
1304+ "./runner-tests/auto-graft-sync" ,
1305+ "build:test-auto-graft-sync" ,
1306+ vec ! [ & outfile, & prev_hash] ,
1307+ )
1308+ . await ;
1309+ prev_hash = hash;
1310+ }
1311+
1312+ let subgraph_name = SubgraphName :: new ( "auto-graft-sync-tip" . to_string ( ) ) . unwrap ( ) ;
1313+ let test_info = TestInfo {
1314+ test_name : test_name. to_string ( ) ,
1315+ hash : prev_hash. clone ( ) ,
1316+ test_dir : "./runner-tests/auto-graft-sync" . to_string ( ) ,
1317+ subgraph_name,
1318+ } ;
1319+
1320+ let base_ctx = fixture:: setup ( & test_info, & stores, & chain, None , None ) . await ;
1321+
1322+ let stop_block = test_ptr ( 3 ) ;
1323+ base_ctx. start_and_sync_to ( stop_block) . await ;
1324+
1325+ let graft_block = Some ( test_ptr ( 3 ) ) ;
1326+ let grafted_ctx = fixture:: setup ( & test_info, & stores, & chain, graft_block, None ) . await ;
1327+ let stop_block = test_ptr ( 4 ) ;
1328+ grafted_ctx. start_and_sync_to ( stop_block) . await ;
1329+
1330+ let query_res = grafted_ctx
1331+ . query ( r#"{ dataSourceCount(id: "4") { id, count } }"# )
1332+ . await
1333+ . unwrap ( ) ;
1334+
1335+ // TODO: The semantically correct value for `count` would be 5. But because the test fixture
1336+ // uses a `NoopTriggersAdapter` the data sources are not reprocessed in the block in which they
1337+ // are created.
1338+ assert_eq ! (
1339+ query_res,
1340+ Some ( object! { dataSourceCount: object!{ id: "4" , count: 4 } } )
1341+ ) ;
1342+
1343+ Ok ( ( ) )
1344+ }
1345+
12641346/// deploy_cmd is the command to run to deploy the subgraph. If it is None, the
12651347/// default `yarn deploy:test` is used.
12661348async fn build_subgraph ( dir : & str , deploy_cmd : Option < & str > ) -> DeploymentHash {
12671349 build_subgraph_with_yarn_cmd ( dir, deploy_cmd. unwrap_or ( "deploy:test" ) ) . await
12681350}
12691351
12701352async fn build_subgraph_with_yarn_cmd ( dir : & str , yarn_cmd : & str ) -> DeploymentHash {
1271- build_subgraph_with_yarn_cmd_and_arg ( dir, yarn_cmd, None ) . await
1353+ build_subgraph_with_yarn_cmd_and_args ( dir, yarn_cmd, vec ! [ ] ) . await
12721354}
12731355
1274- async fn build_subgraph_with_yarn_cmd_and_arg (
1356+ async fn build_subgraph_with_yarn_cmd_and_args (
12751357 dir : & str ,
12761358 yarn_cmd : & str ,
1277- arg : Option < & str > ,
1359+ mut additional_args : Vec < & str > ,
12781360) -> DeploymentHash {
12791361 // Test that IPFS is up.
12801362 IpfsClient :: localhost ( )
@@ -1296,7 +1378,7 @@ async fn build_subgraph_with_yarn_cmd_and_arg(
12961378 run_cmd ( Command :: new ( "yarn" ) . arg ( "codegen" ) . current_dir ( dir) ) ;
12971379
12981380 let mut args = vec ! [ yarn_cmd] ;
1299- args. extend ( arg ) ;
1381+ args. append ( & mut additional_args ) ;
13001382
13011383 // Run `deploy` for the side effect of uploading to IPFS, the graph node url
13021384 // is fake and the actual deploy call is meant to fail.
0 commit comments