diff --git a/test/unit/AavePM/AaveBorrowAndWithdrawUSDCTest.t.sol b/test/unit/AavePM/AaveBorrowAndWithdrawUSDCTest.t.sol index 4613bc9..95817e4 100644 --- a/test/unit/AavePM/AaveBorrowAndWithdrawUSDCTest.t.sol +++ b/test/unit/AavePM/AaveBorrowAndWithdrawUSDCTest.t.sol @@ -56,6 +56,8 @@ contract AavePMBorrowAndWithdrawUSDCTests is AavePMTestSetup { aavePM.aaveSupplyFromContractBalance(); // Borrow USDC immediately, without reinvesting + vm.expectEmit(); + emit IAavePM.AaveBorrowedAndWithdrawnUSDC(owner1, USDC_BORROW_AMOUNT); aavePM.aaveBorrowAndWithdrawUSDC(USDC_BORROW_AMOUNT, owner1); // Check the USDC balance of owner1 diff --git a/test/unit/AavePM/AavePMUpdateTest.t.sol b/test/unit/AavePM/AavePMUpdateTest.t.sol index 99948a7..64b5b01 100644 --- a/test/unit/AavePM/AavePMUpdateTest.t.sol +++ b/test/unit/AavePM/AavePMUpdateTest.t.sol @@ -124,6 +124,11 @@ contract AavePMUpdateTests is AavePMTestSetup { uint16 newManagerDailyInvocationLimit = previousManagerDailyInvocationLimit + MANAGER_DAILY_INVOCATION_LIMIT_CHANGE; + vm.expectEmit(); + emit IAavePM.ManagerDailyInvocationLimitUpdated( + previousManagerDailyInvocationLimit, newManagerDailyInvocationLimit + ); + vm.startPrank(owner1); aavePM.updateManagerDailyInvocationLimit(newManagerDailyInvocationLimit); assertEq(aavePM.getManagerDailyInvocationLimit(), newManagerDailyInvocationLimit); diff --git a/test/unit/AavePM/AaveRepayUSDCFromContractBalanceTest.t.sol b/test/unit/AavePM/AaveRepayUSDCFromContractBalanceTest.t.sol index 40f4e9a..d3098cb 100644 --- a/test/unit/AavePM/AaveRepayUSDCFromContractBalanceTest.t.sol +++ b/test/unit/AavePM/AaveRepayUSDCFromContractBalanceTest.t.sol @@ -51,6 +51,8 @@ contract AaveRepayUSDCFromContractBalanceTests is AavePMTestSetup { assertEq(aavePM.getWithdrawnUSDCTotal(), USDC_BORROW_AMOUNT); // Repay the USDC debt from the contract balance + vm.expectEmit(true, true, true, false); + emit IAavePM.AaveRepayedUSDCFromContractBalance(0); // The data is a placeholder and not checked aavePM.aaveRepayUSDCFromContractBalance(); // Check that the debt has been repaid @@ -139,6 +141,8 @@ contract AaveRepayUSDCFromContractBalanceTests is AavePMTestSetup { // Close the position vm.startPrank(manager1); + vm.expectEmit(); + emit IAavePM.AaveClosedPosition(owner1); aavePM.aaveClosePosition(owner1); vm.stopPrank(); diff --git a/test/unit/AavePM/AaveWithdrawWstETHTest.t.sol b/test/unit/AavePM/AaveWithdrawWstETHTest.t.sol index 940f9e9..3e0ad40 100644 --- a/test/unit/AavePM/AaveWithdrawWstETHTest.t.sol +++ b/test/unit/AavePM/AaveWithdrawWstETHTest.t.sol @@ -31,6 +31,9 @@ contract AaveWithdrawWstETHTests is AavePMTestSetup { IPool(aavePM.getContractAddress("aavePool")).getUserAccountData(address(aavePM)); // Withdraw immediately + + vm.expectEmit(); + emit IAavePM.AaveWithdrawnWstETH(owner1, aavePM.getContractBalance("awstETH")); uint256 collateralDeltaBase = aavePM.aaveWithdrawWstETH(aavePM.getContractBalance("awstETH"), owner1); assertEq(collateralDeltaBase, totalCollateralBaseBefore); diff --git a/test/unit/AavePM/ContractUpgradeTest.t.sol b/test/unit/AavePM/ContractUpgradeTest.t.sol index d2ab66b..38e97aa 100644 --- a/test/unit/AavePM/ContractUpgradeTest.t.sol +++ b/test/unit/AavePM/ContractUpgradeTest.t.sol @@ -3,6 +3,7 @@ pragma solidity 0.8.24; import {AavePMTestSetup} from "test/unit/AavePM/TestSetupTest.t.sol"; +import {IAavePM} from "src/interfaces/IAavePM.sol"; import {AavePM} from "src/AavePM.sol"; import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; import {InvalidUpgrade} from "test/testHelperContracts/InvalidUpgrade.sol"; @@ -19,8 +20,14 @@ contract AavePMContractUpgradeTests is AavePMTestSetup { // Check version before upgrade assertEq(keccak256(abi.encodePacked(aavePM.getVersion())), keccak256(abi.encodePacked(VERSION))); + // This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1 + bytes32 slot = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; + address previousImplementation = address(uint160(uint256(vm.load(address(aavePM), slot)))); + // Upgrade vm.prank(owner1); + vm.expectEmit(); + emit IAavePM.AavePMUpgraded(previousImplementation, address(aavePMUpgradeExample)); aavePM.upgradeToAndCall(address(aavePMUpgradeExample), ""); assertEq(keccak256(abi.encodePacked(aavePM.getVersion())), keccak256(abi.encodePacked(UPGRADE_EXAMPLE_VERSION))); } diff --git a/test/unit/AavePM/DeleverageTest.t.sol b/test/unit/AavePM/DeleverageTest.t.sol index e2733b4..d514885 100644 --- a/test/unit/AavePM/DeleverageTest.t.sol +++ b/test/unit/AavePM/DeleverageTest.t.sol @@ -41,6 +41,12 @@ contract DeleverageTests is AavePMTestSetup { // Get healthFactorTarget before deleverage. uint16 healthFactorTargetBefore = aavePM.getHealthFactorTarget(); + // The first parameter: Whether to check the event signature. + // The second parameter: Whether to check the indexed parameters (topics) of the event. + // The third parameter: Whether to check the unindexed parameters (data) of the event. + // The fourth parameter: Whether to check the event data's values. + vm.expectEmit(true, true, true, false); + emit IAavePM.Deleveraged(0); // The data is a placeholder and not checked aavePM.deleverage(); // Check position debt is zero (, uint256 totalDebtBaseAfter,,,,) = diff --git a/test/unit/AavePM/InitializeTest.t.sol b/test/unit/AavePM/InitializeTest.t.sol index 8934dcc..2e8a0a3 100644 --- a/test/unit/AavePM/InitializeTest.t.sol +++ b/test/unit/AavePM/InitializeTest.t.sol @@ -2,8 +2,14 @@ pragma solidity 0.8.24; import {AavePMTestSetup} from "test/unit/AavePM/TestSetupTest.t.sol"; +import {Test, console} from "forge-std/Test.sol"; -import {console} from "forge-std/Test.sol"; +import {IAavePM} from "src/interfaces/IAavePM.sol"; +import {AavePM} from "src/AavePM.sol"; + +import {HelperConfig} from "script/HelperConfig.s.sol"; +import {DeployAavePM} from "script/DeployAavePM.s.sol"; +import {HelperFunctions} from "script/HelperFunctions.s.sol"; // ================================================================ // │ INITIALIZE TESTS │ @@ -17,12 +23,5 @@ contract AavePMInitializeTests is AavePMTestSetup { assert(aavePM.hasRole(keccak256("MANAGER_ROLE"), owner1)); assert(aavePM.getRoleAdmin(keccak256("MANAGER_ROLE")) == keccak256("OWNER_ROLE")); - - // TODO: Update these tests to use eventBlockNumbers - // string memory currentVersion = aavePM.getVersion(); - // string memory upgradeHistoryVersion = aavePM.getUpgradeHistory()[0].version; - // assert(keccak256(abi.encodePacked(currentVersion)) == keccak256(abi.encodePacked(upgradeHistoryVersion))); - // assert(aavePM.getUpgradeHistory()[0].upgradeTime == block.timestamp); - // assert(aavePM.getUpgradeHistory()[0].upgradeInitiator == defaultFoundryCaller); } } diff --git a/test/unit/AavePM/RebalanceTest.t.sol b/test/unit/AavePM/RebalanceTest.t.sol index 44bdb61..94d459d 100644 --- a/test/unit/AavePM/RebalanceTest.t.sol +++ b/test/unit/AavePM/RebalanceTest.t.sol @@ -49,6 +49,13 @@ contract RebalanceTests is AavePMTestSetup { // Setup contract using the standard rebalance test test_RebalanceSetup(); vm.startPrank(manager1); + + // The first parameter: Whether to check the event signature. + // The second parameter: Whether to check the indexed parameters (topics) of the event. + // The third parameter: Whether to check the unindexed parameters (data) of the event. + // The fourth parameter: Whether to check the event data's values. + vm.expectEmit(true, true, true, false); + emit IAavePM.Rebalanced(0); // The data is a placeholder and not checked aavePM.rebalance(); checkEndHealthFactor(address(aavePM)); vm.stopPrank(); diff --git a/test/unit/AavePM/ReinvestTest.t.sol b/test/unit/AavePM/ReinvestTest.t.sol index 1032440..93c7b15 100644 --- a/test/unit/AavePM/ReinvestTest.t.sol +++ b/test/unit/AavePM/ReinvestTest.t.sol @@ -25,6 +25,13 @@ contract ReinvestTests is AavePMTestSetup { // Used as the setup for other reinvest tests. vm.startPrank(manager1); sendEth(address(aavePM), SEND_VALUE); + + // The first parameter: Whether to check the event signature. + // The second parameter: Whether to check the indexed parameters (topics) of the event. + // The third parameter: Whether to check the unindexed parameters (data) of the event. + // The fourth parameter: Whether to check the event data's values. + vm.expectEmit(true, true, true, false); + emit IAavePM.Reinvested(0); // The data is a placeholder and not checked aavePM.reinvest(); checkEndHealthFactor(address(aavePM)); vm.stopPrank(); diff --git a/test/unit/AavePM/TestSetupTest.t.sol b/test/unit/AavePM/TestSetupTest.t.sol index 4d88e30..bf064d3 100644 --- a/test/unit/AavePM/TestSetupTest.t.sol +++ b/test/unit/AavePM/TestSetupTest.t.sol @@ -62,6 +62,8 @@ contract AavePMTestSetup is Test, HelperFunctions, AavePM { // Call the _initialize function to set up this test contract, // initialized with the same config as the AavePM contract + vm.expectEmit(); + emit IAavePM.AavePMInitialized(msg.sender); _initializeState( defaultFoundryCaller, config.contractAddresses, diff --git a/test/unit/AavePM/WithdrawTokensFromContractBalanceTest.t.sol b/test/unit/AavePM/WithdrawTokensFromContractBalanceTest.t.sol index 97d11fa..5c39a8e 100644 --- a/test/unit/AavePM/WithdrawTokensFromContractBalanceTest.t.sol +++ b/test/unit/AavePM/WithdrawTokensFromContractBalanceTest.t.sol @@ -14,6 +14,13 @@ contract WithdrawTokensFromContractBalanceTest is AavePMTestSetup { function withdrawToken_SetUp() public { vm.startPrank(manager1); sendEth(address(aavePM), SEND_VALUE); + + // The first parameter: Whether to check the event signature. + // The second parameter: Whether to check the indexed parameters (topics) of the event. + // The third parameter: Whether to check the unindexed parameters (data) of the event. + // The fourth parameter: Whether to check the event data's values. + vm.expectEmit(true, true, true, false); + emit IAavePM.AaveSuppliedFromContractBalance(0); // The data is a placeholder and not checked aavePM.aaveSupplyFromContractBalance(); aavePM.aaveBorrowAndWithdrawUSDC(USDC_BORROW_AMOUNT, owner1); aavePM.reinvest(); @@ -58,6 +65,8 @@ contract WithdrawTokensFromContractBalanceTest is AavePMTestSetup { uint256 contractBalanceBefore = IERC20(USDC).balanceOf(address(aavePM)); uint256 ownerBalanceBefore = IERC20(USDC).balanceOf(owner1); + vm.expectEmit(); + emit IAavePM.TokensWithdrawnFromContractBalance("USDC", contractBalanceBefore); aavePM.withdrawTokensFromContractBalance("USDC", owner1); uint256 contractBalanceAfter = IERC20(USDC).balanceOf(address(aavePM));