Skip to content

Commit

Permalink
channel testing correction
Browse files Browse the repository at this point in the history
  • Loading branch information
PavitraAgarwal21 committed Oct 17, 2024
1 parent 019e4d5 commit d4d4edd
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 44 deletions.
13 changes: 9 additions & 4 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub mod ChannelComponent {
channel_members: Map<(u256, ContractAddress), ChannelMember>,
channel_moderators: Map<(u256, ContractAddress), bool>,
channel_nft_classhash: ClassHash,
ban_status: Map<(u256, ContractAddress), bool>,
channel_ban_status: Map<(u256, ContractAddress), bool>,
}

// *************************************************************************
Expand Down Expand Up @@ -144,6 +144,11 @@ pub mod ChannelComponent {
channel_id, channel_nft_classhash, channel_id.try_into().unwrap()
); // use channel_id as salt since its unique

// check that caller is a member of the community
let (membership_status, _) = community_instance
.is_community_member(channel_owner, community_id);
assert(membership_status, NOT_COMMUNITY_MEMBER);

let new_channel = ChannelDetails {
channel_id: channel_id,
community_id: community_id,
Expand Down Expand Up @@ -393,7 +398,7 @@ pub mod ChannelComponent {
fn get_channel_ban_status(
self: @ComponentState<TContractState>, profile: ContractAddress, channel_id: u256
) -> bool {
self.ban_status.read((channel_id, profile))
self.channel_ban_status.read((channel_id, profile))
}
}

Expand Down Expand Up @@ -546,13 +551,13 @@ pub mod ChannelComponent {

// check profile is a channel member
let (is_channel_member, _) = self.is_channel_member(profile, channel_id);
assert(is_channel_member == true, NOT_COMMUNITY_MEMBER);
assert(is_channel_member == true, NOT_CHANNEL_MEMBER);

// update storage
// let channel_member = self.channel_members.read((channel_id, profile));
// let updated_member = ChannelMember { ban_status: ban_status, ..channel_member };
// self.channel_members.write((channel_id, profile), updated_member);
self.ban_status.write((channel_id, profile), ban_status);
self.channel_ban_status.write((channel_id, profile), ban_status);
// emit event
self
.emit(
Expand Down
2 changes: 1 addition & 1 deletion src/mocks/interfaces/IChannelComposable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait IChannelComposable<TState> {
// *************************************************************************
// EXTERNALS
// *************************************************************************
fn create_comminuty(ref self: TState, community_type: CommunityType) -> u256;
fn create_community(ref self: TState) -> u256;
fn join_community(ref self: TState, community_id: u256);
fn leave_community(ref self: TState, community_id: u256);
fn set_community_metadata_uri(ref self: TState, community_id: u256, metadata_uri: ByteArray);
Expand Down
Loading

0 comments on commit d4d4edd

Please sign in to comment.