Skip to content

Commit

Permalink
Test: Adjusted AaveVaultFork.t.sol to have the ability to run L2 ne…
Browse files Browse the repository at this point in the history
…tworks
  • Loading branch information
craterface77 authored and Haypierre committed Jan 16, 2025
1 parent fcab292 commit 60e005c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion script/deployChainAbstractionSetup.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract DeployChainAbstractionSetup is Script, CheckOrDeployEntryPoint, CheckAa
vaultManager.addVault(baseVault);

if (isAaveToken(protocolDataProvider, token)) {
if(isL2) {
if (isL2) {
l2Encoder = address(new L2Encoder(IPool(aavePool)));
} else {
l2Encoder = address(0);
Expand Down
12 changes: 9 additions & 3 deletions test/AaveVault/AaveVaultFork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {IPool} from "aave-v3-origin/core/contracts/interfaces/IPool.sol";
import {InvoiceManager} from "../../src/core/InvoiceManager.sol";
import {IVault} from "../../src/interfaces/IVault.sol";
import {CheckAaveTokenStatus} from "../../script/auxiliary/checkAaveTokenStatus.s.sol";
import {L2Encoder} from "aave-v3-origin/core/contracts/misc/L2Encoder.sol";

contract DeployAndTestAaveVaults is Test, Script, CheckAaveTokenStatus {
VaultManager internal vaultManager;
Expand All @@ -19,6 +20,7 @@ contract DeployAndTestAaveVaults is Test, Script, CheckAaveTokenStatus {
IERC20 internal underlyingToken;
IERC20 internal aToken;
address internal deployer;
address internal l2Encoder;

bool internal isL2 = vm.envBool("IS_L2");
address internal owner = vm.envAddress("OWNER");
Expand All @@ -41,6 +43,11 @@ contract DeployAndTestAaveVaults is Test, Script, CheckAaveTokenStatus {
);

if (isAaveToken(protocolDataProvider, address(underlyingToken))) {
if (isL2) {
l2Encoder = address(new L2Encoder(IPool(aavePool)));
} else {
l2Encoder = address(0);
}
address aTokenAddress = getATokenAddress(protocolDataProvider, address(underlyingToken));
aToken = IERC20(aTokenAddress);
aaveVault = AaveVault(
Expand All @@ -53,8 +60,8 @@ contract DeployAndTestAaveVaults is Test, Script, CheckAaveTokenStatus {
underlyingToken,
aToken,
IPool(aavePool),
false,
address(0)
isL2,
l2Encoder
)
)
)
Expand Down Expand Up @@ -272,7 +279,6 @@ contract DeployAndTestAaveVaults is Test, Script, CheckAaveTokenStatus {
uint256 depositA = 100 * 10 ** 18;
uint256 depositB = 200 * 10 ** 18;


// User A deposits
vm.startPrank(owner);
vaultManager.addVault(aaveVault);
Expand Down
10 changes: 8 additions & 2 deletions test/AaveVault/Deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ contract DepositTest is Test {
assertEq(mockUnderlyingToken.balanceOf(address(mockAavePool)), depositAmount, "Pool balance mismatch");
assertEq(mockUnderlyingToken.balanceOf(address(aaveVaultL1)), 0, "Vault balance mismatch");
assertEq(
vaultManager.vaultShares(alice, aaveVaultL1), aaveVaultL1.underlyingToShares(depositAmount), "Shares mismatch"
vaultManager.vaultShares(alice, aaveVaultL1),
aaveVaultL1.underlyingToShares(depositAmount),
"Shares mismatch"
);
}

Expand All @@ -104,7 +106,11 @@ contract DepositTest is Test {
assertEq(mockUnderlyingToken.balanceOf(address(mockL2AavePool)), depositAmount, "Pool balance mismatch");
assertEq(mockUnderlyingToken.balanceOf(address(aaveVaultL1)), 0, "Vault balance mismatch");
// Verify shares
assertEq(vaultManager.vaultShares(alice, aaveVaultL2), aaveVaultL2.underlyingToShares(depositAmount), "Shares mismatch");
assertEq(
vaultManager.vaultShares(alice, aaveVaultL2),
aaveVaultL2.underlyingToShares(depositAmount),
"Shares mismatch"
);
}

function testDepositFailsWithoutApproval() public {
Expand Down
12 changes: 10 additions & 2 deletions test/AaveVault/Withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ contract WithdrawTest is Test {

// Verify balances
assertEq(mockUnderlyingToken.balanceOf(alice), 900 ether, "Alice did not receive correct L1 withdrawal amount");
assertEq(vaultManager.vaultShares(alice, aaveVaultL1), aaveVaultL1.totalShares() - sharesWithdrawAmount, "Shares mismatch after L1 withdrawal");
assertEq(
vaultManager.vaultShares(alice, aaveVaultL1),
aaveVaultL1.totalShares() - sharesWithdrawAmount,
"Shares mismatch after L1 withdrawal"
);
}

function testQueueAndCompleteWithdrawL2() public {
Expand Down Expand Up @@ -144,6 +148,10 @@ contract WithdrawTest is Test {

// Verify balances
assertEq(mockUnderlyingToken.balanceOf(alice), 900 ether, "Alice did not receive correct L2 withdrawal amount");
assertEq(vaultManager.vaultShares(alice, aaveVaultL2), aaveVaultL2.totalShares() - sharesWithdrawAmount, "Shares mismatch after L2 withdrawal");
assertEq(
vaultManager.vaultShares(alice, aaveVaultL2),
aaveVaultL2.totalShares() - sharesWithdrawAmount,
"Shares mismatch after L2 withdrawal"
);
}
}

0 comments on commit 60e005c

Please sign in to comment.