Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix(solc): adjust flatten format #1172

Merged
merged 1 commit into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ethers-solc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ impl ProjectPathsConfig {
pub fn flatten(&self, target: &Path) -> Result<String> {
tracing::trace!("flattening file");
let graph = Graph::resolve(self)?;
self.flatten_node(target, &graph, &mut Default::default(), false, false, false)
self.flatten_node(target, &graph, &mut Default::default(), false, false, false).map(|x| {
format!("{}\n", utils::RE_THREE_OR_MORE_NEWLINES.replace_all(&x, "\n\n").trim())
})
}

/// Flattens a single node from the dependency graph
Expand Down Expand Up @@ -321,7 +323,6 @@ impl ProjectPathsConfig {
let result = String::from_utf8(content).map_err(|err| {
SolcError::msg(format!("failed to convert extended bytes to string: {}", err))
})?;
let result = utils::RE_THREE_OR_MORE_NEWLINES.replace_all(&result, "\n\n").into_owned();

Ok(result)
}
Expand Down
16 changes: 8 additions & 8 deletions ethers-solc/tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ contract C { }

assert_eq!(
result,
r#"
pragma solidity ^0.8.10;
r#"pragma solidity ^0.8.10;

contract C { }

Expand Down Expand Up @@ -547,8 +546,7 @@ contract C { }

assert_eq!(
result,
r#"
pragma solidity ^0.8.10;
r#"pragma solidity ^0.8.10;
pragma experimental ABIEncoderV2;

contract C { }
Expand Down Expand Up @@ -656,15 +654,16 @@ contract C { }

let result = project.flatten(&f).unwrap();
assert_eq!(
result.trim(),
result,
r#"pragma solidity ^0.8.10;

contract C { }

error IllegalArgument();
error IllegalState();

contract A { }"#
contract A { }
"#
);
}

Expand Down Expand Up @@ -707,7 +706,7 @@ contract C { }

let result = project.flatten(&f).unwrap();
assert_eq!(
result.trim(),
result,
r#"pragma solidity ^0.8.10;

contract C { }
Expand All @@ -716,7 +715,8 @@ contract C { }

contract B { }

contract A { }"#
contract A { }
"#
);
}

Expand Down