Skip to content

Commit

Permalink
solc: adjust flatten format (gakonst#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
YYY committed Apr 23, 2022
1 parent 8444b8e commit 1cba287
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
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

0 comments on commit 1cba287

Please sign in to comment.