Skip to content

Commit

Permalink
Rename mint method
Browse files Browse the repository at this point in the history
  • Loading branch information
zZoMROT committed Jun 23, 2024
1 parent 102edf7 commit 5c1e4dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions contracts/KycNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ contract KycNFT is Ownable, ERC721 {

/**
* @notice See {mint} method. This function using a valid owner's signature instead of only owner permission.
* @param signature The signature of the owner permitting the transfer.
* @param signature The signature of the owner permitting the mint.
*/
function mintWithSignature(address to, uint256 tokenId, bytes calldata signature) external onlyOwnerSignature(tokenId, signature) {
function mint(address to, uint256 tokenId, bytes calldata signature) external onlyOwnerSignature(tokenId, signature) {
_safeMint(to, tokenId);
}

Expand Down
54 changes: 29 additions & 25 deletions test/KycNFT.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,57 +121,61 @@ describe('KycNFT', function () {
});
});

describe('burn', function () {
it('should revert by non-owner', async function () {
const { bob, nft, tokenIds } = await loadFixture(initContracts);
await expect(nft.connect(bob).burn(tokenIds.bob)).to.be.revertedWithCustomError(nft, 'OwnableUnauthorizedAccount');
});

it('should work by owner', async function () {
const { owner, nft, tokenIds } = await loadFixture(initContracts);
await nft.connect(owner).burn(tokenIds.owner);
await expect(nft.ownerOf(tokenIds.owner)).to.be.revertedWithCustomError(nft, 'ERC721NonexistentToken');
});

it('should work by owner for any account', async function () {
const { owner, bob, nft, tokenIds } = await loadFixture(initContracts);
expect(await nft.ownerOf(tokenIds.bob)).to.equal(bob.address);
await nft.connect(owner).burn(tokenIds.bob);
await expect(nft.ownerOf(tokenIds.bob)).to.be.revertedWithCustomError(nft, 'ERC721NonexistentToken');
});
});

describe('mint with signature', function () {
it('should revert with invalid signature', async function () {
const { owner, alice, nft, tokenIds, chainId } = await loadFixture(initContracts);
const signature = await signTokenId(nft, tokenIds.alice, owner, chainId);
const invalidSignature = signature.substring(-2) + '00';
await expect(nft.connect(owner).mintWithSignature(alice, tokenIds.alice, invalidSignature)).to.be.revertedWithCustomError(nft, 'BadSignature');
await expect(nft.connect(owner)['mint(address,uint256,bytes)'](alice, tokenIds.alice, invalidSignature))
.to.be.revertedWithCustomError(nft, 'BadSignature');
});

it('should revert with non-owner signature', async function () {
const { alice, bob, nft, tokenIds, chainId } = await loadFixture(initContracts);
const signature = await signTokenId(nft, tokenIds.alice, bob, chainId);
await expect(nft.connect(bob).mintWithSignature(alice, tokenIds.alice, signature)).to.be.revertedWithCustomError(nft, 'BadSignature');
await expect(nft.connect(bob)['mint(address,uint256,bytes)'](alice, tokenIds.alice, signature))
.to.be.revertedWithCustomError(nft, 'BadSignature');
});

it('should work with owner signature', async function () {
const { owner, alice, bob, nft, tokenIds, chainId } = await loadFixture(initContracts);
const signature = await signTokenId(nft, tokenIds.alice, owner, chainId);
await nft.connect(bob).mintWithSignature(alice, tokenIds.alice, signature);
await nft.connect(bob)['mint(address,uint256,bytes)'](alice, tokenIds.alice, signature);
expect(await nft.ownerOf(tokenIds.alice)).to.equal(alice.address);
});

it('should revert when account already has 1 nft', async function () {
const { owner, bob, nft, tokenIds, chainId } = await loadFixture(initContracts);
const signature = await signTokenId(nft, tokenIds.another, owner, chainId);
await expect(nft.connect(owner).mintWithSignature(bob, tokenIds.another, signature)).to.be.revertedWithCustomError(nft, 'OnlyOneNFTPerAddress');
await expect(nft.connect(owner)['mint(address,uint256,bytes)'](bob, tokenIds.another, signature))
.to.be.revertedWithCustomError(nft, 'OnlyOneNFTPerAddress');
});

it('should revert when tokenId already exist', async function () {
const { owner, alice, nft, tokenIds, chainId } = await loadFixture(initContracts);
const signature = await signTokenId(nft, tokenIds.bob, owner, chainId);
await expect(nft.connect(owner).mintWithSignature(alice, tokenIds.bob, signature)).to.be.revertedWithCustomError(nft, 'ERC721InvalidSender');
await expect(nft.connect(owner)['mint(address,uint256,bytes)'](alice, tokenIds.bob, signature))
.to.be.revertedWithCustomError(nft, 'ERC721InvalidSender');
});
});

describe('burn', function () {
it('should revert by non-owner', async function () {
const { bob, nft, tokenIds } = await loadFixture(initContracts);
await expect(nft.connect(bob).burn(tokenIds.bob)).to.be.revertedWithCustomError(nft, 'OwnableUnauthorizedAccount');
});

it('should work by owner', async function () {
const { owner, nft, tokenIds } = await loadFixture(initContracts);
await nft.connect(owner).burn(tokenIds.owner);
await expect(nft.ownerOf(tokenIds.owner)).to.be.revertedWithCustomError(nft, 'ERC721NonexistentToken');
});

it('should work by owner for any account', async function () {
const { owner, bob, nft, tokenIds } = await loadFixture(initContracts);
expect(await nft.ownerOf(tokenIds.bob)).to.equal(bob.address);
await nft.connect(owner).burn(tokenIds.bob);
await expect(nft.ownerOf(tokenIds.bob)).to.be.revertedWithCustomError(nft, 'ERC721NonexistentToken');
});
});

Expand Down

0 comments on commit 5c1e4dd

Please sign in to comment.