diff --git a/contracts/contracts/RunnerFox.sol b/contracts/contracts/RunnerFox.sol index bba8dc310..a193c8ed4 100644 --- a/contracts/contracts/RunnerFox.sol +++ b/contracts/contracts/RunnerFox.sol @@ -27,18 +27,4 @@ contract RunnerFox is ImmutableERC721 { feeNumerator ) {} - - // Allows minter to mint the next token to a specified address - function mintNextToken(address to) external onlyRole(MINTER_ROLE) returns (uint256) { - uint256 tokenId = ++_currentTokenId; - _mintByID(to, tokenId); - return tokenId; - } - - // Allows minter to mint number of tokens specified to the address - function mintNextTokenByQuantity(address to, uint256 quantity) external onlyRole(MINTER_ROLE) { - for (uint256 i = 0; i < quantity; i++) { - _mintByID(to, ++_currentTokenId); - } - } } \ No newline at end of file diff --git a/contracts/contracts/RunnerSkin.sol b/contracts/contracts/RunnerSkin.sol index 90a938889..05c735ccd 100644 --- a/contracts/contracts/RunnerSkin.sol +++ b/contracts/contracts/RunnerSkin.sol @@ -27,18 +27,4 @@ contract RunnerSkin is ImmutableERC721 { feeNumerator ) {} - - // Allows minter to mint the next token to a specified address - function mintNextToken(address to) external onlyRole(MINTER_ROLE) returns (uint256) { - uint256 tokenId = ++_currentTokenId; - _mintByID(to, tokenId); - return tokenId; - } - - // Allows minter to mint number of tokens specified to the address - function mintNextTokenByQuantity(address to, uint256 quantity) external onlyRole(MINTER_ROLE) { - for (uint256 i = 0; i < quantity; i++) { - _mintByID(to, ++_currentTokenId); - } - } } \ No newline at end of file diff --git a/contracts/test/RunnerFox.test.ts b/contracts/test/RunnerFox.test.ts index 9d89f4602..33271d7d0 100644 --- a/contracts/test/RunnerFox.test.ts +++ b/contracts/test/RunnerFox.test.ts @@ -1,6 +1,8 @@ import { ethers } from "hardhat"; import { expect } from "chai"; import { RunnerFox, OperatorAllowlist__factory, RunnerFox__factory } from "../typechain-types"; +import { BigNumber, constants } from "ethers"; +import { token } from "../typechain-types/@openzeppelin/contracts"; describe("RunnerFox", function () { let contract: RunnerFox; @@ -31,6 +33,11 @@ describe("RunnerFox", function () { await contract.grantMinterRole(owner.address); }); + async function getTokenId(id: number): Promise { + const index = (await contract.mintBatchByQuantityThreshold()).sub(constants.One).add(BigNumber.from(id)); + return index; + } + it("Should be deployed with the correct arguments", async function () { expect(await contract.name()).to.equal("Immutable Runner Fox"); expect(await contract.symbol()).to.equal("IMRC"); @@ -43,31 +50,24 @@ describe("RunnerFox", function () { it("Account with minter role should be able to mint next NFT", async function () { const [owner, recipient] = await ethers.getSigners(); - await contract.connect(owner).mintNextToken(recipient.address); + await contract.connect(owner).mintByQuantity(recipient.address, 1); expect(await contract.balanceOf(recipient.address)).to.equal(1); expect(await contract.totalSupply()).to.equal(1); - expect(await contract.ownerOf(1)).to.equal(recipient.address); - - await contract.connect(owner).mintNextToken(recipient.address); - expect(await contract.balanceOf(recipient.address)).to.equal(2); - expect(await contract.ownerOf(2)).to.equal(recipient.address); - }); - - it("Account with minter role should be able to mint next NFTs in batch", async function () { - const [owner, recipient] = await ethers.getSigners(); + expect(await contract.ownerOf(await getTokenId(1))).to.equal(recipient.address); - await contract.connect(owner).mintNextTokenByQuantity(recipient.address, 3); + await contract.connect(owner).mintByQuantity(recipient.address, 2); expect(await contract.balanceOf(recipient.address)).to.equal(3); - expect(await contract.ownerOf(1)).to.equal(recipient.address); - expect(await contract.ownerOf(2)).to.equal(recipient.address); - expect(await contract.ownerOf(3)).to.equal(recipient.address); + expect(await contract.totalSupply()).to.equal(3); + expect(await contract.ownerOf(await getTokenId(2))).to.equal(recipient.address); + expect(await contract.ownerOf(await getTokenId(3))).to.equal(recipient.address); + await expect(contract.ownerOf(await getTokenId(4))).to.be.revertedWith('ERC721Psi: owner query for nonexistent token'); }); it("Account without minter role should not be able to mint NFTs", async function () { const [_, acc1] = await ethers.getSigners(); const minterRole = await contract.MINTER_ROLE(); await expect( - contract.connect(acc1).mintNextTokenByQuantity(acc1.address, 1) + contract.connect(acc1).mintByQuantity(acc1.address, 1) ).to.be.revertedWith( `AccessControl: account ${acc1.address.toLowerCase()} is missing role ${minterRole}` ); @@ -75,22 +75,24 @@ describe("RunnerFox", function () { it("Account which owns the NFT, should be able to burn the NFT", async function () { const [owner, recipient] = await ethers.getSigners(); + const tokenId = await getTokenId(1); - await contract.connect(owner).mintNextTokenByQuantity(recipient.address, 1); + await contract.connect(owner).mintByQuantity(recipient.address, 1); expect(await contract.balanceOf(recipient.address)).to.equal(1); - expect(await contract.ownerOf(1)).to.equal(recipient.address); + expect(await contract.ownerOf(tokenId)).to.equal(recipient.address); - await contract.connect(recipient).burn(1); + await contract.connect(recipient).burn(tokenId); expect(await contract.balanceOf(recipient.address)).to.equal(0); }); it("Account which doesn't own the NFT, should not be able to burn the NFT", async function () { const [owner, acc1, recipient] = await ethers.getSigners(); + const tokenId = await getTokenId(1); - await contract.connect(owner).mintNextTokenByQuantity(recipient.address, 1); + await contract.connect(owner).mintByQuantity(recipient.address, 1); expect(await contract.balanceOf(recipient.address)).to.equal(1); - expect(await contract.ownerOf(1)).to.equal(recipient.address); + expect(await contract.ownerOf(tokenId)).to.equal(recipient.address); - await expect(contract.connect(acc1).burn(1)).to.be.rejectedWith('IImmutableERC721NotOwnerOrOperator(1)'); + await expect(contract.connect(acc1).burn(tokenId)).to.be.rejectedWith(`IImmutableERC721NotOwnerOrOperator(${tokenId})`); }); }); diff --git a/contracts/test/RunnerSkin.test.ts b/contracts/test/RunnerSkin.test.ts index def356042..4b6a85abf 100644 --- a/contracts/test/RunnerSkin.test.ts +++ b/contracts/test/RunnerSkin.test.ts @@ -1,6 +1,7 @@ import { ethers } from "hardhat"; import { expect } from "chai"; import { OperatorAllowlist__factory, RunnerSkin, RunnerSkin__factory } from "../typechain-types"; +import { BigNumber, constants } from "ethers"; describe("RunnerSkin", function () { let contract: RunnerSkin; @@ -31,6 +32,11 @@ describe("RunnerSkin", function () { await contract.grantMinterRole(owner.address); }); + async function getTokenId(id: number): Promise { + const index = (await contract.mintBatchByQuantityThreshold()).sub(constants.One).add(BigNumber.from(id)); + return index; + } + it("Should be deployed with the correct arguments", async function () { expect(await contract.name()).to.equal("Immutable Runner Skin"); expect(await contract.symbol()).to.equal("IMRS"); @@ -43,53 +49,49 @@ describe("RunnerSkin", function () { it("Account with minter role should be able to mint next NFT", async function () { const [owner, recipient] = await ethers.getSigners(); - await contract.connect(owner).mintNextToken(recipient.address); + await contract.connect(owner).mintByQuantity(recipient.address, 1); expect(await contract.balanceOf(recipient.address)).to.equal(1); - expect(await contract.ownerOf(1)).to.equal(recipient.address); - - await contract.connect(owner).mintNextToken(recipient.address); - expect(await contract.balanceOf(recipient.address)).to.equal(2); - expect(await contract.ownerOf(2)).to.equal(recipient.address); - }); - - it("Account with minter role should be able to mint next NFTs in batch", async function () { - const [owner, recipient] = await ethers.getSigners(); + expect(await contract.totalSupply()).to.equal(1); + expect(await contract.ownerOf(await getTokenId(1))).to.equal(recipient.address); - await contract.connect(owner).mintNextTokenByQuantity(recipient.address, 3); + await contract.connect(owner).mintByQuantity(recipient.address, 2); expect(await contract.balanceOf(recipient.address)).to.equal(3); - expect(await contract.ownerOf(1)).to.equal(recipient.address); - expect(await contract.ownerOf(2)).to.equal(recipient.address); - expect(await contract.ownerOf(3)).to.equal(recipient.address); + expect(await contract.totalSupply()).to.equal(3); + expect(await contract.ownerOf(await getTokenId(2))).to.equal(recipient.address); + expect(await contract.ownerOf(await getTokenId(3))).to.equal(recipient.address); + await expect(contract.ownerOf(await getTokenId(4))).to.be.revertedWith('ERC721Psi: owner query for nonexistent token'); }); it("Account without minter role should not be able to mint NFTs", async function () { const [_, acc1] = await ethers.getSigners(); const minterRole = await contract.MINTER_ROLE(); await expect( - contract.connect(acc1).mintNextTokenByQuantity(acc1.address, 1) - ).to.be.rejectedWith( + contract.connect(acc1).mintByQuantity(acc1.address, 1) + ).to.be.revertedWith( `AccessControl: account ${acc1.address.toLowerCase()} is missing role ${minterRole}` ); }); it("Account which owns the NFT, should be able to burn the NFT", async function () { const [owner, recipient] = await ethers.getSigners(); + const tokenId = await getTokenId(1); - await contract.connect(owner).mintNextTokenByQuantity(recipient.address, 1); + await contract.connect(owner).mintByQuantity(recipient.address, 1); expect(await contract.balanceOf(recipient.address)).to.equal(1); - expect(await contract.ownerOf(1)).to.equal(recipient.address); + expect(await contract.ownerOf(tokenId)).to.equal(recipient.address); - await contract.connect(recipient).burn(1); + await contract.connect(recipient).burn(tokenId); expect(await contract.balanceOf(recipient.address)).to.equal(0); }); it("Account which doesn't own the NFT, should not be able to burn the NFT", async function () { const [owner, acc1, recipient] = await ethers.getSigners(); + const tokenId = await getTokenId(1); - await contract.connect(owner).mintNextTokenByQuantity(recipient.address, 1); + await contract.connect(owner).mintByQuantity(recipient.address, 1); expect(await contract.balanceOf(recipient.address)).to.equal(1); - expect(await contract.ownerOf(1)).to.equal(recipient.address); + expect(await contract.ownerOf(tokenId)).to.equal(recipient.address); - await expect(contract.connect(acc1).burn(1)).to.be.rejectedWith('IImmutableERC721NotOwnerOrOperator(1)'); + await expect(contract.connect(acc1).burn(tokenId)).to.be.rejectedWith(`IImmutableERC721NotOwnerOrOperator(${tokenId})`); }); });