diff --git a/.DS_Store b/.DS_Store index 92fbbac..5008ddf 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/src/interface.cairo b/src/interface.cairo index aa895f8..b68c10b 100644 --- a/src/interface.cairo +++ b/src/interface.cairo @@ -4,11 +4,9 @@ use starknet::{ContractAddress, EthAddress}; pub trait IPushComm { // Push Admin fn set_push_core_address(ref self: TContractState, core_address: EthAddress); - fn get_push_core_address(self: @TContractState) -> EthAddress; - fn get_push_governance_address(self: @TContractState) -> ContractAddress; fn set_push_governance_address(ref self: TContractState, governance_address: ContractAddress); - fn get_push_token_address(self: @TContractState) -> ContractAddress; fn set_push_token_address(ref self: TContractState, push_token_address: ContractAddress); + // Channel fn verify_channel_alias(ref self: TContractState, channel_address: EthAddress); fn add_delegate(ref self: TContractState, delegate: ContractAddress); @@ -25,13 +23,24 @@ pub trait IPushComm { notif_id: u256, notif_settings: ByteArray ); + // User - fn is_user_subscribed( - self: @TContractState, channel: ContractAddress, user: ContractAddress - ) -> bool; fn subscribe(ref self: TContractState, channel: ContractAddress); fn unsubscribe(ref self: TContractState, channel: ContractAddress); fn batch_subscribe(ref self: TContractState, channels: Array); fn batch_unsubscribe(ref self: TContractState, channels: Array); + + // New Getter Functions + fn is_user_subscribed( + self: @TContractState, channel: ContractAddress, user: ContractAddress + ) -> bool; + fn users_count(self: @TContractState) -> u256; fn chain_id(self: @TContractState) -> felt252; + fn chain_name(self: @TContractState) -> felt252; + fn push_core_address(self: @TContractState) -> EthAddress; + fn push_token_address(self: @TContractState) -> ContractAddress; + fn push_governance_address(self: @TContractState) -> ContractAddress; + fn user_to_channel_notifs(self: @TContractState, user: ContractAddress, channel: ContractAddress) -> ByteArray; + fn map_address_users(self: @TContractState, index: u256) -> ContractAddress; + fn delegated_notification_senders(self: @TContractState, channel: ContractAddress, delegate: ContractAddress) -> bool; } diff --git a/src/lib.cairo b/src/lib.cairo index e60350b..d371e6e 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -285,12 +285,6 @@ pub mod PushComm { #[abi(embed_v0)] impl PushComm of super::IPushComm { // User - fn is_user_subscribed( - self: @ContractState, channel: ContractAddress, user: ContractAddress - ) -> bool { - self._is_user_subscribed(channel, user) - } - fn subscribe(ref self: ContractState, channel: ContractAddress) { self._subscribe(channel, get_caller_address()); } @@ -346,10 +340,6 @@ pub mod PushComm { self.push_core_address.write(core_address); } - fn get_push_core_address(self: @ContractState) -> EthAddress { - self.push_core_address.read() - } - // Channel fn verify_channel_alias(ref self: ContractState, channel_address: EthAddress) { self @@ -384,8 +374,6 @@ pub mod PushComm { self._send_notification(channel, recipient, identity) } - - // Infos fn set_push_governance_address( ref self: ContractState, governance_address: ContractAddress ) { @@ -393,21 +381,52 @@ pub mod PushComm { self.governance.write(governance_address); } - fn get_push_governance_address(self: @ContractState) -> ContractAddress { - self.governance.read() - } - fn set_push_token_address(ref self: ContractState, push_token_address: ContractAddress) { self.ownable.assert_only_owner(); self.push_token_address.write(push_token_address); } - fn get_push_token_address(self: @ContractState) -> ContractAddress { + // Getters Functions + fn push_core_address(self: @ContractState) -> EthAddress { + self.push_core_address.read() + } + + fn push_token_address(self: @ContractState) -> ContractAddress { self.push_token_address.read() } + fn is_user_subscribed( + self: @ContractState, channel: ContractAddress, user: ContractAddress + ) -> bool { + self._is_user_subscribed(channel, user) + } + + fn users_count(self: @ContractState) -> u256 { + self.users_count.read() + } + fn chain_id(self: @ContractState) -> felt252 { self.chain_id.read() } + + fn push_governance_address(self: @ContractState) -> ContractAddress { + self.governance.read() + } + + fn chain_name(self: @ContractState) -> felt252 { + self.chain_name.read() + } + + fn user_to_channel_notifs(self: @ContractState, user: ContractAddress, channel: ContractAddress) -> ByteArray { + self.user_to_channel_notifs.entry(user).entry(channel).read() + } + + fn map_address_users(self: @ContractState, index: u256) -> ContractAddress { + self.map_address_users.entry(index).read() + } + + fn delegated_notification_senders(self: @ContractState, channel: ContractAddress, delegate: ContractAddress) -> bool { + self.delegated_notification_senders.entry(channel).entry(delegate).read() + } } } diff --git a/tests/test_channel_settings.cairo b/tests/test_channel_settings.cairo index fdda0d6..a331c51 100644 --- a/tests/test_channel_settings.cairo +++ b/tests/test_channel_settings.cairo @@ -24,6 +24,10 @@ fn test_channel_channel_user_settings() { let notif_settings: ByteArray = "notif_settings"; push_comm.change_user_channel_settings(CHANNEL_ADDRESS, notif_id, notif_settings.clone()); + let modified_notif_settings = format!("@{}+@{}", notif_id, notif_settings); + let setting_saved = push_comm.user_to_channel_notifs(USER_1(), CHANNEL_ADDRESS); + assert(setting_saved == modified_notif_settings, 'Settings saved'); + // Assert UserNotifcationSettingsAdded event was emitted spy .assert_emitted( diff --git a/tests/test_push_admin.cairo b/tests/test_push_admin.cairo index f53d075..441e465 100644 --- a/tests/test_push_admin.cairo +++ b/tests/test_push_admin.cairo @@ -15,7 +15,7 @@ fn test_admin_sets_core_contract_address() { cheat_caller_address(contract_address, PUSH_ADMIN(), CheatSpan::TargetCalls(1)); push_comm.set_push_core_address(CORE_ADDRESS); - let UPDATED_ADDRESS = push_comm.get_push_core_address(); + let UPDATED_ADDRESS = push_comm.push_core_address(); assert(CORE_ADDRESS == UPDATED_ADDRESS, 'Core Contract Update Failed'); } @@ -43,7 +43,7 @@ fn test_admin_set_gov_address() { cheat_caller_address(contract_address, PUSH_ADMIN(), CheatSpan::TargetCalls(1)); push_comm.set_push_governance_address(GOV_ADDRESS); - let UPDATED_ADDRESS = push_comm.get_push_governance_address(); + let UPDATED_ADDRESS = push_comm.push_governance_address(); assert(GOV_ADDRESS == UPDATED_ADDRESS, 'Core Contract Update Failed'); } @@ -71,7 +71,7 @@ fn test_admin_set_push_token_address() { cheat_caller_address(contract_address, PUSH_ADMIN(), CheatSpan::TargetCalls(1)); push_comm.set_push_governance_address(TOKEN_ADDRESS); - let UPDATED_ADDRESS = push_comm.get_push_governance_address(); + let UPDATED_ADDRESS = push_comm.push_governance_address(); assert(TOKEN_ADDRESS == UPDATED_ADDRESS, 'Core Contract Update Failed'); } diff --git a/tests/test_user_operations.cairo b/tests/test_user_operations.cairo index 8e90693..29d2f91 100644 --- a/tests/test_user_operations.cairo +++ b/tests/test_user_operations.cairo @@ -19,10 +19,16 @@ fn test_user_subscription_ops() { let is_user_subscribed = push_comm.is_user_subscribed(CHANNEL_ADDRESS, USER_1()); assert(is_user_subscribed == false, 'Initally user is not subscribed'); + let users_count_before_subscription = push_comm.users_count(); + // user subscribes to the channel cheat_caller_address(contract_address, USER_1(), CheatSpan::TargetCalls(1)); push_comm.subscribe(CHANNEL_ADDRESS); + // users_count should increase + let users_count_after_subscription = push_comm.users_count(); + assert(users_count_before_subscription + 1 == users_count_after_subscription, 'Users count not increased'); + // user should be subscribed to the channel let is_user_subscribed = push_comm.is_user_subscribed(CHANNEL_ADDRESS, USER_1()); assert(is_user_subscribed, 'User should be subscribed');