From 2c54603ac756533f8b6615220a66e58589c0da49 Mon Sep 17 00:00:00 2001 From: NanezX Date: Tue, 21 Nov 2023 20:06:17 -0400 Subject: [PATCH] remove cli subgraph to only use the rain binary --- subgraph/Cargo.lock | 463 ----------------------------------- subgraph/Cargo.toml | 21 -- subgraph/cli/cmd/mod.rs | 70 ------ subgraph/cli/main.rs | 64 ----- subgraph/cli/subgraph/mod.rs | 121 --------- subgraph/tests/cli.rs | 71 ------ 6 files changed, 810 deletions(-) delete mode 100644 subgraph/Cargo.lock delete mode 100644 subgraph/Cargo.toml delete mode 100644 subgraph/cli/cmd/mod.rs delete mode 100644 subgraph/cli/main.rs delete mode 100644 subgraph/cli/subgraph/mod.rs delete mode 100644 subgraph/tests/cli.rs diff --git a/subgraph/Cargo.lock b/subgraph/Cargo.lock deleted file mode 100644 index 50420d375..000000000 --- a/subgraph/Cargo.lock +++ /dev/null @@ -1,463 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "anstream" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" - -[[package]] -name = "anstyle-parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" -dependencies = [ - "anstyle", - "windows-sys", -] - -[[package]] -name = "anyhow" -version = "1.0.75" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "4.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" - -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "hashbrown" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "indexmap" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - -[[package]] -name = "pin-project-lite" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "serde" -version = "1.0.192" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.192" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_yaml" -version = "0.9.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "smallvec" -version = "1.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "subgraph" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "serde", - "serde_yaml", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "syn" -version = "2.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "nu-ansi-term", - "sharded-slab", - "smallvec", - "thread_local", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "unsafe-libyaml" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28467d3e1d3c6586d8f25fa243f544f5800fec42d97032474e17222c2b75cfa" - -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/subgraph/Cargo.toml b/subgraph/Cargo.toml deleted file mode 100644 index 4f8a4eed9..000000000 --- a/subgraph/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "subgraph" -version = "0.1.0" -edition = "2021" - - - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[[bin]] -name = "subgraph-cli" -path = "cli/main.rs" - -[dependencies] -anyhow = "1.0.70" -clap = { version = "4.4.6", features = ["cargo", "derive"] } -serde = { version = "1.0.192", features = ["derive"] } -serde_yaml = "0.9.27" -tracing = "0.1.40" -tracing-subscriber = "0.3.18" - - diff --git a/subgraph/cli/cmd/mod.rs b/subgraph/cli/cmd/mod.rs deleted file mode 100644 index 732995ef5..000000000 --- a/subgraph/cli/cmd/mod.rs +++ /dev/null @@ -1,70 +0,0 @@ -use anyhow::anyhow; -use std::{ - io::{BufRead, BufReader}, - process::{Command, Stdio}, - thread, -}; -use tracing::{debug, error, info}; - -/// Execute the command with the given arguments. -pub fn run(main_cmd: &str, args: &[&str]) -> anyhow::Result<()> { - let mut cmd = Command::new(main_cmd); - - cmd.args(args); - - cmd.stdout(Stdio::piped()); - cmd.stderr(Stdio::piped()); - - let full_cmd = format!("{} {}", main_cmd, args.join(" ")); - info!("Running: {}", full_cmd); - - // Execute the command - let mut child = cmd.spawn()?; - - // Read and print stdout in a separate thread - let stdout_child = child.stdout.take().expect("Should take stdout from child"); - let stdout_reader = BufReader::new(stdout_child); - - let stdout_handle = thread::spawn({ - move || { - for line in stdout_reader.lines() { - if let Ok(line) = line { - debug!("{}", line); - } - } - } - }); - - // Read and print stderr in the main thread - let stderr_reader = BufReader::new(child.stderr.take().expect("Should take stderr from child")); - for line in stderr_reader.lines() { - match line { - Ok(data) => { - debug!("{}", data); - } - Err(err) => { - error!("{}", err.to_string()); - } - } - } - - // Wait for the command to finish and get the exit status - let status = child.wait()?; - - // Wait for the stdout thread to finish - match stdout_handle.join() { - Ok(_) => (), - Err(_) => { - return Err(anyhow!("failed to wait for stdout thread")); - } - } - - if status.success() { - Ok(()) - } else { - return Err(anyhow::anyhow!( - "command execution failed with exit code: {}\n", - status.code().unwrap_or(-1) - )); - } -} diff --git a/subgraph/cli/main.rs b/subgraph/cli/main.rs deleted file mode 100644 index 7a3c6e9fc..000000000 --- a/subgraph/cli/main.rs +++ /dev/null @@ -1,64 +0,0 @@ -mod cmd; -mod subgraph; - -use clap::{Parser, Subcommand}; -use tracing::{subscriber, Level}; - -#[derive(Parser)] -#[clap(author, version, about)] -pub struct Cli { - #[clap(long, short = 'd', global = true)] - pub debug: bool, - - #[clap(subcommand)] - pub subgraph: Subgraph, -} - -#[derive(Subcommand)] -pub enum Subgraph { - #[command(about = "Build the rain subgraph code")] - Build, -} - -fn main() -> anyhow::Result<()> { - let args = Cli::parse(); - - if args.debug { - tracing_subscriber::fmt() - .with_max_level(Level::DEBUG) - .with_target(false) - .init(); - } else { - subscriber::set_global_default(tracing_subscriber::fmt::Subscriber::new())?; - } - - match args.subgraph { - Subgraph::Build => { - let config = subgraph::BuildArgs { - address: "0xff000000000000000000000000000000000000ff".to_string(), - network: "localhost".to_string(), - block_number: 0, - }; - - let resp_build = subgraph::build(config); - if resp_build.is_err() { - tracing::error!("{}", resp_build.err().unwrap().to_string()); - std::process::exit(1); - } - - let resp_codegen_cmd = cmd::run("npm", &["run", "codegen"]); - if resp_codegen_cmd.is_err() { - tracing::error!("{}", resp_codegen_cmd.err().unwrap().to_string()); - std::process::exit(1); - } - - let resp_build_cmd = cmd::run("npm", &["run", "build"]); - if resp_build_cmd.is_err() { - tracing::error!("{}", resp_build_cmd.err().unwrap().to_string()); - std::process::exit(1); - } - - Ok(()) - } - } -} diff --git a/subgraph/cli/subgraph/mod.rs b/subgraph/cli/subgraph/mod.rs deleted file mode 100644 index d57f641a8..000000000 --- a/subgraph/cli/subgraph/mod.rs +++ /dev/null @@ -1,121 +0,0 @@ -use clap::Args; -use serde::{Deserialize, Serialize}; -use std::fs::File; -use std::io::{Read, Write}; - -#[derive(Debug, Serialize, Deserialize)] -struct SubgraphTemplate { - #[serde(rename = "specVersion")] - spec_version: String, - schema: Schema, - #[serde(rename = "dataSources")] - data_sources: Vec, - templates: Vec, -} - -#[derive(Debug, Serialize, Deserialize)] -struct Schema { - file: String, -} - -/// Struct definition for DataSource and Template fields in subgraph YAML file -/// that describe every field for generated code -#[derive(Debug, Serialize, Deserialize)] -struct DataSource { - kind: String, - name: String, - network: String, - source: Source, - mapping: Mapping, -} - -#[derive(Debug, Serialize, Deserialize)] -struct Mapping { - kind: String, - #[serde(rename = "apiVersion")] - api_version: String, - language: String, - entities: Vec, - abis: Vec, - #[serde(rename = "eventHandlers")] - event_handlers: Vec, - file: String, -} - -#[derive(Debug, Serialize, Deserialize)] -struct Abi { - name: String, - file: String, -} - -#[derive(Debug, Serialize, Deserialize)] -struct EventHandler { - event: String, - handler: String, - #[serde(skip_serializing_if = "Option::is_none")] - receipt: Option, -} - -#[derive(Debug, Serialize, Deserialize)] -struct Source { - #[serde(skip_serializing_if = "Option::is_none")] - address: Option, - abi: String, - #[serde(rename = "startBlock", skip_serializing_if = "Option::is_none")] - start_block: Option, -} - -#[derive(Debug, Serialize, Deserialize)] -struct Template { - network: String, - source: Source, -} - -/// Arguments for building the yaml file to generate the code used by subgraph -#[derive(Args, Debug)] -pub struct BuildArgs { - /// Network that the subgraph will index - #[arg(long)] - pub network: String, - - /// Block number where the subgraph will start indexing - #[arg(long = "block")] - pub block_number: u64, - - /// Contract address that the subgraph will be indexing (Assuming one address) - #[arg(long)] - pub address: String, -} - -pub fn build(args: BuildArgs) -> anyhow::Result<()> { - let mut file = File::open("subgraph.template.yaml")?; - let mut contents = String::new(); - file.read_to_string(&mut contents)?; - - let mut yaml_data: SubgraphTemplate = serde_yaml::from_str(&contents)?; - // Update values in dataSources using the given arguments - for data_source in &mut yaml_data.data_sources { - data_source.network = args.network.clone(); - data_source.source.address = Some(format!("\"{}\"", args.address)); - data_source.source.start_block = Some(args.block_number); - } - - // Update values in templates using the given arguments - for template in &mut yaml_data.templates { - template.network = args.network.clone(); - } - - let mut modified_yaml = serde_yaml::to_string(&yaml_data)?; - - // TODO: Modifiy this since when serializing the string does not add the quotes. - // And when the quotes are added using format! macro, then two or three quotes - // are added. - modified_yaml = modified_yaml.replace("'\"", "'"); - modified_yaml = modified_yaml.replace("\"'", "'"); - - let mut modified_file = File::create("subgraph.yaml")?; - - modified_file.write_all(modified_yaml.as_bytes())?; - - Ok(()) -} diff --git a/subgraph/tests/cli.rs b/subgraph/tests/cli.rs deleted file mode 100644 index 2d1033809..000000000 --- a/subgraph/tests/cli.rs +++ /dev/null @@ -1,71 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[test] -fn yaml_serialization_string_single_quotes() -> anyhow::Result<()> { - // Initial YAML - let yaml = " - specVersion: 0.0.5 - address: '0xff0000000000000000000bb000000000000000cc' - "; - - // Address to change in the YAML - let new_address = "0xC3F675E9610e3E1f00874b1dD46BcEa6aFC57049".to_string(); - - #[derive(Debug, Serialize, Deserialize)] - struct Schema { - #[serde(rename = "specVersion")] - spec_version: String, - address: String, - } - - // Deserialize the YAML text - let mut yaml_data: Schema = serde_yaml::from_str(yaml)?; - - // Change the address - yaml_data.address = format!("'{}'", new_address); - - // Serialize back to YAML text - let yaml_resp = serde_yaml::to_string(&yaml_data)?; - - assert!( - !yaml_resp.contains(&format!("'''{}'''", new_address)), - "string with single quotes serialize with multiple single quotes" - ); - - Ok(()) -} - -#[test] -fn yaml_serialization_string_doublele_quotes() -> anyhow::Result<()> { - // Initial YAML - let yaml = " - specVersion: 0.0.5 - address: \"0xff0000000000000000000bb000000000000000cc\" - "; - - // Address to change in the YAML - let new_address = "0xC3F675E9610e3E1f00874b1dD46BcEa6aFC57049".to_string(); - - #[derive(Debug, Serialize, Deserialize)] - struct Schema { - #[serde(rename = "specVersion")] - spec_version: String, - address: String, - } - - // Deserialize the YAML text - let mut yaml_data: Schema = serde_yaml::from_str(yaml)?; - - // Change the address - yaml_data.address = format!("\"{}\"", new_address); - - // Serialize back to YAML text - let yaml_resp = serde_yaml::to_string(&yaml_data)?; - - assert!( - !yaml_resp.contains(&format!("'\"{}\"'", new_address)), - "string with double quotes serialize with multiple quotes" - ); - - Ok(()) -}