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:
Chris
2025-06-03 10:43:52 +02:00
committed by GitHub
parent 8a3c587bbe
commit a77ab501c8
3 changed files with 60 additions and 5 deletions
@@ -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