Skip to content

Commit

Permalink
refactor: use slashed paths (foundry-rs#2536)
Browse files Browse the repository at this point in the history
* refactor: use slashed paths

* refactor: safer ffi function and return non hex as string (foundry-rs#2520)

* bump ethers

* rm leftover
  • Loading branch information
mattsse authored and iFrostizz committed Nov 9, 2022
1 parent 801a066 commit dc18a2d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 66 deletions.
2 changes: 1 addition & 1 deletion anvil/tests/it/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn test_can_change_mining_mode() {
let num = provider.get_block_number().await.unwrap();
assert_eq!(num.as_u64(), 0);

tokio::time::sleep(std::time::Duration::from_millis(500)).await;
tokio::time::sleep(std::time::Duration::from_millis(700)).await;
let num = provider.get_block_number().await.unwrap();
assert_eq!(num.as_u64(), 1);
}
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ walkdir = "2.3.2"
dunce = "1.0.2"
glob = "0.3.0"
globset = "0.4.8"
path-slash = "0.2.0"

# misc
eyre = "0.6"
Expand Down Expand Up @@ -83,7 +84,6 @@ foundry-cli-test-utils = { path = "./test-utils" }
pretty_assertions = "1.0.0"
toml = "0.5"
serial_test = "0.7.0"
path-slash = "0.2.0"

[features]
default = ["rustls"]
Expand Down
4 changes: 3 additions & 1 deletion cli/src/cmd/forge/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use eyre::Context;
use foundry_common::fs;
use foundry_config::Config;
use foundry_utils::parse_tokens;

use rustc_hex::ToHex;
use serde_json::json;
use std::{path::PathBuf, sync::Arc};
Expand Down Expand Up @@ -97,7 +98,7 @@ impl CreateArgs {

if let Some(ref mut path) = self.contract.path {
// paths are absolute in the project's output
*path = format!("{}", canonicalized(project.root().join(&path)).display());
*path = canonicalized(project.root().join(&path)).to_string_lossy().to_string();
}

let (abi, bin, _) = utils::remove_contract(&mut output, &self.contract)?;
Expand Down Expand Up @@ -245,6 +246,7 @@ impl CreateArgs {
}

let (deployed_contract, receipt) = deployer.send_with_receipt().await?;

let address = deployed_contract.address();
if self.json {
let output = json!({
Expand Down
18 changes: 11 additions & 7 deletions cli/src/cmd/forge/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ use crate::{
};
use clap::Parser;
use comfy_table::Table;
use ethers::prelude::{
artifacts::output_selection::{
BytecodeOutputSelection, ContractOutputSelection, DeployedBytecodeOutputSelection,
EvmOutputSelection, EwasmOutputSelection,
use ethers::{
prelude::{
artifacts::output_selection::{
BytecodeOutputSelection, ContractOutputSelection, DeployedBytecodeOutputSelection,
EvmOutputSelection, EwasmOutputSelection,
},
info::ContractInfo,
},
info::ContractInfo,
solc::utils::canonicalize,
};

use serde_json::{to_value, Value};
use std::{fmt, str::FromStr};

Expand Down Expand Up @@ -64,8 +68,8 @@ impl Cmd for InspectArgs {
// Build the project
let project = modified_build_args.project()?;
let outcome = if let Some(ref mut contract_path) = contract.path {
let target_path = dunce::canonicalize(&*contract_path)?;
*contract_path = target_path.to_string_lossy().into_owned();
let target_path = canonicalize(&*contract_path)?;
*contract_path = target_path.to_string_lossy().to_string();
compile::compile_files(&project, vec![target_path], true)
} else {
compile::suppress_compile(&project)
Expand Down
10 changes: 6 additions & 4 deletions cli/src/cmd/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ pub fn remove_contract(
if let Some(suggestion) =
suggestions::did_you_mean(&info.name, output.artifacts().map(|(name, _)| name)).pop()
{
err = format!(
r#"{}
if suggestion != info.name {
err = format!(
r#"{}
Did you mean `{}`?"#,
err, suggestion
);
err, suggestion
);
}
}
eyre::bail!(err)
};
Expand Down
1 change: 1 addition & 0 deletions cli/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ pub fn compile_files(
if !silent {
println!("{output}");
}

Ok(output)
}

Expand Down
7 changes: 1 addition & 6 deletions cli/tests/it/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,7 @@ contract Foo {
cmd.arg("inspect").arg(contract_name).arg("bytecode");
check_output(cmd.stdout_lossy());

let info = format!(
"src{}{}:{}",
std::path::MAIN_SEPARATOR,
path.file_name().unwrap().to_string_lossy(),
contract_name
);
let info = format!("src/{}:{}", path.file_name().unwrap().to_string_lossy(), contract_name);
cmd.forge_fuse().arg("inspect").arg(info).arg("bytecode");
check_output(cmd.stdout_lossy());
});
Expand Down
56 changes: 14 additions & 42 deletions forge/src/multi_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,7 @@ mod tests {
&results,
BTreeMap::from([
(
format!("core{}FailingSetup.t.sol:FailingSetupTest", std::path::MAIN_SEPARATOR)
.as_str(),
"core/FailingSetup.t.sol:FailingSetupTest",
vec![(
"setUp()",
false,
Expand All @@ -535,8 +534,7 @@ mod tests {
)],
),
(
format!("core{}MultipleSetup.t.sol:MultipleSetup", std::path::MAIN_SEPARATOR)
.as_str(),
"core/MultipleSetup.t.sol:MultipleSetup",
vec![(
"setUp()",
false,
Expand All @@ -546,42 +544,29 @@ mod tests {
)],
),
(
format!("core{}Reverting.t.sol:RevertingTest", std::path::MAIN_SEPARATOR)
.as_str(),
"core/Reverting.t.sol:RevertingTest",
vec![("testFailRevert()", true, None, None, None)],
),
(
format!(
"core{}SetupConsistency.t.sol:SetupConsistencyCheck",
std::path::MAIN_SEPARATOR
)
.as_str(),
"core/SetupConsistency.t.sol:SetupConsistencyCheck",
vec![
("testAdd()", true, None, None, None),
("testMultiply()", true, None, None, None),
],
),
(
format!("core{}DSStyle.t.sol:DSStyleTest", std::path::MAIN_SEPARATOR).as_str(),
"core/DSStyle.t.sol:DSStyleTest",
vec![("testFailingAssertions()", true, None, None, None)],
),
(
format!(
"core{}ContractEnvironment.t.sol:ContractEnvironmentTest",
std::path::MAIN_SEPARATOR
)
.as_str(),
"core/ContractEnvironment.t.sol:ContractEnvironmentTest",
vec![
("testAddresses()", true, None, None, None),
("testEnvironment()", true, None, None, None),
],
),
(
format!(
"core{}PaymentFailure.t.sol:PaymentFailureTest",
std::path::MAIN_SEPARATOR
)
.as_str(),
"core/PaymentFailure.t.sol:PaymentFailureTest",
vec![(
"testCantPay()",
false,
Expand All @@ -591,19 +576,14 @@ mod tests {
)],
),
(
format!(
"core{}LibraryLinking.t.sol:LibraryLinkingTest",
std::path::MAIN_SEPARATOR
)
.as_str(),
"core/LibraryLinking.t.sol:LibraryLinkingTest",
vec![
("testDirect()", true, None, None, None),
("testNested()", true, None, None, None),
],
),
(
format!("core{}Abstract.t.sol:AbstractTest", std::path::MAIN_SEPARATOR)
.as_str(),
"core/Abstract.t.sol:AbstractTest",
vec![("testSomething()", true, None, None, None)],
),
]),
Expand All @@ -619,7 +599,7 @@ mod tests {
&results,
BTreeMap::from([
(
format!("logs{}DebugLogs.t.sol:DebugLogsTest", std::path::MAIN_SEPARATOR).as_str(),
"logs/DebugLogs.t.sol:DebugLogsTest",
vec![
(
"test1()",
Expand Down Expand Up @@ -788,7 +768,7 @@ mod tests {
],
),
(
format!("logs{}HardhatLogs.t.sol:HardhatLogsTest", std::path::MAIN_SEPARATOR).as_str(),
"logs/HardhatLogs.t.sol:HardhatLogsTest",
vec![
(
"testInts()",
Expand Down Expand Up @@ -1285,7 +1265,7 @@ Reason: `setEnv` failed to set an environment variable `{}={}`",
for (test_name, result) in test_results {
let logs = decode_console_logs(&result.logs);

match test_name.as_ref() {
match test_name.as_str() {
"testPositive(uint256)" |
"testPositive(int256)" |
"testSuccessfulFuzz(uint128,uint128)" |
Expand Down Expand Up @@ -1372,15 +1352,7 @@ Reason: `setEnv` failed to set an environment variable `{}={}`",
let results = runner
.test(&Filter::new(".*", ".*", ".*Abstract.t.sol".to_string().as_str()), None, true)
.unwrap();
println!("{:?}", results.keys());
assert!(results
.get(
format!("core{}Abstract.t.sol:AbstractTestBase", std::path::MAIN_SEPARATOR)
.as_str()
)
.is_none());
assert!(results
.get(format!("core{}Abstract.t.sol:AbstractTest", std::path::MAIN_SEPARATOR).as_str())
.is_some());
assert!(results.get("core/Abstract.t.sol:AbstractTestBase").is_none());
assert!(results.get("core/Abstract.t.sol:AbstractTest").is_some());
}
}
4 changes: 0 additions & 4 deletions forge/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,8 @@ pub fn fuzz_executor<DB: DatabaseRef>(executor: &Executor) -> FuzzedExecutor {
FuzzedExecutor::new(executor, proptest::test_runner::TestRunner::new(cfg), CALLER)
}

#[cfg(not(windows))]
pub const RE_PATH_SEPARATOR: &str = "/";

#[cfg(windows)]
pub const RE_PATH_SEPARATOR: &str = "\\\\";

pub mod filter {
use super::*;
use regex::Regex;
Expand Down

0 comments on commit dc18a2d

Please sign in to comment.