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

Use makeAddr and changePrank #179

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions test/forge/ERC4626Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,8 @@ contract ERC4626Test is BaseTest, IMorphoFlashLoanCallback {
vm.startPrank(BORROWER);
morpho.supplyCollateral(allMarkets[0], type(uint128).max, BORROWER, hex"");
morpho.borrow(allMarkets[0], 1, 0, BORROWER, BORROWER);
vm.stopPrank();

vm.prank(ONBEHALF);
changePrank(ONBEHALF);
vm.expectRevert(ErrorsLib.WithdrawMorphoFailed.selector);
vault.withdraw(assets, RECEIVER, ONBEHALF);
}
Expand Down
2 changes: 1 addition & 1 deletion test/forge/GuardianTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract GuardianTest is BaseTest {
function testRevokeGuardian(uint256 elapsed) public {
elapsed = bound(elapsed, 0, TIMELOCK - 1);

address guardian = _addrFromHashedString("Guardian2");
address guardian = makeAddr("Guardian2");

vm.prank(OWNER);
vault.submitGuardian(guardian);
Expand Down
10 changes: 4 additions & 6 deletions test/forge/RoleTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract RoleTest is BaseTest {
using MarketParamsLib for MarketParams;

function testSetRiskManager() public {
address newRiskManager = _addrFromHashedString("RiskManager2");
address newRiskManager = makeAddr("RiskManager2");

vm.prank(OWNER);
vault.setRiskManager(newRiskManager);
Expand All @@ -22,7 +22,7 @@ contract RoleTest is BaseTest {
}

function testSetAllocator() public {
address newAllocator = _addrFromHashedString("Allocator2");
address newAllocator = makeAddr("Allocator2");

vm.prank(OWNER);
vault.setIsAllocator(newAllocator, true);
Expand Down Expand Up @@ -124,15 +124,13 @@ contract RoleTest is BaseTest {
vault.setSupplyQueue(supplyQueue);
vault.sortWithdrawQueue(withdrawQueueFromRanks);
vault.reallocate(allocation, allocation);
vm.stopPrank();

vm.startPrank(RISK_MANAGER);
changePrank(RISK_MANAGER);
vault.setSupplyQueue(supplyQueue);
vault.sortWithdrawQueue(withdrawQueueFromRanks);
vault.reallocate(allocation, allocation);
vm.stopPrank();

vm.startPrank(ALLOCATOR);
changePrank(ALLOCATOR);
vault.setSupplyQueue(supplyQueue);
vault.sortWithdrawQueue(withdrawQueueFromRanks);
vault.reallocate(allocation, allocation);
Expand Down
8 changes: 4 additions & 4 deletions test/forge/TimelockTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ contract TimelockTest is BaseTest {
}

function testSubmitGuardian() public {
address guardian = _addrFromHashedString("Guardian2");
address guardian = makeAddr("Guardian2");

vm.prank(OWNER);
vault.submitGuardian(guardian);
Expand Down Expand Up @@ -301,7 +301,7 @@ contract TimelockTest is BaseTest {
}

function testAcceptGuardian() public {
address guardian = _addrFromHashedString("Guardian2");
address guardian = makeAddr("Guardian2");

vm.prank(OWNER);
vault.submitGuardian(guardian);
Expand All @@ -326,7 +326,7 @@ contract TimelockTest is BaseTest {
function testAcceptGuardianTimelockNotElapsed(uint256 elapsed) public {
elapsed = bound(elapsed, 1, TIMELOCK - 1);

address guardian = _addrFromHashedString("Guardian2");
address guardian = makeAddr("Guardian2");

vm.prank(OWNER);
vault.submitGuardian(guardian);
Expand All @@ -340,7 +340,7 @@ contract TimelockTest is BaseTest {
function testAcceptGuardianTimelockExpirationExceeded(uint256 elapsed) public {
elapsed = bound(elapsed, TIMELOCK + TIMELOCK_EXPIRATION + 1, type(uint64).max);

address guardian = _addrFromHashedString("Guardian2");
address guardian = makeAddr("Guardian2");

vm.prank(OWNER);
vault.submitGuardian(guardian);
Expand Down
32 changes: 13 additions & 19 deletions test/forge/helpers/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ contract BaseTest is Test {
MarketParams[] internal allMarkets;

function setUp() public virtual {
OWNER = _addrFromHashedString("Owner");
SUPPLIER = _addrFromHashedString("Supplier");
BORROWER = _addrFromHashedString("Borrower");
REPAYER = _addrFromHashedString("Repayer");
ONBEHALF = _addrFromHashedString("OnBehalf");
RECEIVER = _addrFromHashedString("Receiver");
ALLOCATOR = _addrFromHashedString("Allocator");
RISK_MANAGER = _addrFromHashedString("RiskManager");
GUARDIAN = _addrFromHashedString("Guardian");
FEE_RECIPIENT = _addrFromHashedString("FeeRecipient");
MORPHO_OWNER = _addrFromHashedString("MorphoOwner");
MORPHO_FEE_RECIPIENT = _addrFromHashedString("MorphoFeeRecipient");
OWNER = makeAddr("Owner");
SUPPLIER = makeAddr("Supplier");
BORROWER = makeAddr("Borrower");
REPAYER = makeAddr("Repayer");
ONBEHALF = makeAddr("OnBehalf");
RECEIVER = makeAddr("Receiver");
ALLOCATOR = makeAddr("Allocator");
RISK_MANAGER = makeAddr("RiskManager");
GUARDIAN = makeAddr("Guardian");
FEE_RECIPIENT = makeAddr("FeeRecipient");
MORPHO_OWNER = makeAddr("MorphoOwner");
MORPHO_FEE_RECIPIENT = makeAddr("MorphoFeeRecipient");

morpho = IMorpho(_deploy("lib/morpho-blue/out/Morpho.sol/Morpho.json", abi.encode(MORPHO_OWNER)));
vm.label(address(morpho), "Morpho");
Expand All @@ -93,11 +93,10 @@ contract BaseTest is Test {
vm.startPrank(MORPHO_OWNER);
morpho.enableIrm(address(irm));
morpho.setFeeRecipient(MORPHO_FEE_RECIPIENT);
vm.stopPrank();

vault = new MetaMorpho(OWNER, address(morpho), 0, address(loanToken), "MetaMorpho Vault", "MMV");

vm.startPrank(OWNER);
changePrank(OWNER);
vault.setRiskManager(RISK_MANAGER);
vault.setIsAllocator(ALLOCATOR, true);
vm.stopPrank();
Expand Down Expand Up @@ -143,11 +142,6 @@ contract BaseTest is Test {
vm.stopPrank();
}

function _addrFromHashedString(string memory name) internal returns (address addr) {
addr = address(uint160(uint256(keccak256(bytes(name)))));
vm.label(addr, name);
}

/// @dev Rolls & warps the given number of blocks forward the blockchain.
function _forward(uint256 blocks) internal {
vm.roll(block.number + blocks);
Expand Down