Skip to content

Commit

Permalink
Merge pull request #521 from ikmzkro/feature/#433
Browse files Browse the repository at this point in the history
Allow external access to an event to retrieve how many times a participant has attended the event.
  • Loading branch information
yu23ki14 authored Mar 16, 2024
2 parents 8e66d19 + e893770 commit ff227f2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hardhat/contracts/IMintNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ interface IMintNFT {
string memory _secretPhrase
) external;

function getCountOfParticipation(uint256 _groupId, address _address)
external
view
returns (uint256);

function isHoldingEventNFTByAddress(
address _address,
uint256 _eventId
Expand Down
8 changes: 8 additions & 0 deletions hardhat/contracts/MintNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,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,
Expand Down
24 changes: 24 additions & 0 deletions hardhat/test/MintNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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];
Expand Down

0 comments on commit ff227f2

Please sign in to comment.