diff --git a/src/ERC1155Common.sol b/src/ERC1155Common.sol index 17a9f9a..8dc8cbb 100644 --- a/src/ERC1155Common.sol +++ b/src/ERC1155Common.sol @@ -90,8 +90,7 @@ contract ERC1155Common is onlyRole(MINTER_ROLE) { uint256 length = tos.length; - require(length == amounts.length, "ERC1155: invalid array lengths"); - require(length == datas.length, "ERC1155: invalid array lengths"); + require(length != 0 && length == amounts.length && length == datas.length, "ERC1155: invalid array lengths"); for (uint256 i; i < length; ++i) { _mint(tos[i], id, amounts[i], datas[i]); @@ -101,7 +100,7 @@ contract ERC1155Common is /** * @dev See {ERC1155-uri}. */ - function uri(uint256 tokenId) public view override returns (string memory) { + function uri(uint256 tokenId) public view virtual override returns (string memory) { string memory uri_ = super.uri(tokenId); return string.concat(uri_, tokenId.toString()); } @@ -109,14 +108,14 @@ contract ERC1155Common is /** * @dev Collection name. */ - function name() public view returns (string memory) { + function name() public view virtual returns (string memory) { return _name; } /** * @dev Collection symbol. */ - function symbol() public view returns (string memory) { + function symbol() public view virtual returns (string memory) { return _symbol; } diff --git a/src/mock/launchpad/SampleNFT1155Launchpad.sol b/src/mock/launchpad/SampleNFT1155Launchpad.sol index b070646..67fb4c7 100644 --- a/src/mock/launchpad/SampleNFT1155Launchpad.sol +++ b/src/mock/launchpad/SampleNFT1155Launchpad.sol @@ -1,17 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.19; -import { ERC1155 } from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; -import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol"; import { NFTLaunchpadCommon } from "../../launchpad/NFTLaunchpadCommon.sol"; +import { SampleERC1155, ERC1155Common } from "../SampleERC1155.sol"; -contract SampleNFT1155Launchpad is ERC1155, AccessControl, NFTLaunchpadCommon { - bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); - - constructor(address admin, address minter, string memory uri_) ERC1155(uri_) { - _setupRole(DEFAULT_ADMIN_ROLE, admin); - _setupRole(MINTER_ROLE, minter); - } +contract SampleNFT1155Launchpad is SampleERC1155, NFTLaunchpadCommon { + constructor(address admin, string memory name, string memory symbol, string memory uri) + SampleERC1155(admin, name, symbol, uri) + { } /// @dev Mint NFTs for the launchpad. function mintLaunchpad(address to, uint256 quantity, bytes calldata /* extraData */ ) @@ -35,9 +31,9 @@ contract SampleNFT1155Launchpad is ERC1155, AccessControl, NFTLaunchpadCommon { public view virtual - override(ERC1155, AccessControl, NFTLaunchpadCommon) + override(ERC1155Common, NFTLaunchpadCommon) returns (bool) { - return super.supportsInterface(interfaceId); + return ERC1155Common.supportsInterface(interfaceId) || NFTLaunchpadCommon.supportsInterface(interfaceId); } } diff --git a/src/mock/launchpad/SampleNFT721Launchpad.sol b/src/mock/launchpad/SampleNFT721Launchpad.sol index 6317bee..79e77a1 100644 --- a/src/mock/launchpad/SampleNFT721Launchpad.sol +++ b/src/mock/launchpad/SampleNFT721Launchpad.sol @@ -31,6 +31,6 @@ contract SampleNFT721Launchpad is SampleERC721, NFTLaunchpadCommon { override(ERC721Common, NFTLaunchpadCommon) returns (bool) { - return super.supportsInterface(interfaceId); + return ERC721Common.supportsInterface(interfaceId) || NFTLaunchpadCommon.supportsInterface(interfaceId); } } diff --git a/test/foundry/SampleNFT1155Launchpad.t.sol b/test/foundry/SampleNFT1155Launchpad.t.sol new file mode 100644 index 0000000..4c7ddaf --- /dev/null +++ b/test/foundry/SampleNFT1155Launchpad.t.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import "forge-std/Test.sol"; +import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; +import { SampleNFT1155Launchpad, SampleERC1155 } from "../../src/mock/launchpad/SampleNFT1155Launchpad.sol"; +import { INFTLaunchpad } from "src/interfaces/launchpad/INFTLaunchpad.sol"; +import { IERC1155Common } from "src/interfaces/IERC1155Common.sol"; + +contract SampleERC1155LaunchpadTest is Test { + using Strings for uint256; + + address admin = makeAddr("admin"); + string public constant NAME = "SampleERC721"; + string public constant SYMBOL = "NFT"; + string public constant BASE_URI = "http://example.com/"; + + SampleNFT1155Launchpad internal _t; + + function setUp() public virtual { + _t = new SampleNFT1155Launchpad(admin, NAME, SYMBOL, BASE_URI); + } + + function testSupportInterface() public { + assertEq(_token().supportsInterface(type(INFTLaunchpad).interfaceId), true); + assertEq(_token().supportsInterface(type(IERC1155Common).interfaceId), true); + } + + function _token() internal view virtual returns (SampleNFT1155Launchpad) { + return _t; + } +} diff --git a/test/foundry/SampleNFT721Launchpad.t.sol b/test/foundry/SampleNFT721Launchpad.t.sol new file mode 100644 index 0000000..1d5d0c0 --- /dev/null +++ b/test/foundry/SampleNFT721Launchpad.t.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import "forge-std/Test.sol"; +import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; +import { SampleNFT721Launchpad } from "../../src/mock/launchpad/SampleNFT721Launchpad.sol"; +import { INFTLaunchpad } from "src/interfaces/launchpad/INFTLaunchpad.sol"; +import { IERC721Common } from "src/interfaces/IERC721Common.sol"; + +contract SampleNFT721LaunchpadTest is Test { + using Strings for uint256; + + string public constant NAME = "SampleERC721"; + string public constant SYMBOL = "NFT"; + string public constant BASE_URI = "http://example.com/"; + + SampleNFT721Launchpad internal _t; + + function setUp() public virtual { + _t = new SampleNFT721Launchpad(NAME, SYMBOL, BASE_URI); + } + + function testSupportInterface() public { + assertEq(_token().supportsInterface(type(INFTLaunchpad).interfaceId), true); + assertEq(_token().supportsInterface(type(IERC721Common).interfaceId), true); + } + + function _token() internal view virtual returns (SampleNFT721Launchpad) { + return _t; + } +}