Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolvers returning empty domains causing inverted results #65

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/naming/internal.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
72 changes: 57 additions & 15 deletions src/tests/naming/test_custom_resolver.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractState> {
fn resolve(
self: @ContractState, mut domain: Span<felt252>, field: felt252, hint: Span<felt252>
) -> 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);
Expand All @@ -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
Expand All @@ -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');
}
Loading