Skip to content

Commit 22bb635

Browse files
authored
chore: add lint test for constant params (#11425)
1 parent 3e674ae commit 22bb635

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

crates/forge/tests/cli/lint.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,46 @@ const COUNTER_B: &str = r#"
6666
}
6767
"#;
6868

69+
const COUNTER_WITH_CONST: &str = r#"
70+
// SPDX-License-Identifier: MIT
71+
pragma solidity ^0.8.13;
72+
73+
uint256 constant MAX = 1000000;
74+
75+
contract Counter {
76+
uint256 public number;
77+
78+
function setNumber(uint256 newNumber) public {
79+
number = newNumber;
80+
}
81+
82+
function increment() public {
83+
number++;
84+
}
85+
}
86+
"#;
87+
88+
const COUNTER_TEST_WITH_CONST: &str = r#"
89+
// SPDX-License-Identifier: MIT
90+
pragma solidity ^0.8.13;
91+
92+
import { Counter, MAX } from "../src/Counter.sol";
93+
94+
contract CounterTest {
95+
Counter public counter;
96+
97+
function setUp() public {
98+
counter = new Counter();
99+
}
100+
101+
function testFuzz_setNumber(uint256[MAX] calldata numbers) public {
102+
for (uint256 i = 0; i < numbers.length; ++i) {
103+
counter.setNumber(numbers[i]);
104+
}
105+
}
106+
}
107+
"#;
108+
69109
forgetest!(can_use_config, |prj, cmd| {
70110
prj.wipe_contracts();
71111
prj.add_source("ContractWithLints", CONTRACT).unwrap();
@@ -476,6 +516,20 @@ note[mixed-case-variable]: mutable variables should use mixedCase
476516
]);
477517
});
478518

519+
// <https://github.com/foundry-rs/foundry/issues/11392>
520+
forgetest!(can_lint_param_constants, |prj, cmd| {
521+
prj.wipe_contracts();
522+
prj.add_source("Counter", COUNTER_WITH_CONST).unwrap();
523+
prj.add_test("CounterTest", COUNTER_TEST_WITH_CONST).unwrap();
524+
525+
cmd.forge_fuse().args(["build"]).assert_success().stdout_eq(str![[r#"
526+
[COMPILING_FILES] with [SOLC_VERSION]
527+
[SOLC_VERSION] [ELAPSED]
528+
Compiler run successful!
529+
530+
"#]]);
531+
});
532+
479533
// ------------------------------------------------------------------------------------------------
480534

481535
#[tokio::test]

0 commit comments

Comments
 (0)