Skip to content

Commit

Permalink
refactor: embed checkAuth into checkChainlogKey
Browse files Browse the repository at this point in the history
  • Loading branch information
amusingaxl committed Dec 21, 2023
1 parent ae05451 commit 1358401
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 50 deletions.
38 changes: 11 additions & 27 deletions src/DssSpell.t.base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1516,40 +1516,24 @@ contract DssSpellTestBase is Config, DssTest {
}

/**
* @notice Checks if the deployer of contracts being added to the chainlog has not kept `wards` access to it.
* @dev Reverts if any non-existent keys are present the list.
* @param keys A list of chainlog keys.
* @notice Checks if the the deployer of a contract the chainlog has not kept `wards` access to it.
* @dev Reverts if `key` is not in the chainlog.
*/
function _checkAuth(bytes32[] memory keys) internal {
_vote(address(spell));
_scheduleWaitAndCast(address(spell));
assertTrue(spell.done(), "TestError/spell-not-done");
function _checkAuth(bytes32 key) internal {
address _addr = chainLog.getAddress(key);
string memory contractName = string(abi.encodePacked(key));

for(uint256 i = 0; i < keys.length; i++) {
_checkWards(chainLog.getAddress(keys[i]), string(abi.encodePacked(keys[i])));
}
_checkWards(_addr, contractName);
_checkOsmSrcWards(_addr, contractName);
}

/**
* @notice Same as `_checkAuth`, but specific for OSMs.
* @dev Reverts if any non-existent keys are present the list.
* @param keys A list of chainlog keys for OSMs.
*/
function _checkOsmAuth(bytes32[] memory keys) internal {
_vote(address(spell));
_scheduleWaitAndCast(address(spell));
assertTrue(spell.done(), "TestError/spell-not-done");

for(uint256 i = 0; i < keys.length; i++) {
address _addr = chainLog.getAddress(keys[i]);
string memory _key = string(abi.encodePacked(keys[i]));
_checkWards(_addr, _key);
_checkOsmSrcWards(_addr, _key);
}
function _checkMatchingKeyAddresses(bytes32 key) internal {
assertEq(chainLog.getAddress(key), addr.addr(key), _concat("TestError/Chainlog-key-mismatch-", key));
}

function _checkChainlogKey(bytes32 key) internal {
assertEq(chainLog.getAddress(key), addr.addr(key), _concat("TestError/Chainlog-key-mismatch-", key));
_checkMatchingKeyAddresses(key);
_checkAuth(key);
}

function _checkChainlogVersion(string memory key) internal {
Expand Down
28 changes: 5 additions & 23 deletions src/DssSpell.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,6 @@ contract DssSpellTest is DssSpellTestBase {

// TESTS BELOW CAN BE ENABLED/DISABLED ON DEMAND

function testAuth() private { // make private to disable
bytes32[] memory keys = new bytes32[](2);
keys[0] = "MCD_JOIN_TOKEN_X";
keys[1] = "MCD_CLIP_TOKEN_X";

_checkAuth(keys);
}

function testOsmAuth() private { // make private to disable
bytes32[] memory keys = new bytes32[](3);
keys[0] = "PIP_XXX";
keys[1] = "PIP_YYY";
keys[2] = "PIP_ZZZ";

_checkOsmAuth(keys);
}

function testOracleList() private { // make private to disable
// address ORACLE_WALLET01 = 0x4D6fbF888c374D7964D56144dE0C0cFBd49750D3;

Expand Down Expand Up @@ -300,16 +283,15 @@ contract DssSpellTest is DssSpellTestBase {
}

function testNewChainlogValues() private { // make private to disable

_vote(address(spell));
_scheduleWaitAndCast(address(spell));
assertTrue(spell.done());

// _checkChainlogKey("MCD_PSM_GUSD_A_JAR");
// _checkChainlogKey("MCD_PSM_GUSD_A_INPUT_CONDUIT_JAR");
// _checkChainlogKey("MCD_PSM_PAX_A_JAR");
// _checkChainlogKey("MCD_PSM_PAX_A_INPUT_CONDUIT_JAR");
// _checkChainlogVersion("1.17.1");
_checkChainlogKey("MCD_PSM_GUSD_A_JAR");
_checkChainlogKey("MCD_PSM_GUSD_A_INPUT_CONDUIT_JAR");
_checkChainlogKey("MCD_PSM_PAX_A_JAR");
_checkChainlogKey("MCD_PSM_PAX_A_INPUT_CONDUIT_JAR");
_checkChainlogVersion("1.17.1");
}

function testNewIlkRegistryValues() private { // make private to disable
Expand Down

0 comments on commit 1358401

Please sign in to comment.