Last active
January 21, 2023 03:42
-
-
Save CyrusNuevoDia/57e9f90336a24fd3adf588d984c5ff01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
import "forge-std/Test.sol"; | |
import "solady/utils/LibString.sol"; | |
abstract contract DiamondTest is Test { | |
using LibString for string; | |
function _facetSelectors( | |
string memory facetName | |
) internal returns (bytes4[] memory selectors) { | |
string[] memory output = string( | |
vm.ffi( | |
string( | |
abi.encodePacked("forge inspect ", facetName, " methods") | |
).split(" ") | |
) | |
).split(":"); | |
uint256 count = output.length - 1; | |
string memory part; | |
uint256 end; | |
uint256 start; | |
unchecked { | |
selectors = new bytes4[](count); | |
for (uint256 i = 0; i < count; ++i) { | |
part = output[i]; | |
start = part.indexOf(' "', 0) + 3; | |
end = part.indexOf('"', start); | |
selectors[i] = bytes4(keccak256(bytes(part.slice(start, end)))); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment