From 64a1fc055d570b3121af7c26946b1465149be677 Mon Sep 17 00:00:00 2001 From: Sophie <47993817+sdankel@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:45:32 -0700 Subject: [PATCH 1/6] add new target to forc --- forc-plugins/forc-client/src/constants.rs | 2 + forc-plugins/forc-client/src/lib.rs | 8 ++- forc-plugins/forc-client/src/op/deploy.rs | 6 +-- forc-plugins/forc-client/src/util/node_url.rs | 54 ++++++++++++++++--- forc-plugins/forc-client/src/util/target.rs | 25 +++++++-- forc-plugins/forc-client/src/util/tx.rs | 2 +- forc-plugins/forc-client/tests/deploy.rs | 16 ++++++ 7 files changed, 97 insertions(+), 16 deletions(-) diff --git a/forc-plugins/forc-client/src/constants.rs b/forc-plugins/forc-client/src/constants.rs index f6e1faa4201..94a7a5aab67 100644 --- a/forc-plugins/forc-client/src/constants.rs +++ b/forc-plugins/forc-client/src/constants.rs @@ -6,6 +6,7 @@ pub const BETA_4_ENDPOINT_URL: &str = "https://beta-4.fuel.network"; pub const BETA_5_ENDPOINT_URL: &str = "https://beta-5.fuel.network"; pub const DEVNET_ENDPOINT_URL: &str = "https://devnet.fuel.network"; pub const TESTNET_ENDPOINT_URL: &str = "https://testnet.fuel.network"; +pub const MAINNET_ENDPOINT_URL: &str = "https://mainnet.fuel.network"; pub const BETA_2_FAUCET_URL: &str = "https://faucet-beta-2.fuel.network"; pub const BETA_3_FAUCET_URL: &str = "https://faucet-beta-3.fuel.network"; @@ -13,6 +14,7 @@ pub const BETA_4_FAUCET_URL: &str = "https://faucet-beta-4.fuel.network"; pub const BETA_5_FAUCET_URL: &str = "https://faucet-beta-5.fuel.network"; pub const DEVNET_FAUCET_URL: &str = "https://faucet-devnet.fuel.network"; pub const TESTNET_FAUCET_URL: &str = "https://faucet-testnet.fuel.network"; +pub const MAINNET_FAUCET_URL: &str = "https://faucet-mainnet.fuel.network"; pub const TESTNET_EXPLORER_URL: &str = "https://app.fuel.network"; diff --git a/forc-plugins/forc-client/src/lib.rs b/forc-plugins/forc-client/src/lib.rs index cce5e5ab95e..4536cd19786 100644 --- a/forc-plugins/forc-client/src/lib.rs +++ b/forc-plugins/forc-client/src/lib.rs @@ -24,9 +24,15 @@ pub struct NodeTarget { /// Possible values are: [beta-1, beta-2, beta-3, beta-4, local] #[clap(long)] pub target: Option, - /// Use preset configuration for the latest testnet. + /// Use preset configuration for testnet. /// /// You can also use `--node-url` or `--target` to specify the Fuel node. #[clap(long)] pub testnet: bool, + + /// Use preset configuration for mainnet. + /// + /// You can also use `--node-url` or `--target` to specify the Fuel node. + #[clap(long)] + pub mainnet: bool, } diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index 798fd788826..6c7afb882cc 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -192,7 +192,7 @@ async fn deploy_chunked( let storage_slots = resolve_storage_slots(command, compiled)?; let chain_info = provider.chain_info().await?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::testnet()); + let target = Target::from_str(&chain_info.name).unwrap_or(Target::local()); let contract_url = match target.explorer_url() { Some(explorer_url) => format!("{explorer_url}/contract/0x"), None => "".to_string(), @@ -257,7 +257,7 @@ async fn deploy_new_proxy( .into(); let chain_info = provider.chain_info().await?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::testnet()); + let target = Target::from_str(&chain_info.name).unwrap_or(Target::local()); let contract_url = match target.explorer_url() { Some(explorer_url) => format!("{explorer_url}/contract/0x"), None => "".to_string(), @@ -948,7 +948,7 @@ fn create_deployment_artifact( let contract_id = ContractId::from_str(&deployment_artifact.contract_id).unwrap(); let pkg_name = manifest.project_name(); - let target = Target::from_str(&chain_info.name).unwrap_or(Target::testnet()); + let target = Target::from_str(&chain_info.name).unwrap_or(Target::local()); let (contract_url, block_url) = match target.explorer_url() { Some(explorer_url) => ( format!("{explorer_url}/contract/0x"), diff --git a/forc-plugins/forc-client/src/util/node_url.rs b/forc-plugins/forc-client/src/util/node_url.rs index b7fe3f8bf39..f85e0b85e66 100644 --- a/forc-plugins/forc-client/src/util/node_url.rs +++ b/forc-plugins/forc-client/src/util/node_url.rs @@ -12,18 +12,22 @@ pub fn get_node_url( ) -> Result { let node_url = match ( node_target.testnet, + node_target.mainnet, node_target.target.clone(), node_target.node_url.clone(), ) { - (true, None, None) => Target::testnet().target_url(), - (false, Some(target), None) => target.target_url(), - (false, None, Some(node_url)) => node_url, - (false, None, None) => manifest_network + (true, false, None, None) => Target::testnet().target_url(), + (false, true, None, None) => Target::mainnet().target_url(), + (false, false, Some(target), None) => target.target_url(), + (false, false, None, Some(node_url)) => node_url, + (false, false, None, None) => manifest_network .as_ref() .map(|nw| &nw.url[..]) .unwrap_or(crate::constants::NODE_URL) .to_string(), - _ => bail!("Only one of `--testnet`, `--target`, or `--node-url` should be specified"), + _ => bail!( + "Only one of `--testnet`, `--mainnet`, `--target`, or `--node-url` should be specified" + ), }; Ok(node_url) @@ -35,29 +39,57 @@ fn test_get_node_url_testnet() { target: None, node_url: None, testnet: true, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); assert_eq!("https://testnet.fuel.network", actual); } +#[test] +fn test_get_node_url_mainnet() { + let input = NodeTarget { + target: None, + node_url: None, + testnet: false, + mainnet: true, + }; + + let actual = get_node_url(&input, &None).unwrap(); + assert_eq!("https://mainnet.fuel.network", actual); +} + #[test] fn test_get_node_url_target_devnet() { let input = NodeTarget { target: Some(Target::Devnet), node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); assert_eq!("https://devnet.fuel.network", actual); } +#[test] +fn test_get_node_url_target_mainnet() { + let input = NodeTarget { + target: Some(Target::Mainnet), + node_url: None, + testnet: false, + mainnet: false, + }; + let actual = get_node_url(&input, &None).unwrap(); + assert_eq!("https://mainnet.fuel.network", actual); +} + #[test] fn test_get_node_url_target_testnet() { let input = NodeTarget { target: Some(Target::Testnet), node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); @@ -70,6 +102,7 @@ fn test_get_node_url_beta5() { target: Some(Target::Beta5), node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); assert_eq!("https://beta-5.fuel.network", actual); @@ -81,6 +114,7 @@ fn test_get_node_url_beta4() { target: None, node_url: Some("https://beta-4.fuel.network".to_string()), testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); assert_eq!("https://beta-4.fuel.network", actual); @@ -95,6 +129,7 @@ fn test_get_node_url_url_beta4_manifest() { target: None, node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &Some(network)).unwrap(); @@ -107,6 +142,7 @@ fn test_get_node_url_default() { target: None, node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); @@ -119,6 +155,7 @@ fn test_get_node_url_beta3() { target: Some(Target::Beta3), node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); assert_eq!("https://beta-3.fuel.network", actual); @@ -130,6 +167,7 @@ fn test_get_node_url_local() { target: Some(Target::Local), node_url: None, testnet: false, + mainnet: false, }; let actual = get_node_url(&input, &None).unwrap(); assert_eq!("http://127.0.0.1:4000", actual); @@ -137,26 +175,28 @@ fn test_get_node_url_local() { #[test] #[should_panic( - expected = "Only one of `--testnet`, `--target`, or `--node-url` should be specified" + expected = "Only one of `--testnet`, `--mainnet`, `--target`, or `--node-url` should be specified" )] fn test_get_node_url_local_testnet() { let input = NodeTarget { target: Some(Target::Local), node_url: None, testnet: true, + mainnet: false, }; get_node_url(&input, &None).unwrap(); } #[test] #[should_panic( - expected = "Only one of `--testnet`, `--target`, or `--node-url` should be specified" + expected = "Only one of `--testnet`, `--mainnet`, `--target`, or `--node-url` should be specified" )] fn test_get_node_url_same_url() { let input = NodeTarget { target: Some(Target::Beta3), node_url: Some("beta-3.fuel.network".to_string()), testnet: false, + mainnet: false, }; get_node_url(&input, &None).unwrap(); } diff --git a/forc-plugins/forc-client/src/util/target.rs b/forc-plugins/forc-client/src/util/target.rs index 86b9b947666..2d9715d280e 100644 --- a/forc-plugins/forc-client/src/util/target.rs +++ b/forc-plugins/forc-client/src/util/target.rs @@ -1,8 +1,8 @@ use crate::constants::{ BETA_2_ENDPOINT_URL, BETA_2_FAUCET_URL, BETA_3_ENDPOINT_URL, BETA_3_FAUCET_URL, BETA_4_ENDPOINT_URL, BETA_4_FAUCET_URL, BETA_5_ENDPOINT_URL, BETA_5_FAUCET_URL, - DEVNET_ENDPOINT_URL, DEVNET_FAUCET_URL, NODE_URL, TESTNET_ENDPOINT_URL, TESTNET_EXPLORER_URL, - TESTNET_FAUCET_URL, + DEVNET_ENDPOINT_URL, DEVNET_FAUCET_URL, MAINNET_ENDPOINT_URL, NODE_URL, TESTNET_ENDPOINT_URL, + TESTNET_EXPLORER_URL, TESTNET_FAUCET_URL, }; use anyhow::{bail, Result}; use serde::{Deserialize, Serialize}; @@ -17,6 +17,7 @@ pub enum Target { Beta5, Devnet, Testnet, + Mainnet, Local, } @@ -35,6 +36,7 @@ impl Target { Target::Beta5 => BETA_5_ENDPOINT_URL, Target::Devnet => DEVNET_ENDPOINT_URL, Target::Testnet => TESTNET_ENDPOINT_URL, + Target::Mainnet => MAINNET_ENDPOINT_URL, Target::Local => NODE_URL, }; url.to_string() @@ -48,15 +50,24 @@ impl Target { BETA_5_ENDPOINT_URL => Some(Target::Beta5), DEVNET_ENDPOINT_URL => Some(Target::Devnet), TESTNET_ENDPOINT_URL => Some(Target::Testnet), + MAINNET_ENDPOINT_URL => Some(Target::Mainnet), NODE_URL => Some(Target::Local), _ => None, } } + pub fn local() -> Self { + Target::Local + } + pub fn testnet() -> Self { Target::Testnet } + pub fn mainnet() -> Self { + Target::Mainnet + } + pub fn faucet_url(&self) -> String { match self { Target::Beta2 => BETA_2_FAUCET_URL.to_string(), @@ -65,13 +76,16 @@ impl Target { Target::Beta5 => BETA_5_FAUCET_URL.to_string(), Target::Devnet => DEVNET_FAUCET_URL.to_string(), Target::Testnet => TESTNET_FAUCET_URL.to_string(), + Target::Mainnet => TESTNET_FAUCET_URL.to_string(), Target::Local => "http://localhost:3000".to_string(), } } pub fn explorer_url(&self) -> Option { match self { - Target::Testnet | Target::Devnet => Some(TESTNET_EXPLORER_URL.to_string()), + Target::Testnet | Target::Mainnet | Target::Devnet => { + Some(TESTNET_EXPLORER_URL.to_string()) + } _ => None, } } @@ -88,15 +102,17 @@ impl FromStr for Target { "beta-5" => Ok(Target::Beta5), "devnet" => Ok(Target::Devnet), "testnet" => Ok(Target::Testnet), + "mainnet" => Ok(Target::Mainnet), "local" => Ok(Target::Local), _ => bail!( - "'{s}' is not a valid target name. Possible values: '{}', '{}', '{}', '{}', '{}', '{}', '{}'", + "'{s}' is not a valid target name. Possible values: '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}'", Target::Beta2, Target::Beta3, Target::Beta4, Target::Beta5, Target::Devnet, Target::Testnet, + Target::Mainnet, Target::Local ), } @@ -112,6 +128,7 @@ impl std::fmt::Display for Target { Target::Beta5 => "beta-5", Target::Devnet => "devnet", Target::Testnet => "testnet", + Target::Mainnet => "mainnet", Target::Local => "local", }; write!(f, "{}", s) diff --git a/forc-plugins/forc-client/src/util/tx.rs b/forc-plugins/forc-client/src/util/tx.rs index d5a002e809f..b20ca4be700 100644 --- a/forc-plugins/forc-client/src/util/tx.rs +++ b/forc-plugins/forc-client/src/util/tx.rs @@ -181,7 +181,7 @@ pub(crate) async fn select_account( let first_account = accounts .get(&0) .ok_or_else(|| anyhow::anyhow!("No account derived for this wallet"))?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::testnet()); + let target = Target::from_str(&chain_info.name).unwrap_or(Target::local()); let faucet_link = format!("{}/?address={first_account}", target.faucet_url()); anyhow::bail!("Your wallet does not have any funds to pay for the transaction.\ \n\nIf you are interacting with a testnet consider using the faucet.\ diff --git a/forc-plugins/forc-client/tests/deploy.rs b/forc-plugins/forc-client/tests/deploy.rs index adb83853318..e1f416062ff 100644 --- a/forc-plugins/forc-client/tests/deploy.rs +++ b/forc-plugins/forc-client/tests/deploy.rs @@ -360,6 +360,7 @@ async fn test_simple_deploy() { node_url: Some(node_url), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -401,6 +402,7 @@ async fn test_deploy_submit_only() { node_url: Some(node_url), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -447,6 +449,7 @@ async fn test_deploy_fresh_proxy() { node_url: Some(node_url), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -498,6 +501,7 @@ async fn test_proxy_contract_re_routes_call() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -555,6 +559,7 @@ async fn test_proxy_contract_re_routes_call() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -629,6 +634,7 @@ async fn test_non_owner_fails_to_set_target() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -732,6 +738,7 @@ async fn chunked_deploy() { node_url: Some(node_url), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -764,6 +771,7 @@ async fn chunked_deploy_re_routes_calls() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -806,6 +814,7 @@ async fn chunked_deploy_with_proxy_re_routes_call() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -838,6 +847,7 @@ async fn can_deploy_script() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -868,6 +878,7 @@ async fn deploy_script_calls() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -899,6 +910,7 @@ async fn deploy_script_calls() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, @@ -989,6 +1001,7 @@ async fn can_deploy_predicates() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -1019,6 +1032,7 @@ async fn deployed_predicate_call() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -1164,6 +1178,7 @@ async fn call_with_forc_generated_overrides(node_url: &str, contract_id: Contrac node_url: Some(node_url.to_string()), target: None, testnet: false, + mainnet: false, }; let pkg = Pkg { path: Some(tmp_dir.path().display().to_string()), @@ -1273,6 +1288,7 @@ async fn offset_shifted_abi_works() { node_url: Some(node_url.clone()), target: None, testnet: false, + mainnet: false, }; let cmd = cmd::Deploy { pkg, From a0fa2cc41e622aa1c2ada17826d0ba4adb4096a1 Mon Sep 17 00:00:00 2001 From: Alfie John Date: Tue, 8 Oct 2024 11:45:35 +1100 Subject: [PATCH 2/6] Abstract default target network --- forc-plugins/forc-client/src/op/deploy.rs | 6 +++--- forc-plugins/forc-client/src/util/tx.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index 6c7afb882cc..cdc5d35162c 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -192,7 +192,7 @@ async fn deploy_chunked( let storage_slots = resolve_storage_slots(command, compiled)?; let chain_info = provider.chain_info().await?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::local()); + let target = Target::from_str(&chain_info.name).unwrap_or_default(); let contract_url = match target.explorer_url() { Some(explorer_url) => format!("{explorer_url}/contract/0x"), None => "".to_string(), @@ -257,7 +257,7 @@ async fn deploy_new_proxy( .into(); let chain_info = provider.chain_info().await?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::local()); + let target = Target::from_str(&chain_info.name).unwrap_or_default(); let contract_url = match target.explorer_url() { Some(explorer_url) => format!("{explorer_url}/contract/0x"), None => "".to_string(), @@ -948,7 +948,7 @@ fn create_deployment_artifact( let contract_id = ContractId::from_str(&deployment_artifact.contract_id).unwrap(); let pkg_name = manifest.project_name(); - let target = Target::from_str(&chain_info.name).unwrap_or(Target::local()); + let target = Target::from_str(&chain_info.name).unwrap_or_default(); let (contract_url, block_url) = match target.explorer_url() { Some(explorer_url) => ( format!("{explorer_url}/contract/0x"), diff --git a/forc-plugins/forc-client/src/util/tx.rs b/forc-plugins/forc-client/src/util/tx.rs index b20ca4be700..5b779b0e1f0 100644 --- a/forc-plugins/forc-client/src/util/tx.rs +++ b/forc-plugins/forc-client/src/util/tx.rs @@ -181,7 +181,7 @@ pub(crate) async fn select_account( let first_account = accounts .get(&0) .ok_or_else(|| anyhow::anyhow!("No account derived for this wallet"))?; - let target = Target::from_str(&chain_info.name).unwrap_or(Target::local()); + let target = Target::from_str(&chain_info.name).unwrap_or_default(); let faucet_link = format!("{}/?address={first_account}", target.faucet_url()); anyhow::bail!("Your wallet does not have any funds to pay for the transaction.\ \n\nIf you are interacting with a testnet consider using the faucet.\ From c77c37a11df6c60273a8bd8131dab36643298b16 Mon Sep 17 00:00:00 2001 From: Alfie John Date: Tue, 8 Oct 2024 11:47:34 +1100 Subject: [PATCH 3/6] Add Mainnet explorer URL in case they later diverge --- forc-plugins/forc-client/src/constants.rs | 1 + forc-plugins/forc-client/src/util/target.rs | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/forc-plugins/forc-client/src/constants.rs b/forc-plugins/forc-client/src/constants.rs index 94a7a5aab67..a6d4c40027b 100644 --- a/forc-plugins/forc-client/src/constants.rs +++ b/forc-plugins/forc-client/src/constants.rs @@ -17,6 +17,7 @@ pub const TESTNET_FAUCET_URL: &str = "https://faucet-testnet.fuel.network"; pub const MAINNET_FAUCET_URL: &str = "https://faucet-mainnet.fuel.network"; pub const TESTNET_EXPLORER_URL: &str = "https://app.fuel.network"; +pub const MAINNET_EXPLORER_URL: &str = "https://app.fuel.network"; /// Default PrivateKey to sign transactions submitted to local node. pub const DEFAULT_PRIVATE_KEY: &str = diff --git a/forc-plugins/forc-client/src/util/target.rs b/forc-plugins/forc-client/src/util/target.rs index 2d9715d280e..2b39b6ffc10 100644 --- a/forc-plugins/forc-client/src/util/target.rs +++ b/forc-plugins/forc-client/src/util/target.rs @@ -1,8 +1,8 @@ use crate::constants::{ BETA_2_ENDPOINT_URL, BETA_2_FAUCET_URL, BETA_3_ENDPOINT_URL, BETA_3_FAUCET_URL, BETA_4_ENDPOINT_URL, BETA_4_FAUCET_URL, BETA_5_ENDPOINT_URL, BETA_5_FAUCET_URL, - DEVNET_ENDPOINT_URL, DEVNET_FAUCET_URL, MAINNET_ENDPOINT_URL, NODE_URL, TESTNET_ENDPOINT_URL, - TESTNET_EXPLORER_URL, TESTNET_FAUCET_URL, + DEVNET_ENDPOINT_URL, DEVNET_FAUCET_URL, MAINNET_ENDPOINT_URL, MAINNET_EXPLORER_URL, NODE_URL, + TESTNET_ENDPOINT_URL, TESTNET_EXPLORER_URL, TESTNET_FAUCET_URL, }; use anyhow::{bail, Result}; use serde::{Deserialize, Serialize}; @@ -83,9 +83,8 @@ impl Target { pub fn explorer_url(&self) -> Option { match self { - Target::Testnet | Target::Mainnet | Target::Devnet => { - Some(TESTNET_EXPLORER_URL.to_string()) - } + Target::Testnet | Target::Devnet => Some(TESTNET_EXPLORER_URL.to_string()), + Target::Mainnet => Some(MAINNET_EXPLORER_URL.to_string()), _ => None, } } From a75450a00023c07b8ca1b52dd4ab98d75ae7cffc Mon Sep 17 00:00:00 2001 From: Alfie John Date: Tue, 8 Oct 2024 12:21:39 +1100 Subject: [PATCH 4/6] Only show faucet URL for non-mainnet targets --- forc-plugins/forc-client/src/constants.rs | 1 - forc-plugins/forc-client/src/util/target.rs | 18 +++++++++--------- forc-plugins/forc-client/src/util/tx.rs | 17 ++++++++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/forc-plugins/forc-client/src/constants.rs b/forc-plugins/forc-client/src/constants.rs index a6d4c40027b..853efc35932 100644 --- a/forc-plugins/forc-client/src/constants.rs +++ b/forc-plugins/forc-client/src/constants.rs @@ -14,7 +14,6 @@ pub const BETA_4_FAUCET_URL: &str = "https://faucet-beta-4.fuel.network"; pub const BETA_5_FAUCET_URL: &str = "https://faucet-beta-5.fuel.network"; pub const DEVNET_FAUCET_URL: &str = "https://faucet-devnet.fuel.network"; pub const TESTNET_FAUCET_URL: &str = "https://faucet-testnet.fuel.network"; -pub const MAINNET_FAUCET_URL: &str = "https://faucet-mainnet.fuel.network"; pub const TESTNET_EXPLORER_URL: &str = "https://app.fuel.network"; pub const MAINNET_EXPLORER_URL: &str = "https://app.fuel.network"; diff --git a/forc-plugins/forc-client/src/util/target.rs b/forc-plugins/forc-client/src/util/target.rs index 2b39b6ffc10..aae50248afd 100644 --- a/forc-plugins/forc-client/src/util/target.rs +++ b/forc-plugins/forc-client/src/util/target.rs @@ -68,16 +68,16 @@ impl Target { Target::Mainnet } - pub fn faucet_url(&self) -> String { + pub fn faucet_url(&self) -> Option { match self { - Target::Beta2 => BETA_2_FAUCET_URL.to_string(), - Target::Beta3 => BETA_3_FAUCET_URL.to_string(), - Target::Beta4 => BETA_4_FAUCET_URL.to_string(), - Target::Beta5 => BETA_5_FAUCET_URL.to_string(), - Target::Devnet => DEVNET_FAUCET_URL.to_string(), - Target::Testnet => TESTNET_FAUCET_URL.to_string(), - Target::Mainnet => TESTNET_FAUCET_URL.to_string(), - Target::Local => "http://localhost:3000".to_string(), + Target::Beta2 => Some(BETA_2_FAUCET_URL.to_string()), + Target::Beta3 => Some(BETA_3_FAUCET_URL.to_string()), + Target::Beta4 => Some(BETA_4_FAUCET_URL.to_string()), + Target::Beta5 => Some(BETA_5_FAUCET_URL.to_string()), + Target::Devnet => Some(DEVNET_FAUCET_URL.to_string()), + Target::Testnet => Some(TESTNET_FAUCET_URL.to_string()), + Target::Mainnet => None, + Target::Local => Some("http://localhost:3000".to_string()), } } diff --git a/forc-plugins/forc-client/src/util/tx.rs b/forc-plugins/forc-client/src/util/tx.rs index 5b779b0e1f0..d1ceb751194 100644 --- a/forc-plugins/forc-client/src/util/tx.rs +++ b/forc-plugins/forc-client/src/util/tx.rs @@ -182,11 +182,18 @@ pub(crate) async fn select_account( .get(&0) .ok_or_else(|| anyhow::anyhow!("No account derived for this wallet"))?; let target = Target::from_str(&chain_info.name).unwrap_or_default(); - let faucet_link = format!("{}/?address={first_account}", target.faucet_url()); - anyhow::bail!("Your wallet does not have any funds to pay for the transaction.\ - \n\nIf you are interacting with a testnet consider using the faucet.\ - \n-> {target} network faucet: {faucet_link}\ - \nIf you are interacting with a local node, consider providing a chainConfig which funds your account.") + let message = if let Some(faucet_url) = target.faucet_url() { + format!( + "Your wallet does not have any funds to pay for the transaction.\ + \n\nIf you are interacting with a testnet, consider using the faucet.\ + \n-> {target} network faucet: {}/?address={first_account}\ + \nIf you are interacting with a local node, consider providing a chainConfig which funds your account.", + faucet_url + ) + } else { + "Your wallet does not have any funds to pay for the transaction.".to_string() + }; + anyhow::bail!(message) } let selections = format_base_asset_account_balances(&accounts, &account_balances, base_asset_id); From 78188c6ac777e165c578c397340e0e17626f2a96 Mon Sep 17 00:00:00 2001 From: Alfie John Date: Tue, 8 Oct 2024 12:55:49 +1100 Subject: [PATCH 5/6] Documentation updatess --- docs/book/src/forc/plugins/forc_client/index.md | 12 +++++++++--- forc-plugins/forc-client/src/lib.rs | 12 +++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/docs/book/src/forc/plugins/forc_client/index.md b/docs/book/src/forc/plugins/forc_client/index.md index 13800088b96..88b5f966bea 100644 --- a/docs/book/src/forc/plugins/forc_client/index.md +++ b/docs/book/src/forc/plugins/forc_client/index.md @@ -92,15 +92,21 @@ By default `--default-signer` flag would sign your transactions with the followi 0xde97d8624a438121b86a1956544bd72ed68cd69f2c99555b08b1e8c51ffd511c ``` -## Interacting with the testnet +## Selecting a target network -To interact with the latest testnet, use the `--testnet` flag. When this flag is passed, transactions created by `forc-deploy` will be sent to the latest `testnet`. +By default, `local` is used for the target network. To interact with the latest testnet, use the `--testnet` flag. When this flag is passed, transactions created by `forc-deploy` will be sent to the latest `testnet`: ```sh forc-deploy --testnet ``` -It is also possible to pass the exact node URL while using `forc-deploy` or `forc-run` which can be done using `--node-url` flag. +The same can be done to target mainnet: + +```sh +forc-deploy --mainnet +``` + +It is also possible to pass the exact node URL while using `forc-deploy` or `forc-run` which can be done using `--node-url` flag: ```sh forc-deploy --node-url https://beta-3.fuel.network diff --git a/forc-plugins/forc-client/src/lib.rs b/forc-plugins/forc-client/src/lib.rs index 4536cd19786..b291ecfde90 100644 --- a/forc-plugins/forc-client/src/lib.rs +++ b/forc-plugins/forc-client/src/lib.rs @@ -14,25 +14,27 @@ pub struct NodeTarget { /// If unspecified, checks the manifest's `network` table, then falls back /// to `http://127.0.0.1:4000` /// - /// You can also use `--target` or `--testnet` to specify the Fuel node. + /// You can also use `--target`, `--testnet`, or `--mainnet` to specify the Fuel node. #[clap(long, env = "FUEL_NODE_URL")] pub node_url: Option, + /// Use preset configurations for deploying to a specific target. /// - /// You can also use `--node-url` or `--testnet` to specify the Fuel node. + /// You can also use `--node-url`, `--testnet`, or `--mainnet` to specify the Fuel node. /// - /// Possible values are: [beta-1, beta-2, beta-3, beta-4, local] + /// Possible values are: [beta-1, beta-2, beta-3, beta-4, devnet, local, testnet, mainnet] #[clap(long)] pub target: Option, + /// Use preset configuration for testnet. /// - /// You can also use `--node-url` or `--target` to specify the Fuel node. + /// You can also use `--node-url`, `--target`, or `--mainnet` to specify the Fuel node. #[clap(long)] pub testnet: bool, /// Use preset configuration for mainnet. /// - /// You can also use `--node-url` or `--target` to specify the Fuel node. + /// You can also use `--node-url`, `--target`, or `--testnet` to specify the Fuel node. #[clap(long)] pub mainnet: bool, } From 36ecab670120f57eb29008e0960f82bd539f35b0 Mon Sep 17 00:00:00 2001 From: Joshua Batty Date: Tue, 15 Oct 2024 14:14:58 +1100 Subject: [PATCH 6/6] remove beta and devnet refs (#6634) ## Description Removes any references to beta networks and unmaintained devnet channels. ## Checklist - [ ] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [ ] I have requested a review from the relevant team or maintainers. --- .../src/forc/plugins/forc_client/index.md | 6 +- forc-plugins/forc-client/src/cmd/deploy.rs | 2 +- forc-plugins/forc-client/src/constants.rs | 12 +--- forc-plugins/forc-client/src/lib.rs | 2 +- forc-plugins/forc-client/src/util/node_url.rs | 68 +------------------ forc-plugins/forc-client/src/util/target.rs | 45 ++---------- 6 files changed, 12 insertions(+), 123 deletions(-) diff --git a/docs/book/src/forc/plugins/forc_client/index.md b/docs/book/src/forc/plugins/forc_client/index.md index 88b5f966bea..feb436af788 100644 --- a/docs/book/src/forc/plugins/forc_client/index.md +++ b/docs/book/src/forc/plugins/forc_client/index.md @@ -109,13 +109,13 @@ forc-deploy --mainnet It is also possible to pass the exact node URL while using `forc-deploy` or `forc-run` which can be done using `--node-url` flag: ```sh -forc-deploy --node-url https://beta-3.fuel.network +forc-deploy --node-url https://mainnet.fuel.network ``` -Another alternative is the `--target` option, which provides useful aliases to all targets. For example if you want to deploy to `beta-5` you can use: +Another alternative is the `--target` option, which provides useful aliases to all targets. For example if you want to deploy to `testnet` you can use: ```sh -forc-deploy --target beta-5 +forc-deploy --target testnet ``` Since deploying and running projects on the testnet cost gas, you will need coins to pay for them. You can get some using the [testnet faucet](https://faucet-testnet.fuel.network/). diff --git a/forc-plugins/forc-client/src/cmd/deploy.rs b/forc-plugins/forc-client/src/cmd/deploy.rs index 5553a2fe06b..87428dfbca7 100644 --- a/forc-plugins/forc-client/src/cmd/deploy.rs +++ b/forc-plugins/forc-client/src/cmd/deploy.rs @@ -10,7 +10,7 @@ forc_util::cli_examples! { super::Command { [ Deploy a single contract => "forc deploy bc09bfa7a11a04ce42b0a5abf04fd437387ee49bf4561d575177e2946468b408" ] [ Deploy a single contract from a different path => "forc deploy bc09bfa7a11a04ce42b0a5abf04fd437387ee49bf4561d575177e2946468b408 --path {path}" ] - [ Deploy to a custom network => "forc deploy --node-url https://beta-5.fuel.network/graphql" ] + [ Deploy to a custom network => "forc deploy --node-url https://testnet.fuel.network/graphql" ] } } diff --git a/forc-plugins/forc-client/src/constants.rs b/forc-plugins/forc-client/src/constants.rs index 853efc35932..1b195f733e6 100644 --- a/forc-plugins/forc-client/src/constants.rs +++ b/forc-plugins/forc-client/src/constants.rs @@ -1,21 +1,11 @@ /// Default to localhost to favour the common case of testing. pub const NODE_URL: &str = sway_utils::constants::DEFAULT_NODE_URL; -pub const BETA_2_ENDPOINT_URL: &str = "https://node-beta-2.fuel.network"; -pub const BETA_3_ENDPOINT_URL: &str = "https://beta-3.fuel.network"; -pub const BETA_4_ENDPOINT_URL: &str = "https://beta-4.fuel.network"; -pub const BETA_5_ENDPOINT_URL: &str = "https://beta-5.fuel.network"; -pub const DEVNET_ENDPOINT_URL: &str = "https://devnet.fuel.network"; pub const TESTNET_ENDPOINT_URL: &str = "https://testnet.fuel.network"; pub const MAINNET_ENDPOINT_URL: &str = "https://mainnet.fuel.network"; -pub const BETA_2_FAUCET_URL: &str = "https://faucet-beta-2.fuel.network"; -pub const BETA_3_FAUCET_URL: &str = "https://faucet-beta-3.fuel.network"; -pub const BETA_4_FAUCET_URL: &str = "https://faucet-beta-4.fuel.network"; -pub const BETA_5_FAUCET_URL: &str = "https://faucet-beta-5.fuel.network"; -pub const DEVNET_FAUCET_URL: &str = "https://faucet-devnet.fuel.network"; pub const TESTNET_FAUCET_URL: &str = "https://faucet-testnet.fuel.network"; -pub const TESTNET_EXPLORER_URL: &str = "https://app.fuel.network"; +pub const TESTNET_EXPLORER_URL: &str = "https://app-testnet.fuel.network"; pub const MAINNET_EXPLORER_URL: &str = "https://app.fuel.network"; /// Default PrivateKey to sign transactions submitted to local node. diff --git a/forc-plugins/forc-client/src/lib.rs b/forc-plugins/forc-client/src/lib.rs index b291ecfde90..a4db6b262a1 100644 --- a/forc-plugins/forc-client/src/lib.rs +++ b/forc-plugins/forc-client/src/lib.rs @@ -22,7 +22,7 @@ pub struct NodeTarget { /// /// You can also use `--node-url`, `--testnet`, or `--mainnet` to specify the Fuel node. /// - /// Possible values are: [beta-1, beta-2, beta-3, beta-4, devnet, local, testnet, mainnet] + /// Possible values are: [local, testnet, mainnet] #[clap(long)] pub target: Option, diff --git a/forc-plugins/forc-client/src/util/node_url.rs b/forc-plugins/forc-client/src/util/node_url.rs index f85e0b85e66..58e9dcd87e1 100644 --- a/forc-plugins/forc-client/src/util/node_url.rs +++ b/forc-plugins/forc-client/src/util/node_url.rs @@ -59,18 +59,6 @@ fn test_get_node_url_mainnet() { assert_eq!("https://mainnet.fuel.network", actual); } -#[test] -fn test_get_node_url_target_devnet() { - let input = NodeTarget { - target: Some(Target::Devnet), - node_url: None, - testnet: false, - mainnet: false, - }; - let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://devnet.fuel.network", actual); -} - #[test] fn test_get_node_url_target_mainnet() { let input = NodeTarget { @@ -96,46 +84,6 @@ fn test_get_node_url_target_testnet() { assert_eq!("https://testnet.fuel.network", actual); } -#[test] -fn test_get_node_url_beta5() { - let input = NodeTarget { - target: Some(Target::Beta5), - node_url: None, - testnet: false, - mainnet: false, - }; - let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://beta-5.fuel.network", actual); -} - -#[test] -fn test_get_node_url_beta4() { - let input = NodeTarget { - target: None, - node_url: Some("https://beta-4.fuel.network".to_string()), - testnet: false, - mainnet: false, - }; - let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://beta-4.fuel.network", actual); -} - -#[test] -fn test_get_node_url_url_beta4_manifest() { - let network = Network { - url: "https://beta-4.fuel.network".to_string(), - }; - let input = NodeTarget { - target: None, - node_url: None, - testnet: false, - mainnet: false, - }; - - let actual = get_node_url(&input, &Some(network)).unwrap(); - assert_eq!("https://beta-4.fuel.network", actual); -} - #[test] fn test_get_node_url_default() { let input = NodeTarget { @@ -149,18 +97,6 @@ fn test_get_node_url_default() { assert_eq!("http://127.0.0.1:4000", actual); } -#[test] -fn test_get_node_url_beta3() { - let input = NodeTarget { - target: Some(Target::Beta3), - node_url: None, - testnet: false, - mainnet: false, - }; - let actual = get_node_url(&input, &None).unwrap(); - assert_eq!("https://beta-3.fuel.network", actual); -} - #[test] fn test_get_node_url_local() { let input = NodeTarget { @@ -193,8 +129,8 @@ fn test_get_node_url_local_testnet() { )] fn test_get_node_url_same_url() { let input = NodeTarget { - target: Some(Target::Beta3), - node_url: Some("beta-3.fuel.network".to_string()), + target: Some(Target::Testnet), + node_url: Some("testnet.fuel.network".to_string()), testnet: false, mainnet: false, }; diff --git a/forc-plugins/forc-client/src/util/target.rs b/forc-plugins/forc-client/src/util/target.rs index aae50248afd..3982f91ce07 100644 --- a/forc-plugins/forc-client/src/util/target.rs +++ b/forc-plugins/forc-client/src/util/target.rs @@ -1,8 +1,6 @@ use crate::constants::{ - BETA_2_ENDPOINT_URL, BETA_2_FAUCET_URL, BETA_3_ENDPOINT_URL, BETA_3_FAUCET_URL, - BETA_4_ENDPOINT_URL, BETA_4_FAUCET_URL, BETA_5_ENDPOINT_URL, BETA_5_FAUCET_URL, - DEVNET_ENDPOINT_URL, DEVNET_FAUCET_URL, MAINNET_ENDPOINT_URL, MAINNET_EXPLORER_URL, NODE_URL, - TESTNET_ENDPOINT_URL, TESTNET_EXPLORER_URL, TESTNET_FAUCET_URL, + MAINNET_ENDPOINT_URL, MAINNET_EXPLORER_URL, NODE_URL, TESTNET_ENDPOINT_URL, + TESTNET_EXPLORER_URL, TESTNET_FAUCET_URL, }; use anyhow::{bail, Result}; use serde::{Deserialize, Serialize}; @@ -11,11 +9,6 @@ use std::str::FromStr; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] /// Possible target values that forc-client can interact with. pub enum Target { - Beta2, - Beta3, - Beta4, - Beta5, - Devnet, Testnet, Mainnet, Local, @@ -30,11 +23,6 @@ impl Default for Target { impl Target { pub fn target_url(&self) -> String { let url = match self { - Target::Beta2 => BETA_2_ENDPOINT_URL, - Target::Beta3 => BETA_3_ENDPOINT_URL, - Target::Beta4 => BETA_4_ENDPOINT_URL, - Target::Beta5 => BETA_5_ENDPOINT_URL, - Target::Devnet => DEVNET_ENDPOINT_URL, Target::Testnet => TESTNET_ENDPOINT_URL, Target::Mainnet => MAINNET_ENDPOINT_URL, Target::Local => NODE_URL, @@ -44,11 +32,6 @@ impl Target { pub fn from_target_url(target_url: &str) -> Option { match target_url { - BETA_2_ENDPOINT_URL => Some(Target::Beta2), - BETA_3_ENDPOINT_URL => Some(Target::Beta3), - BETA_4_ENDPOINT_URL => Some(Target::Beta4), - BETA_5_ENDPOINT_URL => Some(Target::Beta5), - DEVNET_ENDPOINT_URL => Some(Target::Devnet), TESTNET_ENDPOINT_URL => Some(Target::Testnet), MAINNET_ENDPOINT_URL => Some(Target::Mainnet), NODE_URL => Some(Target::Local), @@ -70,11 +53,6 @@ impl Target { pub fn faucet_url(&self) -> Option { match self { - Target::Beta2 => Some(BETA_2_FAUCET_URL.to_string()), - Target::Beta3 => Some(BETA_3_FAUCET_URL.to_string()), - Target::Beta4 => Some(BETA_4_FAUCET_URL.to_string()), - Target::Beta5 => Some(BETA_5_FAUCET_URL.to_string()), - Target::Devnet => Some(DEVNET_FAUCET_URL.to_string()), Target::Testnet => Some(TESTNET_FAUCET_URL.to_string()), Target::Mainnet => None, Target::Local => Some("http://localhost:3000".to_string()), @@ -83,7 +61,7 @@ impl Target { pub fn explorer_url(&self) -> Option { match self { - Target::Testnet | Target::Devnet => Some(TESTNET_EXPLORER_URL.to_string()), + Target::Testnet => Some(TESTNET_EXPLORER_URL.to_string()), Target::Mainnet => Some(MAINNET_EXPLORER_URL.to_string()), _ => None, } @@ -95,21 +73,11 @@ impl FromStr for Target { fn from_str(s: &str) -> Result { match s { - "beta-2" => Ok(Target::Beta2), - "beta-3" => Ok(Target::Beta3), - "beta-4" => Ok(Target::Beta4), - "beta-5" => Ok(Target::Beta5), - "devnet" => Ok(Target::Devnet), "testnet" => Ok(Target::Testnet), "mainnet" => Ok(Target::Mainnet), "local" => Ok(Target::Local), _ => bail!( - "'{s}' is not a valid target name. Possible values: '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}'", - Target::Beta2, - Target::Beta3, - Target::Beta4, - Target::Beta5, - Target::Devnet, + "'{s}' is not a valid target name. Possible values: '{}', '{}', '{}'", Target::Testnet, Target::Mainnet, Target::Local @@ -121,11 +89,6 @@ impl FromStr for Target { impl std::fmt::Display for Target { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = match self { - Target::Beta2 => "beta-2", - Target::Beta3 => "beta-3", - Target::Beta4 => "beta-4", - Target::Beta5 => "beta-5", - Target::Devnet => "devnet", Target::Testnet => "testnet", Target::Mainnet => "mainnet", Target::Local => "local",