-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add script to manage super admin #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // SPDX-License-Identifier: CC0-1.0 | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import {Script} from "forge-std/Script.sol"; | ||
| import {console2} from "forge-std/console2.sol"; | ||
|
|
||
| import {StateOracle} from "../src/StateOracle.sol"; | ||
| import {IAdminVerifier} from "../src/interfaces/IAdminVerifier.sol"; | ||
|
|
||
| /// @title ManageAdminVerifiers | ||
| /// @notice Foundry script for adding or removing admin verifiers on an existing `StateOracle`. | ||
| /// @dev | ||
| /// Environment variables expected (all optional except `STATE_ORACLE_ADDRESS`): | ||
| /// - `STATE_ORACLE_ADDRESS`: address of the deployed `StateOracle` proxy/instance. | ||
| /// - `ADMIN_VERIFIER_TO_ADD`: address of the admin verifier to add (single address). | ||
| /// - `ADMIN_VERIFIER_TO_REMOVE`: address of the admin verifier to remove (single address). | ||
| /// | ||
| /// Example: | ||
| /// ```bash | ||
| /// STATE_ORACLE_ADDRESS=0xOracle \ | ||
| /// ADMIN_VERIFIER_TO_ADD=0xVerifier \ | ||
| /// forge script script/ManageAdminVerifiers.s.sol --broadcast --rpc-url $RPC_URL | ||
| /// ``` | ||
| contract ManageAdminVerifiers is Script { | ||
| error NoAdminVerifierAction(); | ||
|
|
||
| modifier broadcast() { | ||
| vm.startBroadcast(); | ||
| _; | ||
| vm.stopBroadcast(); | ||
| } | ||
|
|
||
| function run() external broadcast { | ||
| StateOracle oracle = StateOracle(vm.envAddress("STATE_ORACLE_ADDRESS")); | ||
| address verifierToAdd = vm.envOr("ADMIN_VERIFIER_TO_ADD", address(0)); | ||
| address verifierToRemove = vm.envOr("ADMIN_VERIFIER_TO_REMOVE", address(0)); | ||
| require(verifierToAdd != address(0) || verifierToRemove != address(0), NoAdminVerifierAction()); | ||
|
|
||
| if (verifierToAdd != address(0)) _addAdminVerifier(oracle, verifierToAdd); | ||
| if (verifierToRemove != address(0)) _removeAdminVerifier(oracle, verifierToRemove); | ||
| } | ||
|
|
||
| function addAdminVerifier(StateOracle oracle, address verifier) public broadcast { | ||
| _addAdminVerifier(oracle, verifier); | ||
| } | ||
|
|
||
| function removeAdminVerifier(StateOracle oracle, address verifier) public broadcast { | ||
| _removeAdminVerifier(oracle, verifier); | ||
| } | ||
|
|
||
| function _addAdminVerifier(StateOracle oracle, address verifier) internal { | ||
| IAdminVerifier adminVerifier = IAdminVerifier(verifier); | ||
| if (oracle.isAdminVerifierRegistered(adminVerifier)) { | ||
| console2.log("Admin verifier already registered:", verifier); | ||
| return; | ||
| } | ||
|
|
||
| oracle.addAdminVerifier(adminVerifier); | ||
| console2.log("Added admin verifier:", verifier); | ||
| } | ||
|
|
||
| function _removeAdminVerifier(StateOracle oracle, address verifier) internal { | ||
| IAdminVerifier adminVerifier = IAdminVerifier(verifier); | ||
| if (!oracle.isAdminVerifierRegistered(adminVerifier)) { | ||
| console2.log("Admin verifier not registered, skipping removal:", verifier); | ||
| return; | ||
| } | ||
|
|
||
| oracle.removeAdminVerifier(adminVerifier); | ||
| console2.log("Removed admin verifier:", verifier); | ||
| } | ||
| } | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // SPDX-License-Identifier: CC0-1.0 | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import {Script} from "forge-std/Script.sol"; | ||
| import {console2} from "forge-std/console2.sol"; | ||
|
|
||
| import {AdminVerifierSuperAdmin} from "../../src/verification/admin/AdminVerifierSuperAdmin.sol"; | ||
|
|
||
| /// @title DeployAdminVerifierSuperAdmin | ||
| /// @notice Deploys the test-only verifier outside the production core deployment flow. | ||
| contract DeployAdminVerifierSuperAdmin is Script { | ||
| error InvalidSuperAdmin(); | ||
|
|
||
| function run() external returns (AdminVerifierSuperAdmin verifier) { | ||
| address superAdmin = vm.envAddress("ADMIN_VERIFIER_SUPER_ADMIN_ADDRESS"); | ||
| require(superAdmin != address(0), InvalidSuperAdmin()); | ||
|
|
||
| vm.startBroadcast(); | ||
| verifier = new AdminVerifierSuperAdmin(superAdmin); | ||
| vm.stopBroadcast(); | ||
|
|
||
| console2.log("Admin Verifier (Super Admin) deployed at", address(verifier)); | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // SPDX-License-Identifier: CC0-1.0 | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import {Test} from "forge-std/Test.sol"; | ||
|
|
||
| import {DeployAdminVerifierSuperAdmin} from "../script/test/DeployAdminVerifierSuperAdmin.s.sol"; | ||
| import {ManageAdminVerifiers} from "../script/ManageAdminVerifiers.s.sol"; | ||
| import {IAdminVerifier} from "../src/interfaces/IAdminVerifier.sol"; | ||
| import {AdminVerifierSuperAdmin} from "../src/verification/admin/AdminVerifierSuperAdmin.sol"; | ||
|
|
||
| contract AdminVerifierRegistryMock { | ||
| mapping(IAdminVerifier verifier => bool registered) public isAdminVerifierRegistered; | ||
|
|
||
| function addAdminVerifier(IAdminVerifier verifier) external { | ||
| isAdminVerifierRegistered[verifier] = true; | ||
| } | ||
|
|
||
| function removeAdminVerifier(IAdminVerifier verifier) external { | ||
| isAdminVerifierRegistered[verifier] = false; | ||
| } | ||
| } | ||
|
|
||
| contract ManagementScriptsTest is Test { | ||
| function test_ManageAdminVerifiersRunAddsAndRemovesConfiguredVerifiers() public { | ||
| ManageAdminVerifiers script = new ManageAdminVerifiers(); | ||
| AdminVerifierRegistryMock oracle = new AdminVerifierRegistryMock(); | ||
| IAdminVerifier verifierToAdd = IAdminVerifier(makeAddr("verifierToAdd")); | ||
| IAdminVerifier verifierToRemove = IAdminVerifier(makeAddr("verifierToRemove")); | ||
| oracle.addAdminVerifier(verifierToRemove); | ||
|
|
||
| vm.setEnv("STATE_ORACLE_ADDRESS", vm.toString(address(oracle))); | ||
| vm.setEnv("ADMIN_VERIFIER_TO_ADD", vm.toString(address(verifierToAdd))); | ||
| vm.setEnv("ADMIN_VERIFIER_TO_REMOVE", vm.toString(address(verifierToRemove))); | ||
|
|
||
| script.run(); | ||
|
|
||
| assertTrue(oracle.isAdminVerifierRegistered(verifierToAdd)); | ||
| assertFalse(oracle.isAdminVerifierRegistered(verifierToRemove)); | ||
| } | ||
|
|
||
| function test_DeployAdminVerifierSuperAdminUsesConfiguredOwner() public { | ||
| address superAdmin = makeAddr("superAdmin"); | ||
| vm.setEnv("ADMIN_VERIFIER_SUPER_ADMIN_ADDRESS", vm.toString(superAdmin)); | ||
|
|
||
| AdminVerifierSuperAdmin verifier = new DeployAdminVerifierSuperAdmin().run(); | ||
|
|
||
| assertEq(verifier.owner(), superAdmin); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documented command invokes Foundry's default run entrypoint, but this contract has no run function and never reads the listed environment variables. As written, the example cannot add or remove anything. Can we add a configured entrypoint or document the explicit function signature and arguments instead?