-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df1f678
commit 35fb53d
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use starknet::{ContractAddress, EthAddress}; | ||
|
||
use snforge_std::{ | ||
declare, ContractClassTrait, cheat_caller_address, CheatSpan, spy_events, | ||
EventSpyAssertionsTrait, Event, EventSpyTrait | ||
}; | ||
use push_comm::{PushComm, interface::IPushCommDispatcher, interface::IPushCommDispatcherTrait}; | ||
use super::common::{USER_1, deploy_contract, CHAIN_NAME}; | ||
|
||
#[test] | ||
fn test_channel_channel_user_settings() { | ||
let contract_address = deploy_contract(); | ||
let push_comm = IPushCommDispatcher { contract_address }; | ||
let CHANNEL_ADDRESS: ContractAddress = 'some addrs'.try_into().unwrap(); | ||
let mut spy = spy_events(); | ||
|
||
// user subscribes to the channel | ||
cheat_caller_address(contract_address, USER_1(), CheatSpan::TargetCalls(1)); | ||
push_comm.subscribe(CHANNEL_ADDRESS); | ||
|
||
// change_user_channel_settings | ||
cheat_caller_address(contract_address, CHANNEL_ADDRESS, CheatSpan::TargetCalls(1)); | ||
let notif_id = 1; | ||
let notif_settings: ByteArray = "notif_settings"; | ||
push_comm.change_user_channel_settings(CHANNEL_ADDRESS, notif_id, notif_settings.clone()); | ||
|
||
// Assert UserNotifcationSettingsAdded event was emitted | ||
spy | ||
.assert_emitted( | ||
@array![ | ||
( | ||
contract_address, | ||
PushComm::Event::UserNotifcationSettingsAdded( | ||
PushComm::UserNotifcationSettingsAdded { | ||
channel: CHANNEL_ADDRESS, recipient: USER_1(), notif_id, notif_settings | ||
} | ||
) | ||
) | ||
] | ||
); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected: '')] | ||
fn test_channel_channel_unsubscribed_user_settings() { | ||
let contract_address = deploy_contract(); | ||
let push_comm = IPushCommDispatcher { contract_address }; | ||
let CHANNEL_ADDRESS: ContractAddress = 'some addrs'.try_into().unwrap(); | ||
let mut spy = spy_events(); | ||
|
||
// change_user_channel_settings | ||
cheat_caller_address(contract_address, CHANNEL_ADDRESS, CheatSpan::TargetCalls(1)); | ||
let notif_id = 1; | ||
let notif_settings: ByteArray = "notif_settings"; | ||
push_comm.change_user_channel_settings(CHANNEL_ADDRESS, notif_id, notif_settings.clone()); | ||
} |