From 9518050e56055a17be5e6bc8991a390957563429 Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Tue, 10 Sep 2024 14:49:20 +0530 Subject: [PATCH 1/4] feat: added getter for users_count --- src/interface.cairo | 1 + src/lib.cairo | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/interface.cairo b/src/interface.cairo index aa895f8..652c115 100644 --- a/src/interface.cairo +++ b/src/interface.cairo @@ -29,6 +29,7 @@ pub trait IPushComm { fn is_user_subscribed( self: @TContractState, channel: ContractAddress, user: ContractAddress ) -> bool; + fn users_count(self: @TContractState) -> u256; fn subscribe(ref self: TContractState, channel: ContractAddress); fn unsubscribe(ref self: TContractState, channel: ContractAddress); fn batch_subscribe(ref self: TContractState, channels: Array); diff --git a/src/lib.cairo b/src/lib.cairo index e60350b..8b663c0 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -291,6 +291,10 @@ pub mod PushComm { self._is_user_subscribed(channel, user) } + fn users_count(self: @ContractState) -> u256 { + self.users_count.read() + } + fn subscribe(ref self: ContractState, channel: ContractAddress) { self._subscribe(channel, get_caller_address()); } From ad6d26c839933ea31d41ced609b0ead610202b2d Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Tue, 10 Sep 2024 14:49:36 +0530 Subject: [PATCH 2/4] test: updated test cases acc. to users_count --- tests/test_user_operations.cairo | 6 ++++++ 1 file changed, 6 insertions(+) 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'); From 010d045342801d8c6b1e7648d49d07bf4bb03b3b Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Tue, 10 Sep 2024 15:45:16 +0530 Subject: [PATCH 3/4] feat: added missing getter functions --- .DS_Store | Bin 6148 -> 6148 bytes src/interface.cairo | 22 +++++++++----- src/lib.cairo | 57 +++++++++++++++++++++++------------- tests/test_push_admin.cairo | 6 ++-- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/.DS_Store b/.DS_Store index 92fbbac9d2e146bb973d864eac74ad83de317d59..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 100644 GIT binary patch delta 67 zcmZoMXfc=|&Zs)EP;8=}A_oHyFfuR*Y}^>eKJh@*W_At%4o20D8^1G8<`+@q1WGX^ TfYeMj;Zfe4AhLvcVgm~RE=&+7 delta 120 zcmZoMXfc=|&e%3FQEZ}~q9`K+0|O8XFff!dm6sHs?=S)mgpKKt)BE`Xw$dC+# z`N)z<`T04F8x!N$K}t4rbMSC5wrx!O&ODi4L{XFpXq*BNCjc?X=mS8^u-Q>$KQjQO CoEnz^ diff --git a/src/interface.cairo b/src/interface.cairo index 652c115..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,14 +23,24 @@ pub trait IPushComm { notif_id: u256, notif_settings: ByteArray ); + // User - fn is_user_subscribed( - self: @TContractState, channel: ContractAddress, user: ContractAddress - ) -> bool; - fn users_count(self: @TContractState) -> u256; 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 8b663c0..d371e6e 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -285,16 +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 users_count(self: @ContractState) -> u256 { - self.users_count.read() - } - fn subscribe(ref self: ContractState, channel: ContractAddress) { self._subscribe(channel, get_caller_address()); } @@ -350,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 @@ -388,8 +374,6 @@ pub mod PushComm { self._send_notification(channel, recipient, identity) } - - // Infos fn set_push_governance_address( ref self: ContractState, governance_address: ContractAddress ) { @@ -397,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_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'); } From 4e59f282decdc156447004f400e7de699d2bceec Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Tue, 10 Sep 2024 15:56:53 +0530 Subject: [PATCH 4/4] test: added test cases to check saved notif settings --- tests/test_channel_settings.cairo | 4 ++++ 1 file changed, 4 insertions(+) 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(