Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new target to forc #6621

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions docs/book/src/forc/plugins/forc_client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,30 @@ 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 --node-url https://beta-3.fuel.network
forc-deploy --mainnet
```

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:
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 --target beta-5
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 `testnet` you can use:

```sh
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/).
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
}

Expand Down
14 changes: 3 additions & 11 deletions forc-plugins/forc-client/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
/// 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.
pub const DEFAULT_PRIVATE_KEY: &str =
Expand Down
18 changes: 13 additions & 5 deletions forc-plugins/forc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +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<String>,

/// 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: [local, testnet, mainnet]
#[clap(long)]
pub target: Option<Target>,
/// 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.
/// 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`, `--target`, or `--testnet` to specify the Fuel node.
#[clap(long)]
pub mainnet: bool,
}
6 changes: 3 additions & 3 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_default();
let contract_url = match target.explorer_url() {
Some(explorer_url) => format!("{explorer_url}/contract/0x"),
None => "".to_string(),
Expand Down Expand Up @@ -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_default();
let contract_url = match target.explorer_url() {
Some(explorer_url) => format!("{explorer_url}/contract/0x"),
None => "".to_string(),
Expand Down Expand Up @@ -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_default();
let (contract_url, block_url) = match target.explorer_url() {
Some(explorer_url) => (
format!("{explorer_url}/contract/0x"),
Expand Down
86 changes: 31 additions & 55 deletions forc-plugins/forc-client/src/util/node_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@ pub fn get_node_url(
) -> Result<String> {
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)
Expand All @@ -35,70 +39,49 @@ 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_target_devnet() {
fn test_get_node_url_mainnet() {
let input = NodeTarget {
target: Some(Target::Devnet),
node_url: None,
testnet: false,
};
let actual = get_node_url(&input, &None).unwrap();
assert_eq!("https://devnet.fuel.network", actual);
}

#[test]
fn test_get_node_url_target_testnet() {
let input = NodeTarget {
target: Some(Target::Testnet),
target: None,
node_url: None,
testnet: false,
mainnet: true,
};

let actual = get_node_url(&input, &None).unwrap();
assert_eq!("https://testnet.fuel.network", actual);
assert_eq!("https://mainnet.fuel.network", actual);
}

#[test]
fn test_get_node_url_beta5() {
fn test_get_node_url_target_mainnet() {
let input = NodeTarget {
target: Some(Target::Beta5),
target: Some(Target::Mainnet),
node_url: None,
testnet: false,
mainnet: false,
};
let actual = get_node_url(&input, &None).unwrap();
assert_eq!("https://beta-5.fuel.network", actual);
assert_eq!("https://mainnet.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,
};
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(),
};
fn test_get_node_url_target_testnet() {
let input = NodeTarget {
target: None,
target: Some(Target::Testnet),
node_url: None,
testnet: false,
mainnet: false,
};

let actual = get_node_url(&input, &Some(network)).unwrap();
assert_eq!("https://beta-4.fuel.network", actual);
let actual = get_node_url(&input, &None).unwrap();
assert_eq!("https://testnet.fuel.network", actual);
}

#[test]
Expand All @@ -107,56 +90,49 @@ fn test_get_node_url_default() {
target: None,
node_url: None,
testnet: false,
mainnet: false,
};

let actual = get_node_url(&input, &None).unwrap();
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,
};
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 {
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);
}

#[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()),
target: Some(Target::Testnet),
node_url: Some("testnet.fuel.network".to_string()),
testnet: false,
mainnet: false,
};
get_node_url(&input, &None).unwrap();
}
Loading
Loading