Skip to content

Commit

Permalink
created tests for tokenIdERC1155
Browse files Browse the repository at this point in the history
  • Loading branch information
GWSzeto committed Sep 4, 2024
1 parent 7563cb8 commit 0d73284
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/core/token/ERC1155Core.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ contract ERC1155Core is ERC1155, Core, Multicallable, EIP712 {
override
returns (SupportedCallbackFunction[] memory supportedCallbackFunctions)
{
supportedCallbackFunctions = new SupportedCallbackFunction[](8);
supportedCallbackFunctions = new SupportedCallbackFunction[](9);
supportedCallbackFunctions[0] = SupportedCallbackFunction({
selector: BeforeMintCallbackERC1155.beforeMintERC1155.selector,
mode: CallbackMode.REQUIRED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract TokenIdERC1155 is Module, UpdateTokenIdCallbackERC1155 {
config.callbackFunctions = new CallbackFunction[](1);
config.fallbackFunctions = new FallbackFunction[](1);

config.callbackFunctions[0] = CallbackFunction(this.updateTokenId.selector);
config.callbackFunctions[0] = CallbackFunction(this.updateTokenIdERC1155.selector);

config.fallbackFunctions[0] = FallbackFunction({selector: this.getNextTokenId.selector, permissionBits: 0});

Expand All @@ -57,7 +57,7 @@ contract TokenIdERC1155 is Module, UpdateTokenIdCallbackERC1155 {
CALLBACK FUNCTION
//////////////////////////////////////////////////////////////*/

function updateTokenId(uint256 _tokenId, uint256 _amount) external returns (uint256) {
function updateTokenIdERC1155(uint256 _tokenId, uint256 _amount) external payable override returns (uint256) {
uint256 _nextTokenId = _tokenIdStorage().nextTokenId;

if (_tokenId == type(uint256).max) {
Expand All @@ -66,7 +66,7 @@ contract TokenIdERC1155 is Module, UpdateTokenIdCallbackERC1155 {
return _nextTokenId;
}

if (_tokenId >= _nextTokenId) {
if (_tokenId > _nextTokenId) {
revert TokenIdInvalidTokenId();
}

Expand Down
9 changes: 7 additions & 2 deletions test/module/minting/ClaimableERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {IModuleConfig} from "src/interface/IModuleConfig.sol";
import {BatchMetadataERC1155} from "src/module/token/metadata/BatchMetadataERC1155.sol";
import {BatchMetadataERC721} from "src/module/token/metadata/BatchMetadataERC721.sol";
import {ClaimableERC1155} from "src/module/token/minting/ClaimableERC1155.sol";
import {TokenIdERC1155} from "src/module/token/tokenId/tokenIdERC1155.sol";

contract MockCurrency is ERC20 {

Expand All @@ -46,6 +47,7 @@ contract ClaimableERC1155Test is Test {

ClaimableERC1155 public claimableModule;
BatchMetadataERC1155 public batchMetadataModule;
TokenIdERC1155 public tokenIdModule;

uint256 ownerPrivateKey = 1;
address public owner;
Expand Down Expand Up @@ -108,16 +110,19 @@ contract ClaimableERC1155Test is Test {
core = new ERC1155Core("test", "TEST", "", owner, modules, moduleData);
claimableModule = new ClaimableERC1155();
batchMetadataModule = new BatchMetadataERC1155();
tokenIdModule = new TokenIdERC1155();

// install module
bytes memory encodedInstallParams = abi.encode(owner);
vm.prank(owner);
core.installModule(address(claimableModule), encodedInstallParams);

// install module
bytes memory encodedBatchMetadataInstallParams = "";
vm.prank(owner);
core.installModule(address(batchMetadataModule), encodedBatchMetadataInstallParams);
core.installModule(address(batchMetadataModule), "");

vm.prank(owner);
core.installModule(address(tokenIdModule), "");

// Setup signature vars
typehashClaimSignatureParams =
Expand Down
9 changes: 7 additions & 2 deletions test/module/minting/MintableERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {IModuleConfig} from "src/interface/IModuleConfig.sol";
import {BatchMetadataERC1155} from "src/module/token/metadata/BatchMetadataERC1155.sol";
import {BatchMetadataERC721} from "src/module/token/metadata/BatchMetadataERC721.sol";
import {MintableERC1155} from "src/module/token/minting/MintableERC1155.sol";
import {TokenIdERC1155} from "src/module/token/tokenId/tokenIdERC1155.sol";

contract MockCurrency is ERC20 {

Expand All @@ -46,6 +47,7 @@ contract MintableERC1155Test is Test {

MintableERC1155 public mintableModule;
BatchMetadataERC1155 public batchMetadataModule;
TokenIdERC1155 public tokenIdModule;

uint256 ownerPrivateKey = 1;
address public owner;
Expand Down Expand Up @@ -107,15 +109,18 @@ contract MintableERC1155Test is Test {
core = new ERC1155Core("test", "TEST", "", owner, modules, moduleData);
mintableModule = new MintableERC1155();
batchMetadataModule = new BatchMetadataERC1155();
tokenIdModule = new TokenIdERC1155();

// install module
bytes memory encodedInstallParams = abi.encode(owner);
vm.prank(owner);
core.installModule(address(mintableModule), encodedInstallParams);

bytes memory encodedBatchMetadataInstallParams = "";
vm.prank(owner);
core.installModule(address(batchMetadataModule), encodedBatchMetadataInstallParams);
core.installModule(address(batchMetadataModule), "");

vm.prank(owner);
core.installModule(address(tokenIdModule), "");

// Setup signature vars
typehashMintSignatureParams =
Expand Down
4 changes: 4 additions & 0 deletions test/module/royalty/RoyaltyERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {IModuleConfig} from "src/interface/IModuleConfig.sol";

import {MintableERC1155} from "src/module/token/minting/MintableERC1155.sol";
import {RoyaltyERC1155} from "src/module/token/royalty/RoyaltyERC1155.sol";
import {TokenIdERC1155} from "src/module/token/tokenId/tokenIdERC1155.sol";

contract RoyaltyExt is RoyaltyERC1155 {}

Expand Down Expand Up @@ -49,6 +50,7 @@ contract RoyaltyERC1155Test is Test {

MintableERC1155 public mintableModuleImplementation;
TransferToken public transferTokenContract;
TokenIdERC1155 public tokenIdModule;
ITransferValidator public mockTransferValidator;

uint256 ownerPrivateKey = 1;
Expand Down Expand Up @@ -110,6 +112,7 @@ contract RoyaltyERC1155Test is Test {
core = new ERC1155Core("test", "TEST", "", owner, modules, moduleData);
moduleImplementation = new RoyaltyExt();
mintableModuleImplementation = new MintableERC1155();
tokenIdModule = new TokenIdERC1155();

transferTokenContract = new TransferToken();

Expand All @@ -120,6 +123,7 @@ contract RoyaltyERC1155Test is Test {
vm.startPrank(owner);
core.installModule(address(moduleImplementation), moduleInitializeData);
core.installModule(address(mintableModuleImplementation), mintableModuleInitializeData);
core.installModule(address(tokenIdModule), "");
vm.stopPrank();

typehashMintSignatureParams =
Expand Down
115 changes: 115 additions & 0 deletions test/module/tokenId/tokenIdERC1155.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "lib/forge-std/src/console.sol";

import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";
import {ERC20} from "@solady/tokens/ERC20.sol";
import {Test} from "forge-std/Test.sol";

// Target contract

import {Core} from "src/Core.sol";
import {Module} from "src/Module.sol";

import {Role} from "src/Role.sol";
import {ERC1155Core} from "src/core/token/ERC1155Core.sol";

import {ICore} from "src/interface/ICore.sol";
import {IModuleConfig} from "src/interface/IModuleConfig.sol";

import {BatchMetadataERC1155} from "src/module/token/metadata/BatchMetadataERC1155.sol";
import {BatchMetadataERC721} from "src/module/token/metadata/BatchMetadataERC721.sol";
import {MintableERC1155} from "src/module/token/minting/MintableERC1155.sol";
import {TokenIdERC1155} from "src/module/token/tokenId/tokenIdERC1155.sol";

contract MockCurrency is ERC20 {

function mintTo(address _recipient, uint256 _amount) public {
_mint(_recipient, _amount);
}

/// @dev Returns the name of the token.
function name() public view virtual override returns (string memory) {
return "MockCurrency";
}

/// @dev Returns the symbol of the token.
function symbol() public view virtual override returns (string memory) {
return "MOCK";
}

}

contract MintableERC1155Test is Test {

ERC1155Core public core;

MintableERC1155 public mintableModule;
BatchMetadataERC1155 public batchMetadataModule;
TokenIdERC1155 public tokenIdModule;

uint256 ownerPrivateKey = 1;
address public owner;

address tokenRecipient = address(0x123);

MintableERC1155.MintSignatureParamsERC1155 public mintRequest;

// Constants
address private constant NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

function setUp() public {
owner = vm.addr(ownerPrivateKey);

address[] memory modules;
bytes[] memory moduleData;

core = new ERC1155Core("test", "TEST", "", owner, modules, moduleData);
mintableModule = new MintableERC1155();
batchMetadataModule = new BatchMetadataERC1155();
tokenIdModule = new TokenIdERC1155();

// install module
bytes memory encodedInstallParams = abi.encode(owner);
vm.prank(owner);
core.installModule(address(mintableModule), encodedInstallParams);

vm.prank(owner);
core.installModule(address(batchMetadataModule), "");

vm.prank(owner);
core.installModule(address(tokenIdModule), "");

// Give permissioned actor minter role
vm.prank(owner);
core.grantRoles(owner, Role._MINTER_ROLE);
}

/*//////////////////////////////////////////////////////////////
Tests: beforeMintERC1155
//////////////////////////////////////////////////////////////*/

function test_state_updateTokenId() public {
assertEq(TokenIdERC1155(address(core)).getNextTokenId(), 0);

// increments the tokenId
vm.prank(owner);
core.mint(owner, type(uint256).max, 1, "", "");

assertEq(TokenIdERC1155(address(core)).getNextTokenId(), 1);

// does not increment the tokenId
vm.prank(owner);
core.mint(owner, 1, 1, "", "");

assertEq(TokenIdERC1155(address(core)).getNextTokenId(), 1);
}

function test_revert_updateTokenId() public {
vm.expectRevert(TokenIdERC1155.TokenIdInvalidTokenId.selector);
vm.prank(owner);
core.mint(owner, 2, 1, "", "");
}

}
6 changes: 5 additions & 1 deletion test/module/transferable/TransferableERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ contract Core is ERC1155Core {
bytes[] memory moduleInstallData
) ERC1155Core(name, symbol, contractURI, owner, modules, moduleInstallData) {}

// disable mint and approve callbacks for these tests
// disable mint, approve and tokenId callbacks for these tests
function _beforeMint(address to, uint256 tokenId, uint256 value, bytes memory data) internal override {}
function _beforeApproveForAll(address from, address to, bool approved) internal override {}

function _updateTokenId(uint256 tokenId, uint256 amount) internal override returns (uint256) {
return tokenId;
}

}

contract TransferableERC1155Test is Test {
Expand Down

0 comments on commit 0d73284

Please sign in to comment.