This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cba58ca
commit c043596
Showing
5 changed files
with
136 additions
and
6 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,126 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import "../ProtocolRewardsTest.sol"; | ||
import "../../src/abstract/RewardSplits.sol"; | ||
|
||
contract DepositTest is ProtocolRewardsTest { | ||
function setUp() public override { | ||
super.setUp(); | ||
} | ||
|
||
function testDeposit(uint256 amount, address to) public { | ||
vm.assume(amount < ETH_SUPPLY); | ||
vm.assume(to != address(0)); | ||
|
||
vm.deal(collector, amount); | ||
|
||
vm.prank(collector); | ||
protocolRewards.deposit{value: amount}(to, "test"); | ||
|
||
assertEq(protocolRewards.balanceOf(to), amount); | ||
} | ||
|
||
function testRevert_CannotDepositToAddressZero(uint256 amount) public { | ||
vm.assume(amount < ETH_SUPPLY); | ||
|
||
vm.deal(collector, amount); | ||
|
||
vm.prank(collector); | ||
vm.expectRevert(abi.encodeWithSignature("ADDRESS_ZERO()")); | ||
protocolRewards.deposit{value: amount}(address(0), "test"); | ||
} | ||
|
||
function testDepositBatch(uint8 numRecipients) public { | ||
address[] memory recipients = new address[](numRecipients); | ||
uint256[] memory amounts = new uint256[](numRecipients); | ||
|
||
uint256 totalValue; | ||
|
||
for (uint256 i; i < numRecipients; ++i) { | ||
recipients[i] = makeAddr(vm.toString(i + 1)); | ||
amounts[i] = i + 1 ether; | ||
|
||
totalValue += amounts[i]; | ||
} | ||
|
||
vm.deal(collector, totalValue); | ||
vm.prank(collector); | ||
protocolRewards.depositBatch{value: totalValue}(recipients, amounts, "test"); | ||
|
||
for (uint256 i; i < numRecipients; ++i) { | ||
assertEq(protocolRewards.balanceOf(recipients[i]), amounts[i]); | ||
} | ||
} | ||
|
||
function testRevert_RecipientsAndAmountsLengthMismatch(uint8 numRecipients, uint8 numAmounts) public { | ||
vm.assume(numRecipients != numAmounts); | ||
|
||
address[] memory recipients = new address[](numRecipients); | ||
uint256[] memory amounts = new uint256[](numAmounts); | ||
|
||
uint256 totalValue; | ||
|
||
for (uint256 i; i < numAmounts; ++i) { | ||
amounts[i] = i + 1 ether; | ||
|
||
totalValue += amounts[i]; | ||
} | ||
|
||
for (uint256 i; i < numRecipients; ++i) { | ||
recipients[i] = makeAddr(vm.toString(i + 1)); | ||
} | ||
|
||
vm.deal(collector, totalValue); | ||
|
||
vm.prank(collector); | ||
vm.expectRevert(abi.encodeWithSignature("ARRAY_LENGTH_MISMATCH()")); | ||
protocolRewards.depositBatch{value: totalValue}(recipients, amounts, "test"); | ||
} | ||
|
||
function testRevert_InvalidDepositMsgValue(uint8 numRecipients) public { | ||
vm.assume(numRecipients > 0); | ||
|
||
address[] memory recipients = new address[](numRecipients); | ||
uint256[] memory amounts = new uint256[](numRecipients); | ||
|
||
uint256 totalValue; | ||
|
||
for (uint256 i; i < numRecipients; ++i) { | ||
recipients[i] = makeAddr(vm.toString(i + 1)); | ||
amounts[i] = i + 1 ether; | ||
|
||
totalValue += amounts[i]; | ||
} | ||
|
||
vm.deal(collector, totalValue); | ||
|
||
vm.prank(collector); | ||
vm.expectRevert(abi.encodeWithSignature("INVALID_DEPOSIT()")); | ||
protocolRewards.depositBatch{value: 0}(recipients, amounts, "test"); | ||
} | ||
|
||
function testRevert_RecipientCannotBeAddressZero(uint8 numRecipients) public { | ||
vm.assume(numRecipients > 0); | ||
|
||
address[] memory recipients = new address[](numRecipients); | ||
uint256[] memory amounts = new uint256[](numRecipients); | ||
|
||
uint256 totalValue; | ||
|
||
for (uint256 i; i < numRecipients; ++i) { | ||
recipients[i] = makeAddr(vm.toString(i + 1)); | ||
amounts[i] = i + 1 ether; | ||
|
||
totalValue += amounts[i]; | ||
} | ||
|
||
recipients[0] = address(0); | ||
|
||
vm.deal(collector, totalValue); | ||
|
||
vm.prank(collector); | ||
vm.expectRevert(abi.encodeWithSignature("ADDRESS_ZERO()")); | ||
protocolRewards.depositBatch{value: totalValue}(recipients, amounts, "test"); | ||
} | ||
} |
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
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