Skip to content

Commit

Permalink
feat: make --random-salt default to forc-deploy and remove it as a …
Browse files Browse the repository at this point in the history
…flag (FuelLabs#4760)

## Description
closes FuelLabs#4758.

This PR makes --random-salt the default behaviour of forc-deploy, if
salt information is passed, the passed salt would be used but otherwise,
random-salt would be implied by default. Also adds --default-salt for CI
so that in CI we can always create the same contract id if we want to.
Useful for reproducible deployments.
  • Loading branch information
kayagokalp authored Jul 7, 2023
1 parent 4660fc9 commit d8ee8a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions forc-plugins/forc-client/src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ pub struct Command {
/// --salt contract_b:0x0000000000000000000000000000000000000000000000000000000000000002
#[clap(long)]
pub salt: Option<Vec<String>>,
/// Generate a random salt for the contract.
/// Useful for testing or deploying examples to a shared network.
/// Generate a default salt (0x0000000000000000000000000000000000000000000000000000000000000000) for the contract.
/// Useful for CI, to create reproducable deployments.
#[clap(long)]
pub random_salt: bool,
pub default_salt: bool,
#[clap(flatten)]
pub build_output: BuildOutput,
#[clap(flatten)]
Expand Down
8 changes: 4 additions & 4 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ pub async fn deploy(command: cmd::Deploy) -> Result<Vec<DeployedContract>> {
.check_program_type(vec![TreeType::Contract])
.is_ok()
{
let salt = match (&contract_salt_map, command.random_salt) {
let salt = match (&contract_salt_map, command.default_salt) {
(Some(map), false) => {
if let Some(salt) = map.get(pkg.descriptor.manifest_file.project_name()) {
*salt
} else {
Default::default()
}
}
(None, true) => rand::random(),
(None, false) => Default::default(),
(None, true) => Default::default(),
(None, false) => rand::random(),
(Some(_), true) => {
bail!("Both `--salt` and `--random-salt` were specified: must choose one")
bail!("Both `--salt` and `--default-salt` were specified: must choose one")
}
};
let contract_id =
Expand Down
1 change: 1 addition & 0 deletions test/src/e2e_vm_tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub(crate) async fn deploy_contract(file_name: &str, run_config: &RunConfig) ->
..Default::default()
},
signing_key: Some(SecretKey::from_str(SECRET_KEY).unwrap()),
default_salt: true,
..Default::default()
})
.await
Expand Down

0 comments on commit d8ee8a2

Please sign in to comment.