From 912aa56ba3c4ae999bedd0fa31d527ee1830c349 Mon Sep 17 00:00:00 2001 From: bruno bruno Date: Thu, 6 Jun 2024 13:14:44 +1000 Subject: [PATCH 1/5] GMS-1616: Additional erc1155 unit tests --- .../token/erc1155/abstract/ERC1155Permit.Sol | 2 +- test/token/erc1155/ImmutableERC1155.t.sol | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/contracts/token/erc1155/abstract/ERC1155Permit.Sol b/contracts/token/erc1155/abstract/ERC1155Permit.Sol index 7d90d3f6..c522fe84 100644 --- a/contracts/token/erc1155/abstract/ERC1155Permit.Sol +++ b/contracts/token/erc1155/abstract/ERC1155Permit.Sol @@ -90,7 +90,7 @@ abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImm returns (bool) { return - interfaceId == type(IERC1155Permit).interfaceId || // 0x5604e225 + interfaceId == type(IERC1155Permit).interfaceId || // 0x9e3ae8e4 super.supportsInterface(interfaceId); } diff --git a/test/token/erc1155/ImmutableERC1155.t.sol b/test/token/erc1155/ImmutableERC1155.t.sol index fd282ea7..5f0db52e 100644 --- a/test/token/erc1155/ImmutableERC1155.t.sol +++ b/test/token/erc1155/ImmutableERC1155.t.sol @@ -129,6 +129,10 @@ contract ImmutableERC1155Test is Test { assertEq(immutableERC1155.baseURI(), "test-base-uri"); } + function test_DeploymentShouldSetUri() public { + assertEq(immutableERC1155.uri(0), immutableERC1155.baseURI()); + } + function test_DeploymentAllowlistShouldGiveAdminToOwner() public { bytes32 adminRole = operatorAllowlist.DEFAULT_ADMIN_ROLE(); assertTrue(operatorAllowlist.hasRole(adminRole, owner)); @@ -207,6 +211,14 @@ contract ImmutableERC1155Test is Test { immutableERC1155.permit(owner, spender, true, 1 days, sig); } + function test_PermitRevertsWhenInvalidSignature() public { + bytes memory sig = bytes("invalid_sig"); + + vm.expectRevert(IImmutableERC1155Errors.InvalidSignature.selector); + + immutableERC1155.permit(owner, spender, true, 1 days, sig); + } + /* * Mints */ @@ -374,5 +386,58 @@ contract ImmutableERC1155Test is Test { assertEq(immutableERC1155.balanceOf(owner, 1), 5); assertEq(immutableERC1155.balanceOf(owner, 2), 7); assertEq(immutableERC1155.totalSupply(1), 5); + assertTrue(immutableERC1155.exists(1)); + } + + /* + * SupportsInterface + */ + function test_SupportsInterface() public { + assertTrue(immutableERC1155.supportsInterface(0x9e3ae8e4)); + } + + function test_SupportsInterface_delegatesToSuper() public { + assertTrue(immutableERC1155.supportsInterface(0x01ffc9a7)); //IERC165 + } + + /* + * Royalties + */ + function test_setDefaultRoyaltyReceiver() public { + vm.prank(owner); + address newFeeReceiver = vm.addr(anotherPrivateKey); + immutableERC1155.setDefaultRoyaltyReceiver(newFeeReceiver, 500); + (address receiver, uint256 royaltyAmount) = immutableERC1155.royaltyInfo(1, 20000); + assertEq(receiver, newFeeReceiver); + // 1000 = 20000 (salePrice) * 500 (new royalty amount) / 10000 (feeDenominator) + assertEq(1000, royaltyAmount); + } + + function test_setNFTRoyaltyReceiver() public { + vm.prank(minter); + address newFeeReceiver = vm.addr(anotherPrivateKey); + uint256 tokenID = 10; + immutableERC1155.setNFTRoyaltyReceiver(tokenID, newFeeReceiver, 100); + (address receiver, uint256 royaltyAmount) = immutableERC1155.royaltyInfo(tokenID, 10000); + assertEq(receiver, newFeeReceiver); + // 100 = 10000 (salePrice) * 100 (new royalty amount) / 10000 (feeDenominator) + assertEq(100, royaltyAmount); + } + + function test_setNFTRoyaltyReceiverBatch() public { + vm.prank(minter); + address newFeeReceiver = vm.addr(anotherPrivateKey); + uint256[] memory tokenIDs = new uint256[](3); + tokenIDs[0] = 20; + tokenIDs[1] = 21; + tokenIDs[2] = 22; + + immutableERC1155.setNFTRoyaltyReceiverBatch(tokenIDs, newFeeReceiver, 100); + + for (uint i = 0; i < tokenIDs.length; i++) { + (address receiver, uint256 royaltyAmount) = immutableERC1155.royaltyInfo(tokenIDs[i], 10000); + assertEq(receiver, newFeeReceiver); + assertEq(100, royaltyAmount); + } } } From 386e4593fae4e0adaa7a50bd0581efd0c8be5900 Mon Sep 17 00:00:00 2001 From: bruno bruno Date: Thu, 6 Jun 2024 15:31:08 +1000 Subject: [PATCH 2/5] GMS-1616: Adds unit test to test smart contract wallet as owner --- contracts/token/erc1155/abstract/ERC1155Permit.Sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/token/erc1155/abstract/ERC1155Permit.Sol b/contracts/token/erc1155/abstract/ERC1155Permit.Sol index c522fe84..7a703958 100644 --- a/contracts/token/erc1155/abstract/ERC1155Permit.Sol +++ b/contracts/token/erc1155/abstract/ERC1155Permit.Sol @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; import "@openzeppelin/contracts/interfaces/IERC1271.sol"; import "solidity-bytes-utils/contracts/BytesLib.sol"; import "./IERC1155Permit.sol"; + import {IImmutableERC1155Errors} from "../../../errors/Errors.sol"; abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImmutableERC1155Errors { From 0a89c88cd9db2c70867520ecce058f97d0d509dd Mon Sep 17 00:00:00 2001 From: bruno bruno Date: Thu, 6 Jun 2024 15:32:23 +1000 Subject: [PATCH 3/5] GMS-1616: Adds unit test to test smart contract wallet as owner --- test/token/erc1155/ImmutableERC1155.t.sol | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/token/erc1155/ImmutableERC1155.t.sol b/test/token/erc1155/ImmutableERC1155.t.sol index 5f0db52e..c1624558 100644 --- a/test/token/erc1155/ImmutableERC1155.t.sol +++ b/test/token/erc1155/ImmutableERC1155.t.sol @@ -11,6 +11,7 @@ import {Sign} from "../../utils/Sign.sol"; import {DeployOperatorAllowlist} from "../../utils/DeployAllowlistProxy.sol"; import {MockWallet} from "../../../contracts/mocks/MockWallet.sol"; import {MockWalletFactory} from "../../../contracts/mocks/MockWalletFactory.sol"; +import {MockEIP1271Wallet} from "../../../contracts/mocks/MockEIP1271Wallet.sol"; contract ImmutableERC1155Test is Test { ImmutableERC1155 public immutableERC1155; @@ -20,6 +21,7 @@ contract ImmutableERC1155Test is Test { MockWallet public mockWalletModule; MockWallet public scw; MockWallet public anotherScw; + MockEIP1271Wallet public eip1271Wallet; address[] private operatorAddrs; uint256 deployerPrivateKey = 1; @@ -72,6 +74,8 @@ contract ImmutableERC1155Test is Test { scmf.deploy(address(mockWalletModule), anotherSalt); anotherScwAddress = scmf.getAddress(address(mockWalletModule), anotherSalt); anotherScw = MockWallet(anotherScwAddress); + + eip1271Wallet = new MockEIP1271Wallet(owner); } function _sign( @@ -219,6 +223,15 @@ contract ImmutableERC1155Test is Test { immutableERC1155.permit(owner, spender, true, 1 days, sig); } + function test_PermitSuccess_UsingSmartContractWalletAsOwner() public { + bytes memory sig = _sign(ownerPrivateKey, address(eip1271Wallet), owner, true, 0, 1 days); + + immutableERC1155.permit(address(eip1271Wallet), owner, true, 1 days, sig); + + assertEq(immutableERC1155.isApprovedForAll(address(eip1271Wallet), owner), true); + assertEq(immutableERC1155.nonces(address(eip1271Wallet)), 1); + } + /* * Mints */ From 3f02d2c90a646b410c9030ea507cd48ca594e21d Mon Sep 17 00:00:00 2001 From: bruno bruno Date: Fri, 7 Jun 2024 09:38:44 +1000 Subject: [PATCH 4/5] GMS-1616: revert file --- contracts/token/erc1155/abstract/ERC1155Permit.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/token/erc1155/abstract/ERC1155Permit.sol b/contracts/token/erc1155/abstract/ERC1155Permit.sol index 7a703958..c522fe84 100644 --- a/contracts/token/erc1155/abstract/ERC1155Permit.sol +++ b/contracts/token/erc1155/abstract/ERC1155Permit.sol @@ -7,7 +7,6 @@ import "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; import "@openzeppelin/contracts/interfaces/IERC1271.sol"; import "solidity-bytes-utils/contracts/BytesLib.sol"; import "./IERC1155Permit.sol"; - import {IImmutableERC1155Errors} from "../../../errors/Errors.sol"; abstract contract ERC1155Permit is ERC1155Burnable, EIP712, IERC1155Permit, IImmutableERC1155Errors { From 810df71b38a25671bdad80161718a6243798a3b4 Mon Sep 17 00:00:00 2001 From: bruno bruno Date: Fri, 7 Jun 2024 10:21:34 +1000 Subject: [PATCH 5/5] GMS-1616: Test constructor & deployment in individual test --- test/token/erc1155/ImmutableERC1155.t.sol | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/token/erc1155/ImmutableERC1155.t.sol b/test/token/erc1155/ImmutableERC1155.t.sol index c1624558..5a0410eb 100644 --- a/test/token/erc1155/ImmutableERC1155.t.sol +++ b/test/token/erc1155/ImmutableERC1155.t.sol @@ -120,6 +120,30 @@ contract ImmutableERC1155Test is Test { /* * Contract deployment */ + function test_ValidateDeploymentConstructor() public { + string memory baseURI = "https://base-uri.com"; + string memory contractURI = "https://contract-uri.com"; + uint96 feeNumerator = 500; + address newFeeReceiver = vm.addr(anotherPrivateKey); + + ImmutableERC1155 anotherERC1155 = new ImmutableERC1155( + owner, "new erc1155", "https://base-uri.com", "https://contract-uri.com", address(operatorAllowlist), newFeeReceiver, feeNumerator + ); + + assertEq(anotherERC1155.contractURI(), contractURI); + assertEq(anotherERC1155.baseURI(), baseURI); + + // check owner is admin + bytes32 adminRole = anotherERC1155.DEFAULT_ADMIN_ROLE(); + assertTrue(anotherERC1155.hasRole(adminRole, owner)); + + // check default royalties + (address receiver, uint256 royaltyAmount) = anotherERC1155.royaltyInfo(1, 10000); + assertEq(receiver, newFeeReceiver); + // 500 = 10000 (salePrice) * 500 (feeNumerator) / 10000 (feeDenominator) + assertEq(500, royaltyAmount); + } + function test_DeploymentShouldSetAdminRoleToOwner() public { bytes32 adminRole = immutableERC1155.DEFAULT_ADMIN_ROLE(); assertTrue(immutableERC1155.hasRole(adminRole, owner));