Skip to content

Commit

Permalink
fix: proces_unblock should first check that user is blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Jan 17, 2025
1 parent f767608 commit 7f19e0e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/base/constants/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod Errors {
pub const FOLLOWING: felt252 = 'coloniz: already following!';
pub const NOT_FOLLOWING: felt252 = 'coloniz: user not following!';
pub const BLOCKED_STATUS: felt252 = 'coloniz: user is blocked!';
pub const USER_NOT_BLOCKED: felt252 = 'coloniz: user is not blocked!';
pub const INVALID_POINTED_PUBLICATION: felt252 = 'coloniz: invalid pointed pub!';
pub const INVALID_OWNER: felt252 = 'coloniz: caller is not owner!';
pub const INVALID_PROFILE: felt252 = 'coloniz: profile is not owner!';
Expand Down
3 changes: 2 additions & 1 deletion src/community/community.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ pub mod CommunityComponent {
/// @param community_id The id of the community
/// /// @param permissioned_addresses array of addresses to set for permissioned gatekeeping
fn set_permissioned_addresses(
ref self: ComponentState<TContractState>, community_id: u256,
ref self: ComponentState<TContractState>,
community_id: u256,
permissioned_addresses: Array<ContractAddress>
) {
// check caller is owner
Expand Down
7 changes: 6 additions & 1 deletion src/follownft/follownft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub mod Follow {
.read(follower_profile_address);
assert(follow_id.is_non_zero(), Errors::NOT_FOLLOWING);
let follow_data = self.follow_data_by_follow_id.read(follow_id);

self
.follow_data_by_follow_id
.write(
Expand All @@ -191,6 +192,7 @@ pub mod Follow {
block_status: true,
}
);

self
.emit(
FollowerBlocked {
Expand All @@ -212,8 +214,9 @@ pub mod Follow {
let follow_id = self
.follow_id_by_follower_profile_address
.read(follower_profile_address);
assert(follow_id.is_non_zero(), Errors::NOT_FOLLOWING);
let follow_data = self.follow_data_by_follow_id.read(follow_id);
assert(follow_data.block_status == true, Errors::USER_NOT_BLOCKED);

self
.follow_data_by_follow_id
.write(
Expand All @@ -225,6 +228,7 @@ pub mod Follow {
block_status: false,
}
);

self
.emit(
FollowerUnblocked {
Expand All @@ -234,6 +238,7 @@ pub mod Follow {
timestamp: get_block_timestamp()
}
);

return true;
}

Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/ICommunity.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ pub trait ICommunity<TState> {
paid_gating_details: (ContractAddress, u256),
);
fn set_permissioned_addresses(
ref self: TState,
community_id: u256,
permissioned_addresses: Array<ContractAddress>
ref self: TState, community_id: u256, permissioned_addresses: Array<ContractAddress>
);

// *************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions tests/test_follownft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ fn test_process_unblock() {
let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address };
start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap());
dispatcher.follow(FOLLOWER1.try_into().unwrap());
dispatcher.process_block(FOLLOWER1.try_into().unwrap());
dispatcher.process_unblock(FOLLOWER1.try_into().unwrap());
let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap());
let follow_data = dispatcher.get_follow_data(follow_id);
Expand Down Expand Up @@ -338,6 +339,7 @@ fn test_unblock_event() {
let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address };
start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap());
dispatcher.follow(FOLLOWER1.try_into().unwrap());
dispatcher.process_block(FOLLOWER1.try_into().unwrap());
let mut spy = spy_events();
dispatcher.process_unblock(FOLLOWER1.try_into().unwrap());
let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap());
Expand Down

0 comments on commit 7f19e0e

Please sign in to comment.