Commit f70248a0 authored by Maurelian's avatar Maurelian Committed by GitHub

feat: Scaffolding for DeployAuthSystemInput (#11890)

* feat: Scaffolding for DeployAuthSystemInput

* feat: Scaffolding for DeployAuthSystem Output

* feat: Address feedback and remove comments
parent c8d6dbb4
...@@ -52,3 +52,27 @@ contract DeployAuthSystemInput is CommonBase { ...@@ -52,3 +52,27 @@ contract DeployAuthSystemInput is CommonBase {
return _owners; return _owners;
} }
} }
contract DeployAuthSystemOutput is CommonBase {
Safe internal _safe;
function set(bytes4 sel, address _address) public {
if (sel == this.safe.selector) _safe = Safe(payable(_address));
else revert("DeployAuthSystemOutput: unknown selector");
}
function writeOutputFile(string memory _outfile) public {
string memory out = vm.serializeAddress("outfile", "safe", address(this.safe()));
vm.writeToml(out, _outfile);
}
function checkOutput() public view {
address[] memory addrs = Solarray.addresses(address(this.safe()));
DeployUtils.assertValidContractAddresses(addrs);
}
function safe() public view returns (Safe) {
DeployUtils.assertValidContractAddress(address(_safe));
return _safe;
}
}
...@@ -5,7 +5,7 @@ import { Test } from "forge-std/Test.sol"; ...@@ -5,7 +5,7 @@ import { Test } from "forge-std/Test.sol";
import { stdToml } from "forge-std/StdToml.sol"; import { stdToml } from "forge-std/StdToml.sol";
import { Solarray } from "scripts/libraries/Solarray.sol"; import { Solarray } from "scripts/libraries/Solarray.sol";
import { DeployAuthSystemInput } from "scripts/DeployAuthSystem.s.sol"; import { DeployAuthSystemInput, DeployAuthSystemOutput } from "scripts/DeployAuthSystem.s.sol";
contract DeployAuthSystemInput_Test is Test { contract DeployAuthSystemInput_Test is Test {
DeployAuthSystemInput dasi; DeployAuthSystemInput dasi;
...@@ -55,3 +55,64 @@ contract DeployAuthSystemInput_Test is Test { ...@@ -55,3 +55,64 @@ contract DeployAuthSystemInput_Test is Test {
dasi.set(dasi.owners.selector, owners); dasi.set(dasi.owners.selector, owners);
} }
} }
contract DeployAuthSystemOutput_Test is Test {
using stdToml for string;
DeployAuthSystemOutput daso;
function setUp() public {
daso = new DeployAuthSystemOutput();
}
function test_set_succeeds() public {
address safeAddr = makeAddr("safe");
// Ensure the address has code, since it's expected to be a contract
vm.etch(safeAddr, hex"01");
// Set the output data
daso.set(daso.safe.selector, safeAddr);
// Compare the test data to the getter method
assertEq(safeAddr, address(daso.safe()), "100");
}
function test_getter_whenNotSet_reverts() public {
vm.expectRevert("DeployUtils: zero address");
daso.safe();
}
function test_getter_whenAddrHasNoCode_reverts() public {
address emptyAddr = makeAddr("emptyAddr");
bytes memory expectedErr = bytes(string.concat("DeployUtils: no code at ", vm.toString(emptyAddr)));
daso.set(daso.safe.selector, emptyAddr);
vm.expectRevert(expectedErr);
daso.safe();
}
function test_writeOutputFile_succeeds() public {
string memory root = vm.projectRoot();
// Use the expected data from the test fixture.
string memory expOutPath = string.concat(root, "/test/fixtures/test-deploy-auth-system-out.toml");
string memory expOutToml = vm.readFile(expOutPath);
address expSafe = expOutToml.readAddress(".safe");
// Etch code at each address so the code checks pass when settings values.
vm.etch(expSafe, hex"01");
daso.set(daso.safe.selector, expSafe);
string memory actOutPath = string.concat(root, "/.testdata/test-deploy-auth-system-output.toml");
daso.writeOutputFile(actOutPath);
string memory actOutToml = vm.readFile(actOutPath);
// Clean up before asserting so that we don't leave any files behind.
vm.removeFile(actOutPath);
assertEq(expOutToml, actOutToml);
}
}
safe = "0xDC93f9959c0F9c3849461B6468B4592a19567E09"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment