// SPDX-License-Identifier: MIT pragma solidity ^0.8.16; import "forge-std/Test.sol"; import "forge-std/console2.sol"; import "#/extension/PrimarySale.sol"; contract ExampleContract is PrimarySale { constructor(IPrimarySale.PrimarySaleRecipient[] memory _recipients) PrimarySale(_recipients) {} } contract PrimarySaleTest is Test { address constant ALICE = 0x0000000000000000000000000000000000000010; address constant BOB = 0x0000000000000000000000000000000000000020; PrimarySale c; function setUp() public { IPrimarySale.PrimarySaleRecipient[] memory _recipients = new IPrimarySale.PrimarySaleRecipient[](2); _recipients[0] = IPrimarySale.PrimarySaleRecipient({recipient: ALICE, bps: 5000}); _recipients[1] = IPrimarySale.PrimarySaleRecipient({recipient: BOB, bps: 5000}); c = new ExampleContract(_recipients); } function testCannotCreateIfRecipientZeroAddress() public { IPrimarySale.PrimarySaleRecipient[] memory _recipients = new IPrimarySale.PrimarySaleRecipient[](1); _recipients[0] = IPrimarySale.PrimarySaleRecipient({recipient: address(0), bps: 5000}); vm.expectRevert(abi.encodeWithSignature("RecipientCantBeZeroAddressError()")); new ExampleContract(_recipients); } function testCannotCreateIfBPSInsufficient() public { IPrimarySale.PrimarySaleRecipient[] memory _recipients = new IPrimarySale.PrimarySaleRecipient[](1); _recipients[0] = IPrimarySale.PrimarySaleRecipient({recipient: ALICE, bps: 4999}); vm.expectRevert(abi.encodeWithSignature("InsufficientBPSError()")); new ExampleContract(_recipients); } function testCannotCreateSameRecipient() public { IPrimarySale.PrimarySaleRecipient[] memory _recipients = new IPrimarySale.PrimarySaleRecipient[](2); _recipients[0] = IPrimarySale.PrimarySaleRecipient({recipient: ALICE, bps: 4999}); _recipients[1] = IPrimarySale.PrimarySaleRecipient({recipient: ALICE, bps: 5001}); vm.expectRevert(abi.encodeWithSignature("RecipientAlreadySetError()")); new ExampleContract(_recipients); } function testPrimarySaleRecipients() public { address[] memory recipients = new address[](2); recipients[0] = ALICE; recipients[1] = BOB; assertEq(recipients, c.primarySaleRecipients()); } function testPrimarySaleBps() public { assertEq(5000, c.primarySaleRecipientBps(ALICE)); assertEq(5000, c.primarySaleRecipientBps(BOB)); } }