Skip to content

Commit a8353d2

Browse files
zerosnacksampagent
andcommitted
refactor: prefix private members with underscore
Aligns with the convention already used in StdAssertions, StdInvariant, and StdConfig, and addresses the second goal of #653. Renamed private state variables and helper functions: - StdChains: _stdChainsInitialized, _chains, _defaultRpcUrls, _idToAlias, _fallbackToDefaultRpcUrls, _initializeStdChains, _getChainWithUpdatedRpcUrl, _setChainWithDefaultRpcUrl - StdCheats: _gasMeteringOff, _stdstore, _console2_log_StdCheats - StdStorage: _read, _bytesToBytes32, _flatten - StdStyle: _styleConcat - StdUtils: _addressFromLast20Bytes, _console2_log_StdUtils Renamed private constants: - StdAssertions: _FAILED_SLOT - StdCheats: _UINT256_MAX, _CONSOLE2_ADDRESS - StdConfig: _NUM_TYPES - StdMath: _INT256_MIN - StdUtils: _UINT256_MAX, _INT256_MIN_ABS, _SECP256K1_ORDER, _CONSOLE2_ADDRESS Excluded: 'vm' private constant (universal alias across forge-std). Amp-Thread-ID: https://ampcode.com/threads/T-019e207d-61e2-7644-94cb-9a8861834bb5 Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019e207d-61e2-7644-94cb-9a8861834bb5 Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019e207d-61e2-7644-94cb-9a8861834bb5 Co-authored-by: Amp <amp@ampcode.com>
1 parent 84ab71a commit a8353d2

8 files changed

Lines changed: 155 additions & 152 deletions

File tree

