Skip to content

Commit f962ee0

Browse files
authored
Added additional formatting options (#75)
1 parent 7516fe1 commit f962ee0

12 files changed

Lines changed: 129 additions & 113 deletions

foundry.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ line_length = 120
1111
tab_width = 4
1212
# Style of uint/int256 types
1313
int_types = "long"
14+
# Statement blocks will always be formatted to multiple lines
15+
single_line_statement_blocks = "multi"
16+
# Break the function header into multiple lines, with each parameter on its own line
17+
multiline_func_header = "attributes_first"
18+
# Use double quotes where possible
19+
quote_style = "double"
20+
# Use underscores in large numbers for better readability
21+
number_underscore = "thousands"

src/FuzzLibString.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ library FuzzLibString {
100100
* @dev Converts a single byte to its hexadecimal character representation.
101101
*/
102102
function char(bytes1 b) internal pure returns (bytes1 c) {
103-
if (uint8(b) < 10) return bytes1(uint8(b) + 0x30);
104-
else return bytes1(uint8(b) + 0x57);
103+
if (uint8(b) < 10) {
104+
return bytes1(uint8(b) + 0x30);
105+
} else {
106+
return bytes1(uint8(b) + 0x57);
107+
}
105108
}
106109

107110
/**
@@ -152,7 +155,9 @@ library FuzzLibString {
152155
}
153156

154157
// If the returnData length is less than 68, then the transaction failed silently (without a revert message)
155-
if (returnData.length < 68) return "Transaction reverted silently";
158+
if (returnData.length < 68) {
159+
return "Transaction reverted silently";
160+
}
156161

157162
assembly {
158163
// Slice the sighash.

src/helpers/HelperClamp.sol

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ abstract contract HelperClamp is HelperAssert {
179179
function clamp(uint256 value, uint256 low, uint256 high, bool enableLogs) public returns (uint256) {
180180
// Input validation: Ensure low <= high to prevent overflow
181181
// Without this check, (high - low + 1) could wrap around if low > high
182-
if (low > high) revert InvalidRange(low, high);
182+
if (low > high) {
183+
revert InvalidRange(low, high);
184+
}
183185

184186
// Return values already in range without modification.
185187
// This optimization also handles the full uint256 range [0, type(uint256).max]
@@ -230,7 +232,9 @@ abstract contract HelperClamp is HelperAssert {
230232
int128 high = FuzzSafeCast.toInt128(_high);
231233

232234
// Input validation: Ensure low <= high to prevent overflow
233-
if (low > high) revert InvalidRangeInt128(low, high);
235+
if (low > high) {
236+
revert InvalidRangeInt128(low, high);
237+
}
234238

235239
// Return values already in range without modification.
236240
if (value >= low && value <= high) {
@@ -277,7 +281,9 @@ abstract contract HelperClamp is HelperAssert {
277281
*/
278282

279283
function clampLt(uint256 a, uint256 b, bool enableLogs) public returns (uint256) {
280-
if (b == 0) revert UnsupportedClampLtValue(b);
284+
if (b == 0) {
285+
revert UnsupportedClampLtValue(b);
286+
}
281287
return clamp(a, 0, b - 1, enableLogs);
282288
}
283289

@@ -292,7 +298,9 @@ abstract contract HelperClamp is HelperAssert {
292298
* @return Clamped value in range [int128.min, b-1] as int256
293299
*/
294300
function clampLt(int256 a, int256 b, bool enableLogs) public returns (int256) {
295-
if (b <= type(int128).min) revert UnsupportedClampLtValue(uint256(b));
301+
if (b <= type(int128).min) {
302+
revert UnsupportedClampLtValue(uint256(b));
303+
}
296304
return clamp(a, int256(type(int128).min), b - 1, enableLogs);
297305
}
298306

@@ -331,7 +339,9 @@ abstract contract HelperClamp is HelperAssert {
331339
* @return Clamped value in range [b+1, uint256.max]
332340
*/
333341
function clampGt(uint256 a, uint256 b, bool enableLogs) public returns (uint256) {
334-
if (b == type(uint256).max) revert UnsupportedClampGtValue(b);
342+
if (b == type(uint256).max) {
343+
revert UnsupportedClampGtValue(b);
344+
}
335345
return clamp(a, b + 1, type(uint256).max, enableLogs);
336346
}
337347

@@ -346,7 +356,9 @@ abstract contract HelperClamp is HelperAssert {
346356
* @return Clamped value in range [b+1, int128.max] as int256
347357
*/
348358
function clampGt(int256 a, int256 b, bool enableLogs) public returns (int256) {
349-
if (b >= type(int128).max) revert UnsupportedClampGtValue(uint256(b));
359+
if (b >= type(int128).max) {
360+
revert UnsupportedClampGtValue(uint256(b));
361+
}
350362
return clamp(a, b + 1, type(int128).max, enableLogs);
351363
}
352364

src/helpers/HelperRandom.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ abstract contract HelperRandom {
1818
* @param entropy Random value used as seed for shuffling
1919
*/
2020
function shuffleArray(uint256[] memory shuffle, uint256 entropy) public pure {
21-
if (shuffle.length == 0) revert EmptyArray();
21+
if (shuffle.length == 0) {
22+
revert EmptyArray();
23+
}
2224

2325
for (uint256 i = shuffle.length - 1; i > 0; i--) {
2426
uint256 swapIndex = entropy % (shuffle.length - i);

test/FuzzLibString.t.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ contract FuzzLibStringTest is Test {
2424
function test_toString_int256_positive() public {
2525
assertEq(FuzzLibString.toString(int256(42)), "42");
2626
assertEq(FuzzLibString.toString(int256(1)), "1");
27-
assertEq(FuzzLibString.toString(int256(123456789)), "123456789");
27+
assertEq(FuzzLibString.toString(int256(123_456_789)), "123456789");
2828
}
2929

3030
function test_toString_int256_negative() public {
3131
assertEq(FuzzLibString.toString(int256(-1)), "-1");
3232
assertEq(FuzzLibString.toString(int256(-42)), "-42");
33-
assertEq(FuzzLibString.toString(int256(-123456789)), "-123456789");
33+
assertEq(FuzzLibString.toString(int256(-123_456_789)), "-123456789");
3434
}
3535

3636
function test_toString_int256_max() public {
@@ -88,7 +88,7 @@ contract FuzzLibStringTest is Test {
8888
function test_toString_uint256_multi_digit() public {
8989
assertEq(FuzzLibString.toString(uint256(42)), "42");
9090
assertEq(FuzzLibString.toString(uint256(123)), "123");
91-
assertEq(FuzzLibString.toString(uint256(123456789)), "123456789");
91+
assertEq(FuzzLibString.toString(uint256(123_456_789)), "123456789");
9292
}
9393

9494
function test_toString_uint256_max() public {
@@ -106,7 +106,7 @@ contract FuzzLibStringTest is Test {
106106
assertEq(FuzzLibString.toString(uint256(10)), "10");
107107
assertEq(FuzzLibString.toString(uint256(100)), "100");
108108
assertEq(FuzzLibString.toString(uint256(1000)), "1000");
109-
assertEq(FuzzLibString.toString(uint256(10000)), "10000");
109+
assertEq(FuzzLibString.toString(uint256(10_000)), "10000");
110110
}
111111

112112
function testFuzz_toString_uint256(uint256 value) public {
@@ -227,7 +227,7 @@ contract FuzzLibStringTest is Test {
227227
assertTrue(bytes(result).length >= 2);
228228
assertEq(bytes(result)[0], bytes1("0"));
229229
assertEq(bytes(result)[1], bytes1("x"));
230-
230+
231231
// Length should be 2 (for "0x") + 2 chars per input byte
232232
assertEq(bytes(result).length, 2 + 2 * value.length);
233233

test/HelperClamp.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ contract TestHelperClamp is Test, HelperClamp {
283283
}
284284

285285
function test_clamp_int128_large_ranges() public {
286-
int256 low = -10000;
287-
int256 high = 10000;
286+
int256 low = -10_000;
287+
int256 high = 10_000;
288288

289-
assertEq(this.clamp(int256(50000), low, high), int256(-2)); // range=20001, 50000%20001=9998, -10000+9998=-2
290-
assertEq(this.clamp(int256(-50000), low, high), int256(3)); // range=20001, -50000%20001=10003, -10000+10003=3
289+
assertEq(this.clamp(int256(50_000), low, high), int256(-2)); // range=20001, 50000%20001=9998, -10000+9998=-2
290+
assertEq(this.clamp(int256(-50_000), low, high), int256(3)); // range=20001, -50000%20001=10003, -10000+10003=3
291291
assertEq(this.clamp(int256(0), low, high), int256(0)); // Already in range
292292
}
293293

test/HelperMath.t.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,11 @@ contract TestHelperMath is Test, HelperMath {
283283
function testFuzz_diff_int256(int256 a, int256 b) public {
284284
// Avoid overflow cases where the subtraction might overflow
285285
if (a >= 0 && b < 0) {
286-
vm.assume(a <= type(int256).max + b); // Avoid a - b overflow
287-
} else if (a < 0 && b >= 0) {
288-
vm.assume(b <= type(int256).max + a); // Avoid b - a overflow
289-
}
286+
vm.assume(a <= type(int256).max + b);
287+
} // Avoid a - b overflow
288+
else if (a < 0 && b >= 0) {
289+
vm.assume(b <= type(int256).max + a);
290+
} // Avoid b - a overflow
290291

291292
uint256 result = diff(a, b);
292293
if (a >= b) {

test/HelperRandom.t.sol

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contract TestHelperRandom is Test, HelperRandom {
2626
original[i] = array[i];
2727
}
2828

29-
shuffleArray(array, 12345);
29+
shuffleArray(array, 12_345);
3030

3131
// Check all original elements are still present
3232
for (uint256 i = 0; i < original.length; i++) {
@@ -55,7 +55,7 @@ contract TestHelperRandom is Test, HelperRandom {
5555
originalSum += array[i];
5656
}
5757

58-
shuffleArray(array, 98765);
58+
shuffleArray(array, 98_765);
5959

6060
uint256 shuffledSum = 0;
6161
for (uint256 i = 0; i < array.length; i++) {
@@ -150,14 +150,14 @@ contract TestHelperRandom is Test, HelperRandom {
150150
uint256[] memory array = new uint256[](0);
151151

152152
vm.expectRevert(HelperRandom.EmptyArray.selector);
153-
this.shuffleArray(array, 12345);
153+
this.shuffleArray(array, 12_345);
154154
}
155155

156156
function test_shuffleArray_single_element() public {
157157
uint256[] memory array = new uint256[](1);
158158
array[0] = 42;
159159

160-
shuffleArray(array, 98765);
160+
shuffleArray(array, 98_765);
161161

162162
assertEq(array.length, 1);
163163
assertEq(array[0], 42);
@@ -192,9 +192,13 @@ contract TestHelperRandom is Test, HelperRandom {
192192
uint256 count15 = 0;
193193

194194
for (uint256 i = 0; i < array.length; i++) {
195-
if (array[i] == 5) count5++;
196-
else if (array[i] == 10) count10++;
197-
else if (array[i] == 15) count15++;
195+
if (array[i] == 5) {
196+
count5++;
197+
} else if (array[i] == 10) {
198+
count10++;
199+
} else if (array[i] == 15) {
200+
count15++;
201+
}
198202
}
199203

200204
assertEq(count5, 3);
@@ -243,9 +247,13 @@ contract TestHelperRandom is Test, HelperRandom {
243247
bool foundMaxMinus2 = false;
244248

245249
for (uint256 i = 0; i < array.length; i++) {
246-
if (array[i] == type(uint256).max) foundMax = true;
247-
else if (array[i] == type(uint256).max - 1) foundMaxMinus1 = true;
248-
else if (array[i] == type(uint256).max - 2) foundMaxMinus2 = true;
250+
if (array[i] == type(uint256).max) {
251+
foundMax = true;
252+
} else if (array[i] == type(uint256).max - 1) {
253+
foundMaxMinus1 = true;
254+
} else if (array[i] == type(uint256).max - 2) {
255+
foundMaxMinus2 = true;
256+
}
249257
}
250258

251259
assertTrue(foundMax);
@@ -269,8 +277,11 @@ contract TestHelperRandom is Test, HelperRandom {
269277
uint256 maxCount = 0;
270278

271279
for (uint256 i = 0; i < array.length; i++) {
272-
if (array[i] == 0) zeroCount++;
273-
else if (array[i] == type(uint256).max) maxCount++;
280+
if (array[i] == 0) {
281+
zeroCount++;
282+
} else if (array[i] == type(uint256).max) {
283+
maxCount++;
284+
}
274285
}
275286

276287
assertEq(zeroCount, 2);

test/e2e/echidna/DummyTarget.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ contract DummyTarget {
6767
function failWithInvalidOperation() public pure {
6868
revert InvalidOperation();
6969
}
70-
}
70+
}

test/e2e/echidna/EchidnaEntry.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import "./EchidnaTest.sol";
99
* @author Perimeter <info@perimetersec.io>
1010
*/
1111
contract EchidnaEntry is EchidnaTest {
12-
// This contract serves as the entry point for Echidna
13-
// All functionality is inherited from the parent contracts:
14-
// - EchidnaHandler: handler_* functions
15-
// - EchidnaTest: fuzz_* wrapper functions and _testSelf helper
16-
}
12+
// This contract serves as the entry point for Echidna
13+
// All functionality is inherited from the parent contracts:
14+
// - EchidnaHandler: handler_* functions
15+
// - EchidnaTest: fuzz_* wrapper functions and _testSelf helper
16+
}

0 commit comments

Comments
 (0)