Skip to content

Commit

Permalink
fix(forge): generate evm.legacyAssembly extra output (#8987)
Browse files Browse the repository at this point in the history
fix(forge): include legacyAssembly output
  • Loading branch information
grandizzy authored Sep 30, 2024
1 parent 7559c09 commit 4bcb309
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
21 changes: 10 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ foundry-linking = { path = "crates/linking" }

# solc & compilation utilities
foundry-block-explorers = { version = "0.7.3", default-features = false }
foundry-compilers = { version = "0.11.1", default-features = false }
foundry-compilers = { version = "0.11.3", default-features = false }
foundry-fork-db = "0.3.2"
solang-parser = "=0.3.3"

Expand Down
7 changes: 7 additions & 0 deletions crates/forge/bin/cmd/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ impl InspectArgs {
ContractArtifactField::Assembly | ContractArtifactField::AssemblyOptimized => {
print_json_str(&artifact.assembly, None)?;
}
ContractArtifactField::LegacyAssembly => {
print_json_str(&artifact.legacy_assembly, None)?;
}
ContractArtifactField::MethodIdentifiers => {
print_json(&artifact.method_identifiers)?;
}
Expand Down Expand Up @@ -210,6 +213,7 @@ pub enum ContractArtifactField {
DeployedBytecode,
Assembly,
AssemblyOptimized,
LegacyAssembly,
MethodIdentifiers,
GasEstimates,
StorageLayout,
Expand Down Expand Up @@ -292,6 +296,7 @@ impl_value_enum! {
DeployedBytecode => "deployedBytecode" | "deployed_bytecode" | "deployed-bytecode"
| "deployed" | "deployedbytecode",
Assembly => "assembly" | "asm",
LegacyAssembly => "legacyAssembly" | "legacyassembly" | "legacy_assembly",
AssemblyOptimized => "assemblyOptimized" | "asmOptimized" | "assemblyoptimized"
| "assembly_optimized" | "asmopt" | "assembly-optimized"
| "asmo" | "asm-optimized" | "asmoptimized" | "asm_optimized",
Expand Down Expand Up @@ -324,6 +329,7 @@ impl From<ContractArtifactField> for ContractOutputSelection {
DeployedBytecodeOutputSelection::All,
)),
Caf::Assembly | Caf::AssemblyOptimized => Self::Evm(EvmOutputSelection::Assembly),
Caf::LegacyAssembly => Self::Evm(EvmOutputSelection::LegacyAssembly),
Caf::MethodIdentifiers => Self::Evm(EvmOutputSelection::MethodIdentifiers),
Caf::GasEstimates => Self::Evm(EvmOutputSelection::GasEstimates),
Caf::StorageLayout => Self::StorageLayout,
Expand Down Expand Up @@ -354,6 +360,7 @@ impl PartialEq<ContractOutputSelection> for ContractArtifactField {
(Self::Bytecode, Cos::Evm(Eos::ByteCode(_))) |
(Self::DeployedBytecode, Cos::Evm(Eos::DeployedByteCode(_))) |
(Self::Assembly | Self::AssemblyOptimized, Cos::Evm(Eos::Assembly)) |
(Self::LegacyAssembly, Cos::Evm(Eos::LegacyAssembly)) |
(Self::MethodIdentifiers, Cos::Evm(Eos::MethodIdentifiers)) |
(Self::GasEstimates, Cos::Evm(Eos::GasEstimates)) |
(Self::StorageLayout, Cos::StorageLayout) |
Expand Down
22 changes: 19 additions & 3 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,17 @@ Compiler run successful!

// checks that extra output works
forgetest_init!(can_emit_multiple_extra_output, |prj, cmd| {
cmd.args(["build", "--extra-output", "metadata", "ir-optimized", "--extra-output", "ir"])
.assert_success()
.stdout_eq(str![[r#"
cmd.args([
"build",
"--extra-output",
"metadata",
"legacyAssembly",
"ir-optimized",
"--extra-output",
"ir",
])
.assert_success()
.stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
[SOLC_VERSION] [ELAPSED]
Compiler run successful!
Expand All @@ -753,6 +761,7 @@ Compiler run successful!
let artifact: ConfigurableContractArtifact =
foundry_compilers::utils::read_json_file(&artifact_path).unwrap();
assert!(artifact.metadata.is_some());
assert!(artifact.legacy_assembly.is_some());
assert!(artifact.ir.is_some());
assert!(artifact.ir_optimized.is_some());

Expand All @@ -763,6 +772,7 @@ Compiler run successful!
"metadata",
"ir-optimized",
"evm.bytecode.sourceMap",
"evm.legacyAssembly",
"--force",
])
.root_arg()
Expand All @@ -784,6 +794,12 @@ Compiler run successful!
let sourcemap =
prj.paths().artifacts.join(format!("{TEMPLATE_CONTRACT_ARTIFACT_BASE}.sourcemap"));
std::fs::read_to_string(sourcemap).unwrap();

let legacy_assembly = prj
.paths()
.artifacts
.join(format!("{TEMPLATE_CONTRACT_ARTIFACT_BASE}.legacyAssembly.json"));
std::fs::read_to_string(legacy_assembly).unwrap();
});

forgetest!(can_print_warnings, |prj, cmd| {
Expand Down

0 comments on commit 4bcb309

Please sign in to comment.