Skip to content

Commit

Permalink
scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Oct 26, 2024
1 parent 71a6f02 commit 94a47bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/events/events.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pub mod Events {
use core::num::traits::zero::Zero;
use chainevents_contracts::base::types::{EventDetails, EventRegistration, EventType};
use chainevents_contracts::base::errors::Errors::{
ZERO_ADDRESS_OWNER, ZERO_ADDRESS_CALLER, NOT_OWNER, CLOSED_EVENT, ALREADY_REGISTERED, NOT_REGISTERED, ALREADY_RSVP
ZERO_ADDRESS_OWNER, ZERO_ADDRESS_CALLER, NOT_OWNER, CLOSED_EVENT, ALREADY_REGISTERED,
NOT_REGISTERED, ALREADY_RSVP
};
use chainevents_contracts::interfaces::IEvent::IEvent;
use core::starknet::{
Expand Down Expand Up @@ -177,19 +178,17 @@ pub mod Events {
fn rsvp_for_event(ref self: ContractState, event_id: u256) {
let caller = get_caller_address();

let attendee_event_details = self.attendee_event_details.entry((event_id, caller)).read();
let attendee_event_details = self
.attendee_event_details
.entry((event_id, caller))
.read();

assert(attendee_event_details.attendee_address == caller, NOT_REGISTERED);
assert(attendee_event_details.has_rsvp == false, ALREADY_RSVP);

self.attendee_event_details.entry((event_id, caller)).has_rsvp.write(true);

self.emit(
RSVPForEvent {
event_id,
attendee_address: caller,
}
);
self.emit(RSVPForEvent { event_id, attendee_address: caller, });
}

fn upgrade_event(ref self: ContractState, event_id: u256, paid_amount: u256) {}
Expand Down
12 changes: 7 additions & 5 deletions tests/test_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use starknet::{ContractAddress};

use snforge_std::{
declare, start_cheat_caller_address, stop_cheat_caller_address, ContractClassTrait,
DeclareResultTrait, spy_events, EventSpyAssertionsTrait,
DeclareResultTrait, spy_events, EventSpyAssertionsTrait,
};

use chainevents_contracts::interfaces::IEvent::{IEventDispatcher, IEventDispatcherTrait};
Expand Down Expand Up @@ -104,10 +104,12 @@ fn test_rsvp_for_event_should_emit_event_on_success() {
event_dispatcher.register_for_event(event_id);

let mut spy = spy_events();

event_dispatcher.rsvp_for_event(event_id);

let expected_event = Events::Event::RSVPForEvent(Events::RSVPForEvent { event_id: 1, attendee_address: caller });
let expected_event = Events::Event::RSVPForEvent(
Events::RSVPForEvent { event_id: 1, attendee_address: caller }
);
spy.assert_emitted(@array![(event_contract_address, expected_event)]);

stop_cheat_caller_address(event_contract_address);
Expand All @@ -132,12 +134,12 @@ fn test_should_panic_on_rsvp_for_event_twice() {
start_cheat_caller_address(event_contract_address, caller);

event_dispatcher.register_for_event(event_id);

// first rsvp for event
event_dispatcher.rsvp_for_event(event_id);

// second rsvp for the same event: should panic
event_dispatcher.rsvp_for_event(event_id);

stop_cheat_caller_address(event_contract_address);
}
}

0 comments on commit 94a47bb

Please sign in to comment.