@@ -629,6 +629,115 @@ contract TokenERC1155Test is BaseTest {
629
629
Unit tests: platform fee
630
630
//////////////////////////////////////////////////////////////*/
631
631
632
+ function test_state_PlatformFee_Flat_ERC20 () public {
633
+ vm.warp (1000 );
634
+ uint256 flatPlatformFee = 10 ;
635
+
636
+ vm.startPrank (deployerSigner);
637
+ tokenContract.setFlatPlatformFeeInfo (platformFeeRecipient, flatPlatformFee);
638
+ tokenContract.setPlatformFeeType (TokenERC1155.PlatformFeeType.Flat);
639
+ vm.stopPrank ();
640
+
641
+ // update mintrequest data
642
+ _mintrequest.pricePerToken = 1 ;
643
+ _mintrequest.currency = address (erc20);
644
+ _signature = signMintRequest (_mintrequest, privateKey);
645
+
646
+ // approve erc20 tokens to tokenContract
647
+ vm.prank (recipient);
648
+ erc20.approve (address (tokenContract), _mintrequest.pricePerToken * _mintrequest.quantity);
649
+
650
+ // initial balances and state
651
+ uint256 nextTokenId = tokenContract.nextTokenIdToMint ();
652
+ uint256 currentBalanceOfRecipient = tokenContract.balanceOf (recipient, nextTokenId);
653
+
654
+ uint256 erc20BalanceOfSeller = erc20.balanceOf (address (saleRecipient));
655
+ uint256 erc20BalanceOfRecipient = erc20.balanceOf (address (recipient));
656
+
657
+ // mint with signature
658
+ vm.prank (recipient);
659
+ tokenContract.mintWithSignature (_mintrequest, _signature);
660
+
661
+ // check state after minting
662
+ assertEq (tokenContract.nextTokenIdToMint (), nextTokenId + 1 );
663
+ assertEq (tokenContract.uri (nextTokenId), string (_mintrequest.uri));
664
+ assertEq (tokenContract.balanceOf (recipient, nextTokenId), currentBalanceOfRecipient + _mintrequest.quantity);
665
+
666
+ // check erc20 balances after minting
667
+ assertEq (
668
+ erc20.balanceOf (recipient),
669
+ erc20BalanceOfRecipient - (_mintrequest.pricePerToken * _mintrequest.quantity)
670
+ );
671
+ assertEq (
672
+ erc20.balanceOf (address (saleRecipient)),
673
+ erc20BalanceOfSeller + (_mintrequest.pricePerToken * _mintrequest.quantity) - flatPlatformFee
674
+ );
675
+ }
676
+
677
+ function test_state_PlatformFee_NativeToken () public {
678
+ vm.warp (1000 );
679
+ uint256 flatPlatformFee = 10 ;
680
+
681
+ vm.startPrank (deployerSigner);
682
+ tokenContract.setFlatPlatformFeeInfo (platformFeeRecipient, flatPlatformFee);
683
+ tokenContract.setPlatformFeeType (TokenERC1155.PlatformFeeType.Flat);
684
+ vm.stopPrank ();
685
+
686
+ // update mintrequest data
687
+ _mintrequest.pricePerToken = 1 ;
688
+ _mintrequest.currency = address (NATIVE_TOKEN);
689
+ _signature = signMintRequest (_mintrequest, privateKey);
690
+
691
+ // initial balances and state
692
+ uint256 nextTokenId = tokenContract.nextTokenIdToMint ();
693
+ uint256 currentBalanceOfRecipient = tokenContract.balanceOf (recipient, nextTokenId);
694
+
695
+ uint256 etherBalanceOfSeller = address (saleRecipient).balance;
696
+ uint256 etherBalanceOfRecipient = address (recipient).balance;
697
+
698
+ // mint with signature
699
+ vm.prank (recipient);
700
+ tokenContract.mintWithSignature { value: _mintrequest.pricePerToken * _mintrequest.quantity }(
701
+ _mintrequest,
702
+ _signature
703
+ );
704
+
705
+ // check state after minting
706
+ assertEq (tokenContract.nextTokenIdToMint (), nextTokenId + 1 );
707
+ assertEq (tokenContract.uri (nextTokenId), string (_mintrequest.uri));
708
+ assertEq (tokenContract.balanceOf (recipient, nextTokenId), currentBalanceOfRecipient + _mintrequest.quantity);
709
+
710
+ // check balances after minting
711
+ assertEq (
712
+ address (recipient).balance,
713
+ etherBalanceOfRecipient - (_mintrequest.pricePerToken * _mintrequest.quantity)
714
+ );
715
+ assertEq (
716
+ address (saleRecipient).balance,
717
+ etherBalanceOfSeller + (_mintrequest.pricePerToken * _mintrequest.quantity) - flatPlatformFee
718
+ );
719
+ }
720
+
721
+ function test_revert_PlatformFeeGreaterThanPrice () public {
722
+ vm.warp (1000 );
723
+ uint256 flatPlatformFee = 1 ether ;
724
+
725
+ vm.startPrank (deployerSigner);
726
+ tokenContract.setFlatPlatformFeeInfo (platformFeeRecipient, flatPlatformFee);
727
+ tokenContract.setPlatformFeeType (TokenERC1155.PlatformFeeType.Flat);
728
+ vm.stopPrank ();
729
+
730
+ // update mintrequest data
731
+ _mintrequest.pricePerToken = 1 ;
732
+ _mintrequest.currency = address (erc20);
733
+ _signature = signMintRequest (_mintrequest, privateKey);
734
+
735
+ // mint with signature
736
+ vm.prank (recipient);
737
+ vm.expectRevert ("price less than platform fee " );
738
+ tokenContract.mintWithSignature (_mintrequest, _signature);
739
+ }
740
+
632
741
function test_state_setPlatformFeeInfo () public {
633
742
address _platformFeeRecipient = address (0x123 );
634
743
uint256 _platformFeeBps = 1000 ;
@@ -641,6 +750,33 @@ contract TokenERC1155Test is BaseTest {
641
750
assertEq (_platformFeeBps, bps);
642
751
}
643
752
753
+ function test_state_setFlatPlatformFee () public {
754
+ address _platformFeeRecipient = address (0x123 );
755
+ uint256 _flatFee = 1000 ;
756
+
757
+ vm.prank (deployerSigner);
758
+ tokenContract.setFlatPlatformFeeInfo (_platformFeeRecipient, _flatFee);
759
+
760
+ (address recipient_ , uint256 fee ) = tokenContract.getFlatPlatformFeeInfo ();
761
+ assertEq (_platformFeeRecipient, recipient_);
762
+ assertEq (_flatFee, fee);
763
+ }
764
+
765
+ function test_state_setPlatformFeeType () public {
766
+ address _platformFeeRecipient = address (0x123 );
767
+ uint256 _flatFee = 1000 ;
768
+ TokenERC1155.PlatformFeeType _feeType = TokenERC1155.PlatformFeeType.Flat;
769
+
770
+ vm.prank (deployerSigner);
771
+ tokenContract.setFlatPlatformFeeInfo (_platformFeeRecipient, _flatFee);
772
+
773
+ vm.prank (deployerSigner);
774
+ tokenContract.setPlatformFeeType (_feeType);
775
+
776
+ TokenERC1155.PlatformFeeType updatedFeeType = tokenContract.getPlatformFeeType ();
777
+ assertTrue (updatedFeeType == _feeType);
778
+ }
779
+
644
780
function test_revert_setPlatformFeeInfo_ExceedsMaxBps () public {
645
781
address _platformFeeRecipient = address (0x123 );
646
782
uint256 _platformFeeBps = 10001 ;
@@ -663,6 +799,17 @@ contract TokenERC1155Test is BaseTest {
663
799
);
664
800
vm.prank (address (0x1 ));
665
801
tokenContract.setPlatformFeeInfo (address (1 ), 1000 );
802
+
803
+ vm.expectRevert (
804
+ abi.encodePacked (
805
+ "AccessControl: account " ,
806
+ TWStrings.toHexString (uint160 (address (0x1 )), 20 ),
807
+ " is missing role " ,
808
+ TWStrings.toHexString (uint256 (role), 32 )
809
+ )
810
+ );
811
+ vm.prank (address (0x1 ));
812
+ tokenContract.setFlatPlatformFeeInfo (address (1 ), 1000 );
666
813
}
667
814
668
815
function test_event_platformFeeInfo () public {
0 commit comments