Skip to content

Commit

Permalink
Fixes/events indexed params (#10)
Browse files Browse the repository at this point in the history
* fix: added few more params as indexed

* fix: typo

* fix: test cases
  • Loading branch information
0xNilesh authored Sep 3, 2024
1 parent 13fee55 commit 5b7e4b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
16 changes: 11 additions & 5 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -102,48 +103,53 @@ pub mod PushComm {
pub struct Subscribe {
#[key]
pub channel: ContractAddress,
#[key]
pub user: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct UnSubscribe {
#[key]
pub channel: ContractAddress,
#[key]
pub user: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct AddDelegate {
#[key]
pub channel: ContractAddress,
#[key]
pub delegate: ContractAddress,
}

#[derive(Drop, starknet::Event)]
pub struct RemoveDelegate {
#[key]
pub channel: ContractAddress,
#[key]
pub delegate: ContractAddress,
}

#[derive(Drop, starknet::Event)]
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,
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/test_channel_delegate.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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');
}
10 changes: 5 additions & 5 deletions tests/test_send_notification.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
)
)
Expand All @@ -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');
}

0 comments on commit 5b7e4b1

Please sign in to comment.