From c0435960547d57717779c087963d95ad093ce3f1 Mon Sep 17 00:00:00 2001 From: Rohan Kulkarni Date: Wed, 2 Aug 2023 10:59:12 -0400 Subject: [PATCH] chore: update tests --- test/ProtocolRewardsTest.sol | 10 ++- test/unit/Deposit.t.sol | 126 +++++++++++++++++++++++++++++++++ test/unit/ERC1155Rewards.t.sol | 2 +- test/unit/ERC721Rewards.t.sol | 2 +- test/utils/MockNFTs.sol | 2 +- 5 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 test/unit/Deposit.t.sol diff --git a/test/ProtocolRewardsTest.sol b/test/ProtocolRewardsTest.sol index 1986bf1..1e1ddcd 100644 --- a/test/ProtocolRewardsTest.sol +++ b/test/ProtocolRewardsTest.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "forge-std/Test.sol"; @@ -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 { @@ -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"); } } diff --git a/test/unit/Deposit.t.sol b/test/unit/Deposit.t.sol new file mode 100644 index 0000000..a510ae8 --- /dev/null +++ b/test/unit/Deposit.t.sol @@ -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"); + } +} diff --git a/test/unit/ERC1155Rewards.t.sol b/test/unit/ERC1155Rewards.t.sol index fb2a552..b70f236 100644 --- a/test/unit/ERC1155Rewards.t.sol +++ b/test/unit/ERC1155Rewards.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "../ProtocolRewardsTest.sol"; diff --git a/test/unit/ERC721Rewards.t.sol b/test/unit/ERC721Rewards.t.sol index 07a955a..b1fdd8e 100644 --- a/test/unit/ERC721Rewards.t.sol +++ b/test/unit/ERC721Rewards.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import "../ProtocolRewardsTest.sol"; diff --git a/test/utils/MockNFTs.sol b/test/utils/MockNFTs.sol index e51a41a..c42a726 100644 --- a/test/utils/MockNFTs.sol +++ b/test/utils/MockNFTs.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import {ERC721} from "./ERC721.sol";