Skip to content

Commit f145736

Browse files
committed
tests: Change grafted test to not use hardcoded POIs
We want to make the test independent of the IPFS hash of the subgraphs involved. Instead of using hardcoded POIs, we calculate them during the test
1 parent fd7dfe7 commit f145736

4 files changed

Lines changed: 255 additions & 105 deletions

File tree

pnpm-lock.yaml

Lines changed: 0 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration-tests/grafted/subgraph.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ dataSources:
2626
features:
2727
- grafting
2828
graft:
29-
base: QmTQbJ234d2Po7xKZS5wKPiYuMYsCAqqY4df5czESjEXn4
30-
block: 2
29+
base: '@base@'
30+
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)