Skip to content

Commit aa7385a

Browse files
lutterclaude
andcommitted
tests: Fix grafted integration test with dynamic POI computation
The grafted test was failing because it used hardcoded POI values that became stale when the base subgraph's deployment hash changed. This commit: - Adds `patch_sources()` to dynamically patch source subgraph placeholders (e.g., `@base@`) with actual deployment hashes at runtime - Modifies `deploy()` and `prepare()` to accept source mappings - Replaces hardcoded POI values with dynamic computation using the same algorithm graph-node uses (matching spec version transitions) - Updates Anvil to v1.4.0 for deterministic block hashes The POI computation correctly handles the Legacy→Fast algorithm transition when grafting from spec 0.0.5 to 0.0.6, starting from block 0 (genesis). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a6076fe commit aa7385a

File tree

4 files changed

+273
-52
lines changed

4 files changed

+273
-52
lines changed

tests/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
anvil:
2323
# Pinned to specific version since newer versions do not produce
2424
# deterministic block hashes. Unpin once that's fixed upstream
25-
image: ghcr.io/foundry-rs/foundry:v1.2.3
25+
image: ghcr.io/foundry-rs/foundry:v1.4.0
2626
ports:
2727
- '3021:8545'
2828
command: "'anvil --host 0.0.0.0 --gas-limit 100000000000 --base-fee 1 --block-time 2 --timestamp 1743944919 --mnemonic \"test test test test test test test test test test test junk\"'"

tests/integration-tests/grafted/subgraph.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ dataSources:
2626
features:
2727
- grafting
2828
graft:
29-
base: QmTQbJ234d2Po7xKZS5wKPiYuMYsCAqqY4df5czESjEXn4
29+
base: '@base@'
3030
block: 2

tests/src/subgraph.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,41 @@ impl Subgraph {
4747
Ok(())
4848
}
4949

50+
/// Patch source subgraph placeholders in the manifest with their deployment hashes.
51+
/// This must be called after `patch()` since it reads from `subgraph.yaml.patched`.
52+
pub fn patch_sources(dir: &TestFile, sources: &[(String, String)]) -> anyhow::Result<()> {
53+
if sources.is_empty() {
54+
return Ok(());
55+
}
56+
57+
let patched_path = dir.path.join("subgraph.yaml.patched");
58+
let mut content = fs::read_to_string(&patched_path)?;
59+
60+
for (placeholder, deployment_hash) in sources {
61+
let repl = format!("@{}@", placeholder);
62+
content = content.replace(&repl, deployment_hash);
63+
}
64+
65+
fs::write(&patched_path, content)?;
66+
Ok(())
67+
}
68+
5069
/// Prepare the subgraph for deployment by patching contracts and checking for subgraph datasources
5170
pub async fn prepare(
5271
name: &str,
5372
contracts: &[Contract],
73+
sources: Option<&[(String, String)]>,
5474
) -> anyhow::Result<(TestFile, String, bool)> {
5575
let dir = Self::dir(name);
5676
let name = format!("test/{name}");
5777

5878
Self::patch(&dir, contracts).await?;
5979

80+
// Patch source subgraph placeholders if provided
81+
if let Some(sources) = sources {
82+
Self::patch_sources(&dir, sources)?;
83+
}
84+
6085
// Check if subgraph has subgraph datasources
6186
let yaml_content = fs::read_to_string(dir.path.join("subgraph.yaml.patched"))?;
6287
let yaml: serde_yaml::Value = serde_yaml::from_str(&yaml_content)?;
@@ -68,9 +93,15 @@ impl Subgraph {
6893
Ok((dir, name, has_subgraph_datasource))
6994
}
7095

71-
/// Deploy the subgraph by running the required `graph` commands
72-
pub async fn deploy(name: &str, contracts: &[Contract]) -> anyhow::Result<String> {
73-
let (dir, name, has_subgraph_datasource) = Self::prepare(name, contracts).await?;
96+
/// Deploy the subgraph by running the required `graph` commands.
97+
/// If `sources` is provided, the deployment hashes will be used to patch
98+
/// source subgraph placeholders (e.g., `@source-subgraph@`) in the manifest.
99+
pub async fn deploy(
100+
name: &str,
101+
contracts: &[Contract],
102+
sources: Option<&[(String, String)]>,
103+
) -> anyhow::Result<String> {
104+
let (dir, name, has_subgraph_datasource) = Self::prepare(name, contracts, sources).await?;
74105

75106
// graph codegen subgraph.yaml
76107
let mut prog = Command::new(&CONFIG.graph_cli);

0 commit comments

Comments
 (0)