Skip to content

Commit 16c828b

Browse files
committed
tests: Make the grafted test independent of block numbers
We used to use hardcoded POIs which required us to use fixed block hashes. But since commit f145736 that's no longer needed and we can just use whatever block hashes the chain has, making the test setup less fragile.
1 parent 29df457 commit 16c828b

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

tests/tests/integration_tests.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -865,25 +865,23 @@ async fn test_subgraph_grafting(ctx: TestContext) -> anyhow::Result<()> {
865865

866866
assert!(subgraph.healthy);
867867

868-
// Fixed block hashes from deterministic Anvil config
869-
let block_hashes: Vec<&str> = vec![
870-
"e26fccbd24dcc76074b432becf29cad3bcba11a8467a7b770fad109c2b5d14c2",
871-
"249dbcbee975c22f8c9cc937536945ca463568c42d8933a3f54129dec352e46b",
872-
"408675f81c409dede08d0eeb2b3420a73b067c4fa8c5f0fc49ce369289467c33",
873-
];
868+
// Fetch block hashes from the chain
869+
let mut block_hashes: Vec<String> = Vec::new();
870+
for i in 1..4 {
871+
let hash = get_block_hash(i)
872+
.await
873+
.ok_or_else(|| anyhow!("Failed to get block hash for block {}", i))?;
874+
block_hashes.push(hash);
875+
}
874876

875877
// The deployment hash is dynamic (depends on the base subgraph's hash)
876878
let deployment_hash = DeploymentHash::new(&subgraph.deployment).unwrap();
877879

878-
// Compute the expected POI values dynamically
880+
// Compute the expected POIs using the actual block hashes
879881
let expected_pois = compute_expected_pois(&deployment_hash, &block_hashes);
880882

881883
for i in 1..4 {
882-
let block_hash = get_block_hash(i).await.unwrap();
883-
// We need to make sure that the preconditions for POI are fulfilled
884-
// namely that the blockchain produced the proper block hashes for the
885-
// blocks of which we will check the POI.
886-
assert_eq!(block_hash, block_hashes[(i - 1) as usize]);
884+
let block_hash = &block_hashes[(i - 1) as usize];
887885

888886
const FETCH_POI: &str = r#"
889887
query proofOfIndexing($subgraph: String!, $blockNumber: Int!, $blockHash: String!, $indexer: String!) {
@@ -937,7 +935,7 @@ async fn test_subgraph_grafting(ctx: TestContext) -> anyhow::Result<()> {
937935
/// POI algorithm transition:
938936
/// - Blocks 0-2: Legacy POI digests (from base subgraph)
939937
/// - Block 3+: Fast POI algorithm with transition from Legacy
940-
fn compute_expected_pois(deployment_hash: &DeploymentHash, block_hashes: &[&str]) -> Vec<String> {
938+
fn compute_expected_pois(deployment_hash: &DeploymentHash, block_hashes: &[String]) -> Vec<String> {
941939
let logger = Logger::root(Discard, o!());
942940
let causality_region = "ethereum/test";
943941

0 commit comments

Comments
 (0)