Skip to content

Commit 5101a32

Browse files
authored
test: relax pragmas (foundry-rs#9078)
* test: relax pragmas * test: update rust tests too
1 parent 1465e39 commit 5101a32

File tree

206 files changed

+244
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+244
-228
lines changed

crates/forge/tests/cli/script.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
use crate::constants::TEMPLATE_CONTRACT;
44
use alloy_primitives::{hex, Address, Bytes};
55
use anvil::{spawn, NodeConfig};
6-
use foundry_test_utils::{rpc, ScriptOutcome, ScriptTester};
6+
use foundry_test_utils::{
7+
rpc,
8+
util::{OTHER_SOLC_VERSION, SOLC_VERSION},
9+
ScriptOutcome, ScriptTester,
10+
};
711
use regex::Regex;
812
use serde_json::Value;
913
use std::{env, path::PathBuf, str::FromStr};
@@ -1520,36 +1524,45 @@ forgetest_async!(can_detect_contract_when_multiple_versions, |prj, cmd| {
15201524

15211525
prj.add_script(
15221526
"A.sol",
1523-
r#"pragma solidity 0.8.20;
1527+
&format!(
1528+
r#"
1529+
pragma solidity {SOLC_VERSION};
15241530
import "./B.sol";
15251531
1526-
contract ScriptA {}
1527-
"#,
1532+
contract ScriptA {{}}
1533+
"#
1534+
),
15281535
)
15291536
.unwrap();
15301537

15311538
prj.add_script(
15321539
"B.sol",
1533-
r#"pragma solidity >=0.8.5 <=0.8.20;
1540+
&format!(
1541+
r#"
1542+
pragma solidity >={OTHER_SOLC_VERSION} <={SOLC_VERSION};
15341543
import 'forge-std/Script.sol';
15351544
1536-
contract ScriptB is Script {
1537-
function run() external {
1545+
contract ScriptB is Script {{
1546+
function run() external {{
15381547
vm.broadcast();
15391548
address(0).call("");
1540-
}
1541-
}
1542-
"#,
1549+
}}
1550+
}}
1551+
"#
1552+
),
15431553
)
15441554
.unwrap();
15451555

15461556
prj.add_script(
15471557
"C.sol",
1548-
r#"pragma solidity 0.8.5;
1558+
&format!(
1559+
r#"
1560+
pragma solidity {OTHER_SOLC_VERSION};
15491561
import "./B.sol";
15501562
1551-
contract ScriptC {}
1552-
"#,
1563+
contract ScriptC {{}}
1564+
"#
1565+
),
15531566
)
15541567
.unwrap();
15551568

crates/forge/tests/cli/test_cmd.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)
275275
});
276276

