diff --git a/src/interface/naming.cairo b/src/interface/naming.cairo index 7f3cc42..73d2d64 100644 --- a/src/interface/naming.cairo +++ b/src/interface/naming.cairo @@ -47,6 +47,8 @@ trait INaming { fn reset_address_to_domain(ref self: TContractState); + fn set_domain_to_resolver(ref self: TContractState, domain: Span, resolver: ContractAddress); + // admin fn set_admin(ref self: TContractState, new_admin: ContractAddress); diff --git a/src/naming/main.cairo b/src/naming/main.cairo index 23e2659..b090e30 100644 --- a/src/naming/main.cairo +++ b/src/naming/main.cairo @@ -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, 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) { diff --git a/src/tests/naming/test_usecases.cairo b/src/tests/naming/test_usecases.cairo index 15b76c7..f063cb7 100644 --- a/src/tests/naming/test_usecases.cairo +++ b/src/tests/naming/test_usecases.cairo @@ -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'); +}