Skip to content

Commit

Permalink
refactor: removed core_address from storage and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNilesh committed Nov 1, 2024
1 parent 75b04da commit e5ff018
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 42 deletions.
2 changes: 1 addition & 1 deletion sh/declare.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Load environment variables from .env file
export $(grep -v '^#' ../.env | xargs)
export $(grep -v '^#' .env | xargs)

# Function to print usage information
print_usage() {
Expand Down
2 changes: 1 addition & 1 deletion sh/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Load environment variables from .env file
export $(grep -v '^#' ../.env | xargs)
export $(grep -v '^#' .env | xargs)

# Function to print usage information
print_usage() {
Expand Down
2 changes: 0 additions & 2 deletions src/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use starknet::{ContractAddress, EthAddress};
#[starknet::interface]
pub trait IPushComm<TContractState> {
// Push Admin
fn set_push_core_address(ref self: TContractState, core_address: EthAddress);
fn set_push_governance_address(ref self: TContractState, governance_address: ContractAddress);
fn set_push_token_address(ref self: TContractState, push_token_address: ContractAddress);

Expand Down Expand Up @@ -37,7 +36,6 @@ pub trait IPushComm<TContractState> {
fn users_count(self: @TContractState) -> u256;
fn chain_id(self: @TContractState) -> felt252;
fn chain_name(self: @TContractState) -> felt252;
fn push_core_address(self: @TContractState) -> EthAddress;
fn push_token_address(self: @TContractState) -> ContractAddress;
fn push_governance_address(self: @TContractState) -> ContractAddress;
fn user_to_channel_notifs(self: @TContractState, user: ContractAddress, channel: ContractAddress) -> ByteArray;
Expand Down
12 changes: 1 addition & 11 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,6 @@ pub mod PushComm {
);
}


// Admin
fn set_push_core_address(ref self: ContractState, core_address: EthAddress) {
self.ownable.assert_only_owner();
self.push_core_address.write(core_address);
}

// Channel
fn verify_channel_alias(ref self: ContractState, channel_address: EthAddress) {
self
Expand Down Expand Up @@ -374,6 +367,7 @@ pub mod PushComm {
self._send_notification(channel, recipient, identity)
}

//Admin
fn set_push_governance_address(
ref self: ContractState, governance_address: ContractAddress
) {
Expand All @@ -387,10 +381,6 @@ pub mod PushComm {
}

// Getters Functions
fn push_core_address(self: @ContractState) -> EthAddress {
self.push_core_address.read()
}

fn push_token_address(self: @ContractState) -> ContractAddress {
self.push_token_address.read()
}
Expand Down
27 changes: 0 additions & 27 deletions tests/test_push_admin.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,6 @@ use push_comm::interface::{IPushCommDispatcher, IPushCommDispatcherTrait};
use super::common::{USER_1, PUSH_ADMIN, deploy_contract};


#[test]
fn test_admin_sets_core_contract_address() {
let contract_address = deploy_contract();
let push_comm = IPushCommDispatcher { contract_address };
let CORE_ADDRESS: EthAddress = 'some addrs'.try_into().unwrap();

// admin sets the core channel address
cheat_caller_address(contract_address, PUSH_ADMIN(), CheatSpan::TargetCalls(1));
push_comm.set_push_core_address(CORE_ADDRESS);

let UPDATED_ADDRESS = push_comm.push_core_address();
assert(CORE_ADDRESS == UPDATED_ADDRESS, 'Core Contract Update Failed');
}

#[test]
#[should_panic(expected: 'Caller is not the owner')]
fn test_non_admin_sets_core_contract_fail() {
let contract_address = deploy_contract();
let push_comm = IPushCommDispatcher { contract_address };
let CORE_ADDRESS: EthAddress = 'some addrs'.try_into().unwrap();

// non admin user sets the core channel address
cheat_caller_address(contract_address, USER_1(), CheatSpan::TargetCalls(1));
push_comm.set_push_core_address(CORE_ADDRESS);
}


#[test]
fn test_admin_set_gov_address() {
let contract_address = deploy_contract();
Expand Down

0 comments on commit e5ff018

Please sign in to comment.