mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 04:27:58 +00:00
fix: exclude EVM bytecode from production solc requests (#338)
This is to address issue #320 ## Introduced changes - Added new_required_for_tests() method that includes EVM bytecode flags - Modified new_required() to exclude evm.bytecode and evm.deployedBytecode - Updated test utilities to explicitly request EVM bytecode when needed Signed-off-by: 0xf333 <0x333@tuta.io>
This commit is contained in:
@@ -89,7 +89,7 @@ pub fn build_solidity_with_options(
|
||||
sources.clone(),
|
||||
libraries.clone(),
|
||||
remappings,
|
||||
SolcStandardJsonInputSettingsSelection::new_required(),
|
||||
SolcStandardJsonInputSettingsSelection::new_required_for_tests(),
|
||||
SolcStandardJsonInputSettingsOptimizer::new(
|
||||
solc_optimizer_enabled,
|
||||
optimizer_settings.middle_end_as_string().chars().last(),
|
||||
@@ -154,7 +154,7 @@ pub fn build_solidity_with_options_evm(
|
||||
sources.clone(),
|
||||
libraries.clone(),
|
||||
remappings,
|
||||
SolcStandardJsonInputSettingsSelection::new_required(),
|
||||
SolcStandardJsonInputSettingsSelection::new_required_for_tests(),
|
||||
SolcStandardJsonInputSettingsOptimizer::new(
|
||||
solc_optimizer_enabled,
|
||||
None,
|
||||
@@ -211,7 +211,7 @@ pub fn build_solidity_and_detect_missing_libraries(
|
||||
sources.clone(),
|
||||
libraries.clone(),
|
||||
None,
|
||||
SolcStandardJsonInputSettingsSelection::new_required(),
|
||||
SolcStandardJsonInputSettingsSelection::new_required_for_tests(),
|
||||
SolcStandardJsonInputSettingsOptimizer::new(true, None, &solc_version.default, false),
|
||||
None,
|
||||
None,
|
||||
@@ -285,7 +285,7 @@ pub fn check_solidity_warning(
|
||||
sources.clone(),
|
||||
libraries,
|
||||
None,
|
||||
SolcStandardJsonInputSettingsSelection::new_required(),
|
||||
SolcStandardJsonInputSettingsSelection::new_required_for_tests(),
|
||||
SolcStandardJsonInputSettingsOptimizer::new(true, None, &solc_version.default, false),
|
||||
None,
|
||||
suppressed_warnings,
|
||||
|
||||
@@ -21,8 +21,20 @@ pub struct File {
|
||||
}
|
||||
|
||||
impl File {
|
||||
/// Creates the selection required by our compilation process.
|
||||
/// Creates the selection required for production compilation (excludes EVM bytecode).
|
||||
pub fn new_required() -> Self {
|
||||
Self {
|
||||
per_file: Some(HashSet::from_iter([SelectionFlag::AST])),
|
||||
per_contract: Some(HashSet::from_iter([
|
||||
SelectionFlag::MethodIdentifiers,
|
||||
SelectionFlag::Metadata,
|
||||
SelectionFlag::Yul,
|
||||
])),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates the selection required for test compilation (includes EVM bytecode).
|
||||
pub fn new_required_for_tests() -> Self {
|
||||
Self {
|
||||
per_file: Some(HashSet::from_iter([SelectionFlag::AST])),
|
||||
per_contract: Some(HashSet::from_iter([
|
||||
@@ -49,3 +61,38 @@ impl File {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn production_excludes_evm_bytecode() {
|
||||
let selection = File::new_required();
|
||||
let per_contract = selection.per_contract.unwrap();
|
||||
|
||||
// Production should NOT include EVM bytecode flags
|
||||
assert!(!per_contract.contains(&SelectionFlag::EVMBC));
|
||||
assert!(!per_contract.contains(&SelectionFlag::EVMDBC));
|
||||
|
||||
// But should include other required flags
|
||||
assert!(per_contract.contains(&SelectionFlag::MethodIdentifiers));
|
||||
assert!(per_contract.contains(&SelectionFlag::Metadata));
|
||||
assert!(per_contract.contains(&SelectionFlag::Yul));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tests_include_evm_bytecode() {
|
||||
let selection = File::new_required_for_tests();
|
||||
let per_contract = selection.per_contract.unwrap();
|
||||
|
||||
// Tests should include EVM bytecode flags
|
||||
assert!(per_contract.contains(&SelectionFlag::EVMBC));
|
||||
assert!(per_contract.contains(&SelectionFlag::EVMDBC));
|
||||
|
||||
// And should also include other required flags
|
||||
assert!(per_contract.contains(&SelectionFlag::MethodIdentifiers));
|
||||
assert!(per_contract.contains(&SelectionFlag::Metadata));
|
||||
assert!(per_contract.contains(&SelectionFlag::Yul));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,14 @@ impl Selection {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates the selection required for test compilation (includes EVM bytecode).
|
||||
pub fn new_required_for_tests() -> Self {
|
||||
Self {
|
||||
all: Some(FileSelection::new_required_for_tests()),
|
||||
files: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Extends the user's output selection with flag required by our compilation process.
|
||||
pub fn extend_with_required(&mut self) -> &mut Self {
|
||||
self.all
|
||||
|
||||
Reference in New Issue
Block a user