-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SEN-79 | test: add aave v3 integration tests (#190)
* test: add aave v3 integration tests * fix: ci * fix: doc * chore: update arbi rpc
- Loading branch information
Showing
3 changed files
with
155 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.11; | ||
|
||
import {Errors} from "../../../utils/Errors.sol"; | ||
import {ATokenOracle} from "oracle/aave/ATokenOracle.sol"; | ||
import {IERC20} from "../../../interface/tokens/IERC20.sol"; | ||
import {IAccount} from "../../../interface/core/IAccount.sol"; | ||
import {ArbiIntegrationTestBase} from "../utils/ArbiIntegrationTestBase.sol"; | ||
import {AaveV3Controller} from "controller/aave/AaveV3Controller.sol"; | ||
|
||
|
||
/// @notice runs only on arbitrum | ||
contract AaveV3ArbiIntegrationTest is ArbiIntegrationTestBase { | ||
address account; | ||
address user = cheats.addr(1); | ||
|
||
address aWeth = 0xe50fA9b3c56FfB159cB0FCA61F5c9D750e8128c8; | ||
address aDai = 0x82E64f49Ed5EC1bC6e43DAD4FC8Af9bb3A2312EE; | ||
address pool = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; | ||
|
||
ATokenOracle aTokenOracle; | ||
AaveV3Controller aaveController; | ||
|
||
function setupAaveController() internal { | ||
aTokenOracle = new ATokenOracle(oracle); | ||
oracle.setOracle(aWeth, aTokenOracle); | ||
oracle.setOracle(aDai, aTokenOracle); | ||
|
||
aaveController = new AaveV3Controller(controller); | ||
controller.updateController(pool, aaveController); | ||
controller.updateController(pool, aaveController); | ||
controller.toggleTokenAllowance(aWeth); | ||
} | ||
|
||
function setUp() public { | ||
setupContracts(); | ||
setupOracles(); | ||
setupAaveController(); | ||
setupWethController(); | ||
account = openAccount(user); | ||
} | ||
|
||
function testDepositWeth(uint64 amt) public { | ||
cheats.assume(amt > 1e8 gwei); | ||
// Setup | ||
deposit(user, account, address(0), amt); | ||
wrapEth(account, amt, user); | ||
uint value = IERC20(WETH).balanceOf(account); | ||
|
||
// Encode call data | ||
bytes memory data = abi.encodeWithSignature( | ||
"supply(address,uint256,address,uint16)", | ||
WETH, | ||
value, | ||
account, | ||
0 | ||
); | ||
|
||
// Test | ||
cheats.startPrank(user); | ||
accountManager.approve(account, WETH, pool, value); | ||
accountManager.exec(account, pool, 0, data); | ||
cheats.stopPrank(); | ||
|
||
// Assert | ||
assertGt(IERC20(aWeth).balanceOf(account), 0); | ||
assertEq(IAccount(account).assets(0), aWeth); | ||
} | ||
|
||
function testWithdrawWeth(uint64 amt) public { | ||
// Setup | ||
testDepositWeth(amt); | ||
|
||
// Encode call data | ||
bytes memory data = abi.encodeWithSignature( | ||
"withdraw(address,uint256,address)", | ||
WETH, | ||
type(uint256).max, | ||
account | ||
); | ||
|
||
// Test | ||
cheats.startPrank(user); | ||
accountManager.exec(account, pool, 0, data); | ||
cheats.stopPrank(); | ||
|
||
// Assert | ||
assertEq(IERC20(aWeth).balanceOf(account), 0); | ||
assertGt(IERC20(WETH).balanceOf(account), 0); | ||
assertEq(IAccount(account).assets(0), WETH); | ||
} | ||
|
||
function testDepositDaiError(uint64 amt) public { | ||
// Encode call data | ||
bytes memory data = abi.encodeWithSignature( | ||
"supply(address,uint256,address,uint16)", | ||
aDai, | ||
amt, | ||
account, | ||
0 | ||
); | ||
|
||
// Test | ||
cheats.startPrank(user); | ||
cheats.expectRevert(Errors.FunctionCallRestricted.selector); | ||
accountManager.exec(account, pool, 0, data); | ||
cheats.stopPrank(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.10; | ||
|
||
import {TestBase} from "../../utils/TestBase.sol"; | ||
import {WETHOracle} from "oracle/weth/WETHOracle.sol"; | ||
import {WETHController} from "controller/weth/WETHController.sol"; | ||
|
||
contract ArbiIntegrationTestBase is TestBase { | ||
|
||
// Controller Contracts | ||
WETHController wEthController; | ||
|
||
// Oracle Contracts | ||
WETHOracle wethOracle; | ||
|
||
// Arbitrum Contracts | ||
address constant WETH = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1; | ||
address constant USDT = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9; | ||
|
||
function setupWethController() internal { | ||
wEthController = new WETHController(WETH); | ||
controller.updateController(WETH, wEthController); | ||
controller.toggleTokenAllowance(WETH); | ||
|
||
wethOracle = new WETHOracle(); | ||
oracle.setOracle(WETH, wethOracle); | ||
} | ||
|
||
function setupOracles() internal { | ||
cheats.clearMockedCalls(); | ||
} | ||
|
||
function wrapEth(address account, uint amt, address owner) internal { | ||
bytes memory data = abi.encodeWithSignature("deposit()"); | ||
|
||
cheats.prank(owner); | ||
accountManager.exec(account, WETH, amt, data); | ||
} | ||
} |