Skip to content

Commit

Permalink
test: relax pragmas (foundry-rs#9078)
Browse files Browse the repository at this point in the history
* test: relax pragmas

* test: update rust tests too
  • Loading branch information
DaniPopes authored and rplusq committed Nov 29, 2024
1 parent 9ec7c90 commit 3d56299
Show file tree
Hide file tree
Showing 206 changed files with 244 additions and 228 deletions.
39 changes: 26 additions & 13 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
use crate::constants::TEMPLATE_CONTRACT;
use alloy_primitives::{hex, Address, Bytes};
use anvil::{spawn, NodeConfig};
use foundry_test_utils::{rpc, ScriptOutcome, ScriptTester};
use foundry_test_utils::{
rpc,
util::{OTHER_SOLC_VERSION, SOLC_VERSION},
ScriptOutcome, ScriptTester,
};
use regex::Regex;
use serde_json::Value;
use std::{env, path::PathBuf, str::FromStr};
Expand Down Expand Up @@ -1520,36 +1524,45 @@ forgetest_async!(can_detect_contract_when_multiple_versions, |prj, cmd| {

prj.add_script(
"A.sol",
r#"pragma solidity 0.8.20;
&format!(
r#"
pragma solidity {SOLC_VERSION};
import "./B.sol";
contract ScriptA {}
"#,
contract ScriptA {{}}
"#
),
)
.unwrap();

prj.add_script(
"B.sol",
r#"pragma solidity >=0.8.5 <=0.8.20;
&format!(
r#"
pragma solidity >={OTHER_SOLC_VERSION} <={SOLC_VERSION};
import 'forge-std/Script.sol';
contract ScriptB is Script {
function run() external {
contract ScriptB is Script {{
function run() external {{
vm.broadcast();
address(0).call("");
}
}
"#,
}}
}}
"#
),
)
.unwrap();

prj.add_script(
"C.sol",
r#"pragma solidity 0.8.5;
&format!(
r#"
pragma solidity {OTHER_SOLC_VERSION};
import "./B.sol";
contract ScriptC {}
"#,
contract ScriptC {{}}
"#
),
)
.unwrap();

Expand Down
3 changes: 0 additions & 3 deletions crates/forge/tests/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
});

const SIMPLE_CONTRACT: &str = r#"
pragma solidity 0.8.18;
import "./test.sol";
import "./console.sol";
Expand Down Expand Up @@ -650,7 +648,6 @@ forgetest_init!(can_test_transient_storage_with_isolation, |prj, cmd| {
prj.add_test(
"Contract.t.sol",
r#"
pragma solidity ^0.8.24;
import {Test} from "forge-std/Test.sol";
contract TransientTester {
Expand Down
21 changes: 13 additions & 8 deletions crates/linking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ impl<'a> Linker<'a> {
mod tests {
use super::*;
use alloy_primitives::{fixed_bytes, map::HashMap};
use foundry_compilers::{Project, ProjectCompileOutput, ProjectPathsConfig};
use foundry_compilers::{
multi::MultiCompiler,
solc::{Solc, SolcCompiler},
Project, ProjectCompileOutput, ProjectPathsConfig,
};

struct LinkerTest {
project: Project,
Expand All @@ -303,11 +307,12 @@ mod tests {
.build()
.unwrap();

let solc = Solc::find_or_install(&Version::new(0, 8, 18)).unwrap();
let project = Project::builder()
.paths(paths)
.ephemeral()
.no_artifacts()
.build(Default::default())
.build(MultiCompiler { solc: Some(SolcCompiler::Specific(solc)), vyper: None })
.unwrap();

let mut output = project.compile().unwrap();
Expand Down Expand Up @@ -393,7 +398,7 @@ mod tests {
for (dep_identifier, address) in assertions {
let (file, name) = dep_identifier.split_once(':').unwrap();
if let Some(lib_address) =
libraries.libs.get(&PathBuf::from(file)).and_then(|libs| libs.get(name))
libraries.libs.get(Path::new(file)).and_then(|libs| libs.get(name))
{
assert_eq!(
*lib_address,
Expand Down Expand Up @@ -637,7 +642,7 @@ mod tests {
"default/linking/nested/Nested.t.sol:NestedLib".to_string(),
vec![(
"default/linking/nested/Nested.t.sol:Lib".to_string(),
Address::from_str("0xCD3864eB2D88521a5477691EE589D9994b796834").unwrap(),
Address::from_str("0xddb1Cd2497000DAeA687CEa3dc34Af44084BEa74").unwrap(),
)],
)
.assert_dependencies(
Expand All @@ -647,12 +652,12 @@ mod tests {
// have the same address and nonce.
(
"default/linking/nested/Nested.t.sol:Lib".to_string(),
Address::from_str("0xCD3864eB2D88521a5477691EE589D9994b796834")
Address::from_str("0xddb1Cd2497000DAeA687CEa3dc34Af44084BEa74")
.unwrap(),
),
(
"default/linking/nested/Nested.t.sol:NestedLib".to_string(),
Address::from_str("0x023d9a6bfA39c45997572dC4F87b3E2713b6EBa4")
Address::from_str("0xfebE2F30641170642f317Ff6F644Cee60E7Ac369")
.unwrap(),
),
],
Expand All @@ -662,12 +667,12 @@ mod tests {
vec![
(
"default/linking/nested/Nested.t.sol:Lib".to_string(),
Address::from_str("0xCD3864eB2D88521a5477691EE589D9994b796834")
Address::from_str("0xddb1Cd2497000DAeA687CEa3dc34Af44084BEa74")
.unwrap(),
),
(
"default/linking/nested/Nested.t.sol:NestedLib".to_string(),
Address::from_str("0x023d9a6bfA39c45997572dC4F87b3E2713b6EBa4")
Address::from_str("0xfebE2F30641170642f317Ff6F644Cee60E7Ac369")
.unwrap(),
),
],
Expand Down
5 changes: 3 additions & 2 deletions crates/test-utils/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
/// The default Solc version used when compiling tests.
pub const SOLC_VERSION: &str = "0.8.27";

/// Another Solc version used when compiling tests. Necessary to avoid downloading multiple
/// versions.
/// Another Solc version used when compiling tests.
///
/// Necessary to avoid downloading multiple versions.
pub const OTHER_SOLC_VERSION: &str = "0.8.26";

/// External test builder
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Addr.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/ArbitraryStorage.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Assert.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Assume.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Bank.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Base64.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Broadcast.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/BroadcastRawTransaction.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/ChainId.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/CloneAccount.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Cool.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "lib/ds-test/src/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/CopyStorage.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Deal.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/DeployCode.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Derive.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/EnsNamehash.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Env.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Etch.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/ExpectCall.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/ExpectEmit.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/ExpectRevert.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Fee.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Ffi.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Fork.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Fork2.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "../logs/console.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/Fs.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/GasMetering.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/GasSnapshots.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/GetArtifactPath.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity =0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/GetBlockTimestamp.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity ^0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/GetCode.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity =0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
2 changes: 1 addition & 1 deletion testdata/default/cheats/GetDeployedCode.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity 0.8.18;
pragma solidity =0.8.18;

import "ds-test/test.sol";
import "cheats/Vm.sol";
Expand Down
Loading

0 comments on commit 3d56299

Please sign in to comment.