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

feat: add beta-4 target, and point --testnet to beta-4 network for forc-deploy #4974

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 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
16 changes: 11 additions & 5 deletions docs/book/src/forc/plugins/forc_client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,26 @@ By default `--default-signer` flag would sign your transactions with the followi

## Interacting with the testnet

While using `forc-deploy` or `forc-run` to interact with the testnet you need to pass the testnet end point with `--node-url`
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 `beta-4` testnet.

```sh
forc-deploy --node-url https://beta-3.fuel.network/graphql
forc-deploy --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-beta-3.fuel.network/).
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/graphql
```

Also the default value of the "gas price" parameter is 0 for both `forc-deploy` and `forc-run`. Without changing it you will get an error complaining about gas price being too low. While using testnet you can pass `--gas-price 1` to overcome this issue. So a complete command for deploying to the testnet would look like:
Another alternative is the `--target` option, which provides useful aliases to all targets. For example if you want to deploy to `beta-3` you can use:

```sh
forc-deploy --node-url https://beta-3.fuel.network/graphql --gas-price 1
forc-deploy --target beta-3
```

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-beta-4.fuel.network/).

## Deployment Artifacts

forc-deploy saves the details of each deployment in the `out/deployments` folder within the project's root directory. Below is an example of a deployment artifact:
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 @@ -56,7 +56,7 @@ pub struct Command {
pub manual_signing: bool,
/// Use preset configurations for deploying to a specific target.
///
/// Possible values are: [beta-1, beta-2, beta-3, latest]
/// Possible values are: [beta-1, beta-2, beta-3, beta-4, local]
#[clap(long)]
pub target: Option<Target>,
/// Use preset configuration for the latest testnet.
Expand Down
1 change: 1 addition & 0 deletions forc-plugins/forc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pub mod default {
pub const NODE_URL: &str = sway_utils::constants::DEFAULT_NODE_URL;
pub const BETA_2_ENDPOINT_URL: &str = "node-beta-2.fuel.network/graphql";
pub const BETA_3_ENDPOINT_URL: &str = "beta-3.fuel.network/graphql";
pub const BETA_4_ENDPOINT_URL: &str = "beta-4.fuel.network/graphql";
pub const BETA_4_FAUCET_URL: &str = "https://faucet-beta-4.fuel.network";
}
73 changes: 42 additions & 31 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,44 +199,55 @@ pub async fn deploy(command: cmd::Deploy) -> Result<Vec<DeployedContract>> {

/// Applies specified target information to the provided arguments.
///
/// Basically provides preset configurations for known test-nets.
/// Provides preset configurations for known testnets.
fn apply_target(command: cmd::Deploy) -> Result<cmd::Deploy> {
let deploy_to_latest_testnet = command.testnet;
let target = if deploy_to_latest_testnet {
if command.target.is_some() {
bail!("Both `--testnet` and `--target` were specified: must choose one")
}
Some(Target::Beta3)
} else {
command.target.clone()
let target = match (
command.testnet,
command.target.clone(),
command.node_url.clone(),
) {
(true, None, None) => Some(Target::Beta4),
(false, Some(target), None) => Some(target),
(false, None, Some(node_url)) => Target::from_target_url(node_url.as_str()),
(false, None, None) => None,
_ => bail!("Only one of `--testnet`, `--target`, or `--node-url` should be specified"),
};

// If the user specified a testnet target, we can override the gas price and limit.
if let Some(target) = target {
match target {
cmd::deploy::Target::Beta2 | cmd::deploy::Target::Beta3 => {
// If the user did not specified a gas price, we can use `1` as a gas price for
// beta test-nets.
let gas_price = if command.gas.price == 0 {
1
} else {
command.gas.price
};
if target.is_testnet() {
// If the user did not specify a gas price, we can use `1` as a gas price for
// beta test-nets.
let gas_price = if command.gas.price == 0 {
1
} else {
command.gas.price
};

let target_url = Some(target.target_url().to_string());
Ok(cmd::Deploy {
gas: Gas {
price: gas_price,
..command.gas
},
node_url: target_url,
..command
})
}
cmd::deploy::Target::LATEST => Ok(command),
// fuel_tx::ConsensusParameters::DEFAULT.max_gas_per_tx is the default value for
// the gas.limit field.
let gas_limit = if command.gas.limit
== fuel_tx::ConsensusParameters::DEFAULT.max_gas_per_tx
&& target == cmd::deploy::Target::Beta4
{
1
} else {
command.gas.limit
};
kayagokalp marked this conversation as resolved.
Show resolved Hide resolved

let target_url = Some(target.target_url().to_string());
return Ok(cmd::Deploy {
gas: Gas {
price: gas_price,
limit: gas_limit,
},
node_url: target_url,
..command
});
}
} else {
Ok(command)
}

Ok(command)
}

/// Deploy a single pkg given deploy command and the manifest file
Expand Down
63 changes: 48 additions & 15 deletions forc-plugins/forc-client/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ pub(crate) mod encode;
pub(crate) mod pkg;
pub(crate) mod tx;

use crate::default::{BETA_2_ENDPOINT_URL, BETA_3_ENDPOINT_URL, NODE_URL};
use crate::default::{BETA_2_ENDPOINT_URL, BETA_3_ENDPOINT_URL, BETA_4_ENDPOINT_URL, NODE_URL};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
/// Possible target values that forc-client can interact with.
pub enum Target {
Beta2,
Beta3,
LATEST,
Beta4,
Local,
}

impl Default for Target {
fn default() -> Self {
Self::LATEST
Self::Local
}
}

Expand All @@ -25,7 +26,25 @@ impl Target {
match self {
Target::Beta2 => BETA_2_ENDPOINT_URL,
Target::Beta3 => BETA_3_ENDPOINT_URL,
Target::LATEST => NODE_URL,
Target::Beta4 => BETA_4_ENDPOINT_URL,
Target::Local => NODE_URL,
}
}

pub fn from_target_url(target_url: &str) -> Option<Self> {
match target_url {
BETA_2_ENDPOINT_URL => Some(Target::Beta2),
BETA_3_ENDPOINT_URL => Some(Target::Beta3),
BETA_4_ENDPOINT_URL => Some(Target::Beta4),
NODE_URL => Some(Target::Local),
_ => None,
}
}

pub fn is_testnet(&self) -> bool {
match self {
Target::Beta2 | Target::Beta3 | Target::Beta4 => true,
Target::Local => false,
}
}
}
Expand All @@ -34,16 +53,30 @@ impl FromStr for Target {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s == "latest" {
Ok(Target::LATEST)
} else if s == "beta-2" {
Ok(Target::Beta2)
} else if s == "beta-3" {
Ok(Target::Beta3)
} else {
anyhow::bail!(
"invalid testnet name provided. Possible values are 'beta-2', 'beta-3', 'latest'."
)
match s {
"beta-2" => Ok(Target::Beta2),
"beta-3" => Ok(Target::Beta3),
"beta-4" => Ok(Target::Beta4),
"local" => Ok(Target::Local),
_ => anyhow::bail!(
"'{s}' is not a valid target name. Possible values: '{}', '{}', '{}', '{}'",
Target::Beta2,
Target::Beta3,
Target::Beta4,
Target::Local
),
}
}
}

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::Local => "local",
};
write!(f, "{}", s)
}
}