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

[WIP] Adds reverse lookup support (primary name) #4

Merged
merged 16 commits into from
Jan 17, 2023
Merged
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
4 changes: 2 additions & 2 deletions core/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ aptos_names_funds = "0x78ee3915e67ef5d19fa91d1e05e60ae08751efd12ce58e23fc1109de8

[dependencies.AptosFramework]
git = 'https://github.com/aptos-labs/aptos-core.git'
rev = 'main'
rev = 'framework-mainnet'
subdir = 'aptos-move/framework/aptos-framework'

[dependencies.AptosToken]
git = 'https://github.com/aptos-labs/aptos-core.git'
rev = 'main'
rev = 'framework-mainnet'
subdir = 'aptos-move/framework/aptos-token'
116 changes: 116 additions & 0 deletions core/sources/domain_e2e_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ module aptos_names::domain_e2e_tests {
use aptos_names::time_helper;
use aptos_names::test_helper;
use aptos_names::test_utils;
use aptos_token::token;
use std::option;
use std::signer;
use std::string;
use std::vector;

#[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)]
Expand Down Expand Up @@ -125,6 +127,9 @@ module aptos_names::domain_e2e_tests {
// Lets try to register it again, now that it is expired
test_helper::register_name(rando, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 2, vector::empty<u8>());

// Reverse lookup for |user| should be none.
assert!(option::is_none(&domains::get_reverse_lookup(signer::address_of(user))), 85);

// And again!
let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name(option::none(), test_helper::domain_name());
timestamp::update_global_time_for_test_secs(expiration_time_sec + 5);
Expand Down Expand Up @@ -230,6 +235,7 @@ module aptos_names::domain_e2e_tests {
fun admin_can_force_seize_domain_name_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) {
let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation);
let user = vector::borrow(&users, 0);
let user_addr = signer::address_of(user);

// Register the domain
test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty<u8>());
Expand All @@ -244,6 +250,42 @@ module aptos_names::domain_e2e_tests {
// Ensure the expiration_time_sec is set to the new far future value
let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name(option::none(), test_helper::domain_name());
assert!(time_helper::seconds_to_years(expiration_time_sec) == 200, time_helper::seconds_to_years(expiration_time_sec));

// Ensure that the user's primary name is no longer set.
assert!(option::is_none(&domains::get_reverse_lookup(user_addr)), 1);
}

#[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)]
fun admin_force_seize_domain_name_doesnt_clear_unrelated_primary_name_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) {
let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation);
let user = vector::borrow(&users, 0);
let user_addr = signer::address_of(user);

// Register the domain. This will be the user's reverse lookup
{
test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty<u8>());
let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(user), option::none(), test_helper::domain_name());
assert!(is_owner, 1);
};

// Register another domain. This will **not** be the user's reverse lookup
let domain_name = string::utf8(b"sets");
let fq_domain_name = string::utf8(b"sets.apt");
test_helper::register_name(user, option::none(), domain_name, test_helper::one_year_secs(), fq_domain_name, 1, vector::empty<u8>());
let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(user), option::none(), domain_name);
assert!(is_owner, 1);

// Take the domain name for much longer than users are allowed to register it for
domains::force_create_or_seize_name(myself, option::none(), domain_name, test_helper::two_hundred_year_secs());
let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(myself), option::none(), domain_name);
assert!(is_owner, 2);

// Ensure the expiration_time_sec is set to the new far future value
let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name(option::none(), domain_name);
assert!(time_helper::seconds_to_years(expiration_time_sec) == 200, time_helper::seconds_to_years(expiration_time_sec));

// Ensure that the user's primary name is still set.
assert!(option::is_some(&domains::get_reverse_lookup(user_addr)), 1);
}

#[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)]
Expand Down Expand Up @@ -296,4 +338,78 @@ module aptos_names::domain_e2e_tests {
// Take the domain name for much longer than users are allowed to register it for
domains::force_create_or_seize_name(rando, option::none(), test_helper::domain_name(), test_helper::two_hundred_year_secs());
}

#[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)]
fun clear_name_happy_path_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) {
let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation);
let user = vector::borrow(&users, 0);
let user_addr = signer::address_of(user);

// Register the domain
test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty<u8>());

// Clear my reverse lookup.
domains::clear_reverse_lookup(user);

assert!(option::is_none(&domains::get_reverse_lookup(user_addr)), 1);
}

#[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)]
fun set_primary_name_after_transfer_clears_old_primary_name_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) {
let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation);
let user = vector::borrow(&users, 0);
let user_addr = signer::address_of(user);
let rando = vector::borrow(&users, 1);
let rando_addr = signer::address_of(rando);

// Register the domain
test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty<u8>());
let (is_owner, token_id) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name());
assert!(is_owner, 1);

// Transfer the domain to rando
token::direct_transfer(user, rando, token_id, 1);

// Verify primary name for |user| hasn't changed
assert!(option::is_some(&domains::get_reverse_lookup(user_addr)), 1);
assert!(*option::borrow(&domains::name_resolved_address(option::none(), test_helper::domain_name())) == user_addr, 1);

// |rando| sets his primary name
let subdomain_name_str = string::utf8(b"");
let domain_name_str = string::utf8(b"test");
domains::set_reverse_lookup_entry(rando, subdomain_name_str, domain_name_str);

// |user|'s primary name should be none.
assert!(option::is_none(&domains::get_reverse_lookup(user_addr)), 1);
assert!(*option::borrow(&domains::name_resolved_address(option::none(), test_helper::domain_name())) == rando_addr, 1);
}

#[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)]
fun set_target_address_after_transfer_clears_old_primary_name_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) {
let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation);
let user = vector::borrow(&users, 0);
let user_addr = signer::address_of(user);
let rando = vector::borrow(&users, 1);
let rando_addr = signer::address_of(rando);

// Register the domain
test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty<u8>());
let (is_owner, token_id) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name());
assert!(is_owner, 1);

// Transfer the domain to rando
token::direct_transfer(user, rando, token_id, 1);

// Verify primary name for |user| hasn't changed
assert!(option::is_some(&domains::get_reverse_lookup(user_addr)), 1);
assert!(*option::borrow(&domains::name_resolved_address(option::none(), test_helper::domain_name())) == user_addr, 1);

// |rando| sets target address
let domain_name_str = string::utf8(b"test");
domains::set_domain_address(rando, domain_name_str, rando_addr);

// |user|'s primary name should be none.
assert!(option::is_none(&domains::get_reverse_lookup(user_addr)), 1);
assert!(*option::borrow(&domains::name_resolved_address(option::none(), test_helper::domain_name())) == rando_addr, 1);
}
}
Loading