From 5b7e4b18808d994aa0ae588446c1e873afbdcc1e Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Tue, 3 Sep 2024 21:07:10 +0530 Subject: [PATCH] Fixes/events indexed params (#10) * fix: added few more params as indexed * fix: typo * fix: test cases --- src/lib.cairo | 16 +++++++++++----- tests/test_channel_delegate.cairo | 6 +++--- tests/test_send_notification.cairo | 10 +++++----- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/lib.cairo b/src/lib.cairo index 6b3d06b..e60350b 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -91,9 +91,10 @@ pub mod PushComm { #[derive(Drop, starknet::Event)] pub struct ChannelAlias { - #[key] pub chain_name: felt252, + #[key] pub chain_id: felt252, + #[key] pub channel_owner_address: ContractAddress, pub ethereum_channel_address: EthAddress, } @@ -102,6 +103,7 @@ pub mod PushComm { pub struct Subscribe { #[key] pub channel: ContractAddress, + #[key] pub user: ContractAddress, } @@ -109,6 +111,7 @@ pub mod PushComm { pub struct UnSubscribe { #[key] pub channel: ContractAddress, + #[key] pub user: ContractAddress, } @@ -116,6 +119,7 @@ pub mod PushComm { pub struct AddDelegate { #[key] pub channel: ContractAddress, + #[key] pub delegate: ContractAddress, } @@ -123,6 +127,7 @@ pub mod PushComm { pub struct RemoveDelegate { #[key] pub channel: ContractAddress, + #[key] pub delegate: ContractAddress, } @@ -130,20 +135,21 @@ pub mod PushComm { pub struct SendNotification { #[key] pub channel: ContractAddress, + #[key] pub recipient: ContractAddress, - pub indentity: ByteArray, + pub identity: ByteArray, } #[derive(Drop, starknet::Event)] pub struct UserNotifcationSettingsAdded { #[key] pub channel: ContractAddress, + #[key] pub recipient: ContractAddress, pub notif_id: u256, pub notif_settings: ByteArray, } - #[constructor] fn constructor( ref self: ContractState, @@ -258,14 +264,14 @@ pub mod PushComm { ref self: ContractState, channel: ContractAddress, recipient: ContractAddress, - indentity: ByteArray + identity: ByteArray ) -> bool { let success = self._check_notif_req(channel, recipient); if success { self .emit( SendNotification { - channel: channel, recipient: recipient, indentity: indentity + channel: channel, recipient: recipient, identity: identity } ); return true; diff --git a/tests/test_channel_delegate.cairo b/tests/test_channel_delegate.cairo index bd68c72..de60bbc 100644 --- a/tests/test_channel_delegate.cairo +++ b/tests/test_channel_delegate.cairo @@ -13,7 +13,7 @@ fn test_channel_delegate() { let contract_address = deploy_contract(); let push_comm = IPushCommDispatcher { contract_address }; let CHANNEL_ADDRESS: ContractAddress = 'some addrs'.try_into().unwrap(); - let indentity: ByteArray = "identity"; + let identity: ByteArray = "identity"; let mut spy = spy_events(); // Channel owner set the delegate @@ -35,7 +35,7 @@ fn test_channel_delegate() { // Delegate can send the notification cheat_caller_address(contract_address, USER_1(), CheatSpan::TargetCalls(1)); - let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), indentity.clone()); + let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), identity.clone()); assert(is_success, 'Send notification failed'); // Channel owner remove the delegate @@ -57,6 +57,6 @@ fn test_channel_delegate() { // Removed Delegate can send the notification cheat_caller_address(contract_address, USER_1(), CheatSpan::TargetCalls(1)); - let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), indentity.clone()); + let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), identity.clone()); assert(is_success == false, 'Send notification should fail'); } diff --git a/tests/test_send_notification.cairo b/tests/test_send_notification.cairo index 3042c5c..c846e5b 100644 --- a/tests/test_send_notification.cairo +++ b/tests/test_send_notification.cairo @@ -13,12 +13,12 @@ fn test_channel_owner_send_notification() { let contract_address = deploy_contract(); let push_comm = IPushCommDispatcher { contract_address }; let CHANNEL_ADDRESS: ContractAddress = 'some addrs'.try_into().unwrap(); - let indentity: ByteArray = "identity"; + let identity: ByteArray = "identity"; let mut spy = spy_events(); // Channel owner can send the notification cheat_caller_address(contract_address, CHANNEL_ADDRESS, CheatSpan::TargetCalls(1)); - let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), indentity.clone()); + let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), identity.clone()); assert(is_success, 'Send notification failed'); // Assert SendNotification event was emitted @@ -29,7 +29,7 @@ fn test_channel_owner_send_notification() { contract_address, PushComm::Event::SendNotification( PushComm::SendNotification { - channel: CHANNEL_ADDRESS, recipient: USER_1(), indentity + channel: CHANNEL_ADDRESS, recipient: USER_1(), identity } ) ) @@ -43,10 +43,10 @@ fn test_non_channel_owner_send_notification() { let contract_address = deploy_contract(); let push_comm = IPushCommDispatcher { contract_address }; let CHANNEL_ADDRESS: ContractAddress = 'some addrs'.try_into().unwrap(); - let indentity: ByteArray = "identity"; + let identity: ByteArray = "identity"; // Channel owner can send the notification cheat_caller_address(contract_address, USER_1(), CheatSpan::TargetCalls(1)); - let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), indentity.clone()); + let is_success = push_comm.send_notification(CHANNEL_ADDRESS, USER_1(), identity.clone()); assert(is_success == false, 'Send notification should fail'); }