Skip to content

Commit

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

* feat: Scaffolding for DeployAuthSystem Output

* feat: Address feedback and remove comments
  • Loading branch information
maurelian authored Sep 13, 2024
1 parent c8d6dbb commit f70248a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/contracts-bedrock/scripts/DeployAuthSystem.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,27 @@ contract DeployAuthSystemInput is CommonBase {
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;
}
}
63 changes: 62 additions & 1 deletion packages/contracts-bedrock/test/DeployAuthSystem.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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";
import { DeployAuthSystemInput, DeployAuthSystemOutput } from "scripts/DeployAuthSystem.s.sol";

contract DeployAuthSystemInput_Test is Test {
DeployAuthSystemInput dasi;
Expand Down Expand Up @@ -55,3 +55,64 @@ contract DeployAuthSystemInput_Test is Test {
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
safe = "0xDC93f9959c0F9c3849461B6468B4592a19567E09"

0 comments on commit f70248a

Please sign in to comment.