From d5225a261e9a308c7db3ea5a07d43c8dc14fee7b Mon Sep 17 00:00:00 2001 From: PavitraAgarwal21 Date: Fri, 4 Oct 2024 01:12:51 +0530 Subject: [PATCH] scarb fmt --- src/channel/channel.cairo | 46 ++++++++++++++++++++++++--------------- src/hub/hub.cairo | 2 +- tests/test_channel.cairo | 9 ++------ 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/channel/channel.cairo b/src/channel/channel.cairo index ed484a3..4f2fd07 100644 --- a/src/channel/channel.cairo +++ b/src/channel/channel.cairo @@ -164,24 +164,28 @@ pub mod ChannelComponent { /// @param channel_id: The id of the channel /// @dev The user must be a member of the channel fn leave_channel(ref self: ComponentState, channel_id: u256) { - assert( self.channel_members.read(get_caller_address()).channel_id == channel_id, NOT_CHANNEL_MEMBER ); - assert(!self.channel_members.read(get_caller_address()).ban_status, BANNED_FROM_CHANNEL); - assert(self.channels.read(channel_id).channel_total_members > 1 , 'total_member > 1'); - - self.channel_members.write(get_caller_address(), channelMember { - profile: get_caller_address(), - // todo , what default channel id should set max but not optimize to store - channel_id: 10000000, - total_publications: 0, - channel_token_id: 0, - ban_status: false, - }); - + assert( + !self.channel_members.read(get_caller_address()).ban_status, BANNED_FROM_CHANNEL + ); + assert(self.channels.read(channel_id).channel_total_members > 1, 'total_member > 1'); + self + .channel_members + .write( + get_caller_address(), + channelMember { + profile: get_caller_address(), + // todo , what default channel id should set max but not optimize to store + channel_id: 10000000, + total_publications: 0, + channel_token_id: 0, + ban_status: false, + } + ); let mut new_channel: channelParams = self.channels.read(channel_id); new_channel.channel_total_members -= 1; @@ -227,8 +231,10 @@ pub mod ChannelComponent { fn add_channel_mods( ref self: ComponentState, channel_id: u256, moderator: ContractAddress ) { - - assert(self.channels.read(channel_id).channel_owner == get_caller_address(), NOT_CHANNEL_OWNER); + assert( + self.channels.read(channel_id).channel_owner == get_caller_address(), + NOT_CHANNEL_OWNER + ); self.channel_moderators.write((channel_id, moderator), true); self @@ -251,7 +257,10 @@ pub mod ChannelComponent { ref self: ComponentState, channel_id: u256, moderator: ContractAddress ) { // let channel_member: channelParams = self.channels.read(channel_id); - assert(self.channels.read(channel_id).channel_owner == get_caller_address(), NOT_CHANNEL_OWNER); + assert( + self.channels.read(channel_id).channel_owner == get_caller_address(), + NOT_CHANNEL_OWNER + ); self.channel_moderators.write((channel_id, moderator), false); @@ -273,7 +282,10 @@ pub mod ChannelComponent { ref self: ComponentState, channel_id: u256, censorship_status: bool ) { // let channel_member: channelParams = self.channels.read(channel_id); - assert(self.channels.read(channel_id).channel_owner == get_caller_address(), NOT_CHANNEL_OWNER); + assert( + self.channels.read(channel_id).channel_owner == get_caller_address(), + NOT_CHANNEL_OWNER + ); let mut new_channel: channelParams = self.channels.read(channel_id); new_channel.channel_censorship = censorship_status; self.channels.write(channel_id, new_channel); diff --git a/src/hub/hub.cairo b/src/hub/hub.cairo index db0ee08..f1456f6 100644 --- a/src/hub/hub.cairo +++ b/src/hub/hub.cairo @@ -51,7 +51,7 @@ pub mod KarstHub { component!(path: ProfileComponent, storage: profile, event: ProfileEvent); component!(path: PublicationComponent, storage: publication, event: PublicationEvent); - + #[abi(embed_v0)] impl ChannelImpl = ChannelComponent::KarstChannel; impl ProfileImpl = ProfileComponent::KarstProfile; impl PublicationImpl = PublicationComponent::KarstPublication; diff --git a/tests/test_channel.cairo b/tests/test_channel.cairo index ee75296..fe3d125 100644 --- a/tests/test_channel.cairo +++ b/tests/test_channel.cairo @@ -82,9 +82,6 @@ fn __setup__() -> (ContractAddress, u256, ContractAddress, ByteArray) { } - - - // leave channel testing #[test] fn test_leave_channel() { @@ -219,7 +216,7 @@ fn test_joining_channel() { stop_cheat_caller_address(channel_contract_address); } -//todo working fine failed through the contract assert +//todo working fine failed through the contract assert // if aleready ban does not able to join the channel // #[test] // fn test_already_ban_cannot_join_channel() { @@ -231,9 +228,8 @@ fn test_joining_channel() { // dispatcher.set_ban_status(channel_id, USER_THREE.try_into().unwrap(), true); // stop_cheat_caller_address(channel_contract_address); - // // user -// // cannot able to join +// // cannot able to join // start_cheat_caller_address(channel_contract_address, USER_THREE.try_into().unwrap()); // dispatcher.join_channel(channel_id); // stop_cheat_caller_address(channel_contract_address); @@ -242,7 +238,6 @@ fn test_joining_channel() { // } - #[test] fn test_channel_member() { let (channel_contract_address, channel_id, owner, _) = __setup__();