Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: change testAuth* strategy #374

Merged
merged 15 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 40 additions & 27 deletions src/DssSpell.t.base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1484,54 +1484,67 @@ contract DssSpellTestBase is Config, DssTest {
}
}

function _skipWards(address target, address deployer) internal pure returns (bool) {
// Kept for consistency but in general we don't want to skip checking wards on mainnet
target; deployer;
return false;
}

/**
* @dev Checks if the deployer of a contract has not kept `wards` access to the contract.
* Notice that it depends on `deployers` being kept up-to-date.
*/
function _checkWards(address _addr, string memory contractName) internal {
for (uint256 i = 0; i < deployers.count(); i ++) {
address deployer = deployers.addr(i);
(bool ok, bytes memory data) = _addr.call(
abi.encodeWithSignature("wards(address)", deployer)
);
(bool ok, bytes memory data) = _addr.call(abi.encodeWithSignature("wards(address)", deployer));
if (!ok || data.length != 32) return;

uint256 ward = abi.decode(data, (uint256));
if (ward > 0) {
if (_skipWards(_addr, deployer)) continue;
emit log("Error: Bad Auth");
emit log_named_address(" Deployer Address", deployer);
emit log_named_string(" Affected Contract", contractName);
fail();
fail("Error: Bad Auth");
}
}
}

function _checkSource(address _addr, string memory contractName) internal {
(bool ok, bytes memory data) =
_addr.call(abi.encodeWithSignature("src()"));
/**
* @dev Same as `_checkWards`, but for OSMs' underlying Median contracts.
*/
function _checkOsmSrcWards(address _addr, string memory contractName) internal {
(bool ok, bytes memory data) = _addr.call(abi.encodeWithSignature("src()"));
if (!ok || data.length != 32) return;

address source = abi.decode(data, (address));
string memory sourceName = string(
abi.encodePacked("source of ", contractName)
);
string memory sourceName = string(abi.encodePacked("src of ", contractName));
_checkWards(source, sourceName);
}

function _checkAuth(bool onlySource) internal {
/**
* @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.
*/
function _checkAuth(bytes32[] memory keys) internal {
_vote(address(spell));
_scheduleWaitAndCast(address(spell));
assertTrue(spell.done(), "TestError/spell-not-done");

bytes32[] memory contractNames = chainLog.list();
for(uint256 i = 0; i < contractNames.length; i++) {
address _addr = chainLog.getAddress(contractNames[i]);
string memory contractName = string(
abi.encodePacked(contractNames[i])
);
if (onlySource) _checkSource(_addr, contractName);
else _checkWards(_addr, contractName);
for(uint256 i = 0; i < keys.length; i++) {
_checkWards(chainLog.getAddress(keys[i]), string(abi.encodePacked(keys[i])));
}
}

/**
* @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);
}
}

Expand Down
58 changes: 12 additions & 46 deletions src/DssSpell.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ contract DssSpellTest is DssSpellTestBase {
_testUseEta();
}

function testAuth() public {
_checkAuth(false);
}

function testAuthInSources() public {
_checkAuth(true);
}

function testBytecodeMatches() public {
_testBytecodeMatches();
}
Expand Down Expand Up @@ -184,47 +176,21 @@ contract DssSpellTest is DssSpellTestBase {

// TESTS BELOW CAN BE ENABLED/DISABLED ON DEMAND

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

// validate the spell does what we told it to
//bytes32[] memory ilks = reg.list();
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";

//for(uint256 i = 0; i < ilks.length; i++) {
// uint256 class = reg.class(ilks[i]);
// if (class != 1) { continue; }

// address pip = reg.pip(ilks[i]);
// // skip USDC, TUSD, PAXUSD, GUSD
// if (pip == 0x838212865E2c2f4F7226fCc0A3EFc3EB139eC661 ||
// pip == 0x0ce19eA2C568890e63083652f205554C927a0caa ||
// pip == 0xdF8474337c9D3f66C0b71d31C7D3596E4F517457 ||
// pip == 0x57A00620Ba1f5f81F20565ce72df4Ad695B389d7) {
// continue;
// }

// assertEq(OsmAbstract(pip).wards(ORACLE_WALLET01), 0);
//}
_checkAuth(keys);
}

//_vote(address(spell));
//_scheduleWaitAndCast(address(spell));
//assertTrue(spell.done());
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";

//for(uint256 i = 0; i < ilks.length; i++) {
// uint256 class = reg.class(ilks[i]);
// if (class != 1) { continue; }

// address pip = reg.pip(ilks[i]);
// // skip USDC, TUSD, PAXUSD, GUSD
// if (pip == 0x838212865E2c2f4F7226fCc0A3EFc3EB139eC661 ||
// pip == 0x0ce19eA2C568890e63083652f205554C927a0caa ||
// pip == 0xdF8474337c9D3f66C0b71d31C7D3596E4F517457 ||
// pip == 0x57A00620Ba1f5f81F20565ce72df4Ad695B389d7) {
// continue;
// }

// assertEq(OsmAbstract(pip).wards(ORACLE_WALLET01), 1);
//}
_checkOsmAuth(keys);
}

function testOracleList() private { // make private to disable
Expand Down
Loading