Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow external access to an event to retrieve how many times a participant has attended the event. #521

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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