Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
haythemsellami committed May 24, 2024
1 parent dc5a20d commit 7b8f703
Showing 1 changed file with 120 additions and 1 deletion.
121 changes: 120 additions & 1 deletion test/e2e/BalanceForwarderE2ETest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,130 @@ contract BalanceForwarderE2ETest is FourSixTwoSixAggBase {

uint256 initialStrategyAllocationPoints = 500e18;
_addStrategy(manager, address(eTST), initialStrategyAllocationPoints);

assetTST.mint(user1, user1InitialBalance);

// deposit into aggregator
uint256 amountToDeposit = 10000e18;
{
uint256 balanceBefore = fourSixTwoSixAgg.balanceOf(user1);
uint256 totalSupplyBefore = fourSixTwoSixAgg.totalSupply();
uint256 totalAssetsDepositedBefore = fourSixTwoSixAgg.totalAssetsDeposited();
uint256 userAssetBalanceBefore = assetTST.balanceOf(user1);

vm.startPrank(user1);
assetTST.approve(address(fourSixTwoSixAgg), amountToDeposit);
fourSixTwoSixAgg.deposit(amountToDeposit, user1);
vm.stopPrank();

assertEq(fourSixTwoSixAgg.balanceOf(user1), balanceBefore + amountToDeposit);
assertEq(fourSixTwoSixAgg.totalSupply(), totalSupplyBefore + amountToDeposit);
assertEq(fourSixTwoSixAgg.totalAssetsDeposited(), totalAssetsDepositedBefore + amountToDeposit);
assertEq(assetTST.balanceOf(user1), userAssetBalanceBefore - amountToDeposit);
}
}

function testBalanceForwarderrAddress_Integrity() public view {
assertEq(address(fourSixTwoSixAgg.balanceTracker()), trackingReward);
}

function testEnableBalanceForwarder() public {
vm.prank(user1);
fourSixTwoSixAgg.enableBalanceForwarder();

assertTrue(fourSixTwoSixAgg.balanceForwarderEnabled(user1));
assertEq(
TrackingRewardStreams(trackingReward).balanceOf(user1, address(fourSixTwoSixAgg)),
fourSixTwoSixAgg.balanceOf(user1)
);
}

function testDisableBalanceForwarder() public {
vm.prank(user1);
fourSixTwoSixAgg.enableBalanceForwarder();

assertTrue(fourSixTwoSixAgg.balanceForwarderEnabled(user1));

vm.prank(user1);
fourSixTwoSixAgg.disableBalanceForwarder();

assertFalse(fourSixTwoSixAgg.balanceForwarderEnabled(user1));
assertEq(TrackingRewardStreams(trackingReward).balanceOf(user1, address(fourSixTwoSixAgg)), 0);
}

function testHookWhenReceiverEnabled() public {
vm.prank(user1);
fourSixTwoSixAgg.enableBalanceForwarder();

// deposit into aggregator
uint256 amountToDeposit = 10000e18;
{
uint256 balanceBefore = fourSixTwoSixAgg.balanceOf(user1);
uint256 totalSupplyBefore = fourSixTwoSixAgg.totalSupply();
uint256 totalAssetsDepositedBefore = fourSixTwoSixAgg.totalAssetsDeposited();
uint256 userAssetBalanceBefore = assetTST.balanceOf(user1);

vm.startPrank(user1);
assetTST.approve(address(fourSixTwoSixAgg), amountToDeposit);
fourSixTwoSixAgg.deposit(amountToDeposit, user1);
vm.stopPrank();

assertEq(fourSixTwoSixAgg.balanceOf(user1), balanceBefore + amountToDeposit);
assertEq(fourSixTwoSixAgg.totalSupply(), totalSupplyBefore + amountToDeposit);
assertEq(fourSixTwoSixAgg.totalAssetsDeposited(), totalAssetsDepositedBefore + amountToDeposit);
assertEq(assetTST.balanceOf(user1), userAssetBalanceBefore - amountToDeposit);

assertEq(
TrackingRewardStreams(trackingReward).balanceOf(user1, address(fourSixTwoSixAgg)),
fourSixTwoSixAgg.balanceOf(user1)
);
}
}

function testHookWhenSenderEnabled() public {
vm.prank(user1);
fourSixTwoSixAgg.enableBalanceForwarder();

// deposit into aggregator
uint256 amountToDeposit = 10000e18;
{
uint256 balanceBefore = fourSixTwoSixAgg.balanceOf(user1);
uint256 totalSupplyBefore = fourSixTwoSixAgg.totalSupply();
uint256 totalAssetsDepositedBefore = fourSixTwoSixAgg.totalAssetsDeposited();
uint256 userAssetBalanceBefore = assetTST.balanceOf(user1);

vm.startPrank(user1);
assetTST.approve(address(fourSixTwoSixAgg), amountToDeposit);
fourSixTwoSixAgg.deposit(amountToDeposit, user1);
vm.stopPrank();

assertEq(fourSixTwoSixAgg.balanceOf(user1), balanceBefore + amountToDeposit);
assertEq(fourSixTwoSixAgg.totalSupply(), totalSupplyBefore + amountToDeposit);
assertEq(fourSixTwoSixAgg.totalAssetsDeposited(), totalAssetsDepositedBefore + amountToDeposit);
assertEq(assetTST.balanceOf(user1), userAssetBalanceBefore - amountToDeposit);

assertEq(
TrackingRewardStreams(trackingReward).balanceOf(user1, address(fourSixTwoSixAgg)),
fourSixTwoSixAgg.balanceOf(user1)
);
}

{
uint256 amountToWithdraw = fourSixTwoSixAgg.balanceOf(user1);
uint256 totalAssetsDepositedBefore = fourSixTwoSixAgg.totalAssetsDeposited();
uint256 aggregatorTotalSupplyBefore = fourSixTwoSixAgg.totalSupply();
uint256 user1AssetTSTBalanceBefore = assetTST.balanceOf(user1);

vm.prank(user1);
fourSixTwoSixAgg.redeem(amountToWithdraw, user1, user1);

assertEq(eTST.balanceOf(address(fourSixTwoSixAgg)), 0);
assertEq(fourSixTwoSixAgg.totalAssetsDeposited(), totalAssetsDepositedBefore - amountToWithdraw);
assertEq(fourSixTwoSixAgg.totalSupply(), aggregatorTotalSupplyBefore - amountToWithdraw);
assertEq(
assetTST.balanceOf(user1),
user1AssetTSTBalanceBefore + fourSixTwoSixAgg.convertToAssets(amountToWithdraw)
);
assertEq(TrackingRewardStreams(trackingReward).balanceOf(user1, address(fourSixTwoSixAgg)), 0);
}
}
}

0 comments on commit 7b8f703

Please sign in to comment.