Skip to content

Commit

Permalink
fixes ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Oct 8, 2024
1 parent 4215e34 commit 6d39052
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/hub/pwn_hub.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pub mod PwnHub {
}

#[constructor]
fn constructor(ref self: ContractState) {
self.ownable.initializer(starknet::get_caller_address());
fn constructor(ref self: ContractState, owner: ContractAddress) {
self.ownable.initializer(owner);
}

#[abi(embed_v0)]
Expand Down
4 changes: 2 additions & 2 deletions src/multitoken/category_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ pub mod MultiTokenCategoryRegistry {
}

#[constructor]
fn constructor(ref self: ContractState) {
self.ownable.initializer(starknet::get_caller_address());
fn constructor(ref self: ContractState, owner: ContractAddress) {
self.ownable.initializer(owner);
}

#[abi(embed_v0)]
Expand Down
10 changes: 8 additions & 2 deletions tests/integration/base_integration_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ pub struct Setup {
}

pub fn setup() -> Setup {
let owner = starknet::get_contract_address();

let contract = declare("PwnHub").unwrap();
let (hub_address, _) = contract.deploy(@array![]).unwrap();
let (hub_address, _) = contract.deploy(@array![owner.into()]).unwrap();
let hub = IPwnHubDispatcher { contract_address: hub_address };
println!("DEPLOYED PWNHUB");

let contract = declare("PwnConfig").unwrap();
let (config_address, _) = contract.deploy(@array![]).unwrap();
Expand Down Expand Up @@ -158,9 +161,12 @@ pub fn setup() -> Setup {
let (loan_token_address, _) = contract.deploy(@array![hub_address.into()]).unwrap();
let loan_token = IPwnLoanDispatcher { contract_address: loan_token_address };

let mut calldata: Array<felt252> = array![];
owner.serialize(ref calldata);
let contract = declare("MultiTokenCategoryRegistry").unwrap();
let (registry_address, _) = contract.deploy(@array![]).unwrap();
let (registry_address, _) = contract.deploy(@calldata).unwrap();
let registry = IMultiTokenCategoryRegistryDispatcher { contract_address: registry_address };
println!("DEPLOYED MULTITOKEN");

let contract = declare("PwnSimpleLoan").unwrap();
let (loan_address, _) = contract
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/hub_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn ACCOUNT_1() -> starknet::ContractAddress {

fn deploy() -> IPwnHubDispatcher {
let contract = declare("PwnHub").unwrap();
let (contract_address, _) = contract.deploy(@array![]).unwrap();
let (contract_address, _) = contract.deploy(@array![starknet::get_contract_address().into()]).unwrap();

IPwnHubDispatcher { contract_address }
}
Expand All @@ -34,9 +34,8 @@ mod constructor {

#[test]
fn test_should_set_hub_owner() {
super::cheat_caller_address_global(ACCOUNT_1());
let hub = deploy();
assert_eq!(hub.owner(), ACCOUNT_1());
assert_eq!(hub.owner(), starknet::get_contract_address());
}
}

Expand Down
7 changes: 4 additions & 3 deletions tests/unit/multitoken_category_registry_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ fn ACCOUNT_1() -> starknet::ContractAddress {

fn deploy() -> IMultiTokenCategoryRegistryDispatcher {
let contract = declare("MultiTokenCategoryRegistry").unwrap();
let (contract_address, _) = contract.deploy(@array![]).unwrap();
let (contract_address, _) = contract
.deploy(@array![starknet::get_contract_address().into()])
.unwrap();

IMultiTokenCategoryRegistryDispatcher { contract_address }
}
Expand All @@ -33,9 +35,8 @@ mod constructor {

#[test]
fn test_should_set_contract_owner() {
super::cheat_caller_address_global(ACCOUNT_1());
let registry = deploy();
assert_eq!(registry.owner(), ACCOUNT_1());
assert_eq!(registry.owner(), starknet::get_contract_address());
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/revoked_nonce_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ fn ALICE() -> starknet::ContractAddress {

fn deploy() -> (IRevokedNonceDispatcher, IPwnHubDispatcher) {
let contract = declare("PwnHub").unwrap();
let (contract_address, _) = contract.deploy(@array![]).unwrap();
let (contract_address, _) = contract
.deploy(@array![starknet::get_contract_address().into()])
.unwrap();
let hub = IPwnHubDispatcher { contract_address };

let contract = declare("RevokedNonce").unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/simple_loan_dutch_auction_proposal_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ struct Setup {

fn deploy() -> Setup {
let contract = declare("PwnHub").unwrap();
let (hub_address, _) = contract.deploy(@array![]).unwrap();
let (hub_address, _) = contract
.deploy(@array![starknet::get_contract_address().into()])
.unwrap();
let hub = IPwnHubDispatcher { contract_address: hub_address };

let contract = declare("PwnConfig").unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/simple_loan_fungible_proposal_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ struct Setup {

fn deploy() -> Setup {
let contract = declare("PwnHub").unwrap();
let (hub_address, _) = contract.deploy(@array![]).unwrap();
let (hub_address, _) = contract
.deploy(@array![starknet::get_contract_address().into()])
.unwrap();
let hub = IPwnHubDispatcher { contract_address: hub_address };

let contract = declare("PwnConfig").unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/simple_loan_list_proposal_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ struct Setup {

fn deploy() -> Setup {
let contract = declare("PwnHub").unwrap();
let (hub_address, _) = contract.deploy(@array![]).unwrap();
let (hub_address, _) = contract
.deploy(@array![starknet::get_contract_address().into()])
.unwrap();
let hub = IPwnHubDispatcher { contract_address: hub_address };

let contract = declare("PwnConfig").unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/simple_loan_proposal_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ struct Setup {

pub fn deploy() -> Setup {
let contract = declare("PwnHub").unwrap();
let (hub_address, _) = contract.deploy(@array![]).unwrap();
let (hub_address, _) = contract
.deploy(@array![starknet::get_contract_address().into()])
.unwrap();

let contract = declare("PwnConfig").unwrap();
let (config_address, _) = contract.deploy(@array![]).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/simple_loan_simple_proposal_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ struct Setup {

fn deploy() -> Setup {
let contract = declare("PwnHub").unwrap();
let (hub_address, _) = contract.deploy(@array![]).unwrap();
let (hub_address, _) = contract
.deploy(@array![starknet::get_contract_address().into()])
.unwrap();
let hub = IPwnHubDispatcher { contract_address: hub_address };

let contract = declare("PwnConfig").unwrap();
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/simple_loan_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ pub struct Setup {
pub refinanced_loan_terms: types::Terms
}


pub fn setup() -> Setup {
let owner = starknet::get_contract_address();

let contract = declare("PwnHub").unwrap();
let (hub_address, _) = contract.deploy(@array![]).unwrap();
let (hub_address, _) = contract.deploy(@array![owner.into()]).unwrap();
let hub = IPwnHubDispatcher { contract_address: hub_address };

let contract = declare("PwnConfig").unwrap();
Expand All @@ -120,7 +123,7 @@ pub fn setup() -> Setup {
let loan_token = IPwnLoanDispatcher { contract_address: loan_token_address };

let contract = declare("MultiTokenCategoryRegistry").unwrap();
let (registry_address, _) = contract.deploy(@array![]).unwrap();
let (registry_address, _) = contract.deploy(@array![owner.into()]).unwrap();
let registry = IMultiTokenCategoryRegistryDispatcher { contract_address: registry_address };

let contract = declare("PwnSimpleLoan").unwrap();
Expand Down

0 comments on commit 6d39052

Please sign in to comment.