Skip to content

Commit 533a612

Browse files
committed
gnd: Create networks.json in init --from-contract
Previously, `gnd init --from-contract` would not create a networks.json file, unlike `gnd init --from-example`. This meant users had to manually create the networks.json configuration or experience errors when trying to deploy to different networks. Now, when scaffolding from a contract address, gnd creates a networks.json file with the contract name, address, and start block configuration for the specified network. Issue: I5 from PR 6282 review feedback
1 parent 6f715e1 commit 533a612

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

gnd/src/commands/init.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use anyhow::{anyhow, Context, Result};
1717
use clap::{Parser, ValueEnum};
1818
use graphql_parser::schema as gql;
1919

20+
use crate::config::networks::update_networks_file;
2021
use crate::output::{step, with_spinner, Step};
2122
use crate::prompt::{
2223
get_subgraph_basename, prompt_directory_with_confirm, prompt_subgraph_slug_with_confirm,
@@ -362,6 +363,16 @@ async fn init_from_contract(opt: &InitOpt) -> Result<()> {
362363

363364
generate_scaffold(&directory, &scaffold_options)?;
364365

366+
// Create networks.json with the contract configuration
367+
let networks_path = directory.join("networks.json");
368+
update_networks_file(
369+
&networks_path,
370+
network,
371+
&contract_name,
372+
address,
373+
start_block,
374+
)?;
375+
365376
// Initialize git unless skipped
366377
if !opt.skip_git {
367378
let _ = init_git(&directory);

gnd/tests/cli_commands.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,20 @@ fn test_init_from_contract_with_abi() {
282282
manifest.contains("SimpleContract"),
283283
"Manifest should contain contract name"
284284
);
285+
286+
// Verify networks.json was created with contract config
287+
let networks_path = subgraph_dir.join("networks.json");
288+
assert!(networks_path.exists(), "networks.json should exist");
289+
290+
let networks: serde_json::Value =
291+
serde_json::from_str(&fs::read_to_string(&networks_path).unwrap()).unwrap();
292+
assert!(
293+
networks["mainnet"]["SimpleContract"]["address"]
294+
.as_str()
295+
.unwrap()
296+
.contains("0x5fbdb2315678afecb367f032d93f642f64180aa3"),
297+
"networks.json should contain contract address"
298+
);
285299
}
286300

287301
#[test]

0 commit comments

Comments
 (0)