277277
const SIMPLE_CONTRACT: &str = r#"
278-
pragma solidity 0.8.18;
279-
280278
import "./test.sol";
281279
import "./console.sol";
282280
@@ -650,7 +648,6 @@ forgetest_init!(can_test_transient_storage_with_isolation, |prj, cmd| {
650648
prj.add_test(
651649
"Contract.t.sol",
652650
r#"
653-
pragma solidity ^0.8.24;
654651
import {Test} from "forge-std/Test.sol";
655652
656653
contract TransientTester {

crates/linking/src/lib.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ impl<'a> Linker<'a> {
284284
mod tests {
285285
use super::*;
286286
use alloy_primitives::{fixed_bytes, map::HashMap};
287-
use foundry_compilers::{Project, ProjectCompileOutput, ProjectPathsConfig};
287+
use foundry_compilers::{
288+
multi::MultiCompiler,
289+
solc::{Solc, SolcCompiler},
290+
Project, ProjectCompileOutput, ProjectPathsConfig,
291+
};
288292

289293
struct LinkerTest {
290294
project: Project,
@@ -303,11 +307,12 @@ mod tests {
303307
.build()
304308
.unwrap();
305309

310+
let solc = Solc::find_or_install(&Version::new(0, 8, 18)).unwrap();
306311
let project = Project::builder()
307312
.paths(paths)
308313
.ephemeral()
309314
.no_artifacts()
310-
.build(Default::default())
315+
.build(MultiCompiler { solc: Some(SolcCompiler::Specific(solc)), vyper: None })
311316
.unwrap();
312317

313318
let mut output = project.compile().unwrap();
@@ -393,7 +398,7 @@ mod tests {
393398
for (dep_identifier, address) in assertions {
394399
let (file, name) = dep_identifier.split_once(':').unwrap();
395400
if let Some(lib_address) =
396-
libraries.libs.get(&PathBuf::from(file)).and_then(|libs| libs.get(name))
401+
libraries.libs.get(Path::new(file)).and_then(|libs| libs.get(name))
397402
{
398403
assert_eq!(
399404
*lib_address,
@@ -637,7 +642,7 @@ mod tests {
637642
"default/linking/nested/Nested.t.sol:NestedLib".to_string(),
638643
vec![(
639644
"default/linking/nested/Nested.t.sol:Lib".to_string(),
640-
Address::from_str("0xCD3864eB2D88521a5477691EE589D9994b796834").unwrap(),
645+
Address::from_str("0xddb1Cd2497000DAeA687CEa3dc34Af44084BEa74").unwrap(),
641646
)],
642647
)
643648
.assert_dependencies(
@@ -647,12 +652,12 @@ mod tests {
647652
// have the same address and nonce.
648653
(
649654
"default/linking/nested/Nested.t.sol:Lib".to_string(),
650-
Address::from_str("0xCD3864eB2D88521a5477691EE589D9994b796834")
655+
Address::from_str("0xddb1Cd2497000DAeA687CEa3dc34Af44084BEa74")
651656
.unwrap(),
652657
),
653658
(
654659
"default/linking/nested/Nested.t.sol:NestedLib".to_string(),
655-
Address::from_str("0x023d9a6bfA39c45997572dC4F87b3E2713b6EBa4")
660+
Address::from_str("0xfebE2F30641170642f317Ff6F644Cee60E7Ac369")
656661
.unwrap(),
657662
),
658663
],
@@ -662,12 +667,12 @@ mod tests {
662667
vec![
663668
(
664669
"default/linking/nested/Nested.t.sol:Lib".to_string(),
665-
Address::from_str("0xCD3864eB2D88521a5477691EE589D9994b796834")
670+
Address::from_str("0xddb1Cd2497000DAeA687CEa3dc34Af44084BEa74")
666671
.unwrap(),
667672
),
668673
(
669674
"default/linking/nested/Nested.t.sol:NestedLib".to_string(),
670-
Address::from_str("0x023d9a6bfA39c45997572dC4F87b3E2713b6EBa4")
675+
Address::from_str("0xfebE2F30641170642f317Ff6F644Cee60E7Ac369")
671676
.unwrap(),
672677
),
673678
],

crates/test-utils/src/util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ static NEXT_ID: AtomicUsize = AtomicUsize::new(0);
4949
/// The default Solc version used when compiling tests.
5050
pub const SOLC_VERSION: &str = "0.8.27";
5151

52-
/// Another Solc version used when compiling tests. Necessary to avoid downloading multiple
53-
/// versions.
52+
/// Another Solc version used when compiling tests.
53+
///
54+
/// Necessary to avoid downloading multiple versions.
5455
pub const OTHER_SOLC_VERSION: &str = "0.8.26";
5556

5657
/// External test builder

testdata/default/cheats/Addr.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/ArbitraryStorage.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Assert.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Assume.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Bank.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Base64.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Broadcast.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/BroadcastRawTransaction.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/ChainId.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/CloneAccount.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Cool.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "lib/ds-test/src/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/CopyStorage.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Deal.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/DeployCode.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Derive.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/EnsNamehash.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Env.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Etch.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/ExpectCall.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/ExpectEmit.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/ExpectRevert.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Fee.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Ffi.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Fork.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/Fork2.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "../logs/console.sol";

testdata/default/cheats/Fs.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/GasMetering.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/GasSnapshots.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/GetArtifactPath.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity =0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/GetBlockTimestamp.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity ^0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/GetCode.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity =0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

testdata/default/cheats/GetDeployedCode.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
2-
pragma solidity 0.8.18;
2+
pragma solidity =0.8.18;
33

44
import "ds-test/test.sol";
55
import "cheats/Vm.sol";

0 commit comments

Comments
 (0)