Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/events indexed params #10

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
Loading