Skip to content

Commit

Permalink
feat(forge-cli): Add --no-metadata as CLI compiler option (#7684)
Browse files Browse the repository at this point in the history
* add `no_metadata`, equivalent to adding `bytecode_hash = "none" and cbor_metadata = false`

* add basic smoke test for --no-metadata setting cbor_metadata to false, bytecode_hash to none

* Update core.rs

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
  • Loading branch information
zerosnacks and DaniPopes committed Apr 16, 2024
1 parent 958a850 commit b56176e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions crates/cli/src/opts/build/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ pub struct CoreBuildArgs {
#[serde(skip)]
pub via_ir: bool,

/// Do not append any metadata to the bytecode.
///
/// This is equivalent to setting `bytecode_hash` to `none` and `cbor_metadata` to `false`.
#[arg(long, help_heading = "Compiler options")]
#[serde(skip)]
pub no_metadata: bool,

/// The path to the contract artifacts folder.
#[arg(
long = "out",
Expand Down Expand Up @@ -204,9 +211,15 @@ impl Provider for CoreBuildArgs {
dict.insert("via_ir".to_string(), true.into());
}

if self.no_metadata {
dict.insert("bytecode_hash".to_string(), "none".into());
dict.insert("cbor_metadata".to_string(), false.into());
}

if self.force {
dict.insert("force".to_string(), self.force.into());
}

// we need to ensure no_cache set accordingly
if self.no_cache {
dict.insert("cache".to_string(), false.into());
Expand Down
6 changes: 4 additions & 2 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloy_primitives::{Address, B256, U256};
use foundry_cli::utils as forge_utils;
use foundry_compilers::artifacts::{OptimizerDetails, RevertStrings, YulDetails};
use foundry_compilers::artifacts::{BytecodeHash, OptimizerDetails, RevertStrings, YulDetails};
use foundry_config::{
cache::{CachedChains, CachedEndpoints, StorageCachingConfig},
fs_permissions::{FsAccessPermission, PathPermission},
Expand Down Expand Up @@ -305,8 +305,10 @@ forgetest_init!(can_get_evm_opts, |prj, _cmd| {

// checks that we can set various config values
forgetest_init!(can_set_config_values, |prj, _cmd| {
let config = prj.config_from_output(["--via-ir"]);
let config = prj.config_from_output(["--via-ir", "--no-metadata"]);
assert!(config.via_ir);
assert_eq!(config.cbor_metadata, false);
assert_eq!(config.bytecode_hash, BytecodeHash::None);
});

// tests that solc can be explicitly set
Expand Down

0 comments on commit b56176e

Please sign in to comment.