Skip to content

Commit

Permalink
Add owner check to get_primary_name
Browse files Browse the repository at this point in the history
  • Loading branch information
BriungRi committed Aug 5, 2024
1 parent eeaed6a commit 97f5dd4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core_v2/sources/v2_1_domains.move
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,10 @@ module aptos_names_v2_1::v2_1_domains {
if (option::is_none(&reverse_record.token_addr)) {
return option::none()
};
let record_obj = object::address_to_object<NameRecord>(*option::borrow(&reverse_record.token_addr));
if (!object::owns(record_obj, account_addr)) {
return option::none()
};
let token_addr = *option::borrow(&reverse_record.token_addr);
let record = borrow_global<NameRecord>(token_addr);

Expand Down
85 changes: 85 additions & 0 deletions router/sources/tests/primary_name_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,89 @@ module router::primary_name_tests {
assert!(option::is_none(&v2_primary_subdomain_name), 5);
};
}

#[test(
router = @router,
aptos_names = @aptos_names,
aptos_names_v2_1 = @aptos_names_v2_1,
user1 = @0x077,
user2 = @0x266f,
aptos = @0x1,
foundation = @0xf01d
)]
fun test_primary_name_expiration_and_reassignment(
router: &signer,
aptos_names: &signer,
aptos_names_v2_1: &signer,
user1: signer,
user2: signer,
aptos: signer,
foundation: signer
) {
router::init_module_for_test(router);

// Bump mode
router::set_mode(router, 1);

let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation);
let user1 = vector::borrow(&users, 0);
let user2 = vector::borrow(&users, 1);
let user1_addr = address_of(user1);
let user2_addr = address_of(user2);
let domain_name = utf8(b"test");
let subdomain_name = utf8(b"test");
let subdomain_name_opt = option::some(subdomain_name);

// Register with v1
router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none());

router::register_subdomain(
user1,
domain_name,
subdomain_name,
SECONDS_PER_YEAR,
0,
false,
option::none(),
option::none(),
);

router::set_primary_name(user1, domain_name, subdomain_name_opt);

// Expire the primary name
timestamp::update_global_time_for_test_secs(SECONDS_PER_YEAR + 1);

// Check that user1 no longer has a primary name
let (user1_primary_subdomain_name, user1_primary_domain_name) = get_v1_primary_name(user1_addr);
assert!(option::is_none(&user1_primary_domain_name), 1);
assert!(option::is_none(&user1_primary_subdomain_name), 2);

// Register with user2
router::register_domain(user2, domain_name, SECONDS_PER_YEAR, option::none(), option::none());

router::register_subdomain(
user2,
domain_name,
subdomain_name,
SECONDS_PER_YEAR,
0,
false,
option::none(),
option::none(),
);

router:set_primary_name(user2, domain_name, subdomain_name_opt);

// The primary name is no longer expired, so check again that user1 no
// longer has a primary name
let (user1_primary_subdomain_name, user1_primary_domain_name) =
get_v1_primary_name(user1_addr);
assert!(option::is_none(&user1_primary_domain_name), 1);
assert!(option::is_none(&user1_primary_subdomain_name), 2);

// Check that user2 has the primary name
let (user2_primary_subdomain_name, user2_primary_domain_name) = get_v1_primary_name(user2_addr);
assert!(option::some(domain_name) == user2_primary_domain_name, 3);
assert!(option::some(subdomain_name) == user2_primary_subdomain_name, 4);
}
}

0 comments on commit 97f5dd4

Please sign in to comment.