|
12 | 12 | use std::collections::HashMap; |
13 | 13 | use std::future::Future; |
14 | 14 | use std::pin::Pin; |
15 | | -use std::time::{self, Duration, Instant}; |
| 15 | +use std::time::{Duration, Instant}; |
16 | 16 |
|
17 | 17 | use anyhow::{anyhow, bail, Context, Result}; |
18 | 18 | use graph::components::subgraph::{ |
@@ -1388,24 +1388,6 @@ async fn test_declared_calls_struct_fields(ctx: TestContext) -> anyhow::Result<( |
1388 | 1388 | Ok(()) |
1389 | 1389 | } |
1390 | 1390 |
|
1391 | | -async fn wait_for_blockchain_block(block_number: i32) -> bool { |
1392 | | - // Wait up to 5 minutes for the expected block to appear |
1393 | | - const STATUS_WAIT: Duration = Duration::from_secs(300); |
1394 | | - const REQUEST_REPEATING: Duration = time::Duration::from_secs(1); |
1395 | | - let start = Instant::now(); |
1396 | | - while start.elapsed() < STATUS_WAIT { |
1397 | | - let latest_block = Contract::latest_block().await; |
1398 | | - if let Some(latest_block) = latest_block { |
1399 | | - let number = latest_block.header.number; |
1400 | | - if number >= block_number as u64 { |
1401 | | - return true; |
1402 | | - } |
1403 | | - } |
1404 | | - tokio::time::sleep(REQUEST_REPEATING).await; |
1405 | | - } |
1406 | | - false |
1407 | | -} |
1408 | | - |
1409 | 1391 | /// The main test entrypoint. |
1410 | 1392 | #[graph::test] |
1411 | 1393 | async fn integration_tests() -> anyhow::Result<()> { |
@@ -1452,10 +1434,17 @@ async fn integration_tests() -> anyhow::Result<()> { |
1452 | 1434 | cases |
1453 | 1435 | }; |
1454 | 1436 |
|
1455 | | - // Here we wait for a block in the blockchain in order not to influence |
1456 | | - // block hashes for all the blocks until the end of the grafting tests. |
1457 | | - // Currently the last used block for grafting test is the block 3. |
1458 | | - assert!(wait_for_blockchain_block(SUBGRAPH_LAST_GRAFTING_BLOCK).await); |
| 1437 | + // Mine empty blocks to reach the required block number for grafting tests. |
| 1438 | + // This ensures deterministic block hashes for blocks 1-3 before any |
| 1439 | + // contract deployments occur. |
| 1440 | + status!( |
| 1441 | + "setup", |
| 1442 | + "Mining blocks to reach block {}", |
| 1443 | + SUBGRAPH_LAST_GRAFTING_BLOCK |
| 1444 | + ); |
| 1445 | + Contract::ensure_block(SUBGRAPH_LAST_GRAFTING_BLOCK as u64) |
| 1446 | + .await |
| 1447 | + .context("Failed to mine initial blocks for grafting test")?; |
1459 | 1448 |
|
1460 | 1449 | let contracts = Contract::deploy_all().await?; |
1461 | 1450 |
|
|
0 commit comments