Skip to content

Commit

Permalink
test: channel alias fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eddnewgate committed Aug 30, 2024
1 parent 5bb5b34 commit e415ace
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ pub trait IPushComm<TContractState> {
fn unsubscribe(ref self: TContractState, channel: ContractAddress);
fn batch_subscribe(ref self: TContractState, channels: Array<ContractAddress>);
fn batch_unsubscribe(ref self: TContractState, channels: Array<ContractAddress>);
fn chain_id(self: @TContractState) -> felt252;
}
14 changes: 9 additions & 5 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ pub mod PushComm {

#[starknet::storage_node]
pub struct User {
is_activated: bool,
// TODO: optimized packing
start_block: u64,
subscribed_count: u256,
start_block: u64,
is_activated: bool,
is_subscribed: Map<ContractAddress, bool>,
subscribed: Map<ContractAddress, u256>,
map_address_subscribed: Map<u256, ContractAddress>,
Expand Down Expand Up @@ -313,7 +312,9 @@ pub mod PushComm {
notif_settings: ByteArray
) {
let caller_address = get_caller_address();
assert!(self._is_user_subscribed(channel, caller_address), "User not subscribed to channel");
assert!(
self._is_user_subscribed(channel, caller_address), "User not subscribed to channel"
);

let modified_notif_settings = format!("@{}+@{}", notif_id, notif_settings);
self
Expand Down Expand Up @@ -350,7 +351,6 @@ pub mod PushComm {
ChannelAlias {
chain_name: self.chain_name.read(),
chain_id: self.chain_id.read(),
// chain_id: 1, //self.chain_id.read(),
channel_owner_address: get_caller_address(),
ethereum_channel_address: channel_address
}
Expand Down Expand Up @@ -399,5 +399,9 @@ pub mod PushComm {
fn get_push_token_address(self: @ContractState) -> ContractAddress {
self.push_token_address.read()
}

fn chain_id(self: @ContractState) -> felt252 {
self.chain_id.read()
}
}
}
3 changes: 2 additions & 1 deletion tests/test_channel_alias.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn test_verify_channel_alias() {
let contract_address = deploy_contract();
let push_comm = IPushCommDispatcher { contract_address };
let channel_address: EthAddress = 'some address'.try_into().unwrap();
let chain_id: felt252 = 'SN_SEPOLIA'.try_into().unwrap();

let mut spy = spy_events();

Expand All @@ -29,7 +30,7 @@ fn test_verify_channel_alias() {
PushComm::Event::ChannelAlias(
PushComm::ChannelAlias {
chain_name: CHAIN_NAME(),
chain_id: 1,
chain_id: chain_id,
channel_owner_address: USER_1(),
ethereum_channel_address: channel_address
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_channel_settings.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn test_channel_channel_user_settings() {
}

#[test]
#[should_panic(expected:"User not subscribed to channel")]
#[should_panic(expected: "User not subscribed to channel")]
fn test_channel_channel_unsubscribed_user_settings() {
let contract_address = deploy_contract();
let push_comm = IPushCommDispatcher { contract_address };
Expand All @@ -52,4 +52,4 @@ fn test_channel_channel_unsubscribed_user_settings() {
let notif_id = 1;
let notif_settings: ByteArray = "notif_settings";
push_comm.change_user_channel_settings(CHANNEL_ADDRESS, notif_id, notif_settings.clone());
}
}

0 comments on commit e415ace

Please sign in to comment.