From 6081d471786286b7d14b3b8abf0d1be3b37f6497 Mon Sep 17 00:00:00 2001 From: ikmz Date: Mon, 19 Feb 2024 18:32:41 +0900 Subject: [PATCH 1/2] Add participation count to MintNFT contract --- circom | 2 +- hardhat/contracts/IMintNFT.sol | 5 + hardhat/contracts/MintNFT.sol | 8 + hardhat/test/MintNFT.ts | 1142 ++++++++++++++++---------------- 4 files changed, 597 insertions(+), 560 deletions(-) diff --git a/circom b/circom index ccc8cd74..6cf74202 160000 --- a/circom +++ b/circom @@ -1 +1 @@ -Subproject commit ccc8cd743c38ff4d24f6c8b68a8ad7b3093705db +Subproject commit 6cf74202ebe9a768b67d688eb0ffd8768e73ad50 diff --git a/hardhat/contracts/IMintNFT.sol b/hardhat/contracts/IMintNFT.sol index f5eab4be..f6c8479a 100644 --- a/hardhat/contracts/IMintNFT.sol +++ b/hardhat/contracts/IMintNFT.sol @@ -45,6 +45,11 @@ interface IMintNFT { string memory _secretPhrase ) external; + function getCountOfParticipation(uint256 _groupId, address _address) + external + view + returns (uint256); + function name() external view returns (string memory); function owner() external view returns (address); diff --git a/hardhat/contracts/MintNFT.sol b/hardhat/contracts/MintNFT.sol index fab7a6a2..be68bd58 100644 --- a/hardhat/contracts/MintNFT.sol +++ b/hardhat/contracts/MintNFT.sol @@ -275,6 +275,14 @@ contract MintNFT is isHoldingEventNFT[Hashing.hashingAddressUint256(_addr, _eventId)]; } + function getCountOfParticipation( + uint256 _groupId, + address _address + ) public view returns (uint256) { + bytes32 groupHash = Hashing.hashingAddressUint256(_address, _groupId); + return countOfParticipation[groupHash]; + } + function setEventInfo( uint256 _eventId, uint256 _mintLimit, diff --git a/hardhat/test/MintNFT.ts b/hardhat/test/MintNFT.ts index 1b1b3791..c25113b7 100644 --- a/hardhat/test/MintNFT.ts +++ b/hardhat/test/MintNFT.ts @@ -369,6 +369,12 @@ describe("MintNFT", function () { ); await mintNftTxn2.wait(); expect(await mintNFT.getEventIdOfTokenId(1)).equal(createdEventIds[0]); + expect( + await mintNFT.getCountOfParticipation( + createdGroupId1, + participant1.address + ) + ).equal(1); const { proofCalldata: proofCalldata3 } = await generateProof(); const mintNftTxn3 = await mintNFT @@ -380,6 +386,12 @@ describe("MintNFT", function () { ); await mintNftTxn3.wait(); expect(await mintNFT.getEventIdOfTokenId(2)).equal(createdEventIds[0]); + expect( + await mintNFT.getCountOfParticipation( + createdGroupId1, + participant2.address + ) + ).equal(1); const { proofCalldata: proofCalldata4 } = await generateProof(); const mintNftTxn4 = await mintNFT @@ -391,6 +403,12 @@ describe("MintNFT", function () { ); await mintNftTxn4.wait(); expect(await mintNFT.getEventIdOfTokenId(3)).equal(createdEventIds[1]); + expect( + await mintNFT.getCountOfParticipation( + createdGroupId1, + participant1.address + ) + ).equal(2); const { proofCalldata: proofCalldata5 } = await generateProof(); const mintNftTxn5 = await mintNFT @@ -402,6 +420,12 @@ describe("MintNFT", function () { ); await mintNftTxn5.wait(); expect(await mintNFT.getEventIdOfTokenId(4)).equal(createdEventIds[2]); + expect( + await mintNFT.getCountOfParticipation( + createdGroupId2, + participant1.address + ) + ).equal(1); }); it("get owners of the tokens", async () => { const tokens = [0, 1, 2, 3, 4]; @@ -544,562 +568,562 @@ describe("MintNFT", function () { // }); }); -describe("nft revolution", () => { - let mintNFT: MintNFT; - let eventManager: EventManager; - - let createdGroupId: number; - let createdEventIds: number[] = []; - - let organizer: SignerWithAddress; - let participant1: SignerWithAddress; - let participant2: SignerWithAddress; - let relayer: SignerWithAddress; - - let usedProofCalldata!: any; - - before(async () => { - [organizer, participant1, participant2, relayer] = - await ethers.getSigners(); - - // generate proof - const { publicInputCalldata } = await generateProof(); - - [, mintNFT, eventManager] = await deployAll(organizer, relayer); - - // Create a Group and an Event - await createGroup(eventManager, "First Group"); - const groupsList = await eventManager.getGroups(); - createdGroupId = groupsList[0].groupId.toNumber(); - await createEventRecord(eventManager, { - groupId: createdGroupId, - name: "event1", - description: "event1 description", - date: "2022-07-3O", - mintLimit: 10, - useMtx: false, - nonTransferable: false, - secretPhrase: publicInputCalldata[0], - eventNFTAttributes: attributes, - }); - await createEventRecord(eventManager, { - groupId: createdGroupId, - name: "event2", - description: "event2 description", - date: "2022-07-3O", - mintLimit: 1, - useMtx: false, - nonTransferable: false, - secretPhrase: publicInputCalldata[0], - eventNFTAttributes: attributes, - }); - - const eventsList = await eventManager.getEventRecords(0, 0); - createdEventIds = eventsList.map((event) => event.eventRecordId.toNumber()); - - const { proofCalldata: proofCalldata1 } = await generateProof(); - const mintTxn1 = await mintNFT - .connect(organizer) - .mintParticipateNFT(createdGroupId, createdEventIds[1], proofCalldata1); - await mintTxn1.wait(); - usedProofCalldata = proofCalldata1; - - const { proofCalldata: proofCalldata2 } = await generateProof(); - const mintTxn2 = await mintNFT - .connect(organizer) - .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata2); - await mintTxn2.wait(); - }); - - it("doesn't mint NFT if proof is already used", async () => { - await expect( - mintNFT - .connect(organizer) - .mintParticipateNFT( - createdGroupId, - createdEventIds[1], - usedProofCalldata - ) - ).to.be.revertedWith("invalid secret phrase"); - }); - - it("mint different NFT by participate count", async () => { - const holdingNFT0 = await mintNFT.tokenURI(0); - const holdingNFT1 = await mintNFT.tokenURI(1); - expect(holdingNFT0).equal("ipfs://hogehoge/count0.json"); - expect(holdingNFT1).equal("ipfs://hogehoge/count1.json"); - }); - - it("doesn't mint NFT for an event once attended to the same person twice", async () => { - expect( - await mintNFT.isHoldingEventNFTByAddress( - organizer.address, - createdEventIds[1] - ) - ).equal(true); - const { proofCalldata } = await generateProof(); - await expect( - mintNFT - .connect(organizer) - .mintParticipateNFT(createdGroupId, createdEventIds[1], proofCalldata) - ).to.be.revertedWith("already minted"); - }); - - it("doesn't mint NFT if there are no remaining count", async () => { - const { proofCalldata } = await generateProof(); - await expect( - mintNFT - .connect(participant1) - .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata) - ).to.be.revertedWith("remaining count is zero"); - }); - - it("doesn't mint NFT if wrong secret phrase", async () => { - await expect( - mintNFT - .connect(participant2) - .mintParticipateNFT( - createdGroupId, - createdEventIds[0], - wrongProofCalldata - ) - ).to.be.revertedWith("invalid secret phrase"); - }); -}); - -describe("bulk mint by event owner", () => { - let mintNFT: MintNFT; - let eventManager: EventManager; - - let createdGroupId: number; - let createdEventIds: number[] = []; - - let organizer: SignerWithAddress; - let participant1: SignerWithAddress; - let participant2: SignerWithAddress; - let participant3: SignerWithAddress; - let participant4: SignerWithAddress; - let participant5: SignerWithAddress; - let participant6: SignerWithAddress; - let relayer: SignerWithAddress; - - before(async () => { - [ - organizer, - participant1, - participant2, - participant3, - participant4, - participant5, - participant6, - relayer, - ] = await ethers.getSigners(); - - // generate proof - const { publicInputCalldata } = await generateProof(); - - [, mintNFT, eventManager] = await deployAll(organizer, relayer); - - // Create a Group and an Event - await createGroup(eventManager, "First Group"); - const groupsList = await eventManager.getGroups(); - createdGroupId = groupsList[0].groupId.toNumber(); - await createEventRecord(eventManager, { - groupId: createdGroupId, - name: "event1", - description: "event1 description", - date: "2022-07-3O", - mintLimit: 10, - useMtx: false, - nonTransferable: false, - secretPhrase: publicInputCalldata[0], - eventNFTAttributes: attributes, - }); - await createEventRecord(eventManager, { - groupId: createdGroupId, - name: "event2", - description: "event1 description", - date: "2022-07-3O", - mintLimit: 10, - useMtx: false, - nonTransferable: false, - secretPhrase: publicInputCalldata[0], - eventNFTAttributes: attributes, - }); - - const eventsList = await eventManager.getEventRecords(0, 0); - createdEventIds = eventsList.map((event) => event.eventRecordId.toNumber()); - }); - - it("drop NFTs by event owner", async () => { - await expect( - mintNFT - .connect(organizer) - .dropNFTs(createdEventIds[1], [ - participant1.address, - participant2.address, - participant3.address, - participant4.address, - participant5.address, - participant6.address, - ]) - ) - .to.emit(mintNFT, "DroppedNFTs") - .withArgs(organizer.address, createdEventIds[1]); - console.log(await mintNFT.ownerOf(0)); - console.log(await mintNFT.ownerOf(1)); - - console.log(participant1.address); - - expect(await mintNFT.ownerOf(0)).to.equal(participant1.address); - expect(await mintNFT.ownerOf(1)).to.equal(participant2.address); - expect(await mintNFT.ownerOf(2)).to.equal(participant3.address); - expect(await mintNFT.ownerOf(3)).to.equal(participant4.address); - expect(await mintNFT.ownerOf(4)).to.equal(participant5.address); - expect(await mintNFT.ownerOf(5)).to.equal(participant6.address); - it("should return NFTs by specified Event ID", async () => { - expect(await mintNFT.getNFTHoldersByEvent(createdEventIds[1])).to.equal([ - participant1, - participant2, - participant3, - participant4, - participant5, - participant6, - ]); - }); - }); - it("prohibit drop NFTs by not event owner", async () => { - await expect( - mintNFT - .connect(participant1) - .dropNFTs(createdEventIds[0], [ - participant1.address, - participant2.address, - participant3.address, - participant4.address, - participant5.address, - participant6.address, - ]) - ).revertedWith("you have no permission"); - }); - it("should raise error when the number of NFTs to be dropped is greater than the remaining count", async () => { - const [ - participant7, - participant8, - participant9, - participant10, - participant11, - participant12, - ] = await ethers.getSigners(); - await expect( - mintNFT - .connect(organizer) - .dropNFTs(createdEventIds[1], [ - participant7.address, - participant8.address, - participant9.address, - participant10.address, - participant11.address, - participant12.address, - ]) - ).revertedWith("remaining count is not enough"); - }); -}); - -describe("mint locked flag", () => { - let mintNFT: MintNFT; - let eventManager: EventManager; - let operationController: OperationController; - - let createdGroupId: number; - const createdEventIds: number[] = []; - - let organizer: SignerWithAddress; - let participant1: SignerWithAddress; - let relayer: SignerWithAddress; - - before(async () => { - [organizer, participant1, relayer] = await ethers.getSigners(); - [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); - - // Create a Group and an Event - await createGroup(eventManager, "First Group", organizer); - const groupsList = await eventManager.getGroups(); - createdGroupId = groupsList[0].groupId.toNumber(); - await createEventRecord( - eventManager, - { - groupId: createdGroupId, - name: "event1", - description: "event1 description", - date: "2022-07-3O", - mintLimit: 10, - useMtx: false, - nonTransferable: false, - secretPhrase: - "0x10c7da1d87ac3a86d34053a76768cc39c581d469b68863a9fba17bcdaa048f98", - eventNFTAttributes: attributes, - }, - organizer - ); - const eventsList = await eventManager.getEventRecords(0, 0); - createdEventIds.push(eventsList[0].eventRecordId.toNumber()); - }); - - it("should get mintable flag", async () => { - const flag = await mintNFT.connect(organizer).getIsMintLocked(1); - expect(flag).equal(false); - }); - - it("should change mintable flag by owner", async () => { - await mintNFT.connect(organizer).changeMintLocked(1, true); - const flag = await mintNFT.connect(organizer).getIsMintLocked(1); - expect(flag).equal(true); - }); - - it("No one but the owner should be able to change mintable flag", async () => { - await expect( - mintNFT.connect(participant1).changeMintLocked(1, false) - ).to.be.revertedWith("you have no permission"); - }); - - it("should change flag by admin", async () => { - await expect( - mintNFT.connect(participant1).changeMintLocked(1, false) - ).to.be.revertedWith("you have no permission"); - - eventManager - .connect(organizer) - .grantRole(createdGroupId, participant1.address, ADMIN_ROLE); - await mintNFT.connect(participant1).changeMintLocked(1, false); - - // Clean up - eventManager - .connect(organizer) - .revokeRole(createdGroupId, participant1.address, ADMIN_ROLE); - }); - - it("should change flag by collaborator", async () => { - await expect( - mintNFT.connect(participant1).changeMintLocked(1, false) - ).to.be.revertedWith("you have no permission"); - - eventManager - .connect(organizer) - .grantRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); - await mintNFT.connect(participant1).changeMintLocked(1, false); - - // Clean up - eventManager - .connect(organizer) - .revokeRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); - }); - - it("should not change if paused", async () => { - await operationController.connect(organizer).pause(); - await expect(mintNFT.connect(organizer).changeMintLocked(1, false)).to.be - .reverted; - await operationController.connect(organizer).unpause(); - }); -}); - -describe("non transferable flag", () => { - let mintNFT: MintNFT; - let eventManager: EventManager; - let operationController: OperationController; - - let createdGroupId: number; - const createdEventIds: number[] = []; - - let organizer: SignerWithAddress; - let participant1: SignerWithAddress; - let participant2: SignerWithAddress; - let relayer: SignerWithAddress; - - let correctProofCalldata!: any; - - before(async () => { - [organizer, participant1, participant2, relayer] = - await ethers.getSigners(); - - // generate proof - const { publicInputCalldata, proofCalldata } = await generateProof(); - [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); - correctProofCalldata = publicInputCalldata[0]; - - // Create a Group and an Event - await createGroup(eventManager, "First Group", organizer); - const groupsList = await eventManager.getGroups(); - createdGroupId = groupsList[0].groupId.toNumber(); - - const createEventTxn = await eventManager.createEventRecord( - createdGroupId, - "event1", - "event1 description", - "2022-07-3O", - 10, - false, - false, - correctProofCalldata, - attributes - ); - await createEventTxn.wait(); - const eventsList = await eventManager.getEventRecords(0, 0); - createdEventIds.push(eventsList[0].eventRecordId.toNumber()); - - const mintNftTxn = await mintNFT - .connect(participant1) - .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata); - await mintNftTxn.wait(); - }); - - it("should get non transferable flag", async () => { - const flag = await mintNFT.connect(organizer).getIsNonTransferable(1); - expect(flag).equal(false); - expect(await mintNFT.ownerOf(0)).equal(participant1.address); - await expect( - mintNFT - .connect(participant1) - .transferFrom(participant1.address, participant2.address, 0) - ).not.to.be.reverted; - expect(await mintNFT.ownerOf(0)).equal(participant2.address); - }); - - it("should change non transferable flag by owner", async () => { - await mintNFT.connect(organizer).changeNonTransferable(1, true); - const flag = await mintNFT.connect(organizer).getIsNonTransferable(1); - expect(flag).equal(true); - expect(await mintNFT.ownerOf(0)).equal(participant2.address); - await expect( - mintNFT - .connect(participant2) - .transferFrom(participant2.address, participant1.address, 0) - ).to.be.reverted; - expect(await mintNFT.ownerOf(0)).equal(participant2.address); - }); - - it("No one but the owner should be able to change non transferable flag", async () => { - await expect( - mintNFT.connect(participant1).changeNonTransferable(1, false) - ).to.be.revertedWith("you have no permission"); - }); - - it("should not change if paused", async () => { - await operationController.connect(organizer).pause(); - await expect(mintNFT.connect(organizer).changeNonTransferable(1, false)).to - .be.reverted; - await operationController.connect(organizer).unpause(); - }); -}); - -describe("reset secret phrase", () => { - let mintNFT: MintNFT; - let eventManager: EventManager; - let operationController: OperationController; - - let createdGroupId: number; - const createdEventIds: number[] = []; - - let organizer: SignerWithAddress; - let participant1: SignerWithAddress; - let relayer: SignerWithAddress; - - let correctProofCalldata!: any; - - before(async () => { - [organizer, participant1, relayer] = await ethers.getSigners(); - // deploy all contracts - [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); - // generate proof - const { publicInputCalldata } = await generateProof(); - correctProofCalldata = publicInputCalldata[0]; - - // Create a Group and an Event - await createGroup(eventManager, "First Group", organizer); - const groupsList = await eventManager.getGroups(); - createdGroupId = groupsList[0].groupId.toNumber(); - await createEventRecord( - eventManager, - { - groupId: createdGroupId, - name: "event1", - description: "event1 description", - date: "2022-07-3O", - mintLimit: 10, - useMtx: false, - nonTransferable: false, - secretPhrase: correctProofCalldata, - eventNFTAttributes: attributes, - }, - organizer - ); - const eventsList = await eventManager.getEventRecords(0, 0); - createdEventIds.push(eventsList[0].eventRecordId.toNumber()); - }); - - it("should reset secret phrase", async () => { - const newProofCalldata = - "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; - await expect( - mintNFT.connect(organizer).resetSecretPhrase(1, newProofCalldata) - ).to.emit(mintNFT, "ResetSecretPhrase"); - }); - - it("cannot change by non-owner", async () => { - const newProofCalldata = - "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; - await expect( - mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) - ).to.be.revertedWith("you have no permission"); - }); - - it("should reset secret phrase by admin", async () => { - const newProofCalldata = - "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; - - await expect( - mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) - ).to.be.revertedWith("you have no permission"); - - eventManager - .connect(organizer) - .grantRole(createdGroupId, participant1.address, ADMIN_ROLE); - await mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata); - - // Clean up - eventManager - .connect(organizer) - .revokeRole(createdGroupId, participant1.address, ADMIN_ROLE); - }); - - it("should reset secret phrase by collaborator", async () => { - const newProofCalldata = - "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; - - await expect( - mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) - ).to.be.revertedWith("you have no permission"); - - eventManager - .connect(organizer) - .grantRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); - await mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata); - - // Clean up - eventManager - .connect(organizer) - .revokeRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); - }); - - it("cannot change if paused", async () => { - const newProofCalldata = - "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; - await operationController.connect(organizer).pause(); - await expect( - mintNFT.connect(organizer).resetSecretPhrase(1, newProofCalldata) - ).to.be.reverted; - await operationController.connect(organizer).unpause(); - }); -}); - -describe("setEventInfo", () => {}); +// describe("nft revolution", () => { +// let mintNFT: MintNFT; +// let eventManager: EventManager; + +// let createdGroupId: number; +// let createdEventIds: number[] = []; + +// let organizer: SignerWithAddress; +// let participant1: SignerWithAddress; +// let participant2: SignerWithAddress; +// let relayer: SignerWithAddress; + +// let usedProofCalldata!: any; + +// before(async () => { +// [organizer, participant1, participant2, relayer] = +// await ethers.getSigners(); + +// // generate proof +// const { publicInputCalldata } = await generateProof(); + +// [, mintNFT, eventManager] = await deployAll(organizer, relayer); + +// // Create a Group and an Event +// await createGroup(eventManager, "First Group"); +// const groupsList = await eventManager.getGroups(); +// createdGroupId = groupsList[0].groupId.toNumber(); +// await createEventRecord(eventManager, { +// groupId: createdGroupId, +// name: "event1", +// description: "event1 description", +// date: "2022-07-3O", +// mintLimit: 10, +// useMtx: false, +// nonTransferable: false, +// secretPhrase: publicInputCalldata[0], +// eventNFTAttributes: attributes, +// }); +// await createEventRecord(eventManager, { +// groupId: createdGroupId, +// name: "event2", +// description: "event2 description", +// date: "2022-07-3O", +// mintLimit: 1, +// useMtx: false, +// nonTransferable: false, +// secretPhrase: publicInputCalldata[0], +// eventNFTAttributes: attributes, +// }); + +// const eventsList = await eventManager.getEventRecords(0, 0); +// createdEventIds = eventsList.map((event) => event.eventRecordId.toNumber()); + +// const { proofCalldata: proofCalldata1 } = await generateProof(); +// const mintTxn1 = await mintNFT +// .connect(organizer) +// .mintParticipateNFT(createdGroupId, createdEventIds[1], proofCalldata1); +// await mintTxn1.wait(); +// usedProofCalldata = proofCalldata1; + +// const { proofCalldata: proofCalldata2 } = await generateProof(); +// const mintTxn2 = await mintNFT +// .connect(organizer) +// .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata2); +// await mintTxn2.wait(); +// }); + +// it("doesn't mint NFT if proof is already used", async () => { +// await expect( +// mintNFT +// .connect(organizer) +// .mintParticipateNFT( +// createdGroupId, +// createdEventIds[1], +// usedProofCalldata +// ) +// ).to.be.revertedWith("invalid secret phrase"); +// }); + +// it("mint different NFT by participate count", async () => { +// const holdingNFT0 = await mintNFT.tokenURI(0); +// const holdingNFT1 = await mintNFT.tokenURI(1); +// expect(holdingNFT0).equal("ipfs://hogehoge/count0.json"); +// expect(holdingNFT1).equal("ipfs://hogehoge/count1.json"); +// }); + +// it("doesn't mint NFT for an event once attended to the same person twice", async () => { +// expect( +// await mintNFT.isHoldingEventNFTByAddress( +// organizer.address, +// createdEventIds[1] +// ) +// ).equal(true); +// const { proofCalldata } = await generateProof(); +// await expect( +// mintNFT +// .connect(organizer) +// .mintParticipateNFT(createdGroupId, createdEventIds[1], proofCalldata) +// ).to.be.revertedWith("already minted"); +// }); + +// it("doesn't mint NFT if there are no remaining count", async () => { +// const { proofCalldata } = await generateProof(); +// await expect( +// mintNFT +// .connect(participant1) +// .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata) +// ).to.be.revertedWith("remaining count is zero"); +// }); + +// it("doesn't mint NFT if wrong secret phrase", async () => { +// await expect( +// mintNFT +// .connect(participant2) +// .mintParticipateNFT( +// createdGroupId, +// createdEventIds[0], +// wrongProofCalldata +// ) +// ).to.be.revertedWith("invalid secret phrase"); +// }); +// }); + +// describe("bulk mint by event owner", () => { +// let mintNFT: MintNFT; +// let eventManager: EventManager; + +// let createdGroupId: number; +// let createdEventIds: number[] = []; + +// let organizer: SignerWithAddress; +// let participant1: SignerWithAddress; +// let participant2: SignerWithAddress; +// let participant3: SignerWithAddress; +// let participant4: SignerWithAddress; +// let participant5: SignerWithAddress; +// let participant6: SignerWithAddress; +// let relayer: SignerWithAddress; + +// before(async () => { +// [ +// organizer, +// participant1, +// participant2, +// participant3, +// participant4, +// participant5, +// participant6, +// relayer, +// ] = await ethers.getSigners(); + +// // generate proof +// const { publicInputCalldata } = await generateProof(); + +// [, mintNFT, eventManager] = await deployAll(organizer, relayer); + +// // Create a Group and an Event +// await createGroup(eventManager, "First Group"); +// const groupsList = await eventManager.getGroups(); +// createdGroupId = groupsList[0].groupId.toNumber(); +// await createEventRecord(eventManager, { +// groupId: createdGroupId, +// name: "event1", +// description: "event1 description", +// date: "2022-07-3O", +// mintLimit: 10, +// useMtx: false, +// nonTransferable: false, +// secretPhrase: publicInputCalldata[0], +// eventNFTAttributes: attributes, +// }); +// await createEventRecord(eventManager, { +// groupId: createdGroupId, +// name: "event2", +// description: "event1 description", +// date: "2022-07-3O", +// mintLimit: 10, +// useMtx: false, +// nonTransferable: false, +// secretPhrase: publicInputCalldata[0], +// eventNFTAttributes: attributes, +// }); + +// const eventsList = await eventManager.getEventRecords(0, 0); +// createdEventIds = eventsList.map((event) => event.eventRecordId.toNumber()); +// }); + +// it("drop NFTs by event owner", async () => { +// await expect( +// mintNFT +// .connect(organizer) +// .dropNFTs(createdEventIds[1], [ +// participant1.address, +// participant2.address, +// participant3.address, +// participant4.address, +// participant5.address, +// participant6.address, +// ]) +// ) +// .to.emit(mintNFT, "DroppedNFTs") +// .withArgs(organizer.address, createdEventIds[1]); +// console.log(await mintNFT.ownerOf(0)); +// console.log(await mintNFT.ownerOf(1)); + +// console.log(participant1.address); + +// expect(await mintNFT.ownerOf(0)).to.equal(participant1.address); +// expect(await mintNFT.ownerOf(1)).to.equal(participant2.address); +// expect(await mintNFT.ownerOf(2)).to.equal(participant3.address); +// expect(await mintNFT.ownerOf(3)).to.equal(participant4.address); +// expect(await mintNFT.ownerOf(4)).to.equal(participant5.address); +// expect(await mintNFT.ownerOf(5)).to.equal(participant6.address); +// it("should return NFTs by specified Event ID", async () => { +// expect(await mintNFT.getNFTHoldersByEvent(createdEventIds[1])).to.equal([ +// participant1, +// participant2, +// participant3, +// participant4, +// participant5, +// participant6, +// ]); +// }); +// }); +// it("prohibit drop NFTs by not event owner", async () => { +// await expect( +// mintNFT +// .connect(participant1) +// .dropNFTs(createdEventIds[0], [ +// participant1.address, +// participant2.address, +// participant3.address, +// participant4.address, +// participant5.address, +// participant6.address, +// ]) +// ).revertedWith("you have no permission"); +// }); +// it("should raise error when the number of NFTs to be dropped is greater than the remaining count", async () => { +// const [ +// participant7, +// participant8, +// participant9, +// participant10, +// participant11, +// participant12, +// ] = await ethers.getSigners(); +// await expect( +// mintNFT +// .connect(organizer) +// .dropNFTs(createdEventIds[1], [ +// participant7.address, +// participant8.address, +// participant9.address, +// participant10.address, +// participant11.address, +// participant12.address, +// ]) +// ).revertedWith("remaining count is not enough"); +// }); +// }); + +// describe("mint locked flag", () => { +// let mintNFT: MintNFT; +// let eventManager: EventManager; +// let operationController: OperationController; + +// let createdGroupId: number; +// const createdEventIds: number[] = []; + +// let organizer: SignerWithAddress; +// let participant1: SignerWithAddress; +// let relayer: SignerWithAddress; + +// before(async () => { +// [organizer, participant1, relayer] = await ethers.getSigners(); +// [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); + +// // Create a Group and an Event +// await createGroup(eventManager, "First Group", organizer); +// const groupsList = await eventManager.getGroups(); +// createdGroupId = groupsList[0].groupId.toNumber(); +// await createEventRecord( +// eventManager, +// { +// groupId: createdGroupId, +// name: "event1", +// description: "event1 description", +// date: "2022-07-3O", +// mintLimit: 10, +// useMtx: false, +// nonTransferable: false, +// secretPhrase: +// "0x10c7da1d87ac3a86d34053a76768cc39c581d469b68863a9fba17bcdaa048f98", +// eventNFTAttributes: attributes, +// }, +// organizer +// ); +// const eventsList = await eventManager.getEventRecords(0, 0); +// createdEventIds.push(eventsList[0].eventRecordId.toNumber()); +// }); + +// it("should get mintable flag", async () => { +// const flag = await mintNFT.connect(organizer).getIsMintLocked(1); +// expect(flag).equal(false); +// }); + +// it("should change mintable flag by owner", async () => { +// await mintNFT.connect(organizer).changeMintLocked(1, true); +// const flag = await mintNFT.connect(organizer).getIsMintLocked(1); +// expect(flag).equal(true); +// }); + +// it("No one but the owner should be able to change mintable flag", async () => { +// await expect( +// mintNFT.connect(participant1).changeMintLocked(1, false) +// ).to.be.revertedWith("you have no permission"); +// }); + +// it("should change flag by admin", async () => { +// await expect( +// mintNFT.connect(participant1).changeMintLocked(1, false) +// ).to.be.revertedWith("you have no permission"); + +// eventManager +// .connect(organizer) +// .grantRole(createdGroupId, participant1.address, ADMIN_ROLE); +// await mintNFT.connect(participant1).changeMintLocked(1, false); + +// // Clean up +// eventManager +// .connect(organizer) +// .revokeRole(createdGroupId, participant1.address, ADMIN_ROLE); +// }); + +// it("should change flag by collaborator", async () => { +// await expect( +// mintNFT.connect(participant1).changeMintLocked(1, false) +// ).to.be.revertedWith("you have no permission"); + +// eventManager +// .connect(organizer) +// .grantRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); +// await mintNFT.connect(participant1).changeMintLocked(1, false); + +// // Clean up +// eventManager +// .connect(organizer) +// .revokeRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); +// }); + +// it("should not change if paused", async () => { +// await operationController.connect(organizer).pause(); +// await expect(mintNFT.connect(organizer).changeMintLocked(1, false)).to.be +// .reverted; +// await operationController.connect(organizer).unpause(); +// }); +// }); + +// describe("non transferable flag", () => { +// let mintNFT: MintNFT; +// let eventManager: EventManager; +// let operationController: OperationController; + +// let createdGroupId: number; +// const createdEventIds: number[] = []; + +// let organizer: SignerWithAddress; +// let participant1: SignerWithAddress; +// let participant2: SignerWithAddress; +// let relayer: SignerWithAddress; + +// let correctProofCalldata!: any; + +// before(async () => { +// [organizer, participant1, participant2, relayer] = +// await ethers.getSigners(); + +// // generate proof +// const { publicInputCalldata, proofCalldata } = await generateProof(); +// [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); +// correctProofCalldata = publicInputCalldata[0]; + +// // Create a Group and an Event +// await createGroup(eventManager, "First Group", organizer); +// const groupsList = await eventManager.getGroups(); +// createdGroupId = groupsList[0].groupId.toNumber(); + +// const createEventTxn = await eventManager.createEventRecord( +// createdGroupId, +// "event1", +// "event1 description", +// "2022-07-3O", +// 10, +// false, +// false, +// correctProofCalldata, +// attributes +// ); +// await createEventTxn.wait(); +// const eventsList = await eventManager.getEventRecords(0, 0); +// createdEventIds.push(eventsList[0].eventRecordId.toNumber()); + +// const mintNftTxn = await mintNFT +// .connect(participant1) +// .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata); +// await mintNftTxn.wait(); +// }); + +// it("should get non transferable flag", async () => { +// const flag = await mintNFT.connect(organizer).getIsNonTransferable(1); +// expect(flag).equal(false); +// expect(await mintNFT.ownerOf(0)).equal(participant1.address); +// await expect( +// mintNFT +// .connect(participant1) +// .transferFrom(participant1.address, participant2.address, 0) +// ).not.to.be.reverted; +// expect(await mintNFT.ownerOf(0)).equal(participant2.address); +// }); + +// it("should change non transferable flag by owner", async () => { +// await mintNFT.connect(organizer).changeNonTransferable(1, true); +// const flag = await mintNFT.connect(organizer).getIsNonTransferable(1); +// expect(flag).equal(true); +// expect(await mintNFT.ownerOf(0)).equal(participant2.address); +// await expect( +// mintNFT +// .connect(participant2) +// .transferFrom(participant2.address, participant1.address, 0) +// ).to.be.reverted; +// expect(await mintNFT.ownerOf(0)).equal(participant2.address); +// }); + +// it("No one but the owner should be able to change non transferable flag", async () => { +// await expect( +// mintNFT.connect(participant1).changeNonTransferable(1, false) +// ).to.be.revertedWith("you have no permission"); +// }); + +// it("should not change if paused", async () => { +// await operationController.connect(organizer).pause(); +// await expect(mintNFT.connect(organizer).changeNonTransferable(1, false)).to +// .be.reverted; +// await operationController.connect(organizer).unpause(); +// }); +// }); + +// describe("reset secret phrase", () => { +// let mintNFT: MintNFT; +// let eventManager: EventManager; +// let operationController: OperationController; + +// let createdGroupId: number; +// const createdEventIds: number[] = []; + +// let organizer: SignerWithAddress; +// let participant1: SignerWithAddress; +// let relayer: SignerWithAddress; + +// let correctProofCalldata!: any; + +// before(async () => { +// [organizer, participant1, relayer] = await ethers.getSigners(); +// // deploy all contracts +// [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); +// // generate proof +// const { publicInputCalldata } = await generateProof(); +// correctProofCalldata = publicInputCalldata[0]; + +// // Create a Group and an Event +// await createGroup(eventManager, "First Group", organizer); +// const groupsList = await eventManager.getGroups(); +// createdGroupId = groupsList[0].groupId.toNumber(); +// await createEventRecord( +// eventManager, +// { +// groupId: createdGroupId, +// name: "event1", +// description: "event1 description", +// date: "2022-07-3O", +// mintLimit: 10, +// useMtx: false, +// nonTransferable: false, +// secretPhrase: correctProofCalldata, +// eventNFTAttributes: attributes, +// }, +// organizer +// ); +// const eventsList = await eventManager.getEventRecords(0, 0); +// createdEventIds.push(eventsList[0].eventRecordId.toNumber()); +// }); + +// it("should reset secret phrase", async () => { +// const newProofCalldata = +// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; +// await expect( +// mintNFT.connect(organizer).resetSecretPhrase(1, newProofCalldata) +// ).to.emit(mintNFT, "ResetSecretPhrase"); +// }); + +// it("cannot change by non-owner", async () => { +// const newProofCalldata = +// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; +// await expect( +// mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) +// ).to.be.revertedWith("you have no permission"); +// }); + +// it("should reset secret phrase by admin", async () => { +// const newProofCalldata = +// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; + +// await expect( +// mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) +// ).to.be.revertedWith("you have no permission"); + +// eventManager +// .connect(organizer) +// .grantRole(createdGroupId, participant1.address, ADMIN_ROLE); +// await mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata); + +// // Clean up +// eventManager +// .connect(organizer) +// .revokeRole(createdGroupId, participant1.address, ADMIN_ROLE); +// }); + +// it("should reset secret phrase by collaborator", async () => { +// const newProofCalldata = +// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; + +// await expect( +// mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) +// ).to.be.revertedWith("you have no permission"); + +// eventManager +// .connect(organizer) +// .grantRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); +// await mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata); + +// // Clean up +// eventManager +// .connect(organizer) +// .revokeRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); +// }); + +// it("cannot change if paused", async () => { +// const newProofCalldata = +// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; +// await operationController.connect(organizer).pause(); +// await expect( +// mintNFT.connect(organizer).resetSecretPhrase(1, newProofCalldata) +// ).to.be.reverted; +// await operationController.connect(organizer).unpause(); +// }); +// }); + +// describe("setEventInfo", () => {}); From d619d3707de44543aaae49b8ecccc0ca5463dac6 Mon Sep 17 00:00:00 2001 From: ikmz Date: Mon, 19 Feb 2024 18:35:26 +0900 Subject: [PATCH 2/2] Add NFT revolution tests for minting and ownership --- hardhat/test/MintNFT.ts | 1118 +++++++++++++++++++-------------------- 1 file changed, 559 insertions(+), 559 deletions(-) diff --git a/hardhat/test/MintNFT.ts b/hardhat/test/MintNFT.ts index c25113b7..1a7af3bc 100644 --- a/hardhat/test/MintNFT.ts +++ b/hardhat/test/MintNFT.ts @@ -568,562 +568,562 @@ describe("MintNFT", function () { // }); }); -// describe("nft revolution", () => { -// let mintNFT: MintNFT; -// let eventManager: EventManager; - -// let createdGroupId: number; -// let createdEventIds: number[] = []; - -// let organizer: SignerWithAddress; -// let participant1: SignerWithAddress; -// let participant2: SignerWithAddress; -// let relayer: SignerWithAddress; - -// let usedProofCalldata!: any; - -// before(async () => { -// [organizer, participant1, participant2, relayer] = -// await ethers.getSigners(); - -// // generate proof -// const { publicInputCalldata } = await generateProof(); - -// [, mintNFT, eventManager] = await deployAll(organizer, relayer); - -// // Create a Group and an Event -// await createGroup(eventManager, "First Group"); -// const groupsList = await eventManager.getGroups(); -// createdGroupId = groupsList[0].groupId.toNumber(); -// await createEventRecord(eventManager, { -// groupId: createdGroupId, -// name: "event1", -// description: "event1 description", -// date: "2022-07-3O", -// mintLimit: 10, -// useMtx: false, -// nonTransferable: false, -// secretPhrase: publicInputCalldata[0], -// eventNFTAttributes: attributes, -// }); -// await createEventRecord(eventManager, { -// groupId: createdGroupId, -// name: "event2", -// description: "event2 description", -// date: "2022-07-3O", -// mintLimit: 1, -// useMtx: false, -// nonTransferable: false, -// secretPhrase: publicInputCalldata[0], -// eventNFTAttributes: attributes, -// }); - -// const eventsList = await eventManager.getEventRecords(0, 0); -// createdEventIds = eventsList.map((event) => event.eventRecordId.toNumber()); - -// const { proofCalldata: proofCalldata1 } = await generateProof(); -// const mintTxn1 = await mintNFT -// .connect(organizer) -// .mintParticipateNFT(createdGroupId, createdEventIds[1], proofCalldata1); -// await mintTxn1.wait(); -// usedProofCalldata = proofCalldata1; - -// const { proofCalldata: proofCalldata2 } = await generateProof(); -// const mintTxn2 = await mintNFT -// .connect(organizer) -// .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata2); -// await mintTxn2.wait(); -// }); - -// it("doesn't mint NFT if proof is already used", async () => { -// await expect( -// mintNFT -// .connect(organizer) -// .mintParticipateNFT( -// createdGroupId, -// createdEventIds[1], -// usedProofCalldata -// ) -// ).to.be.revertedWith("invalid secret phrase"); -// }); - -// it("mint different NFT by participate count", async () => { -// const holdingNFT0 = await mintNFT.tokenURI(0); -// const holdingNFT1 = await mintNFT.tokenURI(1); -// expect(holdingNFT0).equal("ipfs://hogehoge/count0.json"); -// expect(holdingNFT1).equal("ipfs://hogehoge/count1.json"); -// }); - -// it("doesn't mint NFT for an event once attended to the same person twice", async () => { -// expect( -// await mintNFT.isHoldingEventNFTByAddress( -// organizer.address, -// createdEventIds[1] -// ) -// ).equal(true); -// const { proofCalldata } = await generateProof(); -// await expect( -// mintNFT -// .connect(organizer) -// .mintParticipateNFT(createdGroupId, createdEventIds[1], proofCalldata) -// ).to.be.revertedWith("already minted"); -// }); - -// it("doesn't mint NFT if there are no remaining count", async () => { -// const { proofCalldata } = await generateProof(); -// await expect( -// mintNFT -// .connect(participant1) -// .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata) -// ).to.be.revertedWith("remaining count is zero"); -// }); - -// it("doesn't mint NFT if wrong secret phrase", async () => { -// await expect( -// mintNFT -// .connect(participant2) -// .mintParticipateNFT( -// createdGroupId, -// createdEventIds[0], -// wrongProofCalldata -// ) -// ).to.be.revertedWith("invalid secret phrase"); -// }); -// }); - -// describe("bulk mint by event owner", () => { -// let mintNFT: MintNFT; -// let eventManager: EventManager; - -// let createdGroupId: number; -// let createdEventIds: number[] = []; - -// let organizer: SignerWithAddress; -// let participant1: SignerWithAddress; -// let participant2: SignerWithAddress; -// let participant3: SignerWithAddress; -// let participant4: SignerWithAddress; -// let participant5: SignerWithAddress; -// let participant6: SignerWithAddress; -// let relayer: SignerWithAddress; - -// before(async () => { -// [ -// organizer, -// participant1, -// participant2, -// participant3, -// participant4, -// participant5, -// participant6, -// relayer, -// ] = await ethers.getSigners(); - -// // generate proof -// const { publicInputCalldata } = await generateProof(); - -// [, mintNFT, eventManager] = await deployAll(organizer, relayer); - -// // Create a Group and an Event -// await createGroup(eventManager, "First Group"); -// const groupsList = await eventManager.getGroups(); -// createdGroupId = groupsList[0].groupId.toNumber(); -// await createEventRecord(eventManager, { -// groupId: createdGroupId, -// name: "event1", -// description: "event1 description", -// date: "2022-07-3O", -// mintLimit: 10, -// useMtx: false, -// nonTransferable: false, -// secretPhrase: publicInputCalldata[0], -// eventNFTAttributes: attributes, -// }); -// await createEventRecord(eventManager, { -// groupId: createdGroupId, -// name: "event2", -// description: "event1 description", -// date: "2022-07-3O", -// mintLimit: 10, -// useMtx: false, -// nonTransferable: false, -// secretPhrase: publicInputCalldata[0], -// eventNFTAttributes: attributes, -// }); - -// const eventsList = await eventManager.getEventRecords(0, 0); -// createdEventIds = eventsList.map((event) => event.eventRecordId.toNumber()); -// }); - -// it("drop NFTs by event owner", async () => { -// await expect( -// mintNFT -// .connect(organizer) -// .dropNFTs(createdEventIds[1], [ -// participant1.address, -// participant2.address, -// participant3.address, -// participant4.address, -// participant5.address, -// participant6.address, -// ]) -// ) -// .to.emit(mintNFT, "DroppedNFTs") -// .withArgs(organizer.address, createdEventIds[1]); -// console.log(await mintNFT.ownerOf(0)); -// console.log(await mintNFT.ownerOf(1)); - -// console.log(participant1.address); - -// expect(await mintNFT.ownerOf(0)).to.equal(participant1.address); -// expect(await mintNFT.ownerOf(1)).to.equal(participant2.address); -// expect(await mintNFT.ownerOf(2)).to.equal(participant3.address); -// expect(await mintNFT.ownerOf(3)).to.equal(participant4.address); -// expect(await mintNFT.ownerOf(4)).to.equal(participant5.address); -// expect(await mintNFT.ownerOf(5)).to.equal(participant6.address); -// it("should return NFTs by specified Event ID", async () => { -// expect(await mintNFT.getNFTHoldersByEvent(createdEventIds[1])).to.equal([ -// participant1, -// participant2, -// participant3, -// participant4, -// participant5, -// participant6, -// ]); -// }); -// }); -// it("prohibit drop NFTs by not event owner", async () => { -// await expect( -// mintNFT -// .connect(participant1) -// .dropNFTs(createdEventIds[0], [ -// participant1.address, -// participant2.address, -// participant3.address, -// participant4.address, -// participant5.address, -// participant6.address, -// ]) -// ).revertedWith("you have no permission"); -// }); -// it("should raise error when the number of NFTs to be dropped is greater than the remaining count", async () => { -// const [ -// participant7, -// participant8, -// participant9, -// participant10, -// participant11, -// participant12, -// ] = await ethers.getSigners(); -// await expect( -// mintNFT -// .connect(organizer) -// .dropNFTs(createdEventIds[1], [ -// participant7.address, -// participant8.address, -// participant9.address, -// participant10.address, -// participant11.address, -// participant12.address, -// ]) -// ).revertedWith("remaining count is not enough"); -// }); -// }); - -// describe("mint locked flag", () => { -// let mintNFT: MintNFT; -// let eventManager: EventManager; -// let operationController: OperationController; - -// let createdGroupId: number; -// const createdEventIds: number[] = []; - -// let organizer: SignerWithAddress; -// let participant1: SignerWithAddress; -// let relayer: SignerWithAddress; - -// before(async () => { -// [organizer, participant1, relayer] = await ethers.getSigners(); -// [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); - -// // Create a Group and an Event -// await createGroup(eventManager, "First Group", organizer); -// const groupsList = await eventManager.getGroups(); -// createdGroupId = groupsList[0].groupId.toNumber(); -// await createEventRecord( -// eventManager, -// { -// groupId: createdGroupId, -// name: "event1", -// description: "event1 description", -// date: "2022-07-3O", -// mintLimit: 10, -// useMtx: false, -// nonTransferable: false, -// secretPhrase: -// "0x10c7da1d87ac3a86d34053a76768cc39c581d469b68863a9fba17bcdaa048f98", -// eventNFTAttributes: attributes, -// }, -// organizer -// ); -// const eventsList = await eventManager.getEventRecords(0, 0); -// createdEventIds.push(eventsList[0].eventRecordId.toNumber()); -// }); - -// it("should get mintable flag", async () => { -// const flag = await mintNFT.connect(organizer).getIsMintLocked(1); -// expect(flag).equal(false); -// }); - -// it("should change mintable flag by owner", async () => { -// await mintNFT.connect(organizer).changeMintLocked(1, true); -// const flag = await mintNFT.connect(organizer).getIsMintLocked(1); -// expect(flag).equal(true); -// }); - -// it("No one but the owner should be able to change mintable flag", async () => { -// await expect( -// mintNFT.connect(participant1).changeMintLocked(1, false) -// ).to.be.revertedWith("you have no permission"); -// }); - -// it("should change flag by admin", async () => { -// await expect( -// mintNFT.connect(participant1).changeMintLocked(1, false) -// ).to.be.revertedWith("you have no permission"); - -// eventManager -// .connect(organizer) -// .grantRole(createdGroupId, participant1.address, ADMIN_ROLE); -// await mintNFT.connect(participant1).changeMintLocked(1, false); - -// // Clean up -// eventManager -// .connect(organizer) -// .revokeRole(createdGroupId, participant1.address, ADMIN_ROLE); -// }); - -// it("should change flag by collaborator", async () => { -// await expect( -// mintNFT.connect(participant1).changeMintLocked(1, false) -// ).to.be.revertedWith("you have no permission"); - -// eventManager -// .connect(organizer) -// .grantRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); -// await mintNFT.connect(participant1).changeMintLocked(1, false); - -// // Clean up -// eventManager -// .connect(organizer) -// .revokeRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); -// }); - -// it("should not change if paused", async () => { -// await operationController.connect(organizer).pause(); -// await expect(mintNFT.connect(organizer).changeMintLocked(1, false)).to.be -// .reverted; -// await operationController.connect(organizer).unpause(); -// }); -// }); - -// describe("non transferable flag", () => { -// let mintNFT: MintNFT; -// let eventManager: EventManager; -// let operationController: OperationController; - -// let createdGroupId: number; -// const createdEventIds: number[] = []; - -// let organizer: SignerWithAddress; -// let participant1: SignerWithAddress; -// let participant2: SignerWithAddress; -// let relayer: SignerWithAddress; - -// let correctProofCalldata!: any; - -// before(async () => { -// [organizer, participant1, participant2, relayer] = -// await ethers.getSigners(); - -// // generate proof -// const { publicInputCalldata, proofCalldata } = await generateProof(); -// [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); -// correctProofCalldata = publicInputCalldata[0]; - -// // Create a Group and an Event -// await createGroup(eventManager, "First Group", organizer); -// const groupsList = await eventManager.getGroups(); -// createdGroupId = groupsList[0].groupId.toNumber(); - -// const createEventTxn = await eventManager.createEventRecord( -// createdGroupId, -// "event1", -// "event1 description", -// "2022-07-3O", -// 10, -// false, -// false, -// correctProofCalldata, -// attributes -// ); -// await createEventTxn.wait(); -// const eventsList = await eventManager.getEventRecords(0, 0); -// createdEventIds.push(eventsList[0].eventRecordId.toNumber()); - -// const mintNftTxn = await mintNFT -// .connect(participant1) -// .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata); -// await mintNftTxn.wait(); -// }); - -// it("should get non transferable flag", async () => { -// const flag = await mintNFT.connect(organizer).getIsNonTransferable(1); -// expect(flag).equal(false); -// expect(await mintNFT.ownerOf(0)).equal(participant1.address); -// await expect( -// mintNFT -// .connect(participant1) -// .transferFrom(participant1.address, participant2.address, 0) -// ).not.to.be.reverted; -// expect(await mintNFT.ownerOf(0)).equal(participant2.address); -// }); - -// it("should change non transferable flag by owner", async () => { -// await mintNFT.connect(organizer).changeNonTransferable(1, true); -// const flag = await mintNFT.connect(organizer).getIsNonTransferable(1); -// expect(flag).equal(true); -// expect(await mintNFT.ownerOf(0)).equal(participant2.address); -// await expect( -// mintNFT -// .connect(participant2) -// .transferFrom(participant2.address, participant1.address, 0) -// ).to.be.reverted; -// expect(await mintNFT.ownerOf(0)).equal(participant2.address); -// }); - -// it("No one but the owner should be able to change non transferable flag", async () => { -// await expect( -// mintNFT.connect(participant1).changeNonTransferable(1, false) -// ).to.be.revertedWith("you have no permission"); -// }); - -// it("should not change if paused", async () => { -// await operationController.connect(organizer).pause(); -// await expect(mintNFT.connect(organizer).changeNonTransferable(1, false)).to -// .be.reverted; -// await operationController.connect(organizer).unpause(); -// }); -// }); - -// describe("reset secret phrase", () => { -// let mintNFT: MintNFT; -// let eventManager: EventManager; -// let operationController: OperationController; - -// let createdGroupId: number; -// const createdEventIds: number[] = []; - -// let organizer: SignerWithAddress; -// let participant1: SignerWithAddress; -// let relayer: SignerWithAddress; - -// let correctProofCalldata!: any; - -// before(async () => { -// [organizer, participant1, relayer] = await ethers.getSigners(); -// // deploy all contracts -// [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); -// // generate proof -// const { publicInputCalldata } = await generateProof(); -// correctProofCalldata = publicInputCalldata[0]; - -// // Create a Group and an Event -// await createGroup(eventManager, "First Group", organizer); -// const groupsList = await eventManager.getGroups(); -// createdGroupId = groupsList[0].groupId.toNumber(); -// await createEventRecord( -// eventManager, -// { -// groupId: createdGroupId, -// name: "event1", -// description: "event1 description", -// date: "2022-07-3O", -// mintLimit: 10, -// useMtx: false, -// nonTransferable: false, -// secretPhrase: correctProofCalldata, -// eventNFTAttributes: attributes, -// }, -// organizer -// ); -// const eventsList = await eventManager.getEventRecords(0, 0); -// createdEventIds.push(eventsList[0].eventRecordId.toNumber()); -// }); - -// it("should reset secret phrase", async () => { -// const newProofCalldata = -// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; -// await expect( -// mintNFT.connect(organizer).resetSecretPhrase(1, newProofCalldata) -// ).to.emit(mintNFT, "ResetSecretPhrase"); -// }); - -// it("cannot change by non-owner", async () => { -// const newProofCalldata = -// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; -// await expect( -// mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) -// ).to.be.revertedWith("you have no permission"); -// }); - -// it("should reset secret phrase by admin", async () => { -// const newProofCalldata = -// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; - -// await expect( -// mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) -// ).to.be.revertedWith("you have no permission"); - -// eventManager -// .connect(organizer) -// .grantRole(createdGroupId, participant1.address, ADMIN_ROLE); -// await mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata); - -// // Clean up -// eventManager -// .connect(organizer) -// .revokeRole(createdGroupId, participant1.address, ADMIN_ROLE); -// }); - -// it("should reset secret phrase by collaborator", async () => { -// const newProofCalldata = -// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; - -// await expect( -// mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) -// ).to.be.revertedWith("you have no permission"); - -// eventManager -// .connect(organizer) -// .grantRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); -// await mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata); - -// // Clean up -// eventManager -// .connect(organizer) -// .revokeRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); -// }); - -// it("cannot change if paused", async () => { -// const newProofCalldata = -// "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; -// await operationController.connect(organizer).pause(); -// await expect( -// mintNFT.connect(organizer).resetSecretPhrase(1, newProofCalldata) -// ).to.be.reverted; -// await operationController.connect(organizer).unpause(); -// }); -// }); - -// describe("setEventInfo", () => {}); +describe("nft revolution", () => { + let mintNFT: MintNFT; + let eventManager: EventManager; + + let createdGroupId: number; + let createdEventIds: number[] = []; + + let organizer: SignerWithAddress; + let participant1: SignerWithAddress; + let participant2: SignerWithAddress; + let relayer: SignerWithAddress; + + let usedProofCalldata!: any; + + before(async () => { + [organizer, participant1, participant2, relayer] = + await ethers.getSigners(); + + // generate proof + const { publicInputCalldata } = await generateProof(); + + [, mintNFT, eventManager] = await deployAll(organizer, relayer); + + // Create a Group and an Event + await createGroup(eventManager, "First Group"); + const groupsList = await eventManager.getGroups(); + createdGroupId = groupsList[0].groupId.toNumber(); + await createEventRecord(eventManager, { + groupId: createdGroupId, + name: "event1", + description: "event1 description", + date: "2022-07-3O", + mintLimit: 10, + useMtx: false, + nonTransferable: false, + secretPhrase: publicInputCalldata[0], + eventNFTAttributes: attributes, + }); + await createEventRecord(eventManager, { + groupId: createdGroupId, + name: "event2", + description: "event2 description", + date: "2022-07-3O", + mintLimit: 1, + useMtx: false, + nonTransferable: false, + secretPhrase: publicInputCalldata[0], + eventNFTAttributes: attributes, + }); + + const eventsList = await eventManager.getEventRecords(0, 0); + createdEventIds = eventsList.map((event) => event.eventRecordId.toNumber()); + + const { proofCalldata: proofCalldata1 } = await generateProof(); + const mintTxn1 = await mintNFT + .connect(organizer) + .mintParticipateNFT(createdGroupId, createdEventIds[1], proofCalldata1); + await mintTxn1.wait(); + usedProofCalldata = proofCalldata1; + + const { proofCalldata: proofCalldata2 } = await generateProof(); + const mintTxn2 = await mintNFT + .connect(organizer) + .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata2); + await mintTxn2.wait(); + }); + + it("doesn't mint NFT if proof is already used", async () => { + await expect( + mintNFT + .connect(organizer) + .mintParticipateNFT( + createdGroupId, + createdEventIds[1], + usedProofCalldata + ) + ).to.be.revertedWith("invalid secret phrase"); + }); + + it("mint different NFT by participate count", async () => { + const holdingNFT0 = await mintNFT.tokenURI(0); + const holdingNFT1 = await mintNFT.tokenURI(1); + expect(holdingNFT0).equal("ipfs://hogehoge/count0.json"); + expect(holdingNFT1).equal("ipfs://hogehoge/count1.json"); + }); + + it("doesn't mint NFT for an event once attended to the same person twice", async () => { + expect( + await mintNFT.isHoldingEventNFTByAddress( + organizer.address, + createdEventIds[1] + ) + ).equal(true); + const { proofCalldata } = await generateProof(); + await expect( + mintNFT + .connect(organizer) + .mintParticipateNFT(createdGroupId, createdEventIds[1], proofCalldata) + ).to.be.revertedWith("already minted"); + }); + + it("doesn't mint NFT if there are no remaining count", async () => { + const { proofCalldata } = await generateProof(); + await expect( + mintNFT + .connect(participant1) + .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata) + ).to.be.revertedWith("remaining count is zero"); + }); + + it("doesn't mint NFT if wrong secret phrase", async () => { + await expect( + mintNFT + .connect(participant2) + .mintParticipateNFT( + createdGroupId, + createdEventIds[0], + wrongProofCalldata + ) + ).to.be.revertedWith("invalid secret phrase"); + }); +}); + +describe("bulk mint by event owner", () => { + let mintNFT: MintNFT; + let eventManager: EventManager; + + let createdGroupId: number; + let createdEventIds: number[] = []; + + let organizer: SignerWithAddress; + let participant1: SignerWithAddress; + let participant2: SignerWithAddress; + let participant3: SignerWithAddress; + let participant4: SignerWithAddress; + let participant5: SignerWithAddress; + let participant6: SignerWithAddress; + let relayer: SignerWithAddress; + + before(async () => { + [ + organizer, + participant1, + participant2, + participant3, + participant4, + participant5, + participant6, + relayer, + ] = await ethers.getSigners(); + + // generate proof + const { publicInputCalldata } = await generateProof(); + + [, mintNFT, eventManager] = await deployAll(organizer, relayer); + + // Create a Group and an Event + await createGroup(eventManager, "First Group"); + const groupsList = await eventManager.getGroups(); + createdGroupId = groupsList[0].groupId.toNumber(); + await createEventRecord(eventManager, { + groupId: createdGroupId, + name: "event1", + description: "event1 description", + date: "2022-07-3O", + mintLimit: 10, + useMtx: false, + nonTransferable: false, + secretPhrase: publicInputCalldata[0], + eventNFTAttributes: attributes, + }); + await createEventRecord(eventManager, { + groupId: createdGroupId, + name: "event2", + description: "event1 description", + date: "2022-07-3O", + mintLimit: 10, + useMtx: false, + nonTransferable: false, + secretPhrase: publicInputCalldata[0], + eventNFTAttributes: attributes, + }); + + const eventsList = await eventManager.getEventRecords(0, 0); + createdEventIds = eventsList.map((event) => event.eventRecordId.toNumber()); + }); + + it("drop NFTs by event owner", async () => { + await expect( + mintNFT + .connect(organizer) + .dropNFTs(createdEventIds[1], [ + participant1.address, + participant2.address, + participant3.address, + participant4.address, + participant5.address, + participant6.address, + ]) + ) + .to.emit(mintNFT, "DroppedNFTs") + .withArgs(organizer.address, createdEventIds[1]); + console.log(await mintNFT.ownerOf(0)); + console.log(await mintNFT.ownerOf(1)); + + console.log(participant1.address); + + expect(await mintNFT.ownerOf(0)).to.equal(participant1.address); + expect(await mintNFT.ownerOf(1)).to.equal(participant2.address); + expect(await mintNFT.ownerOf(2)).to.equal(participant3.address); + expect(await mintNFT.ownerOf(3)).to.equal(participant4.address); + expect(await mintNFT.ownerOf(4)).to.equal(participant5.address); + expect(await mintNFT.ownerOf(5)).to.equal(participant6.address); + it("should return NFTs by specified Event ID", async () => { + expect(await mintNFT.getNFTHoldersByEvent(createdEventIds[1])).to.equal([ + participant1, + participant2, + participant3, + participant4, + participant5, + participant6, + ]); + }); + }); + it("prohibit drop NFTs by not event owner", async () => { + await expect( + mintNFT + .connect(participant1) + .dropNFTs(createdEventIds[0], [ + participant1.address, + participant2.address, + participant3.address, + participant4.address, + participant5.address, + participant6.address, + ]) + ).revertedWith("you have no permission"); + }); + it("should raise error when the number of NFTs to be dropped is greater than the remaining count", async () => { + const [ + participant7, + participant8, + participant9, + participant10, + participant11, + participant12, + ] = await ethers.getSigners(); + await expect( + mintNFT + .connect(organizer) + .dropNFTs(createdEventIds[1], [ + participant7.address, + participant8.address, + participant9.address, + participant10.address, + participant11.address, + participant12.address, + ]) + ).revertedWith("remaining count is not enough"); + }); +}); + +describe("mint locked flag", () => { + let mintNFT: MintNFT; + let eventManager: EventManager; + let operationController: OperationController; + + let createdGroupId: number; + const createdEventIds: number[] = []; + + let organizer: SignerWithAddress; + let participant1: SignerWithAddress; + let relayer: SignerWithAddress; + + before(async () => { + [organizer, participant1, relayer] = await ethers.getSigners(); + [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); + + // Create a Group and an Event + await createGroup(eventManager, "First Group", organizer); + const groupsList = await eventManager.getGroups(); + createdGroupId = groupsList[0].groupId.toNumber(); + await createEventRecord( + eventManager, + { + groupId: createdGroupId, + name: "event1", + description: "event1 description", + date: "2022-07-3O", + mintLimit: 10, + useMtx: false, + nonTransferable: false, + secretPhrase: + "0x10c7da1d87ac3a86d34053a76768cc39c581d469b68863a9fba17bcdaa048f98", + eventNFTAttributes: attributes, + }, + organizer + ); + const eventsList = await eventManager.getEventRecords(0, 0); + createdEventIds.push(eventsList[0].eventRecordId.toNumber()); + }); + + it("should get mintable flag", async () => { + const flag = await mintNFT.connect(organizer).getIsMintLocked(1); + expect(flag).equal(false); + }); + + it("should change mintable flag by owner", async () => { + await mintNFT.connect(organizer).changeMintLocked(1, true); + const flag = await mintNFT.connect(organizer).getIsMintLocked(1); + expect(flag).equal(true); + }); + + it("No one but the owner should be able to change mintable flag", async () => { + await expect( + mintNFT.connect(participant1).changeMintLocked(1, false) + ).to.be.revertedWith("you have no permission"); + }); + + it("should change flag by admin", async () => { + await expect( + mintNFT.connect(participant1).changeMintLocked(1, false) + ).to.be.revertedWith("you have no permission"); + + eventManager + .connect(organizer) + .grantRole(createdGroupId, participant1.address, ADMIN_ROLE); + await mintNFT.connect(participant1).changeMintLocked(1, false); + + // Clean up + eventManager + .connect(organizer) + .revokeRole(createdGroupId, participant1.address, ADMIN_ROLE); + }); + + it("should change flag by collaborator", async () => { + await expect( + mintNFT.connect(participant1).changeMintLocked(1, false) + ).to.be.revertedWith("you have no permission"); + + eventManager + .connect(organizer) + .grantRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); + await mintNFT.connect(participant1).changeMintLocked(1, false); + + // Clean up + eventManager + .connect(organizer) + .revokeRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); + }); + + it("should not change if paused", async () => { + await operationController.connect(organizer).pause(); + await expect(mintNFT.connect(organizer).changeMintLocked(1, false)).to.be + .reverted; + await operationController.connect(organizer).unpause(); + }); +}); + +describe("non transferable flag", () => { + let mintNFT: MintNFT; + let eventManager: EventManager; + let operationController: OperationController; + + let createdGroupId: number; + const createdEventIds: number[] = []; + + let organizer: SignerWithAddress; + let participant1: SignerWithAddress; + let participant2: SignerWithAddress; + let relayer: SignerWithAddress; + + let correctProofCalldata!: any; + + before(async () => { + [organizer, participant1, participant2, relayer] = + await ethers.getSigners(); + + // generate proof + const { publicInputCalldata, proofCalldata } = await generateProof(); + [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); + correctProofCalldata = publicInputCalldata[0]; + + // Create a Group and an Event + await createGroup(eventManager, "First Group", organizer); + const groupsList = await eventManager.getGroups(); + createdGroupId = groupsList[0].groupId.toNumber(); + + const createEventTxn = await eventManager.createEventRecord( + createdGroupId, + "event1", + "event1 description", + "2022-07-3O", + 10, + false, + false, + correctProofCalldata, + attributes + ); + await createEventTxn.wait(); + const eventsList = await eventManager.getEventRecords(0, 0); + createdEventIds.push(eventsList[0].eventRecordId.toNumber()); + + const mintNftTxn = await mintNFT + .connect(participant1) + .mintParticipateNFT(createdGroupId, createdEventIds[0], proofCalldata); + await mintNftTxn.wait(); + }); + + it("should get non transferable flag", async () => { + const flag = await mintNFT.connect(organizer).getIsNonTransferable(1); + expect(flag).equal(false); + expect(await mintNFT.ownerOf(0)).equal(participant1.address); + await expect( + mintNFT + .connect(participant1) + .transferFrom(participant1.address, participant2.address, 0) + ).not.to.be.reverted; + expect(await mintNFT.ownerOf(0)).equal(participant2.address); + }); + + it("should change non transferable flag by owner", async () => { + await mintNFT.connect(organizer).changeNonTransferable(1, true); + const flag = await mintNFT.connect(organizer).getIsNonTransferable(1); + expect(flag).equal(true); + expect(await mintNFT.ownerOf(0)).equal(participant2.address); + await expect( + mintNFT + .connect(participant2) + .transferFrom(participant2.address, participant1.address, 0) + ).to.be.reverted; + expect(await mintNFT.ownerOf(0)).equal(participant2.address); + }); + + it("No one but the owner should be able to change non transferable flag", async () => { + await expect( + mintNFT.connect(participant1).changeNonTransferable(1, false) + ).to.be.revertedWith("you have no permission"); + }); + + it("should not change if paused", async () => { + await operationController.connect(organizer).pause(); + await expect(mintNFT.connect(organizer).changeNonTransferable(1, false)).to + .be.reverted; + await operationController.connect(organizer).unpause(); + }); +}); + +describe("reset secret phrase", () => { + let mintNFT: MintNFT; + let eventManager: EventManager; + let operationController: OperationController; + + let createdGroupId: number; + const createdEventIds: number[] = []; + + let organizer: SignerWithAddress; + let participant1: SignerWithAddress; + let relayer: SignerWithAddress; + + let correctProofCalldata!: any; + + before(async () => { + [organizer, participant1, relayer] = await ethers.getSigners(); + // deploy all contracts + [, mintNFT, eventManager, operationController] = await deployAll(organizer, relayer); + // generate proof + const { publicInputCalldata } = await generateProof(); + correctProofCalldata = publicInputCalldata[0]; + + // Create a Group and an Event + await createGroup(eventManager, "First Group", organizer); + const groupsList = await eventManager.getGroups(); + createdGroupId = groupsList[0].groupId.toNumber(); + await createEventRecord( + eventManager, + { + groupId: createdGroupId, + name: "event1", + description: "event1 description", + date: "2022-07-3O", + mintLimit: 10, + useMtx: false, + nonTransferable: false, + secretPhrase: correctProofCalldata, + eventNFTAttributes: attributes, + }, + organizer + ); + const eventsList = await eventManager.getEventRecords(0, 0); + createdEventIds.push(eventsList[0].eventRecordId.toNumber()); + }); + + it("should reset secret phrase", async () => { + const newProofCalldata = + "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; + await expect( + mintNFT.connect(organizer).resetSecretPhrase(1, newProofCalldata) + ).to.emit(mintNFT, "ResetSecretPhrase"); + }); + + it("cannot change by non-owner", async () => { + const newProofCalldata = + "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; + await expect( + mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) + ).to.be.revertedWith("you have no permission"); + }); + + it("should reset secret phrase by admin", async () => { + const newProofCalldata = + "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; + + await expect( + mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) + ).to.be.revertedWith("you have no permission"); + + eventManager + .connect(organizer) + .grantRole(createdGroupId, participant1.address, ADMIN_ROLE); + await mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata); + + // Clean up + eventManager + .connect(organizer) + .revokeRole(createdGroupId, participant1.address, ADMIN_ROLE); + }); + + it("should reset secret phrase by collaborator", async () => { + const newProofCalldata = + "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; + + await expect( + mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata) + ).to.be.revertedWith("you have no permission"); + + eventManager + .connect(organizer) + .grantRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); + await mintNFT.connect(participant1).resetSecretPhrase(1, newProofCalldata); + + // Clean up + eventManager + .connect(organizer) + .revokeRole(createdGroupId, participant1.address, COLLABORATOR_ROLE); + }); + + it("cannot change if paused", async () => { + const newProofCalldata = + "0x1f376ca3150d51a164c711287cff6e77e2127d635a1534b41d5624472f000000"; + await operationController.connect(organizer).pause(); + await expect( + mintNFT.connect(organizer).resetSecretPhrase(1, newProofCalldata) + ).to.be.reverted; + await operationController.connect(organizer).unpause(); + }); +}); + +describe("setEventInfo", () => {});