Skip to content

Commit

Permalink
Merge pull request #59 from starknet-id/testnet
Browse files Browse the repository at this point in the history
merge remove admin
  • Loading branch information
Th0rgal authored Jun 10, 2024
2 parents f440c3b + 25ecd41 commit 0c58006
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 32 deletions.
2 changes: 0 additions & 2 deletions src/interface/naming.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,4 @@ trait INaming<TContractState> {
fn blacklist_renewal_contract(ref self: TContractState, contract: ContractAddress);

fn toggle_ar_discount_renew(ref self: TContractState);

fn update_admin(ref self: TContractState, new_admin: ContractAddress);
}
8 changes: 0 additions & 8 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ mod Naming {
starknetid_contract: ContractAddress,
_pricing_contract: ContractAddress,
_referral_contract: ContractAddress,
_admin_address: ContractAddress,
_domain_data: LegacyMap<felt252, DomainData>,
_hash_to_domain: LegacyMap<(felt252, usize), felt252>,
_address_to_domain: LegacyMap<(ContractAddress, usize), felt252>,
Expand All @@ -155,7 +154,6 @@ mod Naming {
self.starknetid_contract.write(starknetid);
self._pricing_contract.write(pricing);
self._referral_contract.write(referral);
self._admin_address.write(admin);
self.ownable.initializer(admin);
}

Expand Down Expand Up @@ -709,12 +707,6 @@ mod Naming {

// ADMIN

fn update_admin(ref self: ContractState, new_admin: ContractAddress) {
assert(get_caller_address() == self._admin_address.read(), 'you are not admin');
self.ownable.initializer(new_admin);
self._admin_address.write(Zeroable::zero());
}

fn set_expiry(
ref self: ContractState, root_domain: felt252, expiry: u64
) {
Expand Down
14 changes: 0 additions & 14 deletions src/tests/naming/test_abuses.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,6 @@ fn test_renewal_period_too_long() {
naming.renew(th0rgal, 9130, ContractAddressZeroable::zero(), 0, 0);
}

#[test]
#[available_gas(2000000000)]
#[should_panic(expected: ('you are not admin', 'ENTRYPOINT_FAILED'))]
fn test_non_admin_cannot_set_admin() {
// setup
let (_, _, _, naming) = deploy();
let non_admin_address = contract_address_const::<0x456>();
set_contract_address(non_admin_address);

// A non-admin tries to set a new admin
let new_admin = contract_address_const::<0x789>();
naming.update_admin(new_admin);
}

#[test]
#[available_gas(2000000000)]
#[should_panic(expected: ('Caller is not the owner', 'ENTRYPOINT_FAILED'))]
Expand Down
28 changes: 20 additions & 8 deletions src/tests/naming/test_admin_update.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,28 @@ fn test_update_admin() {
let new_admin = contract_address_const::<0x456>();

let ownable2Step = IOwnableTwoStepDispatcher { contract_address: naming.contract_address };

// we call the update_admin function with the new admin
set_contract_address(admin);
naming.update_admin(new_admin);
assert(ownable2Step.owner() == new_admin, 'change of admin failed');
assert(ownable2Step.owner() == admin, 'admin not initialized');

// Now we go back to the first admin, this time using the ownable2Step
set_contract_address(new_admin);
ownable2Step.transfer_ownership(admin);
set_contract_address(admin);
ownable2Step.transfer_ownership(new_admin);
set_contract_address(new_admin);
ownable2Step.accept_ownership();
assert(ownable2Step.owner() == admin, 'change of admin failed');
assert(ownable2Step.owner() == new_admin, 'change of admin failed');
}


#[test]
#[available_gas(2000000000)]
#[should_panic(expected: ('Caller is not the owner', 'ENTRYPOINT_FAILED'))]
fn test_non_admin_cannot_set_admin() {
// setup
let (_, _, _, naming) = deploy();
let ownable2Step = IOwnableTwoStepDispatcher { contract_address: naming.contract_address };
let non_admin_address = contract_address_const::<0x456>();
set_contract_address(non_admin_address);

// A non-admin tries to set a new admin
let new_admin = contract_address_const::<0x789>();
ownable2Step.transfer_ownership(new_admin);
}

0 comments on commit 0c58006

Please sign in to comment.