Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kulkarohan committed Aug 2, 2023
1 parent cba58ca commit c043596
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 6 deletions.
10 changes: 7 additions & 3 deletions test/ProtocolRewardsTest.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "forge-std/Test.sol";
Expand All @@ -8,12 +8,15 @@ import "../src/ProtocolRewards.sol";
import "./utils/MockNFTs.sol";

contract ProtocolRewardsTest is Test {
uint256 internal constant ETH_SUPPLY = 120_200_000 ether;

ProtocolRewards internal protocolRewards;

address internal collector;
address internal creator;
address internal mintReferral;
address internal createReferral;
address internal mintReferral;
address internal firstMinter;
address internal zora;

function setUp() public virtual {
Expand All @@ -23,8 +26,9 @@ contract ProtocolRewardsTest is Test {

collector = makeAddr("collector");
creator = makeAddr("creator");
mintReferral = makeAddr("mintReferral");
createReferral = makeAddr("createReferral");
mintReferral = makeAddr("mintReferral");
firstMinter = makeAddr("firstMinter");
zora = makeAddr("zora");
}
}
126 changes: 126 additions & 0 deletions test/unit/Deposit.t.sol
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");
}
}
2 changes: 1 addition & 1 deletion test/unit/ERC1155Rewards.t.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "../ProtocolRewardsTest.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ERC721Rewards.t.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "../ProtocolRewardsTest.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/utils/MockNFTs.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {ERC721} from "./ERC721.sol";
Expand Down

0 comments on commit c043596

Please sign in to comment.