src/StdAssertions.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract contract StdAssertions {
3333
event log_named_array(string key, int256[] val);
3434
event log_named_array(string key, address[] val);
3535

36-
bytes32 private constant FAILED_SLOT = bytes32("failed");
36+
bytes32 private constant _FAILED_SLOT = bytes32("failed");
3737

3838
bool private _failed;
3939

@@ -43,13 +43,13 @@ abstract contract StdAssertions {
4343
if (_failed) {
4444
return true;
4545
} else {
46-
return vm.load(address(vm), FAILED_SLOT) != bytes32(0);
46+
return vm.load(address(vm), _FAILED_SLOT) != bytes32(0);
4747
}
4848
}
4949

5050
/// @notice Marks the test as failed and records the failure in storage.
5151
function fail() internal virtual {
52-
vm.store(address(vm), FAILED_SLOT, bytes32(uint256(1)));
52+
vm.store(address(vm), _FAILED_SLOT, bytes32(uint256(1)));
5353
_failed = true;
5454
}
5555

src/StdChains.sol

Lines changed: 86 additions & 84 deletions
Large diffs are not rendered by default.

src/StdCheats.sol

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {Vm} from "./Vm.sol";
88
abstract contract StdCheatsSafe {
99
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
1010

11-
uint256 private constant UINT256_MAX =
11+
uint256 private constant _UINT256_MAX =
1212
115792089237316195423570985008687907853269984665640564039457584007913129639935;
1313

14-
bool private gasMeteringOff;
14+
bool private _gasMeteringOff;
1515

1616
// Data structures to parse Transaction objects from the broadcast artifact
1717
// that conform to EIP1559. The Raw structs are what are parsed from the JSON
@@ -283,7 +283,7 @@ abstract contract StdCheatsSafe {
283283
// implemented by `addr`, which should be taken into account when this function is used.
284284
function _isPayable(address addr) private returns (bool) {
285285
require(
286-
addr.balance < UINT256_MAX,
286+
addr.balance < _UINT256_MAX,
287287
"StdCheats _isPayable(address): Balance equals max uint256, so it cannot receive any more funds"
288288
);
289289
uint256 origBalanceTest = address(this).balance;
@@ -629,14 +629,14 @@ abstract contract StdCheatsSafe {
629629
// i.e. funcA() noGasMetering { funcB() }, where funcB has noGasMetering as well.
630630
// funcA will have `gasStartedOff` as false, funcB will have it as true,
631631
// so we only turn metering back on at the end of the funcA
632-
bool gasStartedOff = gasMeteringOff;
633-
gasMeteringOff = true;
632+
bool gasStartedOff = _gasMeteringOff;
633+
_gasMeteringOff = true;
634634

635635
_;
636636

637637
// if gas metering was on when this modifier was called, turn it back on at the end
638638
if (!gasStartedOff) {
639-
gasMeteringOff = false;
639+
_gasMeteringOff = false;
640640
vm.resumeGasMetering();
641641
}
642642
}
@@ -668,9 +668,9 @@ abstract contract StdCheatsSafe {
668668
abstract contract StdCheats is StdCheatsSafe {
669669
using stdStorage for StdStorage;
670670

671-
StdStorage private stdstore;
671+
StdStorage private _stdstore;
672672
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
673-
address private constant CONSOLE2_ADDRESS = 0x000000000000000000636F6e736F6c652e6c6f67;
673+
address private constant _CONSOLE2_ADDRESS = 0x000000000000000000636F6e736F6c652e6c6f67;
674674

675675
/// @notice Advances the block timestamp forward by `time` seconds.
676676
function skip(uint256 time) internal virtual {
@@ -733,15 +733,15 @@ abstract contract StdCheats is StdCheatsSafe {
733733
/// @notice Changes the active prank to `msgSender`.
734734
/// @dev Deprecated. Use `vm.startPrank` instead.
735735
function changePrank(address msgSender) internal virtual {
736-
console2_log_StdCheats("changePrank is deprecated. Please use vm.startPrank instead.");
736+
_console2_log_StdCheats("changePrank is deprecated. Please use vm.startPrank instead.");
737737
vm.stopPrank();
738738
vm.startPrank(msgSender);
739739
}
740740

741741
/// @notice Changes the active prank to `msgSender` with `txOrigin` as `tx.origin`.
742742
/// @dev Deprecated. Use `vm.startPrank` instead.
743743
function changePrank(address msgSender, address txOrigin) internal virtual {
744-
console2_log_StdCheats("changePrank is deprecated. Please use vm.startPrank instead.");
744+
_console2_log_StdCheats("changePrank is deprecated. Please use vm.startPrank instead.");
745745
vm.stopPrank();
746746
vm.startPrank(msgSender, txOrigin);
747747
}
@@ -828,7 +828,7 @@ abstract contract StdCheats is StdCheatsSafe {
828828
uint256 prevBal = abi.decode(balData, (uint256));
829829

830830
// update balance
831-
stdstore.target(token).sig(0x70a08231).with_key(to).checked_write(give);
831+
_stdstore.target(token).sig(0x70a08231).with_key(to).checked_write(give);
832832

833833
// update total supply
834834
if (adjust) {
@@ -839,7 +839,7 @@ abstract contract StdCheats is StdCheatsSafe {
839839
} else {
840840
totSup += (give - prevBal);
841841
}
842-
stdstore.target(token).sig(0x18160ddd).checked_write(totSup);
842+
_stdstore.target(token).sig(0x18160ddd).checked_write(totSup);
843843
}
844844
}
845845

@@ -850,7 +850,7 @@ abstract contract StdCheats is StdCheatsSafe {
850850
uint256 prevBal = abi.decode(balData, (uint256));
851851

852852
// update balance
853-
stdstore.target(token).sig(0x00fdd58e).with_key(to).with_key(id).checked_write(give);
853+
_stdstore.target(token).sig(0x00fdd58e).with_key(to).with_key(id).checked_write(give);
854854

855855
// update total supply
856856
if (adjust) {
@@ -865,7 +865,7 @@ abstract contract StdCheats is StdCheatsSafe {
865865
} else {
866866
totSup += (give - prevBal);
867867
}
868-
stdstore.target(token).sig(0xbd85b039).with_key(id).checked_write(totSup);
868+
_stdstore.target(token).sig(0xbd85b039).with_key(id).checked_write(totSup);
869869
}
870870
}
871871

@@ -885,11 +885,11 @@ abstract contract StdCheats is StdCheatsSafe {
885885
uint256 toPrevBal = abi.decode(toBalData, (uint256));
886886

887887
// update balances
888-
stdstore.target(token).sig(0x70a08231).with_key(abi.decode(ownerData, (address))).checked_write(--fromPrevBal);
889-
stdstore.target(token).sig(0x70a08231).with_key(to).checked_write(++toPrevBal);
888+
_stdstore.target(token).sig(0x70a08231).with_key(abi.decode(ownerData, (address))).checked_write(--fromPrevBal);
889+
_stdstore.target(token).sig(0x70a08231).with_key(to).checked_write(++toPrevBal);
890890

891891
// update owner
892-
stdstore.target(token).sig(0x6352211e).with_key(id).checked_write(to);
892+
_stdstore.target(token).sig(0x6352211e).with_key(id).checked_write(to);
893893
}
894894

895895
/// @notice Etches the runtime bytecode of `what` (from the artifacts directory) at `where`.
@@ -915,8 +915,8 @@ abstract contract StdCheats is StdCheatsSafe {
915915
}
916916

917917
// Used to prevent the compilation of console, which shortens the compilation time when console is not used elsewhere.
918-
function console2_log_StdCheats(string memory p0) private view {
919-
(bool status,) = address(CONSOLE2_ADDRESS).staticcall(abi.encodeWithSignature("log(string)", p0));
918+
function _console2_log_StdCheats(string memory p0) private view {
919+
(bool status,) = address(_CONSOLE2_ADDRESS).staticcall(abi.encodeWithSignature("log(string)", p0));
920920
status;
921921
}
922922
}

src/StdConfig.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ contract StdConfig {
3838
VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));
3939

4040
/// @dev Types: `bool`, `address`, `bytes32`, `uint`, `int`, `string`, `bytes`.
41-
uint8 private constant NUM_TYPES = 7;
41+
uint8 private constant _NUM_TYPES = 7;
4242

4343
// -- ERRORS ---------------------------------------------------------------
4444

@@ -114,7 +114,7 @@ contract StdConfig {
114114
}
115115

116116
// Iterate through all the available `TypeKind`s (except `None`) to create the sub-section paths
117-
for (uint8 t = 1; t <= NUM_TYPES; t++) {
117+
for (uint8 t = 1; t <= _NUM_TYPES; t++) {
118118
TypeKind ty = TypeKind(t);
119119
string memory typePath = string.concat("$.", chain_key, ".", ty.toTomlKey());
120120

src/StdMath.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ pragma solidity >=0.8.13 <0.9.0;
33

44
/// @notice Mathematical utility functions for unsigned and signed integers.
55
library stdMath {
6-
int256 private constant INT256_MIN = -57896044618658097711785492504343953926634992332820282019728792003956564819968;
6+
int256 private constant _INT256_MIN =
7+
-57896044618658097711785492504343953926634992332820282019728792003956564819968;
78

89
/// @notice Computes the absolute value of a signed integer.
910
/// @param a The signed integer to compute the absolute value of.
1011
/// @return The absolute value as an unsigned integer.
1112
function abs(int256 a) internal pure returns (uint256) {
1213
// Required or it will fail when `a = type(int256).min`
13-
if (a == INT256_MIN) {
14+
if (a == _INT256_MIN) {
1415
return 57896044618658097711785492504343953926634992332820282019728792003956564819968;
1516
}
1617

src/StdStorage.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ library stdStorageSafe {
3636
/// @notice Returns the encoded call parameters (keys or raw calldata) for the configured target function.
3737
function getCallParams(StdStorage storage self) internal view returns (bytes memory) {
3838
if (self._calldata.length == 0) {
39-
return flatten(self._keys);
39+
return _flatten(self._keys);
4040
} else {
4141
return self._calldata;
4242
}
@@ -46,7 +46,7 @@ library stdStorageSafe {
4646
function callTarget(StdStorage storage self) internal view returns (bool, bytes32) {
4747
bytes memory cd = abi.encodePacked(self._sig, getCallParams(self));
4848
(bool success, bytes memory rdat) = self._target.staticcall(cd);
49-
bytes32 result = bytesToBytes32(rdat, 32 * self._depth);
49+
bytes32 result = _bytesToBytes32(rdat, 32 * self._depth);
5050

5151
return (success, result);
5252
}
@@ -225,7 +225,7 @@ library stdStorageSafe {
225225
return self;
226226
}
227227

228-
function read(StdStorage storage self) private returns (bytes memory) {
228+
function _read(StdStorage storage self) private returns (bytes memory) {
229229
FindData storage data = find(self, false);
230230
uint256 mask = getMaskByOffsets(data.offsetLeft, data.offsetRight);
231231
uint256 value = (uint256(vm.load(self._target, bytes32(data.slot))) & mask) >> data.offsetRight;
@@ -235,7 +235,7 @@ library stdStorageSafe {
235235

236236
/// @notice Reads the found storage slot value as bytes32.
237237
function read_bytes32(StdStorage storage self) internal returns (bytes32) {
238-
return abi.decode(read(self), (bytes32));
238+
return abi.decode(_read(self), (bytes32));
239239
}
240240

241241
/// @notice Reads the found storage slot value as bool.
@@ -249,17 +249,17 @@ library stdStorageSafe {
249249

250250
/// @notice Reads the found storage slot value as address.
251251
function read_address(StdStorage storage self) internal returns (address) {
252-
return abi.decode(read(self), (address));
252+
return abi.decode(_read(self), (address));
253253
}
254254

255255
/// @notice Reads the found storage slot value as uint256.
256256
function read_uint(StdStorage storage self) internal returns (uint256) {
257-
return abi.decode(read(self), (uint256));
257+
return abi.decode(_read(self), (uint256));
258258
}
259259

260260
/// @notice Reads the found storage slot value as int256.
261261
function read_int(StdStorage storage self) internal returns (int256) {
262-
return abi.decode(read(self), (int256));
262+
return abi.decode(_read(self), (int256));
263263
}
264264

265265
/// @notice Returns the parent mapping slot index and the key used to reach the found slot.
@@ -299,7 +299,7 @@ library stdStorageSafe {
299299
return uint256(root_slot);
300300
}
301301

302-
function bytesToBytes32(bytes memory b, uint256 offset) private pure returns (bytes32) {
302+
function _bytesToBytes32(bytes memory b, uint256 offset) private pure returns (bytes32) {
303303
bytes32 out;
304304

305305
// Cap read length by remaining bytes from `offset`, and at most 32 bytes to avoid out-of-bounds
@@ -313,7 +313,7 @@ library stdStorageSafe {
313313
return out;
314314
}
315315

316-
function flatten(bytes32[] memory b) private pure returns (bytes memory) {
316+
function _flatten(bytes32[] memory b) private pure returns (bytes memory) {
317317
bytes memory result = new bytes(b.length * 32);
318318
for (uint256 i = 0; i < b.length; i++) {
319319
bytes32 k = b[i];

src/StdStyle.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ library StdStyle {
1919
string constant INVERSE = "\u001b[7m";
2020
string constant RESET = "\u001b[0m";
2121

22-
function styleConcat(string memory style, string memory self) private pure returns (string memory) {
22+
function _styleConcat(string memory style, string memory self) private pure returns (string memory) {
2323
return string(abi.encodePacked(style, self, RESET));
2424
}
2525

2626
/// @notice Returns `self` wrapped in red ANSI color codes.
2727
function red(string memory self) internal pure returns (string memory) {
28-
return styleConcat(RED, self);
28+
return _styleConcat(RED, self);
2929
}
3030

3131
/// @notice Returns the string representation of `self` wrapped in red ANSI color codes.
@@ -60,7 +60,7 @@ library StdStyle {
6060

6161
/// @notice Returns `self` wrapped in green ANSI color codes.
6262
function green(string memory self) internal pure returns (string memory) {
63-
return styleConcat(GREEN, self);
63+
return _styleConcat(GREEN, self);
6464
}
6565

6666
/// @notice Returns the string representation of `self` wrapped in green ANSI color codes.
@@ -95,7 +95,7 @@ library StdStyle {
9595

9696
/// @notice Returns `self` wrapped in yellow ANSI color codes.
9797
function yellow(string memory self) internal pure returns (string memory) {
98-
return styleConcat(YELLOW, self);
98+
return _styleConcat(YELLOW, self);
9999
}
100100

101101
/// @notice Returns the string representation of `self` wrapped in yellow ANSI color codes.
@@ -130,7 +130,7 @@ library StdStyle {
130130

131131
/// @notice Returns `self` wrapped in blue ANSI color codes.
132132
function blue(string memory self) internal pure returns (string memory) {
133-
return styleConcat(BLUE, self);
133+
return _styleConcat(BLUE, self);
134134
}
135135

136136
/// @notice Returns the string representation of `self` wrapped in blue ANSI color codes.
@@ -165,7 +165,7 @@ library StdStyle {
165165

166166
/// @notice Returns `self` wrapped in magenta ANSI color codes.
167167
function magenta(string memory self) internal pure returns (string memory) {
168-
return styleConcat(MAGENTA, self);
168+
return _styleConcat(MAGENTA, self);
169169
}
170170

171171
/// @notice Returns the string representation of `self` wrapped in magenta ANSI color codes.
@@ -200,7 +200,7 @@ library StdStyle {
200200

201201
/// @notice Returns `self` wrapped in cyan ANSI color codes.
202202
function cyan(string memory self) internal pure returns (string memory) {
203-
return styleConcat(CYAN, self);
203+
return _styleConcat(CYAN, self);
204204
}
205205

206206
/// @notice Returns the string representation of `self` wrapped in cyan ANSI color codes.
@@ -235,7 +235,7 @@ library StdStyle {
235235

236236
/// @notice Returns `self` wrapped in bold ANSI style codes.
237237
function bold(string memory self) internal pure returns (string memory) {
238-
return styleConcat(BOLD, self);
238+
return _styleConcat(BOLD, self);
239239
}
240240

241241
/// @notice Returns the string representation of `self` wrapped in bold ANSI style codes.
@@ -270,7 +270,7 @@ library StdStyle {
270270

271271
/// @notice Returns `self` wrapped in dim ANSI style codes.
272272
function dim(string memory self) internal pure returns (string memory) {
273-
return styleConcat(DIM, self);
273+
return _styleConcat(DIM, self);
274274
}
275275

276276
/// @notice Returns the string representation of `self` wrapped in dim ANSI style codes.
@@ -305,7 +305,7 @@ library StdStyle {
305305

306306
/// @notice Returns `self` wrapped in italic ANSI style codes.
307307
function italic(string memory self) internal pure returns (string memory) {
308-
return styleConcat(ITALIC, self);
308+
return _styleConcat(ITALIC, self);
309309
}
310310

311311
/// @notice Returns the string representation of `self` wrapped in italic ANSI style codes.
@@ -340,7 +340,7 @@ library StdStyle {
340340

341341
/// @notice Returns `self` wrapped in underline ANSI style codes.
342342
function underline(string memory self) internal pure returns (string memory) {
343-
return styleConcat(UNDERLINE, self);
343+
return _styleConcat(UNDERLINE, self);
344344
}
345345

346346
/// @notice Returns the string representation of `self` wrapped in underline ANSI style codes.
@@ -375,7 +375,7 @@ library StdStyle {
375375

376376
/// @notice Returns `self` wrapped in inverse ANSI style codes.
377377
function inverse(string memory self) internal pure returns (string memory) {
378-
return styleConcat(INVERSE, self);
378+
return _styleConcat(INVERSE, self);
379379
}
380380

381381
/// @notice Returns the string representation of `self` wrapped in inverse ANSI style codes.

0 commit comments

Comments
 (0)