Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
8dd17a7b
Unverified
Commit
8dd17a7b
authored
Apr 12, 2024
by
Maurelian
Committed by
GitHub
Apr 12, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ctb: Move _getL1ContractFunctionAbis to CommonTest (#10139)
parent
3113b238
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
43 deletions
+44
-43
ForgeArtifacts.sol
packages/contracts-bedrock/scripts/ForgeArtifacts.sol
+42
-0
Specs.t.sol
packages/contracts-bedrock/test/Specs.t.sol
+2
-43
No files found.
packages/contracts-bedrock/scripts/ForgeArtifacts.sol
View file @
8dd17a7b
...
...
@@ -16,6 +16,16 @@ struct StorageSlot {
string _type;
}
struct AbiEntry {
string fnName;
bytes4 sel;
}
struct Abi {
string contractName;
AbiEntry[] entries;
}
/// @title ForgeArtifacts
/// @notice Library for interacting with the forge artifacts.
library ForgeArtifacts {
...
...
@@ -133,6 +143,38 @@ library ForgeArtifacts {
slot_ = abi.decode(rawSlot, (StorageSlot));
}
/// @notice Returns the function ABIs of all L1 contracts.
function getL1ContractFunctionAbis() internal returns (Abi[] memory abis_) {
string[] memory command = new string[](3);
command[0] = Executables.bash;
command[1] = "-c";
command[2] = string.concat(
Executables.find,
" src/{L1,governance,universal/ProxyAdmin.sol} -type f -exec basename {} \\;",
" | ",
Executables.sed,
" 's/\\.[^.]*$//'",
" | ",
Executables.jq,
" -R -s 'split(\"\n\")[:-1]'"
);
string[] memory contractNames = abi.decode(vm.parseJson(string(vm.ffi(command))), (string[]));
abis_ = new Abi[](contractNames.length);
for (uint256 i; i < contractNames.length; i++) {
string memory contractName = contractNames[i];
string[] memory methodIdentifiers = ForgeArtifacts.getMethodIdentifiers(contractName);
abis_[i].contractName = contractName;
abis_[i].entries = new AbiEntry[](methodIdentifiers.length);
for (uint256 j; j < methodIdentifiers.length; j++) {
string memory fnName = methodIdentifiers[j];
bytes4 sel = bytes4(keccak256(abi.encodePacked(fnName)));
abis_[i].entries[j] = AbiEntry({ fnName: fnName, sel: sel });
}
}
}
/// @notice Accepts a filepath and then ensures that the directory
/// exists for the file to live in.
function ensurePath(string memory _path) internal {
...
...
packages/contracts-bedrock/test/Specs.t.sol
View file @
8dd17a7b
...
...
@@ -2,6 +2,7 @@
pragma solidity ^0.8.15;
import { CommonTest } from "test/setup/CommonTest.sol";
import { Abi, AbiEntry } from "scripts/ForgeArtifacts.sol";
import { Executables } from "scripts/Executables.sol";
import { console2 as console } from "forge-std/console2.sol";
import { ProtocolVersions } from "src/L1/ProtocolVersions.sol";
...
...
@@ -18,16 +19,6 @@ import { ForgeArtifacts } from "scripts/ForgeArtifacts.sol";
/// properties of the new function. The `Spec` struct reppresents this documentation. However, this contract does
/// not actually test to verify these properties, only that a spec is defined.
contract Specification_Test is CommonTest {
struct AbiEntry {
string fnName;
bytes4 sel;
}
struct Abi {
string contractName;
AbiEntry[] entries;
}
enum Role {
NOAUTH,
PROPOSER,
...
...
@@ -485,7 +476,7 @@ contract Specification_Test is CommonTest {
/// @notice Ensures that there's an auth spec for every L1 contract function.
function testContractAuth() public {
Abi[] memory abis =
_
getL1ContractFunctionAbis();
Abi[] memory abis =
ForgeArtifacts.
getL1ContractFunctionAbis();
for (uint256 i = 0; i < abis.length; i++) {
string memory contractName = abis[i].contractName;
...
...
@@ -504,36 +495,4 @@ contract Specification_Test is CommonTest {
}
}
}
/// @dev Returns the function ABIs of all L1 contracts.
function _getL1ContractFunctionAbis() internal returns (Abi[] memory abis_) {
string[] memory command = new string[](3);
command[0] = Executables.bash;
command[1] = "-c";
command[2] = string.concat(
Executables.find,
" src/{L1,governance,universal/ProxyAdmin.sol} -type f -exec basename {} \\;",
" | ",
Executables.sed,
" 's/\\.[^.]*$//'",
" | ",
Executables.jq,
" -R -s 'split(\"\n\")[:-1]'"
);
string[] memory contractNames = abi.decode(vm.parseJson(string(vm.ffi(command))), (string[]));
abis_ = new Abi[](contractNames.length);
for (uint256 i; i < contractNames.length; i++) {
string memory contractName = contractNames[i];
string[] memory methodIdentifiers = ForgeArtifacts.getMethodIdentifiers(contractName);
abis_[i].contractName = contractName;
abis_[i].entries = new AbiEntry[](methodIdentifiers.length);
for (uint256 j; j < methodIdentifiers.length; j++) {
string memory fnName = methodIdentifiers[j];
bytes4 sel = bytes4(keccak256(abi.encodePacked(fnName)));
abis_[i].entries[j] = AbiEntry({ fnName: fnName, sel: sel });
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment