mubarak23 / chainevents-contracts

cairo contract implementation for chainevents
1 stars 4 forks source link

End event registration Function #17

Open mubarak23 opened 2 days ago

mubarak23 commented 2 days ago

As an event owner, i should be able end event registration,

Only event owner can call this function

    fn end_event_registration(
        ref self: TContractState, event_id: u256
    );

set is_closed inside event details to TRUE and emit EndEventRegistration event

Write unit test for this function that cover the following

Provide an ETH

codeZe-us commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Mid level Cairo Developer

How I plan on tackling this issue

I will write a function that takes event_id as a parameter, check if the caller is the event owner, set the is_closed field in the event details to true, then emit an end_event_registration event. Also, I will ensure the function verifies only when the event owner calls it, then revert it when the caller is not the owner. Test included as well.

anonfedora commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

A fullstack Blockchain developer, with extensive experience in building smart contracts.

How I plan on tackling this issue

The end_event_registration function must: Ensure only the owner can end the registration. Set the is_closed field to true when the registration ends. Emit the EndEventRegistration event upon successful closure.

GoSTEAN commented 2 days ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a blockchain developer with experience with solidity and cairo

How I plan on tackling this issue

Define the function signature with the required parameters and return types.

cairo
fn end_event_registration(ref self: TContractState, event_id: u256);

Step 2: Check Caller Permission

Verify that only the event owner can call the function by comparing the caller's address with the event owner's address.

cairo
assert self.get_event_owner(event_id) == self.get_caller(), "Only event owner can call this function";

Step 3: Update Event Details

Retrieve the event details, set is_closed to TRUE, and update the event details.

cairo
let event_details = self.get_event_details(event_id);
event_details.is_closed = TRUE;
self.set_event_details(event_id, event_details);

Step 4: Emit EndEventRegistration Event

Emit the EndEventRegistration event with the event ID.

cairo
emit EndEventRegistration(event_id);

Step 5: Write Unit Tests

Write unit tests to cover the following scenarios:

  1. Successful event registration closure.
  2. Non-owner caller attempting to close registration.
  3. Verification of emitted EndEventRegistration event.

Example unit test:

cairo
#[test]
fn test_end_event_registration_success() {
    // Setup
    let contract = TContractState::new();
    let event_id = 1;
    let owner = 0x1234567890abcdef;

    // Set event owner
    contract.set_event_owner(event_id, owner);

    // Call end_event_registration as owner
    contract.end_event_registration(event_id);

    // Assert is_closed is TRUE

[21/10, 1:03 pm] Meta AI: Here are 5 steps to solve the "End Event Registration" function:

Step 1: Define the Function Signature

Define the function signature with the required parameters and return types.

cairo
fn end_event_registration(ref self: TContractState, event_id: u256);

Step 2: Check Caller Permission

Verify that only the event owner can call the function by comparing the caller's address with the event owner's address.

cairo
assert self.get_event_owner(event_id) == self.get_caller(), "Only event owner can call this function";

Step 3: Update Event Details

Retrieve the event details, set is_closed to TRUE, and update the event details.

cairo
let event_details = self.get_event_details(event_id);
event_details.is_closed = TRUE;
self.set_event_details(event_id, event_details);

Step 4: Emit EndEventRegistration Event

Emit the EndEventRegistration event with the event ID.

cairo
emit EndEventRegistration(event_id);

Step 5: Write Unit Tests

Write unit tests to cover the following scenarios:

  1. Successful event registration closure.
  2. Non-owner caller attempting to close registration.
  3. Verification of emitted EndEventRegistration event.

Example unit test:

cairo
#[test]
fn test_end_event_registration_success() {
    // Setup
    let contract = TContractState::new();
    let event_id = 1;
    let owner = 0x1234567890abcdef;

    // Set event owner
    contract.set_event_owner(event_id, owner);

    // Call end_event_registration as owner
    contract.end_event_registration(event_id);

    // Assert is_closed is TRUE
    assert contract.get_event_details(event_id).is_closed == TRUE;
}
Gerson2102 commented 1 day ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged


Hey! I'm Gerson. 👋

Member of Dojo Coding. I have contributed before to other Cairo projects like:

Can I work on this issue?

Check my OnlyDust profile, I've contributed to many projects: Profile


How I plan on tackling this issue

Plan to Solve the Issue:

  1. Study the codebase to understand the current structure and functionality.
  2. Understand the problem that needs to be solved by thoroughly reading the issue details.
  3. Leverage all provided resources within the issue to get a better grasp of the task at hand.
  4. If I encounter roadblocks, I will ask questions ASAP in the Telegram group to move forward effectively.
  5. I will open a PR and wait for ur feedback

nickgore commented 7 hours ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, I'm data analyst / SC dev. For last half a year i ve been helping CarmineFinance improving their option AMM as well as developing new products, thus i have quite extensive hand on experience with Cairo. I would love to contribute to this issue or tackle something more challenging.

How I plan on tackling this issue

  1. Add body for fn end_event_registration
    • assert if caller is event owner. Owner for given event_id can be obtained from storage mapevent_owners or alernatively i can properly implement fn event_owner and use it)
    • update i.e set is_closed to true in event details for given event_id, could be found in storage event_details map.
    • emit EndEventRegistration (event_id and owner are known by now. name can be obtained from event details.)
  2. Add 3 unit test.
    • in first test we just need to add_event and use end_event_registration with same caller mock. then assert is_close in event details of given event.
    • in second test we mock different callers for add_event and end_event_registration. -> then func will panuc due to assert
    • the same as first but instead of assert - check if appropriate event is present and check if it contains correct data
nickgore commented 7 hours ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, I'm data analyst / SC dev. For last half a year i ve been helping CarmineFinance improving their option AMM as well as developing new products, thus i have quite extensive hand on experience with Cairo. I would love to contribute to this issue or tackle something more challenging.

How I plan on tackling this issue

  1. Add body for fn end_event_registration
  • assert if caller is event owner. Owner for given event_id can be obtained from storage mapevent_owners or alernatively i can properly implement fn event_owner and use it)
  • update i.e set is_closed to true in event details for given event_id, could be found in storage event_details map.
  • emit EndEventRegistration (event_id and owner are known by now. name can be obtained from event details.)
  1. Add 3 unit test.
  • in first test we just need to add_event and use end_event_registration with same caller mock. then assert is_close in event details of given event.
  • in second test we mock different callers for add_event and end_event_registration. -> then func will panuc due to assert
  • the same as first but instead of assert - check if appropriate event is present and check if it contains correct data

ETA - friday morning CET

MullerTheScientist commented 6 hours ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a full-stack developer with experience in QA testing and languages like Python, Cairo, Solidity, React, and JavaScript.

How I plan on tackling this issue

I will Test for the following Valid event owner: Verify the function sets is_closed to true. Non-event owner: Verify the function panics with the expected error message. Emitted event: Verify the EndEventRegistration event is emitted with the correct event_id.