Skip to content

Commit

Permalink
feat: Scaffolding for DeployAuthSystemInput (#11889)
Browse files Browse the repository at this point in the history
* feat: Scaffolding for DeployAuthSystemInput

* fix: Remove undefined import

* feat: Address feedback
  • Loading branch information
maurelian authored Sep 13, 2024
1 parent d432185 commit 3ba35fa
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/contracts-bedrock/scripts/DeployAuthSystem.s.sol
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;
}
}
57 changes: 57 additions & 0 deletions packages/contracts-bedrock/test/DeployAuthSystem.t.sol
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);
}
}
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"
]

0 comments on commit 3ba35fa

Please sign in to comment.