diff --git a/src/interface.cairo b/src/interface.cairo index bbaf205..aa895f8 100644 --- a/src/interface.cairo +++ b/src/interface.cairo @@ -33,4 +33,5 @@ pub trait IPushComm { fn unsubscribe(ref self: TContractState, channel: ContractAddress); fn batch_subscribe(ref self: TContractState, channels: Array); fn batch_unsubscribe(ref self: TContractState, channels: Array); + fn chain_id(self: @TContractState) -> felt252; } diff --git a/src/lib.cairo b/src/lib.cairo index 4353415..6b3d06b 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -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, subscribed: Map, map_address_subscribed: Map, @@ -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 @@ -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 } @@ -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() + } } } diff --git a/tests/test_channel_alias.cairo b/tests/test_channel_alias.cairo index 1824f5d..06d1873 100644 --- a/tests/test_channel_alias.cairo +++ b/tests/test_channel_alias.cairo @@ -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(); @@ -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 } diff --git a/tests/test_channel_settings.cairo b/tests/test_channel_settings.cairo index 38564ea..fdda0d6 100644 --- a/tests/test_channel_settings.cairo +++ b/tests/test_channel_settings.cairo @@ -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 }; @@ -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()); -} \ No newline at end of file +}