forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Scaffolding for DeployAuthSystemInput (ethereum-optimism#11889)
* feat: Scaffolding for DeployAuthSystemInput * fix: Remove undefined import * feat: Address feedback
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.15; | ||
|
||
import { Script } from "forge-std/Script.sol"; | ||
import { CommonBase } from "forge-std/Base.sol"; | ||
import { stdToml } from "forge-std/StdToml.sol"; | ||
|
||
import { GnosisSafe as Safe } from "safe-contracts/GnosisSafe.sol"; | ||
|
||
import { DeployUtils } from "scripts/libraries/DeployUtils.sol"; | ||
import { Solarray } from "scripts/libraries/Solarray.sol"; | ||
|
||
// This file follows the pattern of Superchain.s.sol. Refer to that file for more details. | ||
contract DeployAuthSystemInput is CommonBase { | ||
using stdToml for string; | ||
|
||
// Generic safe inputs | ||
// Note: these will need to be replaced with settings specific to the different Safes in the system. | ||
uint256 internal _threshold; | ||
address[] internal _owners; | ||
|
||
function set(bytes4 _sel, uint256 _value) public { | ||
if (_sel == this.threshold.selector) _threshold = _value; | ||
else revert("DeployAuthSystemInput: unknown selector"); | ||
} | ||
|
||
function set(bytes4 _sel, address[] memory _addrs) public { | ||
if (_sel == this.owners.selector) { | ||
require(_owners.length == 0, "DeployAuthSystemInput: owners already set"); | ||
for (uint256 i = 0; i < _addrs.length; i++) { | ||
_owners.push(_addrs[i]); | ||
} | ||
} else { | ||
revert("DeployAuthSystemInput: unknown selector"); | ||
} | ||
} | ||
|
||
function loadInputFile(string memory _infile) public { | ||
string memory toml = vm.readFile(_infile); | ||
|
||
set(this.threshold.selector, toml.readUint(".safe.threshold")); | ||
set(this.owners.selector, toml.readAddressArray(".safe.owners")); | ||
} | ||
|
||
function threshold() public view returns (uint256) { | ||
require(_threshold != 0, "DeployAuthSystemInput: threshold not set"); | ||
return _threshold; | ||
} | ||
|
||
function owners() public view returns (address[] memory) { | ||
require(_owners.length != 0, "DeployAuthSystemInput: owners not set"); | ||
return _owners; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.15; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
import { stdToml } from "forge-std/StdToml.sol"; | ||
import { Solarray } from "scripts/libraries/Solarray.sol"; | ||
|
||
import { DeployAuthSystemInput } from "scripts/DeployAuthSystem.s.sol"; | ||
|
||
contract DeployAuthSystemInput_Test is Test { | ||
DeployAuthSystemInput dasi; | ||
|
||
uint256 threshold = 5; | ||
address[] owners; | ||
|
||
function setUp() public { | ||
dasi = new DeployAuthSystemInput(); | ||
address[] memory _owners = Solarray.addresses( | ||
0x1111111111111111111111111111111111111111, | ||
0x2222222222222222222222222222222222222222, | ||
0x3333333333333333333333333333333333333333, | ||
0x4444444444444444444444444444444444444444, | ||
0x5555555555555555555555555555555555555555, | ||
0x6666666666666666666666666666666666666666, | ||
0x7777777777777777777777777777777777777777 | ||
); | ||
|
||
for (uint256 i = 0; i < _owners.length; i++) { | ||
owners.push(_owners[i]); | ||
} | ||
} | ||
|
||
function test_loadInputFile_succeeds() public { | ||
string memory root = vm.projectRoot(); | ||
string memory path = string.concat(root, "/test/fixtures/test-deploy-auth-system-in.toml"); | ||
|
||
dasi.loadInputFile(path); | ||
|
||
assertEq(threshold, dasi.threshold(), "100"); | ||
assertEq(owners.length, dasi.owners().length, "200"); | ||
} | ||
|
||
function test_getters_whenNotSet_revert() public { | ||
vm.expectRevert("DeployAuthSystemInput: threshold not set"); | ||
dasi.threshold(); | ||
|
||
vm.expectRevert("DeployAuthSystemInput: owners not set"); | ||
dasi.owners(); | ||
} | ||
|
||
function test_setters_ownerAlreadySet_revert() public { | ||
dasi.set(dasi.owners.selector, owners); | ||
|
||
vm.expectRevert("DeployAuthSystemInput: owners already set"); | ||
dasi.set(dasi.owners.selector, owners); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/contracts-bedrock/test/fixtures/test-deploy-auth-system-in.toml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[safe] | ||
threshold = 5 | ||
owners = [ | ||
"0x1111111111111111111111111111111111111111", | ||
"0x2222222222222222222222222222222222222222", | ||
"0x3333333333333333333333333333333333333333", | ||
"0x4444444444444444444444444444444444444444", | ||
"0x5555555555555555555555555555555555555555", | ||
"0x6666666666666666666666666666666666666666", | ||
"0x7777777777777777777777777777777777777777" | ||
] |