Skip to content

Commit

Permalink
feat: add set_domain_to_resolver function
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Nov 2, 2023
1 parent ca38e29 commit eb8c583
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/interface/naming.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ trait INaming<TContractState> {

fn reset_address_to_domain(ref self: TContractState);

fn set_domain_to_resolver(ref self: TContractState, domain: Span<felt252>, resolver: ContractAddress);

// admin
fn set_admin(ref self: TContractState, new_admin: ContractAddress);

Expand Down
20 changes: 20 additions & 0 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,26 @@ mod Naming {
self.set_address_to_domain_util(address, array![0].span());
}

fn set_domain_to_resolver(
ref self: ContractState, domain: Span<felt252>, resolver: ContractAddress
) {
self.assert_control_domain(domain, get_caller_address());

// Write domain owner
let hashed_domain = self.hash_domain(domain);
let current_domain_data = self._domain_data.read(hashed_domain);
let new_domain_data = DomainData {
owner: current_domain_data.owner,
resolver,
address: current_domain_data.address,
expiry: current_domain_data.expiry,
key: current_domain_data.key,
parent_key: current_domain_data.parent_key,
};
self._domain_data.write(hashed_domain, new_domain_data);
self.emit(Event::DomainResolverUpdate(DomainResolverUpdate { domain, resolver }));
}

// ADMIN

fn set_admin(ref self: ContractState, new_admin: ContractAddress) {
Expand Down
29 changes: 29 additions & 0 deletions src/tests/naming/test_usecases.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,32 @@ fn test_set_address_to_domain() {
let expect_domain1 = naming.address_to_domain(caller);
assert(expect_domain1 == first_domain, 'wrong rev resolving b');
}

#[test]
#[available_gas(2000000000)]
fn test_set_domain_to_resolver() {
// setup
let (eth, pricing, identity, naming) = deploy();
let caller = contract_address_const::<0x123>();
set_contract_address(caller);
let id1: u128 = 1;
let domain: felt252 = 82939898252385817;

//we mint the id
identity.mint(id1);

// buy the domain
let (_, price1) = pricing.compute_buy_price(11, 365);
eth.approve(naming.contract_address, price1);
naming
.buy(
id1, domain, 365, ContractAddressZeroable::zero(), ContractAddressZeroable::zero(), 0, 0
);

// set resolver
let resolver = contract_address_const::<0x456>();
naming.set_domain_to_resolver(array![domain].span(), resolver);

let data = naming.domain_to_data(array![domain].span());
assert(data.resolver == resolver, 'wrong resolver');
}

0 comments on commit eb8c583

Please sign in to comment.