// SPDX-License-Identifier: MIT pragma solidity ^0.8.16; import "forge-std/Test.sol"; import "forge-std/console2.sol"; import "#/extension/RoyaltySplitter.sol"; contract ExampleContract is RoyaltySplitter { constructor(RoyaltyRecipient[] memory _recipients, Metadata memory _metadata, uint16 _royaltyBps) RoyaltySplitter(_recipients, _metadata, _royaltyBps) {} function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC2981).interfaceId; } } contract RoyaltySplitterTest is Test { address constant ALICE = 0x0000000000000000000000000000000000000010; address constant BOB = 0x0000000000000000000000000000000000000020; address constant WHO = 0x0000000000000000000000000000000000000040; RoyaltySplitter c; function setUp() public { IRoyaltySplitter.RoyaltyRecipient[] memory _recipients = new IRoyaltySplitter.RoyaltyRecipient[](2); _recipients[0] = IRoyaltySplitter.RoyaltyRecipient({recipient: ALICE, shares: 5000}); _recipients[1] = IRoyaltySplitter.RoyaltyRecipient({recipient: BOB, shares: 5000}); IContractMetadata.Metadata memory _metadata = IContractMetadata.Metadata({name: "Test", description: "Test", imageURI: "Test"}); c = new ExampleContract(_recipients, _metadata, 5000); } function testCannotCreateIfRecipientZeroAddress() public { IRoyaltySplitter.RoyaltyRecipient[] memory _recipients = new IRoyaltySplitter.RoyaltyRecipient[](1); _recipients[0] = IRoyaltySplitter.RoyaltyRecipient({recipient: address(0), shares: 5000}); vm.expectRevert(abi.encodeWithSignature("AccountCantBeZeroAddressError()")); new ExampleContract(_recipients, IContractMetadata.Metadata({ name: "Test", description: "Test", imageURI: "Test" }), 5000); } function testCannotCreateIfZeroShares() public { IRoyaltySplitter.RoyaltyRecipient[] memory _recipients = new IRoyaltySplitter.RoyaltyRecipient[](1); _recipients[0] = IRoyaltySplitter.RoyaltyRecipient({recipient: ALICE, shares: 0}); vm.expectRevert(abi.encodeWithSignature("SharesCantBeZeroError()")); new ExampleContract(_recipients, IContractMetadata.Metadata({ name: "Test", description: "Test", imageURI: "Test" }), 5000); } function testTotalShares() public { assertEq(c.totalShares(), 10000); } function testReleased() public { assertEq(c.totalReleased(), 0); vm.deal(address(c), 1 ether); assertEq(c.releasable(ALICE), 0.5 ether); assertEq(c.releasable(BOB), 0.5 ether); c.releaseAll(); assertEq(c.totalReleased(), 1 ether); assertEq(c.released(ALICE), 0.5 ether); assertEq(c.released(BOB), 0.5 ether); } function testCannotReleaseIfNoShares() public { vm.expectRevert(abi.encodeWithSignature("NoSharesError(address)", WHO)); c.release(payable(WHO)); } function testCannotReleaseIfNoPayment() public { vm.expectRevert(abi.encodeWithSignature("NoPaymentError(address)", BOB)); c.release(payable(BOB)); } function testReleases() public { vm.deal(address(c), 1 ether); c.release(payable(BOB)); assertEq(c.released(BOB), 0.5 ether); } function testShares() public { assertEq(c.shares(ALICE), 5000); assertEq(c.shares(BOB), 5000); } function testPayee() public { assertEq(c.payee(0), ALICE); assertEq(c.payee(1), BOB); } function testRoylatyInfo() public { (address expectedAddress, uint256 expectedRoyalty) = (address(c), 5e17); (address actualAddress, uint256 actualRoyalty) = c.royaltyInfo(1, 1e18); assertEq(actualAddress, expectedAddress); assertEq(actualRoyalty, expectedRoyalty); } function testRoylatyInfoWithOneReciever() public { IRoyaltySplitter.RoyaltyRecipient[] memory recipients = new IRoyaltySplitter.RoyaltyRecipient[](1); recipients[0] = IRoyaltySplitter.RoyaltyRecipient({recipient: ALICE, shares: 10000}); RoyaltySplitter temp = new ExampleContract(recipients, IContractMetadata.Metadata({ name: "Test", description: "Test", imageURI: "Test" }), 5000); (address expectedAddress, uint256 expectedRoyalty) = (ALICE, 5e17); (address actualAddress, uint256 actualRoyalty) = temp.royaltyInfo(1, 1e18); assertEq(actualAddress, expectedAddress); assertEq(actualRoyalty, expectedRoyalty); } }