diff --git a/src/naming/internal.cairo b/src/naming/internal.cairo index ee374a0..624828e 100644 --- a/src/naming/internal.cairo +++ b/src/naming/internal.cairo @@ -152,8 +152,9 @@ impl InternalImpl of InternalTrait { .resolve(domain.slice(0, parent_start), field, hint); if resolver_res == 0 { let hashed_domain = self.hash_domain(domain); - return (0, hashed_domain); + return (hashed_domain, 0); } + // we skip computing the domain_hash if we already have a response return (0, resolver_res); } else { let hashed_domain = self.hash_domain(domain); diff --git a/src/naming/main.cairo b/src/naming/main.cairo index 4df93a7..be3cddf 100644 --- a/src/naming/main.cairo +++ b/src/naming/main.cairo @@ -704,9 +704,7 @@ mod Naming { self._admin_address.write(new_admin); } - fn set_expiry( - ref self: ContractState, root_domain: felt252, expiry: u64 - ) { + fn set_expiry(ref self: ContractState, root_domain: felt252, expiry: u64) { assert(get_caller_address() == self._admin_address.read(), 'you are not admin'); let hashed_domain = self.hash_domain(array![root_domain].span()); let domain_data = self._domain_data.read(hashed_domain); diff --git a/src/tests/naming/test_custom_resolver.cairo b/src/tests/naming/test_custom_resolver.cairo index 7381041..b063117 100644 --- a/src/tests/naming/test_custom_resolver.cairo +++ b/src/tests/naming/test_custom_resolver.cairo @@ -50,14 +50,32 @@ mod CustomResolver { } +#[starknet::contract] +mod EmptyCustomResolver { + use core::array::SpanTrait; + use naming::interface::resolver::IResolver; + + #[storage] + struct Storage {} + + + #[abi(embed_v0)] + impl AdditionResolveImpl of IResolver { + fn resolve( + self: @ContractState, mut domain: Span, field: felt252, hint: Span + ) -> felt252 { + 0 + } + } +} + + #[test] #[available_gas(2000000000)] fn test_custom_resolver() { // setup let (eth, pricing, identity, naming) = deploy(); - let custom_resolver = IERC20CamelDispatcher { - contract_address: utils::deploy(CustomResolver::TEST_CLASS_HASH, ArrayTrait::new()) - }; + let custom_resolver = utils::deploy(CustomResolver::TEST_CLASS_HASH, ArrayTrait::new()); let caller = contract_address_const::<0x123>(); set_contract_address(caller); @@ -73,17 +91,8 @@ fn test_custom_resolver() { // we allow the naming to take our money eth.approve(naming.contract_address, price); - // we buy with no resolver, no sponsor, no discount and empty metadata - naming - .buy( - id, - th0rgal, - 365, - custom_resolver.contract_address, - ContractAddressZeroable::zero(), - 0, - 0 - ); + // we buy with a custom resolver, no sponsor, no discount and empty metadata + naming.buy(id, th0rgal, 365, custom_resolver, ContractAddressZeroable::zero(), 0, 0); let domain = array![th0rgal].span(); // by default we should have nothing written @@ -92,9 +101,42 @@ fn test_custom_resolver() { assert(naming.domain_to_address(domain, array![].span()) == caller, 'wrong domain target'); let domain = array![1, 2, 3, th0rgal].span(); - let new_target = contract_address_const::<0x6>(); // let's try the resolving assert(naming.resolve(domain, 'starknet', array![].span()) == 1 + 2 + 3, 'wrong target'); assert(naming.domain_to_address(domain, array![].span()) == new_target, 'wrong target'); } + + +#[test] +#[available_gas(2000000000)] +fn test_empty_custom_resolver() { + // setup + let (eth, pricing, identity, naming) = deploy(); + let custom_resolver = utils::deploy(EmptyCustomResolver::TEST_CLASS_HASH, ArrayTrait::new()); + + let caller = contract_address_const::<0x123>(); + set_contract_address(caller); + let id: u128 = 1; + let th0rgal: felt252 = 33133781693; + + //we mint an id + identity.mint(id); + + // we check how much a domain costs + let (_, price) = pricing.compute_buy_price(7, 365); + + // we allow the naming to take our money + eth.approve(naming.contract_address, price); + + // we buy with a custom resolver, no sponsor, no discount and empty metadata + naming.buy(id, th0rgal, 365, custom_resolver, ContractAddressZeroable::zero(), 0, 0); + let domain = array![th0rgal].span(); + // by default we should have nothing written + assert(naming.resolve(domain, 'starknet', array![].span()) == 0, 'non empty starknet field'); + // so it should resolve to the starknetid owner + assert(naming.domain_to_address(domain, array![].span()) == caller, 'wrong domain target'); + let domain = array![1, th0rgal].span(); + // let's try the resolving + assert(naming.domain_to_address(domain, array![].span()).into() == 0, 'wrong target'); +}