Title: Solidity Contract for Interaction Verification
Description: Develop a Solidity contract to handle interaction verification on the "Vibe to Earn" platform. Interactions are verified through QR code scans. The contract should provide a function for users to submit a QR code scan (interaction) that includes the event ID and the attendee’s wallet address.
Acceptance Criteria
Contract Deployment
The contract should be deployable on the Ethereum blockchain.
The contract should initialize with zero interactions recorded.
QR Code Interaction Submission
Users must be able to submit a QR code scan (interaction).
Each interaction must include the event ID and the attendee’s wallet address.
The contract should store interactions securely.
Interaction Validation
The contract should validate the interaction to ensure it includes a valid event ID and wallet address.
Duplicate interactions for the same event and attendee should be prevented.
Admin Functions
Only the admin should be able to manage event IDs and interaction data.
The admin should be able to review and manage interactions if necessary.
Events
Events should be emitted for each QR code interaction submission and validation.
Solidity Contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract InteractionVerification {
struct Interaction {
uint eventId;
address attendee;
bool isValid;
}
address public admin;
uint public interactionCount;
mapping(uint => Interaction) public interactions;
mapping(uint => mapping(address => bool)) public eventAttendees;
event InteractionSubmitted(uint interactionId, uint eventId, address attendee);
event InteractionValidated(uint interactionId, uint eventId, address attendee);
modifier onlyAdmin() {
require(msg.sender == admin, "Only admin can perform this action");
_;
}
constructor() {
admin = msg.sender;
interactionCount = 0;
}
function submitInteraction(uint _eventId) public {
require(!eventAttendees[_eventId][msg.sender], "Interaction already submitted for this event");
interactionCount++;
interactions[interactionCount] = Interaction({
eventId: _eventId,
attendee: msg.sender,
isValid: true
});
eventAttendees[_eventId][msg.sender] = true;
emit InteractionSubmitted(interactionCount, _eventId, msg.sender);
emit InteractionValidated(interactionCount, _eventId, msg.sender);
}
function validateInteraction(uint _interactionId) public view returns (bool) {
Interaction memory interaction = interactions[_interactionId];
return interaction.isValid;
}
function invalidateInteraction(uint _interactionId) public onlyAdmin {
interactions[_interactionId].isValid = false;
}
// Function to get interaction details
function getInteraction(uint _interactionId) public view returns (uint eventId, address attendee, bool isValid) {
Interaction memory interaction = interactions[_interactionId];
return (interaction.eventId, interaction.attendee, interaction.isValid);
}
}
Test Cases
Deployment:
Deploy the contract and verify the admin, interactionCount, and initial state of interactions.
QR Code Interaction Submission:
Submit a new interaction with a valid event ID.
Verify the interaction is stored with the correct event ID and attendee's wallet address.
Emit InteractionSubmitted and InteractionValidated events.
Interaction Validation:
Validate an interaction to ensure it is marked as valid.
Prevent duplicate interactions for the same event and attendee.
Admin Functions:
Invalidate an interaction and verify its status is updated.
Ensure only the admin can perform interaction invalidation.
Events:
Emit appropriate events for interaction submission and validation.
Edge Cases:
Test behavior when attempting to submit duplicate interactions for the same event and attendee.
Ensure the contract handles multiple interactions and validations correctly.
Verify no unauthorized users can invalidate interactions.
Ticket: Interaction Verification Solidity Contract
Title: Solidity Contract for Interaction Verification
Description: Develop a Solidity contract to handle interaction verification on the "Vibe to Earn" platform. Interactions are verified through QR code scans. The contract should provide a function for users to submit a QR code scan (interaction) that includes the event ID and the attendee’s wallet address.
Acceptance Criteria
Contract Deployment
The contract should be deployable on the Ethereum blockchain.
The contract should initialize with zero interactions recorded.
QR Code Interaction Submission
Users must be able to submit a QR code scan (interaction).
Each interaction must include the event ID and the attendee’s wallet address.
The contract should store interactions securely.
Interaction Validation
The contract should validate the interaction to ensure it includes a valid event ID and wallet address.
Duplicate interactions for the same event and attendee should be prevented.
Admin Functions
Only the admin should be able to manage event IDs and interaction data.
The admin should be able to review and manage interactions if necessary.
Events
Solidity Contract
Test Cases
Deployment:
QR Code Interaction Submission:
Submit a new interaction with a valid event ID.
Verify the interaction is stored with the correct event ID and attendee's wallet address.
Emit
InteractionSubmitted
andInteractionValidated
events.Interaction Validation:
Validate an interaction to ensure it is marked as valid.
Prevent duplicate interactions for the same event and attendee.
Admin Functions:
Invalidate an interaction and verify its status is updated.
Ensure only the admin can perform interaction invalidation.
Events:
Edge Cases:
Test behavior when attempting to submit duplicate interactions for the same event and attendee.
Ensure the contract handles multiple interactions and validations correctly.
Verify no unauthorized users can invalidate interactions.