Skip to content

Commit

Permalink
scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
PavitraAgarwal21 committed Oct 3, 2024
1 parent 3e40955 commit d5225a2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
46 changes: 29 additions & 17 deletions src/channel/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<TContractState>, 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;
Expand Down Expand Up @@ -227,8 +231,10 @@ pub mod ChannelComponent {
fn add_channel_mods(
ref self: ComponentState<TContractState>, 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
Expand All @@ -251,7 +257,10 @@ pub mod ChannelComponent {
ref self: ComponentState<TContractState>, 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);

Expand All @@ -273,7 +282,10 @@ pub mod ChannelComponent {
ref self: ComponentState<TContractState>, 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);
Expand Down
2 changes: 1 addition & 1 deletion src/hub/hub.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractState>;
impl ProfileImpl = ProfileComponent::KarstProfile<ContractState>;
impl PublicationImpl = PublicationComponent::KarstPublication<ContractState>;
Expand Down
9 changes: 2 additions & 7 deletions tests/test_channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ fn __setup__() -> (ContractAddress, u256, ContractAddress, ByteArray) {
}





// leave channel testing
#[test]
fn test_leave_channel() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
Expand All @@ -242,7 +238,6 @@ fn test_joining_channel() {

// }


#[test]
fn test_channel_member() {
let (channel_contract_address, channel_id, owner, _) = __setup__();
Expand Down

0 comments on commit d5225a2

Please sign in to comment.