diff --git a/bulk/sources/bulk.move b/bulk/sources/bulk.move index e6c01ee5..6112ad24 100644 --- a/bulk/sources/bulk.move +++ b/bulk/sources/bulk.move @@ -15,8 +15,7 @@ module bulk::bulk { /// Domains only public entry fun bulk_migrate_domain( - user: &signer, - domain_names: vector + user: &signer, domain_names: vector ) { let idx = 0; while (idx < vector::length(&domain_names)) { @@ -28,14 +27,11 @@ module bulk::bulk { /// Subdomains only public entry fun bulk_migrate_subdomain( - user: &signer, - domain_names: vector, - subdomain_names: vector>, + user: &signer, domain_names: vector, subdomain_names: vector>, ) { - assert!( - vector::length(&domain_names) == vector::length(&subdomain_names), - error::invalid_argument(EDOMAIN_AND_SUBDOMAIN_MUST_HAVE_SAME_LENGTH) - ); + assert!(vector::length(&domain_names) + == vector::length(&subdomain_names), + error::invalid_argument(EDOMAIN_AND_SUBDOMAIN_MUST_HAVE_SAME_LENGTH)); let idx = 0; while (idx < vector::length(&domain_names)) { let domain_name = *vector::borrow(&domain_names, idx); @@ -49,14 +45,11 @@ module bulk::bulk { /// Domains only public entry fun bulk_renew_domain( - user: &signer, - domain_names: vector, - renewal_duration_secs: vector, + user: &signer, domain_names: vector, renewal_duration_secs: vector, ) { - assert!( - vector::length(&domain_names) == vector::length(&renewal_duration_secs), - error::invalid_argument(EDOMAIN_AND_RENEWAL_DURATION_MUST_HAVE_SAME_LENGTH) - ); + assert!(vector::length(&domain_names) + == vector::length(&renewal_duration_secs), + error::invalid_argument(EDOMAIN_AND_RENEWAL_DURATION_MUST_HAVE_SAME_LENGTH)); let idx = 0; while (idx < vector::length(&domain_names)) { let domain_name = *vector::borrow(&domain_names, idx); @@ -94,16 +87,14 @@ module bulk::bulk { ) { let idx = 0; while (idx < vector::length(&domain_names)) { - router::register_subdomain( - domain_admin, + router::register_subdomain(domain_admin, *vector::borrow(&domain_names, idx), *vector::borrow(&subdomain_names, idx), *vector::borrow(&expiration_time_secs, idx), *vector::borrow(&expiration_policies, idx), *vector::borrow(&transferrable, idx), option::some(*vector::borrow(&target_addrs, idx)), - option::some(*vector::borrow(&to_addrs, idx)), - ); + option::some(*vector::borrow(&to_addrs, idx)),); idx = idx + 1 } } diff --git a/bulk/sources/bulk_tests.move b/bulk/sources/bulk_tests.move index 8625546f..5dc39c72 100644 --- a/bulk/sources/bulk_tests.move +++ b/bulk/sources/bulk_tests.move @@ -12,15 +12,7 @@ module bulk::bulk_tests { const MAX_MODE: u8 = 1; const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_bulk_migrate_happy_path( router: &signer, aptos_names: &signer, @@ -31,7 +23,9 @@ module bulk::bulk_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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 user1_addr = signer::address_of(user1); let domain_name1 = utf8(b"test1"); @@ -40,108 +34,77 @@ module bulk::bulk_tests { let subdomain_name_opt = option::some(subdomain_name); // Register with v1 - router::register_domain(user1, domain_name1, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_domain(user1, domain_name2, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user1, + router::register_domain(user1, domain_name1, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_domain(user1, domain_name2, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user1, domain_name1, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); - router::register_subdomain( - user1, + option::none(),); + router::register_subdomain(user1, domain_name2, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); // Bump mode router::set_mode(router, 1); - bulk_migrate_domain( - user1, - vector [ - domain_name1, - domain_name2, - ] - ); - bulk_migrate_subdomain( - user1, - vector [ - domain_name1, - domain_name2, - ], vector [ - subdomain_name_opt, - subdomain_name_opt, - ] - ); + bulk_migrate_domain(user1, vector[domain_name1, domain_name2,]); + bulk_migrate_subdomain(user1, + vector[domain_name1, domain_name2,], + vector[subdomain_name_opt, subdomain_name_opt,]); // Verify names no longer exist in v1 { - let (is_owner, _) = aptos_names::domains::is_owner_of_name(user1_addr, option::none(), domain_name1); + let (is_owner, _) = + aptos_names::domains::is_owner_of_name(user1_addr, option::none(), + domain_name1); assert!(!is_owner, 1); - let (is_owner, _) = aptos_names::domains::is_owner_of_name(user1_addr, subdomain_name_opt, domain_name1); + let (is_owner, _) = + aptos_names::domains::is_owner_of_name(user1_addr, subdomain_name_opt, + domain_name1); assert!(!is_owner, 2); - let (is_owner, _) = aptos_names::domains::is_owner_of_name(user1_addr, option::none(), domain_name2); + let (is_owner, _) = + aptos_names::domains::is_owner_of_name(user1_addr, option::none(), + domain_name2); assert!(!is_owner, 2); - let (is_owner, _) = aptos_names::domains::is_owner_of_name(user1_addr, subdomain_name_opt, domain_name2); + let (is_owner, _) = + aptos_names::domains::is_owner_of_name(user1_addr, subdomain_name_opt, + domain_name2); assert!(!is_owner, 2); }; // Verify names exist in v2 now { - assert!( - aptos_names_v2_1::v2_1_domains::is_token_owner( - user1_addr, - domain_name1, - option::none() - ) && !aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name1, option::none()), - 3 - ); - assert!( - aptos_names_v2_1::v2_1_domains::is_token_owner( - user1_addr, - domain_name1, - subdomain_name_opt, - ) && !aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name1, subdomain_name_opt), - 4 - ); - assert!( - aptos_names_v2_1::v2_1_domains::is_token_owner( - user1_addr, - domain_name2, - option::none() - ) && !aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name2, option::none()), - 3 - ); - assert!( - aptos_names_v2_1::v2_1_domains::is_token_owner( - user1_addr, - domain_name2, - subdomain_name_opt, - ) && !aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name2, subdomain_name_opt), - 4 - ); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user1_addr, domain_name1, + option::none()) && !aptos_names_v2_1::v2_1_domains::is_name_expired( + domain_name1, option::none()), + 3); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user1_addr, domain_name1, + subdomain_name_opt,) && !aptos_names_v2_1::v2_1_domains::is_name_expired( + domain_name1, subdomain_name_opt), + 4); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user1_addr, domain_name2, + option::none()) && !aptos_names_v2_1::v2_1_domains::is_name_expired( + domain_name2, option::none()), + 3); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user1_addr, domain_name2, + subdomain_name_opt,) && !aptos_names_v2_1::v2_1_domains::is_name_expired( + domain_name2, subdomain_name_opt), + 4); } } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_bulk_renew_happy_path( router: &signer, aptos_names: &signer, @@ -152,7 +115,9 @@ module bulk::bulk_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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 domain_name = utf8(b"test"); @@ -160,12 +125,13 @@ module bulk::bulk_tests { router::set_mode(router, 1); // Register with v2 - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Update time to 7 months later timestamp::update_global_time_for_test_secs(60 * 60 * 24 * 30 * 7); - bulk_renew_domain(user1, vector [ domain_name ], vector [ SECONDS_PER_YEAR ]); + bulk_renew_domain(user1, vector[domain_name], vector[SECONDS_PER_YEAR]); // Verify names new expiration let expiration = router::get_expiration(domain_name, option::none()); diff --git a/bulk_clear/sources/script.move b/bulk_clear/sources/script.move index bb1e0a7f..7e94caed 100644 --- a/bulk_clear/sources/script.move +++ b/bulk_clear/sources/script.move @@ -3,39 +3,13 @@ script { use std::string; fun main(admin: &signer) { - let names = vector [ - b"520", - b"eth", - b"ape", - b"314", - b"360", - b"crypto", - b"bacon", - b"dao", - b"xyz", - b"wallet", - b"defi", - b"art", - b"coffee", - b"neil", - b"cryptography", - b"god", - b"420", - b"hiking", - b"sports", - b"233", - b"111", - b"000", - b"hahaha", - b"666", - b"911", - b"abc", - b"get", - ]; + let names = vector[ + b"520", b"eth", b"ape", b"314", b"360", b"crypto", b"bacon", b"dao", b"xyz", b"wallet", b"defi", b"art", b"coffee", b"neil", b"cryptography", b"god", b"420", b"hiking", b"sports", b"233", b"111", b"000", b"hahaha", b"666", b"911", b"abc", b"get",]; while (!std::vector::is_empty(&names)) { let name = std::string::utf8(std::vector::pop_back(&mut names)); - aptos_names::domains::force_clear_registration(admin, option::none(), name); + aptos_names::domains::force_clear_registration(admin, + option::none(), name); } } } diff --git a/bulk_force_renewal/sources/script.move b/bulk_force_renewal/sources/script.move index 0ed7b29f..223cbcc1 100644 --- a/bulk_force_renewal/sources/script.move +++ b/bulk_force_renewal/sources/script.move @@ -5,20 +5,15 @@ script { const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; fun main(admin: &signer) { - let names = vector [ - b"name01", - b"name02", - ]; + let names = vector[b"name01", b"name02",]; let years_to_expire = 100; while (!std::vector::is_empty(&names)) { let name = std::string::utf8(std::vector::pop_back(&mut names)); - aptos_names_v2_1::v2_1_domains::force_set_name_expiration( - admin, + aptos_names_v2_1::v2_1_domains::force_set_name_expiration(admin, name, option::none(), - timestamp::now_seconds() + SECONDS_PER_YEAR * years_to_expire, - ) + timestamp::now_seconds() + SECONDS_PER_YEAR * years_to_expire,) } } } diff --git a/bulk_migrate/sources/script.move b/bulk_migrate/sources/script.move index 0ac7cdc7..501265e6 100644 --- a/bulk_migrate/sources/script.move +++ b/bulk_migrate/sources/script.move @@ -2,10 +2,7 @@ script { use std::string::utf8; fun main(user: &signer) { - let names = vector [ - utf8(b"name01"), - utf8(b"name02"), - ]; + let names = vector[utf8(b"name01"), utf8(b"name02"),]; bulk::bulk::bulk_migrate_domain(user, names); } diff --git a/core/sources/config.move b/core/sources/config.move index 592b00de..897db75a 100644 --- a/core/sources/config.move +++ b/core/sources/config.move @@ -51,10 +51,10 @@ module aptos_names::config { config: PropertyMap, } - public(friend) fun initialize_v1(framework: &signer, admin_address: address, fund_destination_address: address) acquires ConfigurationV1 { - move_to(framework, ConfigurationV1 { - config: property_map::empty(), - }); + public(friend) fun initialize_v1( + framework: &signer, admin_address: address, fund_destination_address: address + ) acquires ConfigurationV1 { + move_to(framework, ConfigurationV1 { config: property_map::empty(), }); // Temporarily set this to framework to allow other methods below to be set with framework signer set_v1(@aptos_names, config_key_admin_address(), &signer::address_of(framework)); @@ -66,8 +66,10 @@ module aptos_names::config { set_max_domain_length(framework, 63); // TODO: SET THIS TO SOMETHING REAL - set_tokendata_description(framework, string::utf8(b"This is an official Aptos Labs Name Service Name")); - set_tokendata_url_prefix(framework, string::utf8(b"https://www.aptosnames.com/api/mainnet/v1/metadata/")); + set_tokendata_description(framework, + string::utf8(b"This is an official Aptos Labs Name Service Name")); + set_tokendata_url_prefix(framework, + string::utf8(b"https://www.aptosnames.com/api/mainnet/v1/metadata/")); // 0.2 APT set_subdomain_price(framework, octas() / 5); @@ -77,7 +79,8 @@ module aptos_names::config { set_domain_price_for_length(framework, (5 * octas()), 6); // TODO: SET REAL VALUES FOR PUBLIC KEY AND UNRESTRICTED MINT ENABLED - let public_key = x"667a0687c3e7fc831366372667c11e4aa4502be09e7c99a5303711ce4f0b0fe2"; + let public_key = + x"667a0687c3e7fc831366372667c11e4aa4502be09e7c99a5303711ce4f0b0fe2"; set_captcha_public_key(framework, public_key); set_unrestricted_mint_enabled(framework, true); @@ -86,7 +89,6 @@ module aptos_names::config { set_v1(@aptos_names, config_key_admin_address(), &admin_address); } - // // Configuration Shortcuts // @@ -129,7 +131,8 @@ module aptos_names::config { /// The account will be used to manage names that are being used in a way that is harmful to others. /// Alternatively, the deployer can be used to perform admin actions. public fun signer_is_admin(sign: &signer): bool acquires ConfigurationV1 { - signer::address_of(sign) == admin_address() || signer::address_of(sign) == @aptos_names || signer::address_of(sign) == @router_signer + signer::address_of(sign) == admin_address() || signer::address_of(sign) == + @aptos_names || signer::address_of(sign) == @router_signer } public fun assert_signer_is_admin(sign: &signer) acquires ConfigurationV1 { @@ -175,13 +178,13 @@ module aptos_names::config { #[view] public fun reregistration_grace_sec(): u64 acquires ConfigurationV1 { let key = config_key_reregistration_grace_sec(); - let key_exists = property_map::contains_key(&borrow_global(@aptos_names).config, &key); + let key_exists = + property_map::contains_key(&borrow_global(@aptos_names).config, &key); if (key_exists) { read_u64_v1(@aptos_names, &key) } else { // Default to 0 if key DNE - 0 - } + 0 } } // @@ -206,7 +209,9 @@ module aptos_names::config { set_v1(@aptos_names, config_key_admin_address(), &addr) } - public entry fun set_max_number_of_years_registered(sign: &signer, max_years_registered: u8) acquires ConfigurationV1 { + public entry fun set_max_number_of_years_registered( + sign: &signer, max_years_registered: u8 + ) acquires ConfigurationV1 { assert_signer_is_admin(sign); assert!(max_years_registered > 0, error::invalid_argument(EINVALID_VALUE)); set_v1(@aptos_names, config_key_max_number_of_years_registered(), &max_years_registered) @@ -224,12 +229,16 @@ module aptos_names::config { set_v1(@aptos_names, config_key_min_domain_length(), &domain_length) } - public entry fun set_tokendata_description(sign: &signer, description: String) acquires ConfigurationV1 { + public entry fun set_tokendata_description( + sign: &signer, description: String + ) acquires ConfigurationV1 { assert_signer_is_admin(sign); set_v1(@aptos_names, config_key_tokendata_description(), &description) } - public entry fun set_tokendata_url_prefix(sign: &signer, description: String) acquires ConfigurationV1 { + public entry fun set_tokendata_url_prefix( + sign: &signer, description: String + ) acquires ConfigurationV1 { assert_signer_is_admin(sign); set_v1(@aptos_names, config_key_tokendata_url_prefix(), &description) } @@ -239,26 +248,36 @@ module aptos_names::config { set_v1(@aptos_names, config_key_subdomain_price(), &price) } - public entry fun set_domain_price_for_length(sign: &signer, price: u64, length: u64) acquires ConfigurationV1 { + public entry fun set_domain_price_for_length( + sign: &signer, price: u64, length: u64 + ) acquires ConfigurationV1 { assert_signer_is_admin(sign); assert!(price > 0, error::invalid_argument(EINVALID_VALUE)); assert!(length > 0, error::invalid_argument(EINVALID_VALUE)); set_v1(@aptos_names, config_key_domain_price(length), &price) } - public entry fun set_captcha_public_key(sign: &signer, public_key: vector) acquires ConfigurationV1 { + public entry fun set_captcha_public_key( + sign: &signer, public_key: vector + ) acquires ConfigurationV1 { assert_signer_is_admin(sign); - set_v1(@aptos_names, config_key_captcha_public_key(), &ed25519::new_unvalidated_public_key_from_bytes(public_key)); + set_v1(@aptos_names, + config_key_captcha_public_key(), + &ed25519::new_unvalidated_public_key_from_bytes(public_key)); } // set if we want to allow users to bypass signature verification // when unrestricted_mint_enabled == false, signature verification is required for registering a domain - public entry fun set_unrestricted_mint_enabled(sign: &signer, unrestricted_mint_enabled: bool) acquires ConfigurationV1 { + public entry fun set_unrestricted_mint_enabled( + sign: &signer, unrestricted_mint_enabled: bool + ) acquires ConfigurationV1 { assert_signer_is_admin(sign); set_v1(@aptos_names, config_key_unrestricted_mint_enabled(), &unrestricted_mint_enabled); } - public entry fun set_reregistration_grace_sec(sign: &signer, reregistration_grace_sec: u64) acquires ConfigurationV1 { + public entry fun set_reregistration_grace_sec( + sign: &signer, reregistration_grace_sec: u64 + ) acquires ConfigurationV1 { assert_signer_is_admin(sign); set_v1(@aptos_names, config_key_reregistration_grace_sec(), &reregistration_grace_sec); } @@ -368,7 +387,9 @@ module aptos_names::config { } public fun read_unvalidated_public_key(addr: address, key: &String): UnvalidatedPublicKey acquires ConfigurationV1 { - let value = property_map::borrow_value(property_map::borrow(&borrow_global(addr).config, key)); + let value = + property_map::borrow_value(property_map::borrow(&borrow_global( + addr).config, key)); // remove the length of this vector recorded at index 0 vector::remove(&mut value, 0); ed25519::new_unvalidated_public_key_from_bytes(value) @@ -389,7 +410,8 @@ module aptos_names::config { #[test_only] public fun initialize_aptoscoin_for(framework: &signer) { - let (burn_cap, mint_cap) = aptos_framework::aptos_coin::initialize_for_test(framework); + let (burn_cap, mint_cap) = aptos_framework::aptos_coin::initialize_for_test( + framework); coin::register(framework); coin::destroy_burn_cap(burn_cap); coin::destroy_mint_cap(mint_cap); @@ -475,10 +497,11 @@ module aptos_names::config { assert!(admin_address() == signer::address_of(rando), 6); } - #[test(myself = @aptos_names, rando = @0x266f, aptos = @0x1)] #[expected_failure(abort_code = 393218, location = aptos_framework::aptos_account)] - fun test_cant_set_foundation_address_without_coin(myself: &signer, rando: &signer, aptos: &signer) acquires ConfigurationV1 { + fun test_cant_set_foundation_address_without_coin( + myself: &signer, rando: &signer, aptos: &signer + ) acquires ConfigurationV1 { account::create_account_for_test(signer::address_of(myself)); account::create_account_for_test(signer::address_of(rando)); account::create_account_for_test(signer::address_of(aptos)); @@ -494,7 +517,9 @@ module aptos_names::config { #[test(myself = @aptos_names, rando = @0x266f, aptos = @0x1)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun test_foundation_config_requires_admin(myself: &signer, rando: &signer, aptos: &signer) acquires ConfigurationV1 { + fun test_foundation_config_requires_admin( + myself: &signer, rando: &signer, aptos: &signer + ) acquires ConfigurationV1 { account::create_account_for_test(signer::address_of(myself)); account::create_account_for_test(signer::address_of(rando)); account::create_account_for_test(signer::address_of(aptos)); @@ -508,7 +533,9 @@ module aptos_names::config { #[test(myself = @aptos_names, rando = @0x266f, aptos = @0x1)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun test_admin_config_requires_admin(myself: &signer, rando: &signer, aptos: &signer) acquires ConfigurationV1 { + fun test_admin_config_requires_admin( + myself: &signer, rando: &signer, aptos: &signer + ) acquires ConfigurationV1 { account::create_account_for_test(signer::address_of(myself)); account::create_account_for_test(signer::address_of(rando)); account::create_account_for_test(signer::address_of(aptos)); diff --git a/core/sources/domain_e2e_tests.move b/core/sources/domain_e2e_tests.move index ba306b10..cb2ad828 100644 --- a/core/sources/domain_e2e_tests.move +++ b/core/sources/domain_e2e_tests.move @@ -14,61 +14,99 @@ module aptos_names::domain_e2e_tests { use std::vector; #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun 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); + fun 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 rando = vector::borrow(&users, 1); 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Set an address and verify it - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), user_addr); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + user_addr); // Ensure the owner can clear the address test_helper::clear_name_address(user, option::none(), test_helper::domain_name()); // And also can clear if the user is the registered address, but not owner - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), signer::address_of(rando)); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + signer::address_of(rando)); test_helper::clear_name_address(rando, option::none(), test_helper::domain_name()); // Set it back for following tests - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), user_addr); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + user_addr); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun e2e_test_with_valid_signature(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { + fun e2e_test_with_valid_signature( + myself: &signer, + user: signer, + aptos: signer, + rando: signer, + foundation: signer + ) { /* - Signature generated with scripts/generateKeys.ts - yarn ts-node --compilerOptions '{"target": "es6", "module": "commonjs", "esModuleInterop": true}' ./scripts/generateKeys.ts - - let proof_struct = RegisterDomainProofChallenge { - account_address: AccountAddress::from_hex_literal(APTOS_NAMES).unwrap(), - module_name: String::from("verify"), - struct_name: String::from("RegisterDomainProofChallenge"), - sequence_number: 0, - register_address: *register_account.address(), - domain_name: String::from("test"), - chain_id: 4, - }; - */ - - let signature: vector = x"f004a92a27f962352456bb5b6728d4d37361d16b5932ed012f8f07bc94e3e73dbf38b643b6e16caa97ff313d48c8fe524325529b7c0e9abf7bd9d5183ff97a03"; + Signature generated with scripts/generateKeys.ts + yarn ts-node --compilerOptions '{"target": "es6", "module": "commonjs", "esModuleInterop": true}' ./scripts/generateKeys.ts + + let proof_struct = RegisterDomainProofChallenge { + account_address: AccountAddress::from_hex_literal(APTOS_NAMES).unwrap(), + module_name: String::from("verify"), + struct_name: String::from("RegisterDomainProofChallenge"), + sequence_number: 0, + register_address: *register_account.address(), + domain_name: String::from("test"), + chain_id: 4, + }; + */ + + let signature: vector = + x"f004a92a27f962352456bb5b6728d4d37361d16b5932ed012f8f07bc94e3e73dbf38b643b6e16caa97ff313d48c8fe524325529b7c0e9abf7bd9d5183ff97a03"; e2e_test_with_signature(myself, user, aptos, rando, foundation, signature); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 65537, location = aptos_names::verify)] - fun e2e_test_with_invalid_signature(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let signature: vector = x"2b0340b4529e3f90f0b1af7364241c51172c1133f0c077b7836962c3f104115832ccec0b74382533c33d9bd14a6e68021e5c23439242ddd43047e7929084ac01"; + fun e2e_test_with_invalid_signature( + myself: &signer, + user: signer, + aptos: signer, + rando: signer, + foundation: signer + ) { + let signature: vector = + x"2b0340b4529e3f90f0b1af7364241c51172c1133f0c077b7836962c3f104115832ccec0b74382533c33d9bd14a6e68021e5c23439242ddd43047e7929084ac01"; e2e_test_with_signature(myself, user, aptos, rando, foundation, signature); } #[test_only] - fun e2e_test_with_signature(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer, signature: vector) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun e2e_test_with_signature( + myself: &signer, + user: signer, + aptos: signer, + rando: signer, + foundation: signer, + signature: vector + ) { + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); @@ -78,367 +116,625 @@ module aptos_names::domain_e2e_tests { config::set_unrestricted_mint_enabled(myself, false); // 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, signature); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + signature); // Set an address and verify it - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), user_addr); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + user_addr); // Ensure the owner can clear the address test_helper::clear_name_address(user, option::none(), test_helper::domain_name()); // And also can clear if the user is the registered address, but not owner - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), signer::address_of(rando)); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + signer::address_of(rando)); test_helper::clear_name_address(rando, option::none(), test_helper::domain_name()); // Set it back for following tests - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), user_addr); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + user_addr); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327696, location = aptos_names::domains)] - fun test_register_domain_abort_with_disabled_unrestricted_mint(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun test_register_domain_abort_with_disabled_unrestricted_mint( + 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); chain_id::initialize_for_test(&aptos, 4); config::set_unrestricted_mint_enabled(myself, false); - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun names_are_registerable_after_expiry_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun names_are_registerable_after_expiry_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 rando = vector::borrow(&users, 1); // 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Set the time past the domain's expiration time - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name(option::none(), test_helper::domain_name()); + 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); // It should now be: expired, registered, AND registerable assert!(domains::name_is_expired(option::none(), test_helper::domain_name()), 80); - assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), 81); - assert!(domains::name_is_registerable(option::none(), test_helper::domain_name()), 82); + assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), + 81); + assert!(domains::name_is_registerable(option::none(), test_helper::domain_name()), + 82); // 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()); + test_helper::register_name(rando, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 2, + vector::empty()); // Reverse lookup for |user| should be none. - assert!(option::is_none(&domains::get_reverse_lookup(signer::address_of(user))), 85); + 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()); + 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); // It should now be: expired, registered, AND registerable assert!(domains::name_is_expired(option::none(), test_helper::domain_name()), 80); - assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), 81); - assert!(domains::name_is_registerable(option::none(), test_helper::domain_name()), 82); + assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), + 81); + assert!(domains::name_is_registerable(option::none(), test_helper::domain_name()), + 82); // 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(), 3, vector::empty()); + test_helper::register_name(rando, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 3, + vector::empty()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 196611, location = aptos_names::domains)] - fun dont_allow_double_domain_registrations_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun dont_allow_double_domain_registrations_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); // 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Ensure we can't register it again - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327689, location = aptos_names::domains)] - fun dont_allow_rando_to_set_domain_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun dont_allow_rando_to_set_domain_address_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 rando = vector::borrow(&users, 1); // 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Ensure we can't set it as a rando. The expected target address doesn't matter as it won't get hit - test_helper::set_name_address(rando, option::none(), test_helper::domain_name(), @aptos_names); + test_helper::set_name_address(rando, option::none(), test_helper::domain_name(), + @aptos_names); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327682, location = aptos_names::domains)] - fun dont_allow_rando_to_clear_domain_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun dont_allow_rando_to_clear_domain_address_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 rando = vector::borrow(&users, 1); // Register the domain, and set its address - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), signer::address_of(user)); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + signer::address_of(user)); // Ensure we can't clear it as a rando test_helper::clear_name_address(rando, option::none(), test_helper::domain_name()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun owner_can_clear_domain_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun owner_can_clear_domain_address_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 rando = vector::borrow(&users, 1); // Register the domain, and set its address - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), signer::address_of(rando)); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + signer::address_of(rando)); // Ensure we can clear as owner test_helper::clear_name_address(user, option::none(), test_helper::domain_name()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun admin_can_force_set_name_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun admin_can_force_set_name_address_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 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); domains::force_set_domain_address(myself, test_helper::domain_name(), rando_addr); - let (_property_version, _expiration_time_sec, target_address) = domains::get_name_record_v1_props_for_name(option::none(), test_helper::domain_name()); - test_utils::print_actual_expected(b"set_domain_address: ", target_address, option::some(rando_addr), false); + let (_property_version, _expiration_time_sec, target_address) = + domains::get_name_record_v1_props_for_name(option::none(), + test_helper::domain_name()); + test_utils::print_actual_expected(b"set_domain_address: ", target_address, + option::some(rando_addr), false); assert!(target_address == option::some(rando_addr), 33); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun rando_cant_force_set_name_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun rando_cant_force_set_name_address_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 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Rando is not allowed to do this domains::force_set_domain_address(rando, test_helper::domain_name(), rando_addr); } - #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - 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); + 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()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(user), option::none(), test_helper::domain_name()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(user), option::none(), + test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(user), option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(user), option::none(), + test_helper::domain_name()); assert!(is_owner, 1); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 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(), test_helper::domain_name(), test_helper::two_hundred_year_secs()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(myself), option::none(), test_helper::domain_name()); + domains::force_create_or_seize_name(myself, option::none(), + test_helper::domain_name(), test_helper::two_hundred_year_secs()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(myself), option::none(), + test_helper::domain_name()); assert!(is_owner, 2); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(myself), option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(myself), option::none(), + test_helper::domain_name()); assert!(is_owner, 2); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 1); // 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)); + 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); + 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()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(user), option::none(), test_helper::domain_name()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(user), option::none(), + test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(user), option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(user), option::none(), + test_helper::domain_name()); assert!(is_owner, 1); - assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 1); + assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), + 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()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(user), option::none(), domain_name); + test_helper::register_name(user, + option::none(), + domain_name, + test_helper::one_year_secs(), + fq_domain_name, + 1, + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(user), option::none(), domain_name); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(user), option::none(), domain_name); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(user), option::none(), domain_name); assert!(is_owner, 1); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 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); + 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, 1); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(myself), option::none(), domain_name); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(myself), option::none(), domain_name); assert!(is_owner, 2); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 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)); + 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)] - fun admin_can_force_create_domain_name_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let _ = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun admin_can_force_create_domain_name_e2e_test( + myself: &signer, + user: signer, + aptos: signer, + rando: signer, + foundation: signer + ) { + let _ = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); // No domain is registered yet - assert!(!domains::name_is_registered(option::none(), test_helper::domain_name()), 1); + assert!(!domains::name_is_registered(option::none(), test_helper::domain_name()), + 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(), test_helper::domain_name(), test_helper::two_hundred_year_secs()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(myself), option::none(), test_helper::domain_name()); + domains::force_create_or_seize_name(myself, option::none(), + test_helper::domain_name(), test_helper::two_hundred_year_secs()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(myself), option::none(), + test_helper::domain_name()); assert!(is_owner, 2); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(myself), option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(myself), option::none(), + test_helper::domain_name()); assert!(is_owner, 2); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 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(), test_helper::domain_name()); - assert!(time_helper::seconds_to_years(expiration_time_sec) == 200, time_helper::seconds_to_years(expiration_time_sec)); + 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)); // Try to nuke the domain assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), 3); domains::force_clear_registration(myself, option::none(), test_helper::domain_name()); - assert!(!domains::name_is_registered(option::none(), test_helper::domain_name()), 4); + assert!(!domains::name_is_registered(option::none(), test_helper::domain_name()), + 4); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun admin_can_force_set_expiration(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun admin_can_force_set_expiration( + 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); // Register the domain - test_helper::register_name( - user, + test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, - vector::empty() - ); + vector::empty()); { - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name( - option::none(), - test_helper::domain_name() - ); + 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) == 1, 1); }; - domains::force_set_expiration( - myself, - option::none(), - test_helper::domain_name(), - test_helper::two_hundred_year_secs() - ); + domains::force_set_expiration(myself, option::none(), test_helper::domain_name(), + test_helper::two_hundred_year_secs()); { - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name( - option::none(), - test_helper::domain_name() - ); + 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, 1); } } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun only_admin_can_force_set_expiration(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun only_admin_can_force_set_expiration( + 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); // Register the domain - test_helper::register_name( - user, + test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, - vector::empty() - ); + vector::empty()); { - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name( - option::none(), - test_helper::domain_name() - ); + 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) == 1, 1); }; // User can't force set - domains::force_set_expiration( - user, - option::none(), - test_helper::domain_name(), - test_helper::two_hundred_year_secs() - ); + domains::force_set_expiration(user, option::none(), test_helper::domain_name(), + test_helper::two_hundred_year_secs()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun rando_cant_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); + fun rando_cant_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 rando = vector::borrow(&users, 1); // 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()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(user), option::none(), test_helper::domain_name()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(user), option::none(), + test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(user), option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(user), option::none(), + test_helper::domain_name()); assert!(is_owner, 1); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 1); // 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()); + 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)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun rando_cant_force_create_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); + fun rando_cant_force_create_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 rando = vector::borrow(&users, 1); // No domain is registered yet - assert!(!domains::name_is_registered(option::none(), test_helper::domain_name()), 1); + assert!(!domains::name_is_registered(option::none(), test_helper::domain_name()), + 1); // 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()); + 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); + 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Clear my reverse lookup. domains::clear_reverse_lookup(user); @@ -447,18 +743,33 @@ module aptos_names::domain_e2e_tests { } #[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); + 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()); - let (is_owner, _) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + let (is_owner, _) = + domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, token_id) = domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, token_id) = + domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 1); @@ -467,7 +778,9 @@ module aptos_names::domain_e2e_tests { // 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); + 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""); @@ -476,22 +789,39 @@ module aptos_names::domain_e2e_tests { // |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); + 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); + 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()); - let (is_owner, _) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + let (is_owner, _) = + domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, token_id) = domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, token_id) = + domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 1); @@ -500,7 +830,9 @@ module aptos_names::domain_e2e_tests { // 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); + 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"); @@ -508,55 +840,92 @@ module aptos_names::domain_e2e_tests { // |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); + 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 owner_of_expired_name_is_not_owner(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun owner_of_expired_name_is_not_owner( + 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()); - let (is_owner, _token_id) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 1); // Set the time past the domain's expiration time - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name(option::none(), test_helper::domain_name()); + 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); - let (is_owner, _token_id) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); assert!(!is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); assert!(domains::name_is_expired(option::none(), test_helper::domain_name()), 2); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun test_nonregistered_record_expiry(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { + fun test_nonregistered_record_expiry( + myself: &signer, + user: signer, + aptos: signer, + rando: signer, + foundation: signer + ) { test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); // Non-registered domain should be expired { - let is_expired = domains::name_is_expired(option::none(), test_helper::domain_name()); + let is_expired = + domains::name_is_expired(option::none(), test_helper::domain_name()); assert!(is_expired, 1); }; // Non-registered subdomain should be expired { - let is_expired = domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()); + let is_expired = + domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_expired, 1); }; } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 196611, location = aptos_names::domains)] - fun test_register_during_reregistration_grace(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun test_register_during_reregistration_grace( + 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); @@ -564,48 +933,57 @@ module aptos_names::domain_e2e_tests { config::set_reregistration_grace_sec(myself, time_helper::days_to_seconds(30)); // Register the domain - test_helper::register_name( - user, + test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, - vector::empty() - ); - let (is_owner, _token_id) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 1); // Set the time right before the domain's expiration time + grace period - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name(option::none(), test_helper::domain_name()); + 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 + config::reregistration_grace_sec()); // Not owner anymore, name has expired - let (is_owner, _token_id) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); assert!(!is_owner, 1); // Is owner, but name has expired - let (is_owner, _token_id) = domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); assert!(domains::name_is_expired(option::none(), test_helper::domain_name()), 2); // Register the domain again. Should fail because it's still in the grace period - test_helper::register_name( - user, + test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 2, - vector::empty() - ); + vector::empty()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun test_register_after_reregistration_grace(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun test_register_after_reregistration_grace( + 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); @@ -613,61 +991,73 @@ module aptos_names::domain_e2e_tests { config::set_reregistration_grace_sec(myself, time_helper::days_to_seconds(30)); // Register the domain - test_helper::register_name( - user, + test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, - vector::empty() - ); - let (is_owner, _token_id) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); assert!(!domains::name_is_expired(option::none(), test_helper::domain_name()), 1); // Set the time past the domain's expiration time + grace period - 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 + config::reregistration_grace_sec() + 1); + 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 + config::reregistration_grace_sec() + + 1); // Not owner anymore, name has expired - let (is_owner, _token_id) = domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_owner_of_name(user_addr, option::none(), test_helper::domain_name()); assert!(!is_owner, 1); // Is owner but name has expired - let (is_owner, _token_id) = domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(user_addr, option::none(), test_helper::domain_name()); assert!(is_owner, 1); assert!(domains::name_is_expired(option::none(), test_helper::domain_name()), 2); // Register the domain again. Works because it's past the grace period - test_helper::register_name( - user, + test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 2, - vector::empty() - ); + vector::empty()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun clear_registration_property_version_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun clear_registration_property_version_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 i = 1; while (i < 10) { domains::register_domain(user, test_helper::domain_name(), 1); { - let (property_version, _expiration_time_sec, _target_address) = domains::get_name_record_v1_props_for_name(option::none(), test_helper::domain_name()); + let (property_version, _expiration_time_sec, _target_address) = + domains::get_name_record_v1_props_for_name(option::none(), + test_helper::domain_name()); // Property version should properly increment assert!(property_version == i, i); }; - domains::force_clear_registration(myself, option::none(), test_helper::domain_name()); + domains::force_clear_registration(myself, option::none(), + test_helper::domain_name()); i = i + 1; }; } - } diff --git a/core/sources/domains.move b/core/sources/domains.move index 83f9cb70..6248dd37 100644 --- a/core/sources/domains.move +++ b/core/sources/domains.move @@ -145,87 +145,82 @@ module aptos_names::domains { config::initialize_v1(account, admin_address, funds_address); - move_to( - account, - NameRegistryV1 { - registry: table::new(), - } - ); + move_to(account, NameRegistryV1 { registry: table::new(), }); - move_to(account, SetNameAddressEventsV1 { - set_name_events: account::new_event_handle(account), - }); + move_to(account, + SetNameAddressEventsV1 { + set_name_events: account::new_event_handle(account), + }); - move_to(account, RegisterNameEventsV1 { - register_name_events: account::new_event_handle(account), - }); + move_to(account, + RegisterNameEventsV1 { + register_name_events: account::new_event_handle(account), + }); token_helper::initialize(account); } public entry fun init_reverse_lookup_registry_v1(account: &signer) { - assert!(signer::address_of(account) == @aptos_names, error::permission_denied(ENOT_AUTHORIZED)); + assert!(signer::address_of(account) == @aptos_names, + error::permission_denied(ENOT_AUTHORIZED)); if (!exists(@aptos_names)) { - move_to(account, ReverseLookupRegistryV1 { - registry: table::new() - }); + move_to(account, ReverseLookupRegistryV1 { registry: table::new() }); - move_to(account, SetReverseLookupEventsV1 { - set_reverse_lookup_events: account::new_event_handle(account), - }); + move_to(account, + SetReverseLookupEventsV1 { + set_reverse_lookup_events: account::new_event_handle< + SetReverseLookupEventV1>(account), + }); }; } fun register_domain_generic( - sign: &signer, - domain_name: String, - num_years: u8 + sign: &signer, domain_name: String, num_years: u8 ) acquires NameRegistryV1, RegisterNameEventsV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { - assert!( - num_years > 0 && num_years <= config::max_number_of_years_registered(), - error::out_of_range(EINVALID_NUMBER_YEARS) - ); + assert!(num_years > 0 && num_years <= config::max_number_of_years_registered(), + error::out_of_range(EINVALID_NUMBER_YEARS)); let subdomain_name = option::none(); - assert!(name_is_registerable(subdomain_name, domain_name), error::invalid_state(ENAME_NOT_AVAILABLE)); + assert!(name_is_registerable(subdomain_name, domain_name), + error::invalid_state(ENAME_NOT_AVAILABLE)); // Conver the num_years to its seconds representation for the inner method - let registration_duration_secs: u64 = time_helper::years_to_seconds((num_years as u64)); + let registration_duration_secs: u64 = time_helper::years_to_seconds( + (num_years as u64)); let (is_valid, length) = utf8_utils::string_is_allowed(&domain_name); assert!(is_valid, error::invalid_argument(EDOMAIN_HAS_INVALID_CHARACTERS)); assert!(length <= config::max_domain_length(), error::out_of_range(EDOMAIN_TOO_LONG)); - assert!(length >= config::min_domain_length(), error::out_of_range(EDOMAIN_TOO_SHORT)); + assert!(length >= config::min_domain_length(), + error::out_of_range(EDOMAIN_TOO_SHORT)); let price = price_model::price_for_domain_v1(length, num_years); coin::transfer(sign, config::fund_destination_address(), price); - register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, price); + register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, + price); } /// A wrapper around `register_name` as an entry function. /// Option is not currently serializable, so we have these convenience methods public entry fun register_domain( - sign: &signer, - domain_name: String, - num_years: u8 + sign: &signer, domain_name: String, num_years: u8 ) acquires NameRegistryV1, RegisterNameEventsV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); - assert!(config::unrestricted_mint_enabled(), error::permission_denied(EVALID_SIGNATURE_REQUIRED)); + assert!(config::unrestricted_mint_enabled(), + error::permission_denied(EVALID_SIGNATURE_REQUIRED)); register_domain_generic(sign, domain_name, num_years); } public entry fun register_domain_with_signature( - sign: &signer, - domain_name: String, - num_years: u8, - signature: vector + sign: &signer, domain_name: String, num_years: u8, signature: vector ) acquires NameRegistryV1, RegisterNameEventsV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); let account_address = signer::address_of(sign); - verify::assert_register_domain_signature_verifies(signature, account_address, domain_name); + verify::assert_register_domain_signature_verifies(signature, account_address, + domain_name); register_domain_generic(sign, domain_name, num_years); } @@ -233,39 +228,38 @@ module aptos_names::domains { /// Option is not currently serializable, so we have these convenience method /// `expiration_time_sec` is the timestamp, in seconds, when the name expires public entry fun register_subdomain( - sign: &signer, - subdomain_name: String, - domain_name: String, - expiration_time_sec: u64 + sign: &signer, subdomain_name: String, domain_name: String, expiration_time_sec: u64 ) acquires NameRegistryV1, RegisterNameEventsV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); - assert!( - name_is_registerable(option::some(subdomain_name), domain_name), - error::invalid_state(ENAME_NOT_AVAILABLE) - ); + assert!(name_is_registerable(option::some(subdomain_name), domain_name), + error::invalid_state(ENAME_NOT_AVAILABLE)); // We are registering a subdomain name: this has no cost, but is only doable by the owner of the domain let (is_valid, length) = utf8_utils::string_is_allowed(&subdomain_name); assert!(is_valid, error::invalid_argument(ESUBDOMAIN_HAS_INVALID_CHARACTERS)); - assert!(length <= config::max_domain_length(), error::out_of_range(ESUBDOMAIN_TOO_LONG)); - assert!(length >= config::min_domain_length(), error::out_of_range(ESUBDOMAIN_TOO_SHORT)); + assert!(length <= config::max_domain_length(), + error::out_of_range(ESUBDOMAIN_TOO_LONG)); + assert!(length >= config::min_domain_length(), + error::out_of_range(ESUBDOMAIN_TOO_SHORT)); // Ensure signer owns the domain we're registering a subdomain for let signer_addr = signer::address_of(sign); let (is_owner, _) = is_token_owner(signer_addr, option::none(), domain_name); assert!(is_owner, error::permission_denied(ENOT_OWNER_OF_NAME)); - assert!( - !name_is_expired(option::none(), domain_name), - error::invalid_state(ECANNOT_REGISTER_SUBDOMAIN_WHILE_DOMAIN_IS_EXPIRED) - ); + assert!(!name_is_expired(option::none(), domain_name), + error::invalid_state(ECANNOT_REGISTER_SUBDOMAIN_WHILE_DOMAIN_IS_EXPIRED)); let registration_duration_secs = expiration_time_sec - timestamp::now_seconds(); let price = price_model::price_for_subdomain_v1(registration_duration_secs); coin::transfer(sign, config::fund_destination_address(), price); - register_name_internal(sign, option::some(subdomain_name), domain_name, registration_duration_secs, price); + register_name_internal(sign, + option::some(subdomain_name), + domain_name, + registration_duration_secs, + price); } /// Register a name. Accepts an optional subdomain name, a required domain name, and a registration duration in seconds. @@ -290,38 +284,36 @@ module aptos_names::domains { // if it is a subdomain, and it expires later than its domain, throw an error // This is done here so that any governance moderation activities must abide by the same invariant if (option::is_some(&subdomain_name)) { - let domain_name_record_key = create_name_record_key_v1(option::none(), domain_name); - let (_property_version, domain_expiration_time_sec, _target_address) = get_name_record_v1_props( - table::borrow(&aptos_names.registry, domain_name_record_key) - ); - assert!( - name_expiration_time_secs <= domain_expiration_time_sec, - error::out_of_range(ESUBDOMAIN_CAN_NOT_EXCEED_DOMAIN_REGISTRATION) - ); + let domain_name_record_key = create_name_record_key_v1(option::none(), + domain_name); + let (_property_version, domain_expiration_time_sec, _target_address) = + get_name_record_v1_props(table::borrow(&aptos_names.registry, + domain_name_record_key)); + assert!(name_expiration_time_secs <= domain_expiration_time_sec, + error::out_of_range(ESUBDOMAIN_CAN_NOT_EXCEED_DOMAIN_REGISTRATION)); }; // Create the token, and transfer it to the user - let tokendata_id = token_helper::ensure_token_data(subdomain_name, domain_name, config::domain_type()); + let tokendata_id = + token_helper::ensure_token_data(subdomain_name, domain_name, + config::domain_type()); let token_id = token_helper::create_token(tokendata_id); - - let (property_keys, property_values, property_types) = get_name_property_map( - subdomain_name, - name_expiration_time_secs - ); - token_id = token_helper::set_token_props( - token_helper::get_token_signer_address(), + let (property_keys, property_values, property_types) = + get_name_property_map(subdomain_name, name_expiration_time_secs); + token_id = token_helper::set_token_props(token_helper::get_token_signer_address(), property_keys, property_values, property_types, - token_id - ); + token_id); token_helper::transfer_token_to(sign, token_id); // Add this domain to the registry let (_creator, _collection, _name, property_version) = token::get_token_id_fields(&token_id); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); - let name_record = create_name_record_v1(property_version, name_expiration_time_secs, option::none()); + let name_record = + create_name_record_v1(property_version, name_expiration_time_secs, + option::none()); table::upsert(&mut aptos_names.registry, name_record_key, name_record); @@ -335,43 +327,34 @@ module aptos_names::domains { set_name_address_internal(subdomain_name, domain_name, signer::address_of(sign)); }; - event::emit_event( - &mut borrow_global_mut(@aptos_names).register_name_events, + event::emit_event(&mut borrow_global_mut( + @aptos_names).register_name_events, RegisterNameEventV1 { subdomain_name, domain_name, registration_fee_octas: price, property_version, expiration_time_secs: name_expiration_time_secs, - }, - ); + },); } /// Forcefully set the name of a domain. /// This is a privileged operation, used via governance, to forcefully set a domain address /// This can be used, for example, to forcefully set the domain for a system address domain public entry fun force_set_domain_address( - sign: &signer, - domain_name: String, - new_owner: address + sign: &signer, domain_name: String, new_owner: address ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { force_set_name_address(sign, option::none(), domain_name, new_owner); } public entry fun force_set_subdomain_address( - sign: &signer, - subdomain_name: String, - domain_name: String, - new_owner: address + sign: &signer, subdomain_name: String, domain_name: String, new_owner: address ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { force_set_name_address(sign, option::some(subdomain_name), domain_name, new_owner); } fun force_set_name_address( - sign: &signer, - subdomain_name: Option, - domain_name: String, - new_owner: address + sign: &signer, subdomain_name: Option, domain_name: String, new_owner: address ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { config::assert_signer_is_admin(sign); // If the domain name is a primary name, clear it. @@ -385,20 +368,18 @@ module aptos_names::domains { /// This allows, for example, to create a domain for the system address for 100 years so we don't need to worry about expiry /// Or for moderation purposes, it allows us to seize a racist/harassing domain for 100 years, and park it somewhere safe public entry fun force_create_or_seize_domain_name( - sign: &signer, - domain_name: String, - registration_duration_secs: u64 + sign: &signer, domain_name: String, registration_duration_secs: u64 ) acquires NameRegistryV1, RegisterNameEventsV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { - force_create_or_seize_name(sign, option::none(), domain_name, registration_duration_secs); + force_create_or_seize_name(sign, option::none(), domain_name, + registration_duration_secs); } public entry fun force_create_or_seize_subdomain_name( - sign: &signer, - subdomain_name: String, - domain_name: String, + sign: &signer, subdomain_name: String, domain_name: String, registration_duration_secs: u64 ) acquires NameRegistryV1, RegisterNameEventsV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { - force_create_or_seize_name(sign, option::some(subdomain_name), domain_name, registration_duration_secs); + force_create_or_seize_name(sign, option::some(subdomain_name), domain_name, + registration_duration_secs); } public fun force_create_or_seize_name( @@ -409,17 +390,17 @@ module aptos_names::domains { ) acquires NameRegistryV1, RegisterNameEventsV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { config::assert_signer_is_admin(sign); // Register the name - register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, 0); + register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, + 0); } public entry fun force_set_expiration( - sign: &signer, - subdomain_name: Option, - domain_name: String, + sign: &signer, subdomain_name: Option, domain_name: String, expiration_time_sec: u64 ) acquires NameRegistryV1 { config::assert_signer_is_admin(sign); - assert!(name_is_registered(subdomain_name, domain_name), error::not_found(ENAME_NOT_EXIST)); + assert!(name_is_registered(subdomain_name, domain_name), + error::not_found(ENAME_NOT_EXIST)); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); let aptos_names = borrow_global_mut(@aptos_names); let name_record = table::borrow_mut(&mut aptos_names.registry, name_record_key); @@ -430,9 +411,7 @@ module aptos_names::domains { /// This removes a name mapping from the registry; functionally this 'expires' it. /// This is a privileged operation, used via governance. public entry fun force_clear_registration( - sign: &signer, - subdomain_name: Option, - domain_name: String + sign: &signer, subdomain_name: Option, domain_name: String ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetReverseLookupEventsV1 { config::assert_signer_is_admin(sign); @@ -448,8 +427,7 @@ module aptos_names::domains { /// Clears the user's reverse lookup. public fun force_clear_reverse_lookup( - admin: &signer, - account_addr: address, + admin: &signer, account_addr: address, ) acquires ReverseLookupRegistryV1, SetReverseLookupEventsV1 { config::assert_signer_is_admin(admin); clear_reverse_lookup_internal(account_addr); @@ -459,7 +437,9 @@ module aptos_names::domains { /// Returns true if the name is available for registration /// if this is a subdomain, and the domain doesn't exist, returns false /// Doesn't use the `name_is_expired` or `name_is_registered` internally to share the borrow - public fun name_is_registerable(subdomain_name: Option, domain_name: String): bool acquires NameRegistryV1 { + public fun name_is_registerable( + subdomain_name: Option, domain_name: String + ): bool acquires NameRegistryV1 { // If this is a subdomain, ensure the domain also exists, and is not expired: i.e not registerable // So if the domain name is registerable, we return false, as the subdomain is not registerable if (option::is_some(&subdomain_name) && name_is_registerable(option::none(), domain_name)) { @@ -473,7 +453,8 @@ module aptos_names::domains { let aptos_names = borrow_global(@aptos_names); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); let name_record = table::borrow(&aptos_names.registry, name_record_key); - let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props(name_record); + let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props( + name_record); let now = timestamp::now_seconds(); if (expiration_time_sec > now) { // Name has not expired. It is not available. @@ -492,34 +473,40 @@ module aptos_names::domains { } /// Returns true if the name is not registered OR (is registered AND is expired) - public fun name_is_expired(subdomain_name: Option, domain_name: String): bool acquires NameRegistryV1 { - if (!name_is_registered(subdomain_name, domain_name)) { - true - } else { + public fun name_is_expired( + subdomain_name: Option, domain_name: String + ): bool acquires NameRegistryV1 { + if (!name_is_registered(subdomain_name, domain_name)) { true } + else { let aptos_names = borrow_global(@aptos_names); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); let name_record = table::borrow(&aptos_names.registry, name_record_key); - let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props(name_record); + let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props( + name_record); time_is_expired(expiration_time_sec) } } /// Returns true if the name is not registered OR (is registered AND is expired AND past grace period) - public fun name_is_expired_past_grace(subdomain_name: Option, domain_name: String): bool acquires NameRegistryV1 { - if (!name_is_registered(subdomain_name, domain_name)) { - true - } else { + public fun name_is_expired_past_grace( + subdomain_name: Option, domain_name: String + ): bool acquires NameRegistryV1 { + if (!name_is_registered(subdomain_name, domain_name)) { true } + else { let aptos_names = borrow_global(@aptos_names); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); let name_record = table::borrow(&aptos_names.registry, name_record_key); - let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props(name_record); + let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props( + name_record); time_is_expired(expiration_time_sec + config::reregistration_grace_sec()) } } /// Returns true if the name is registered /// If the name does not exist, returns false - public fun name_is_registered(subdomain_name: Option, domain_name: String): bool acquires NameRegistryV1 { + public fun name_is_registered( + subdomain_name: Option, domain_name: String + ): bool acquires NameRegistryV1 { let aptos_names = borrow_global(@aptos_names); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); table::contains(&aptos_names.registry, name_record_key) @@ -527,10 +514,10 @@ module aptos_names::domains { /// Given a domain and/or a subdomain, returns the name record public fun get_name_record_v1( - subdomain_name: Option, - domain_name: String + subdomain_name: Option, domain_name: String ): NameRecordV1 acquires NameRegistryV1 { - assert!(name_is_registered(subdomain_name, domain_name), error::not_found(ENAME_NOT_EXIST)); + assert!(name_is_registered(subdomain_name, domain_name), + error::not_found(ENAME_NOT_EXIST)); let aptos_names = borrow_global(@aptos_names); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); *table::borrow(&aptos_names.registry, name_record_key) @@ -538,10 +525,10 @@ module aptos_names::domains { /// Given a domain and/or a subdomain, returns the name record properties public fun get_name_record_v1_props_for_name( - subdomain_name: Option, - domain_name: String + subdomain_name: Option, domain_name: String ): (u64, u64, Option
) acquires NameRegistryV1 { - assert!(name_is_registered(subdomain_name, domain_name), error::not_found(ENAME_NOT_EXIST)); + assert!(name_is_registered(subdomain_name, domain_name), + error::not_found(ENAME_NOT_EXIST)); let aptos_names = borrow_global(@aptos_names); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); get_name_record_v1_props(table::borrow(&aptos_names.registry, name_record_key)) @@ -550,15 +537,11 @@ module aptos_names::domains { /// Returns (true, token_id) if owner_address ownes the name otherwise (false, __) /// Please use this one instead of is_owner_of_name public fun is_token_owner( - owner_address: address, - subdomain_name: Option, - domain_name: String + owner_address: address, subdomain_name: Option, domain_name: String ): (bool, TokenId) { - let token_data_id = token_helper::build_tokendata_id( - token_helper::get_token_signer_address(), - subdomain_name, - domain_name - ); + let token_data_id = + token_helper::build_tokendata_id(token_helper::get_token_signer_address(), + subdomain_name, domain_name); let token_id = token_helper::latest_token_id(&token_data_id); (token::balance_of(owner_address, token_id) > 0, token_id) } @@ -569,30 +552,28 @@ module aptos_names::domains { /// Check if the address is the owner of the given aptos_name /// If the name does not exist or owner owns an expired name, returns false public fun is_owner_of_name( - owner_address: address, - subdomain_name: Option, - domain_name: String + owner_address: address, subdomain_name: Option, domain_name: String ): (bool, TokenId) acquires NameRegistryV1 { - let token_data_id = token_helper::build_tokendata_id( - token_helper::get_token_signer_address(), - subdomain_name, - domain_name - ); + let token_data_id = + token_helper::build_tokendata_id(token_helper::get_token_signer_address(), + subdomain_name, domain_name); let token_id = token_helper::latest_token_id(&token_data_id); - (token::balance_of(owner_address, token_id) > 0 && !name_is_expired(subdomain_name, domain_name), token_id) + (token::balance_of(owner_address, token_id) > 0 && !name_is_expired(subdomain_name, + domain_name), + token_id) } /// gets the address pointed to by a given name /// Is `Option
` because the name may not be registered, or it may not have an address associated with it public fun name_resolved_address( - subdomain_name: Option, - domain_name: String + subdomain_name: Option, domain_name: String ): Option
acquires NameRegistryV1 { let aptos_names = borrow_global(@aptos_names); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); if (table::contains(&aptos_names.registry, name_record_key)) { let name_record = table::borrow(&aptos_names.registry, name_record_key); - let (_property_version, _expiration_time_sec, target_address) = get_name_record_v1_props(name_record); + let (_property_version, _expiration_time_sec, target_address) = get_name_record_v1_props( + name_record); target_address } else { option::none
() @@ -600,29 +581,21 @@ module aptos_names::domains { } public entry fun set_domain_address( - sign: &signer, - domain_name: String, - new_address: address + sign: &signer, domain_name: String, new_address: address ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); set_name_address(sign, option::none(), domain_name, new_address); } public entry fun set_subdomain_address( - sign: &signer, - subdomain_name: String, - domain_name: String, - new_address: address + sign: &signer, subdomain_name: String, domain_name: String, new_address: address ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); set_name_address(sign, option::some(subdomain_name), domain_name, new_address); } public fun set_name_address( - sign: &signer, - subdomain_name: Option, - domain_name: String, - new_address: address + sign: &signer, subdomain_name: Option, domain_name: String, new_address: address ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); // If the domain name is a primary name, clear it. @@ -633,15 +606,17 @@ module aptos_names::domains { assert!(is_owner, error::permission_denied(ENOT_OWNER_OF_NAME)); let (is_owner, token_id) = is_token_owner(signer_addr, subdomain_name, domain_name); assert!(is_owner, error::permission_denied(ENOT_OWNER_OF_NAME)); - assert!(!name_is_expired(subdomain_name, domain_name), error::invalid_state(ENAME_EXPIRED)); - - let name_record = set_name_address_internal(subdomain_name, domain_name, new_address); - let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props(&name_record); - let (property_keys, property_values, property_types) = get_name_property_map( - subdomain_name, - expiration_time_sec - ); - token_helper::set_token_props(signer_addr, property_keys, property_values, property_types, token_id); + assert!(!name_is_expired(subdomain_name, domain_name), + error::invalid_state(ENAME_EXPIRED)); + + let name_record = + set_name_address_internal(subdomain_name, domain_name, new_address); + let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props( + &name_record); + let (property_keys, property_values, property_types) = + get_name_property_map(subdomain_name, expiration_time_sec); + token_helper::set_token_props(signer_addr, property_keys, property_values, + property_types, token_id); // If the signer's reverse lookup is the domain, and the new address is not the signer, clear the signer's reverse lookup. // Example: @@ -649,9 +624,7 @@ module aptos_names::domains { // The owner wants to set bob.apt to point to @b. // The new state should be bob.apt points to @b, and the reverse lookup of @a should be none. let maybe_reverse_lookup = get_reverse_lookup(signer_addr); - if (option::is_none(&maybe_reverse_lookup)) { - return - }; + if (option::is_none(&maybe_reverse_lookup)) { return }; let current_reverse_lookup = option::borrow(&maybe_reverse_lookup); let key = NameRecordKeyV1 { subdomain_name, domain_name }; if (*current_reverse_lookup == key && signer_addr != new_address) { @@ -660,38 +633,31 @@ module aptos_names::domains { } fun set_name_address_internal( - subdomain_name: Option, - domain_name: String, - new_address: address + subdomain_name: Option, domain_name: String, new_address: address ): NameRecordV1 acquires NameRegistryV1, SetNameAddressEventsV1 { - assert!(name_is_registered(subdomain_name, domain_name), error::not_found(ENAME_NOT_EXIST)); + assert!(name_is_registered(subdomain_name, domain_name), + error::not_found(ENAME_NOT_EXIST)); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); let aptos_names = borrow_global_mut(@aptos_names); let name_record = table::borrow_mut(&mut aptos_names.registry, name_record_key); - let (property_version, expiration_time_sec, _target_address) = get_name_record_v1_props(name_record); + let (property_version, expiration_time_sec, _target_address) = get_name_record_v1_props( + name_record); name_record.target_address = option::some(new_address); - emit_set_name_address_event_v1( - subdomain_name, + emit_set_name_address_event_v1(subdomain_name, domain_name, property_version, expiration_time_sec, - option::some(new_address), - ); + option::some(new_address),); *name_record } - public entry fun clear_domain_address( - sign: &signer, - domain_name: String - ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { + public entry fun clear_domain_address(sign: &signer, domain_name: String) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); clear_name_address(sign, option::none(), domain_name); } public entry fun clear_subdomain_address( - sign: &signer, - subdomain_name: String, - domain_name: String + sign: &signer, subdomain_name: String, domain_name: String ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); clear_name_address(sign, option::some(subdomain_name), domain_name); @@ -700,12 +666,11 @@ module aptos_names::domains { /// This is a shared entry point for clearing the address of a domain or subdomain /// It enforces owner permissions public fun clear_name_address( - sign: &signer, - subdomain_name: Option, - domain_name: String + sign: &signer, subdomain_name: Option, domain_name: String ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(sign), error::unavailable(ENOT_ENABLED)); - assert!(name_is_registered(subdomain_name, domain_name), error::not_found(ENAME_NOT_EXIST)); + assert!(name_is_registered(subdomain_name, domain_name), + error::not_found(ENAME_NOT_EXIST)); let signer_addr = signer::address_of(sign); @@ -720,62 +685,56 @@ module aptos_names::domains { // Only the owner or the registered address can clear the address let (is_owner, token_id) = is_token_owner(signer_addr, subdomain_name, domain_name); - let is_name_resolved_address = name_resolved_address(subdomain_name, domain_name) == option::some
( - signer_addr - ); + let is_name_resolved_address = + name_resolved_address(subdomain_name, domain_name) + == option::some
(signer_addr); - assert!( - (is_owner && !name_is_expired(subdomain_name, domain_name)) || is_name_resolved_address, - error::permission_denied(ENOT_AUTHORIZED) - ); + assert!((is_owner && !name_is_expired(subdomain_name, domain_name)) + || is_name_resolved_address, + error::permission_denied(ENOT_AUTHORIZED)); let name_record_key = create_name_record_key_v1(subdomain_name, domain_name); let aptos_names = borrow_global_mut(@aptos_names); let name_record = table::borrow_mut(&mut aptos_names.registry, name_record_key); - let (property_version, expiration_time_sec, _target_address) = get_name_record_v1_props(name_record); + let (property_version, expiration_time_sec, _target_address) = get_name_record_v1_props( + name_record); name_record.target_address = option::none(); - emit_set_name_address_event_v1( - subdomain_name, + emit_set_name_address_event_v1(subdomain_name, domain_name, property_version, expiration_time_sec, - option::none(), - ); + option::none(),); if (is_owner) { - let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props(name_record); - let (property_keys, property_values, property_types) = get_name_property_map( - subdomain_name, - expiration_time_sec - ); - token_helper::set_token_props(signer_addr, property_keys, property_values, property_types, token_id); + let (_property_version, expiration_time_sec, _target_address) = get_name_record_v1_props( + name_record); + let (property_keys, property_values, property_types) = + get_name_property_map(subdomain_name, expiration_time_sec); + token_helper::set_token_props(signer_addr, property_keys, property_values, + property_types, token_id); }; } /// Entry function for |set_reverse_lookup|. public entry fun set_reverse_lookup_entry( - account: &signer, - subdomain_name: String, - domain_name: String + account: &signer, subdomain_name: String, domain_name: String ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(account), error::unavailable(ENOT_ENABLED)); - let key = NameRecordKeyV1 { - subdomain_name: if (string::length(&subdomain_name) > 0) { - option::some(subdomain_name) - } else { - option::none() - }, - domain_name - }; + let key = + NameRecordKeyV1 { + subdomain_name: if (string::length(&subdomain_name) > 0) { + option::some(subdomain_name) + } else { + option::none() + }, + domain_name + }; set_reverse_lookup(account, &key); } /// Sets the |account|'s reverse lookup, aka "primary name". This allows a user to specify which of their Aptos Names /// is their "primary", so that dapps can display the user's primary name rather than their address. - public fun set_reverse_lookup( - account: &signer, - key: &NameRecordKeyV1 - ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { + public fun set_reverse_lookup(account: &signer, key: &NameRecordKeyV1) acquires NameRegistryV1, ReverseLookupRegistryV1, SetNameAddressEventsV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(account), error::unavailable(ENOT_ENABLED)); let account_addr = signer::address_of(account); let (maybe_subdomain_name, domain_name) = get_name_record_key_v1_props(key); @@ -784,9 +743,7 @@ module aptos_names::domains { } /// Entry function for clearing reverse lookup. - public entry fun clear_reverse_lookup_entry( - account: &signer - ) acquires ReverseLookupRegistryV1, SetReverseLookupEventsV1 { + public entry fun clear_reverse_lookup_entry(account: &signer) acquires ReverseLookupRegistryV1, SetReverseLookupEventsV1 { assert!(config::is_enabled_for_nonadmin(account), error::unavailable(ENOT_ENABLED)); clear_reverse_lookup(account); } @@ -800,8 +757,10 @@ module aptos_names::domains { /// Returns the reverse lookup for an address if any. public fun get_reverse_lookup(account_addr: address): Option acquires ReverseLookupRegistryV1 { - assert!(exists(@aptos_names), error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); - let registry = &borrow_global_mut(@aptos_names).registry; + assert!(exists(@aptos_names), + error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); + let registry = + &borrow_global_mut(@aptos_names).registry; if (table::contains(registry, account_addr)) { option::some(*table::borrow(registry, account_addr)) } else { @@ -809,56 +768,45 @@ module aptos_names::domains { } } - fun set_reverse_lookup_internal( - account: &signer, - key: &NameRecordKeyV1 - ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetReverseLookupEventsV1 { + fun set_reverse_lookup_internal(account: &signer, key: &NameRecordKeyV1) acquires NameRegistryV1, ReverseLookupRegistryV1, SetReverseLookupEventsV1 { let account_addr = signer::address_of(account); let (maybe_subdomain_name, domain_name) = get_name_record_key_v1_props(key); let (is_owner, _) = is_token_owner(account_addr, maybe_subdomain_name, domain_name); assert!(is_owner, error::permission_denied(ENOT_AUTHORIZED)); - assert!(!name_is_expired(maybe_subdomain_name, domain_name), error::invalid_state(ENAME_EXPIRED)); - assert!(exists(@aptos_names), error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); - let registry = &mut borrow_global_mut(@aptos_names).registry; + assert!(!name_is_expired(maybe_subdomain_name, domain_name), + error::invalid_state(ENAME_EXPIRED)); + assert!(exists(@aptos_names), + error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); + let registry = + &mut borrow_global_mut(@aptos_names).registry; table::upsert(registry, account_addr, *key); - emit_set_reverse_lookup_event_v1( - maybe_subdomain_name, - domain_name, - option::some(account_addr) - ); + emit_set_reverse_lookup_event_v1(maybe_subdomain_name, domain_name, + option::some(account_addr)); } - fun clear_reverse_lookup_internal( - account_addr: address - ) acquires ReverseLookupRegistryV1, SetReverseLookupEventsV1 { + fun clear_reverse_lookup_internal(account_addr: address) acquires ReverseLookupRegistryV1, SetReverseLookupEventsV1 { let maybe_reverse_lookup = get_reverse_lookup(account_addr); - if (option::is_none(&maybe_reverse_lookup)) { - return - }; + if (option::is_none(&maybe_reverse_lookup)) { return }; let NameRecordKeyV1 { subdomain_name, domain_name } = option::borrow(&maybe_reverse_lookup); - assert!(exists(@aptos_names), error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); - let registry = &mut borrow_global_mut(@aptos_names).registry; + assert!(exists(@aptos_names), + error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); + let registry = + &mut borrow_global_mut(@aptos_names).registry; table::remove(registry, account_addr); - emit_set_reverse_lookup_event_v1( - *subdomain_name, - *domain_name, - option::none() - ); + emit_set_reverse_lookup_event_v1(*subdomain_name, *domain_name, option::none()); } fun clear_reverse_lookup_for_name( - subdomain_name: Option, - domain_name: String + subdomain_name: Option, domain_name: String ) acquires NameRegistryV1, ReverseLookupRegistryV1, SetReverseLookupEventsV1 { // If the name is a primary name, clear it let maybe_target_address = name_resolved_address(subdomain_name, domain_name); if (option::is_some(&maybe_target_address)) { let target_address = option::borrow(&maybe_target_address); let maybe_reverse_lookup = get_reverse_lookup(*target_address); - if (option::is_some( - &maybe_reverse_lookup - ) && NameRecordKeyV1 { subdomain_name, domain_name } == *option::borrow(&maybe_reverse_lookup)) { + if (option::is_some(&maybe_reverse_lookup) && NameRecordKeyV1 { subdomain_name, domain_name } + == *option::borrow(&maybe_reverse_lookup)) { clear_reverse_lookup_internal(*target_address); }; }; @@ -871,41 +819,34 @@ module aptos_names::domains { expiration_time_secs: u64, new_address: Option
) acquires SetNameAddressEventsV1 { - let event = SetNameAddressEventV1 { - subdomain_name, - domain_name, - property_version, - expiration_time_secs, - new_address, - }; + let event = + SetNameAddressEventV1 { + subdomain_name, + domain_name, + property_version, + expiration_time_secs, + new_address, + }; - event::emit_event( - &mut borrow_global_mut(@aptos_names).set_name_events, - event, - ); + event::emit_event(&mut borrow_global_mut< + SetNameAddressEventsV1>(@aptos_names).set_name_events, event,); } fun emit_set_reverse_lookup_event_v1( - subdomain_name: Option, - domain_name: String, - target_address: Option
+ subdomain_name: Option, domain_name: String, target_address: Option
) acquires SetReverseLookupEventsV1 { - let event = SetReverseLookupEventV1 { - subdomain_name, - domain_name, - target_address, - }; + let event = + SetReverseLookupEventV1 { subdomain_name, domain_name, target_address, }; - assert!(exists(@aptos_names), error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); - event::emit_event( - &mut borrow_global_mut(@aptos_names).set_reverse_lookup_events, - event, - ); + assert!(exists(@aptos_names), + error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); + event::emit_event(&mut borrow_global_mut< + SetReverseLookupEventsV1>(@aptos_names).set_reverse_lookup_events, + event,); } public fun get_name_property_map( - subdomain_name: Option, - expiration_time_sec: u64 + subdomain_name: Option, expiration_time_sec: u64 ): (vector, vector>, vector) { let type; if (option::is_some(&subdomain_name)) { @@ -916,36 +857,30 @@ module aptos_names::domains { let expiration_time_sec = property_map::create_property_value(&expiration_time_sec); let property_keys: vector = vector[config::config_key_type(), config::config_key_expiration_time_sec()]; - let property_values: vector> = vector[ property_map::borrow_value(&type), property_map::borrow_value( - &expiration_time_sec - )]; - let property_types: vector = vector[property_map::borrow_type(&type), property_map::borrow_type( - &expiration_time_sec - )]; + let property_values: vector> = vector[ + property_map::borrow_value(&type), + property_map::borrow_value(&expiration_time_sec)]; + let property_types: vector = vector[ + property_map::borrow_type(&type), + property_map::borrow_type(&expiration_time_sec)]; (property_keys, property_values, property_types) } public fun create_name_record_v1( - property_version: u64, - expiration_time_sec: u64, - target_address: Option
+ property_version: u64, expiration_time_sec: u64, target_address: Option
): NameRecordV1 { - NameRecordV1 { - property_version, - expiration_time_sec, - target_address, - } + NameRecordV1 { property_version, expiration_time_sec, target_address, } } - public fun get_name_record_v1_props(name_record: &NameRecordV1): (u64, u64, Option
) { + public fun get_name_record_v1_props(name_record: &NameRecordV1) + : (u64, u64, Option
) { (name_record.property_version, name_record.expiration_time_sec, name_record.target_address) } - public fun create_name_record_key_v1(subdomain_name: Option, domain_name: String): NameRecordKeyV1 { - NameRecordKeyV1 { - subdomain_name, - domain_name, - } + public fun create_name_record_key_v1( + subdomain_name: Option, domain_name: String + ): NameRecordKeyV1 { + NameRecordKeyV1 { subdomain_name, domain_name, } } /// Given a time, returns true if that time is in the past, false otherwise @@ -953,7 +888,9 @@ module aptos_names::domains { timestamp::now_seconds() >= expiration_time_sec } - public fun get_name_record_key_v1_props(name_record_key: &NameRecordKeyV1): (Option, String) { + public fun get_name_record_key_v1_props( + name_record_key: &NameRecordKeyV1 + ): (Option, String) { (name_record_key.subdomain_name, name_record_key.domain_name) } @@ -975,7 +912,8 @@ module aptos_names::domains { #[test_only] public fun get_set_reverse_lookup_event_v1_count(): u64 acquires SetReverseLookupEventsV1 { - assert!(exists(@aptos_names), error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); + assert!(exists(@aptos_names), + error::invalid_state(EREVERSE_LOOKUP_NOT_INITIALIZED)); event::counter(&borrow_global(@aptos_names).set_reverse_lookup_events) } diff --git a/core/sources/is_enabled_tests.move b/core/sources/is_enabled_tests.move index 902e1f0f..2eb55dd1 100644 --- a/core/sources/is_enabled_tests.move +++ b/core/sources/is_enabled_tests.move @@ -17,7 +17,8 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Disable ANS @@ -36,7 +37,8 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Disable ANS @@ -48,8 +50,7 @@ module aptos_names::is_enabled_tests { user, test_helper::domain_name(), 1, - x"f004a92a27f962352456bb5b6728d4d37361d16b5932ed012f8f07bc94e3e73dbf38b643b6e16caa97ff313d48c8fe524325529b7c0e9abf7bd9d5183ff97a03" - ); + x"f004a92a27f962352456bb5b6728d4d37361d16b5932ed012f8f07bc94e3e73dbf38b643b6e16caa97ff313d48c8fe524325529b7c0e9abf7bd9d5183ff97a03"); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] @@ -61,19 +62,16 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Disable ANS config::set_is_enabled(myself, false); // Register the subdomain fails - domains::register_subdomain( - user, - test_helper::subdomain_name(), - test_helper::domain_name(), - 1, - ); + domains::register_subdomain(user, test_helper::subdomain_name(), + test_helper::domain_name(), 1,); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] @@ -85,7 +83,8 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user2 = vector::borrow(&users, 1); @@ -96,7 +95,8 @@ module aptos_names::is_enabled_tests { config::set_is_enabled(myself, false); // Should not be able to set address because ANS write is disabled - domains::set_domain_address(user, test_helper::domain_name(), signer::address_of(user2)) + domains::set_domain_address(user, test_helper::domain_name(), + signer::address_of(user2)) } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] @@ -108,29 +108,22 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user2 = vector::borrow(&users, 1); // Register the domain succeeds domains::register_domain(user, test_helper::domain_name(), 1); - domains::register_subdomain( - user, - test_helper::subdomain_name(), - test_helper::domain_name(), - 1, - ); + domains::register_subdomain(user, test_helper::subdomain_name(), + test_helper::domain_name(), 1,); // Disable ANS write config::set_is_enabled(myself, false); // Should not be able to set address because ANS write is disabled - domains::set_subdomain_address( - user, - test_helper::subdomain_name(), - test_helper::domain_name(), - signer::address_of(user2) - ) + domains::set_subdomain_address(user, test_helper::subdomain_name(), + test_helper::domain_name(), signer::address_of(user2)) } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] @@ -142,12 +135,14 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain succeeds domains::register_domain(user, test_helper::domain_name(), 1); - domains::set_domain_address(user, test_helper::domain_name(), signer::address_of(user)); + domains::set_domain_address(user, test_helper::domain_name(), + signer::address_of(user)); // Disable ANS write config::set_is_enabled(myself, false); @@ -165,28 +160,22 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain succeeds domains::register_domain(user, test_helper::domain_name(), 1); - domains::register_subdomain( - user, - test_helper::subdomain_name(), - test_helper::domain_name(), - 1, - ); - domains::set_subdomain_address( - user, - test_helper::subdomain_name(), - test_helper::domain_name(), - signer::address_of(user) - ); + domains::register_subdomain(user, test_helper::subdomain_name(), + test_helper::domain_name(), 1,); + domains::set_subdomain_address(user, test_helper::subdomain_name(), + test_helper::domain_name(), signer::address_of(user)); // Disable ANS write config::set_is_enabled(myself, false); // Should not be able to clear address because ANS write is disabled - domains::clear_subdomain_address(user, test_helper::subdomain_name(), test_helper::domain_name()) + domains::clear_subdomain_address(user, test_helper::subdomain_name(), + test_helper::domain_name()) } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] @@ -198,18 +187,21 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain succeeds domains::register_domain(user, test_helper::domain_name(), 1); - domains::set_reverse_lookup_entry(user, string::utf8(b""), test_helper::domain_name()); + domains::set_reverse_lookup_entry(user, string::utf8(b""), + test_helper::domain_name()); // Disable ANS write config::set_is_enabled(myself, false); // Should not be able to set primary name because ANS write is disabled - domains::set_reverse_lookup_entry(user, string::utf8(b""), test_helper::domain_name()); + domains::set_reverse_lookup_entry(user, string::utf8(b""), + test_helper::domain_name()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] @@ -221,18 +213,16 @@ module aptos_names::is_enabled_tests { rando: signer, foundation: signer ) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + let users = + test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain succeeds domains::register_domain(user, test_helper::domain_name(), 1); - domains::register_subdomain( - user, - test_helper::subdomain_name(), - test_helper::domain_name(), - 1, - ); - domains::set_reverse_lookup_entry(user, string::utf8(b""), test_helper::domain_name()); + domains::register_subdomain(user, test_helper::subdomain_name(), + test_helper::domain_name(), 1,); + domains::set_reverse_lookup_entry(user, string::utf8(b""), + test_helper::domain_name()); // Disable ANS write config::set_is_enabled(myself, false); diff --git a/core/sources/price_model.move b/core/sources/price_model.move index 3f799f3b..b3b163fb 100644 --- a/core/sources/price_model.move +++ b/core/sources/price_model.move @@ -3,7 +3,6 @@ module aptos_names::price_model { use aptos_std::math64; use std::error; - /// The domain length is too short- currently the minimum is 2 characters const EDOMAIN_TOO_SHORT: u64 = 1; @@ -27,7 +26,8 @@ module aptos_names::price_model { public fun price_for_domain_v1(domain_length: u64, registration_years: u8): u64 { assert!(domain_length >= 2, error::out_of_range(EDOMAIN_TOO_SHORT)); let length_to_charge_for = math64::min(domain_length, 6); - scale_price_for_years(config::domain_price_for_length(length_to_charge_for), registration_years) + scale_price_for_years(config::domain_price_for_length(length_to_charge_for), + registration_years) } /// Subdomains have a fixed unit cost @@ -104,15 +104,15 @@ module aptos_names::price_model { YearPricePair { years: 7, expected_price: 1085 }, YearPricePair { years: 8, expected_price: 1360 }, YearPricePair { years: 9, expected_price: 1680 }, - YearPricePair { years: 10, expected_price: 2050 }, - ]; + YearPricePair { years: 10, expected_price: 2050 },]; account::create_account_for_test(signer::address_of(myself)); account::create_account_for_test(signer::address_of(framework)); while (vector::length(&prices_and_years) > 0) { let pair = vector::pop_back(&mut prices_and_years); - let price = scale_price_for_years(100 * config::octas(), pair.years) / config::octas(); + let price = + scale_price_for_years(100 * config::octas(), pair.years) / config::octas(); assert!(price == pair.expected_price, price); }; } diff --git a/core/sources/subdomain_e2e_tests.move b/core/sources/subdomain_e2e_tests.move index 153cfa41..eb02333a 100644 --- a/core/sources/subdomain_e2e_tests.move +++ b/core/sources/subdomain_e2e_tests.move @@ -9,171 +9,370 @@ module aptos_names::subdomain_e2e_tests { use std::vector; use aptos_names::time_helper; - #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun 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); + fun 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 rando = vector::borrow(&users, 1); 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Set an address and verify it - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), user_addr); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + user_addr); // Ensure the owner can clear the address test_helper::clear_name_address(user, option::none(), test_helper::domain_name()); // And also can clear if the user is the registered address, but not owner - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), signer::address_of(rando)); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + signer::address_of(rando)); test_helper::clear_name_address(rando, option::none(), test_helper::domain_name()); // Set it back for following tests - test_helper::set_name_address(user, option::none(), test_helper::domain_name(), user_addr); + test_helper::set_name_address(user, option::none(), test_helper::domain_name(), + user_addr); // Register a subdomain! - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); // Set a subdomain address and verify it - test_helper::set_name_address(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), user_addr); + test_helper::set_name_address(user, option::some(test_helper::subdomain_name()), + test_helper::domain_name(), user_addr); // Ensure these also work :-) - test_helper::clear_name_address(user, option::some(test_helper::subdomain_name()), test_helper::domain_name()); + test_helper::clear_name_address(user, option::some(test_helper::subdomain_name()), + test_helper::domain_name()); // And also can clear if is registered address, but not owner - test_helper::set_name_address(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), signer::address_of(rando)); - test_helper::clear_name_address(rando, option::some(test_helper::subdomain_name()), test_helper::domain_name()); + test_helper::set_name_address(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + signer::address_of(rando)); + test_helper::clear_name_address(rando, option::some(test_helper::subdomain_name()), + test_helper::domain_name()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun names_are_registerable_after_expiry_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun names_are_registerable_after_expiry_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 rando = vector::borrow(&users, 1); // 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Register a subdomain! - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), timestamp::now_seconds() + test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + timestamp::now_seconds() + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); // Set the time past the domain's expiration time - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), test_helper::domain_name()); + let (_, expiration_time_sec, _) = + domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), + test_helper::domain_name()); timestamp::update_global_time_for_test_secs(expiration_time_sec + 5); // The domain should now be: expired, registered, AND registerable assert!(domains::name_is_expired(option::none(), test_helper::domain_name()), 80); - assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), 81); - assert!(domains::name_is_registerable(option::none(), test_helper::domain_name()), 82); + assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), + 81); + assert!(domains::name_is_registerable(option::none(), test_helper::domain_name()), + 82); // The subdomain now be: expired, registered, AND NOT registerable (because the domain is expired, too) - assert!(domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 90); - assert!(domains::name_is_registered(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 91); - assert!(!domains::name_is_registerable(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 92); + assert!(domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 90); + assert!(domains::name_is_registered(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 91); + assert!(!domains::name_is_registerable(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 92); // 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()); + test_helper::register_name(rando, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 2, + vector::empty()); // The subdomain should now be registerable: it's both expired AND the domain is registered - assert!(domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 93); - assert!(domains::name_is_registered(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 94); - assert!(domains::name_is_registerable(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 95); + assert!(domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 93); + assert!(domains::name_is_registered(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 94); + assert!(domains::name_is_registerable(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 95); // and likewise for the subdomain - test_helper::register_name(rando, option::some(test_helper::subdomain_name()), test_helper::domain_name(), timestamp::now_seconds() + test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 2, vector::empty()); + test_helper::register_name(rando, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + timestamp::now_seconds() + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 2, + vector::empty()); // And again! - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), test_helper::domain_name()); + let (_, expiration_time_sec, _) = + domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), + test_helper::domain_name()); timestamp::update_global_time_for_test_secs(expiration_time_sec + 5); - // The domain should now be: expired, registered, AND registerable assert!(domains::name_is_expired(option::none(), test_helper::domain_name()), 80); - assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), 81); - assert!(domains::name_is_registerable(option::none(), test_helper::domain_name()), 82); + assert!(domains::name_is_registered(option::none(), test_helper::domain_name()), + 81); + assert!(domains::name_is_registerable(option::none(), test_helper::domain_name()), + 82); // The subdomain now be: expired, registered, AND NOT registerable (because the domain is expired, too) - assert!(domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 90); - assert!(domains::name_is_registered(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 91); - assert!(!domains::name_is_registerable(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 92); + assert!(domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 90); + assert!(domains::name_is_registered(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 91); + assert!(!domains::name_is_registerable(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 92); // 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(), 3, vector::empty()); + test_helper::register_name(rando, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 3, + vector::empty()); // The subdomain should now be registerable: it's both expired AND the domain is registered - assert!(domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 93); - assert!(domains::name_is_registered(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 94); - assert!(domains::name_is_registerable(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 95); + assert!(domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 93); + assert!(domains::name_is_registered(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 94); + assert!(domains::name_is_registerable(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 95); // and likewise for the subdomain - test_helper::register_name(rando, option::some(test_helper::subdomain_name()), test_helper::domain_name(), timestamp::now_seconds() + test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 3, vector::empty()); + test_helper::register_name(rando, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + timestamp::now_seconds() + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 3, + vector::empty()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 196611, location = aptos_names::domains)] - fun dont_allow_double_subdomain_registrations_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun dont_allow_double_subdomain_registrations_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); // 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()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); // Try to register a subdomain twice (ensure we can't) - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327689, location = aptos_names::domains)] - fun dont_allow_rando_to_set_subdomain_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun dont_allow_rando_to_set_subdomain_address_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 rando = vector::borrow(&users, 1); // Register the domain and subdomain - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); // Ensure we can't clear it as a rando. The expected target address doesn't matter as it won't get hit - test_helper::set_name_address(rando, option::some(test_helper::subdomain_name()), test_helper::domain_name(), @aptos_names); + test_helper::set_name_address(rando, option::some(test_helper::subdomain_name()), + test_helper::domain_name(), @aptos_names); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327689, location = aptos_names::domains)] - fun dont_allow_rando_to_clear_subdomain_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun dont_allow_rando_to_clear_subdomain_address_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 rando = vector::borrow(&users, 1); // Register the domain and subdomain - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); - test_helper::set_name_address(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), signer::address_of(user)); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); + test_helper::set_name_address(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + signer::address_of(user)); // Ensure we can't clear it as a rando. The expected target address doesn't matter as it won't get hit - test_helper::set_name_address(rando, option::some(test_helper::subdomain_name()), test_helper::domain_name(), @aptos_names); + test_helper::set_name_address(rando, option::some(test_helper::subdomain_name()), + test_helper::domain_name(), @aptos_names); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun admin_can_force_set_subdomain_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun admin_can_force_set_subdomain_address_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 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()); - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); - - domains::force_set_subdomain_address(myself, test_helper::subdomain_name(), test_helper::domain_name(), rando_addr); - let (_property_version, _expiration_time_sec, target_address) = domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), test_helper::domain_name()); - test_utils::print_actual_expected(b"set_subdomain_address: ", target_address, option::some(rando_addr), false); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); + + domains::force_set_subdomain_address(myself, test_helper::subdomain_name(), + test_helper::domain_name(), rando_addr); + let (_property_version, _expiration_time_sec, target_address) = + domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), + test_helper::domain_name()); + test_utils::print_actual_expected(b"set_subdomain_address: ", target_address, + option::some(rando_addr), false); assert!(target_address == option::some(rando_addr), 33); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun rando_cant_force_set_subdomain_address_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun rando_cant_force_set_subdomain_address_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 rando = vector::borrow(&users, 1); @@ -181,155 +380,303 @@ module aptos_names::subdomain_e2e_tests { let rando_addr = signer::address_of(rando); // Register the domain and subdomain - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); // Rando is not allowed to do this - domains::force_set_subdomain_address(rando, test_helper::subdomain_name(), test_helper::domain_name(), rando_addr); + domains::force_set_subdomain_address(rando, test_helper::subdomain_name(), + test_helper::domain_name(), rando_addr); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun admin_can_force_seize_subdomain_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); + fun admin_can_force_seize_subdomain_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); // Register the domain and subdomain - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(user), option::some(test_helper::subdomain_name()), test_helper::domain_name()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(user), + option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(user), option::some(test_helper::subdomain_name()), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(user), + option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_owner, 1); - assert!(!domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 1); + assert!(!domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 1); // Take the subdomain name for much longer than users are allowed to register it for - domains::force_create_or_seize_name(myself, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(myself), option::some(test_helper::subdomain_name()), test_helper::domain_name()); + domains::force_create_or_seize_name(myself, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(myself), + option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_owner, 2); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(myself), option::some(test_helper::subdomain_name()), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(myself), + option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_owner, 2); - assert!(!domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 2); + assert!(!domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 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::some(test_helper::subdomain_name()), test_helper::domain_name()); - assert!(time_helper::seconds_to_years(expiration_time_sec) == 1, time_helper::seconds_to_years(expiration_time_sec)); + let (_, expiration_time_sec, _) = + domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), + test_helper::domain_name()); + assert!(time_helper::seconds_to_years(expiration_time_sec) == 1, + time_helper::seconds_to_years(expiration_time_sec)); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun admin_can_force_create_subdomain_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); + fun admin_can_force_create_subdomain_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); // No subdomain is registered yet - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - assert!(!domains::name_is_registered(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 1); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + assert!(!domains::name_is_registered(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 1); // Take the subdomain name - domains::force_create_or_seize_name(myself, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(myself), option::some(test_helper::subdomain_name()), test_helper::domain_name()); + domains::force_create_or_seize_name(myself, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(myself), + option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_owner, 2); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(myself), option::some(test_helper::subdomain_name()), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(myself), + option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_owner, 2); - assert!(!domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 2); + assert!(!domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 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::some(test_helper::subdomain_name()), test_helper::domain_name()); - assert!(time_helper::seconds_to_years(expiration_time_sec) == 1, time_helper::seconds_to_years(expiration_time_sec)); + let (_, expiration_time_sec, _) = + domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), + test_helper::domain_name()); + assert!(time_helper::seconds_to_years(expiration_time_sec) == 1, + time_helper::seconds_to_years(expiration_time_sec)); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 131086, location = aptos_names::domains)] - fun admin_cant_force_create_subdomain_more_than_domain_time_e2e_test(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun admin_cant_force_create_subdomain_more_than_domain_time_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); // No subdomain is registered yet- domain is registered for 1 year - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - assert!(!domains::name_is_registered(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 1); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + assert!(!domains::name_is_registered(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 1); // Take the subdomain name for longer than domain: this should explode - domains::force_create_or_seize_name(myself, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs() + 1); + domains::force_create_or_seize_name(myself, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs() + 1); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] - fun admin_can_force_set_expiration(myself: &signer, user: signer, aptos: signer, rando: signer, foundation: signer) { - let users = test_helper::e2e_test_setup(myself, user, &aptos, rando, &foundation); + fun admin_can_force_set_expiration( + 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); // Register the subdomain - test_helper::register_name( - user, + test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, - vector::empty() - ); - test_helper::register_name( - user, + vector::empty()); + test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, - vector::empty() - ); + vector::empty()); { - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name( - option::some(test_helper::subdomain_name()), - test_helper::domain_name() - ); + let (_, expiration_time_sec, _) = + domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(time_helper::seconds_to_years(expiration_time_sec) == 1, 1); }; - domains::force_set_expiration( - myself, + domains::force_set_expiration(myself, option::some(test_helper::subdomain_name()), test_helper::domain_name(), - test_helper::two_hundred_year_secs() - ); + test_helper::two_hundred_year_secs()); { - let (_, expiration_time_sec, _) = domains::get_name_record_v1_props_for_name( - option::some(test_helper::subdomain_name()), - test_helper::domain_name() - ); + let (_, expiration_time_sec, _) = + domains::get_name_record_v1_props_for_name(option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(time_helper::seconds_to_years(expiration_time_sec) == 200, 1); } } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun rando_cant_force_seize_subdomain_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); + fun rando_cant_force_seize_subdomain_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 rando = vector::borrow(&users, 1); // Register the domain and subdomain - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - test_helper::register_name(user, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_subdomain_name(), 1, vector::empty()); - let (is_owner, _token_id) = domains::is_owner_of_name(signer::address_of(user), option::some(test_helper::subdomain_name()), test_helper::domain_name()); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + test_helper::register_name(user, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_subdomain_name(), + 1, + vector::empty()); + let (is_owner, _token_id) = + domains::is_owner_of_name(signer::address_of(user), + option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_owner, 1); - let (is_owner, _token_id) = domains::is_token_owner(signer::address_of(user), option::some(test_helper::subdomain_name()), test_helper::domain_name()); + let (is_owner, _token_id) = + domains::is_token_owner(signer::address_of(user), + option::some(test_helper::subdomain_name()), + test_helper::domain_name()); assert!(is_owner, 1); - assert!(!domains::name_is_expired(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 1); + assert!(!domains::name_is_expired(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 1); // Attempt (and fail) to take the subdomain name for much longer than users are allowed to register it for - domains::force_create_or_seize_name(rando, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::two_hundred_year_secs()); + domains::force_create_or_seize_name(rando, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::two_hundred_year_secs()); } #[test(myself = @aptos_names, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names::config)] - fun rando_cant_force_create_subdomain_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); + fun rando_cant_force_create_subdomain_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 rando = vector::borrow(&users, 1); // Register a domain, and ensure no subdomain is registered yet - test_helper::register_name(user, option::none(), test_helper::domain_name(), test_helper::one_year_secs(), test_helper::fq_domain_name(), 1, vector::empty()); - assert!(!domains::name_is_registered(option::some(test_helper::subdomain_name()), test_helper::domain_name()), 1); + test_helper::register_name(user, + option::none(), + test_helper::domain_name(), + test_helper::one_year_secs(), + test_helper::fq_domain_name(), + 1, + vector::empty()); + assert!(!domains::name_is_registered(option::some(test_helper::subdomain_name()), + test_helper::domain_name()), + 1); // Attempt (and fail) to take the subdomain name for much longer than users are allowed to register it for - domains::force_create_or_seize_name(rando, option::some(test_helper::subdomain_name()), test_helper::domain_name(), test_helper::two_hundred_year_secs()); + domains::force_create_or_seize_name(rando, + option::some(test_helper::subdomain_name()), + test_helper::domain_name(), + test_helper::two_hundred_year_secs()); } } diff --git a/core/sources/test_helper.move b/core/sources/test_helper.move index 0de83239..3a8493da 100644 --- a/core/sources/test_helper.move +++ b/core/sources/test_helper.move @@ -48,7 +48,13 @@ module aptos_names::test_helper { string::utf8(b"sub.test.apt") } - public fun e2e_test_setup(myself: &signer, user: signer, aptos: &signer, rando: signer, foundation: &signer): vector { + public fun e2e_test_setup( + myself: &signer, + user: signer, + aptos: &signer, + rando: signer, + foundation: &signer + ): vector { account::create_account_for_test(@aptos_names); let new_accounts = setup_and_fund_accounts(aptos, foundation, vector[user, rando]); timestamp::set_time_has_started_for_testing(aptos); @@ -73,26 +79,32 @@ module aptos_names::test_helper { let user_balance_before = coin::balance(user_addr); let user_reverse_lookup_before = domains::get_reverse_lookup(user_addr); - let maybe_target_address = domains::name_resolved_address(subdomain_name, domain_name); - let name_reverse_lookup_before = if (option::is_some(&maybe_target_address)) { - domains::get_reverse_lookup(*option::borrow(&maybe_target_address)) - } else { - option::none() - }; - let is_expired_before = domains::name_is_registered(subdomain_name, domain_name) && domains::name_is_expired(subdomain_name, domain_name); + let maybe_target_address = domains::name_resolved_address(subdomain_name, + domain_name); + let name_reverse_lookup_before = + if (option::is_some(&maybe_target_address)) { + domains::get_reverse_lookup(*option::borrow(&maybe_target_address)) + } else { + option::none() + }; + let is_expired_before = + domains::name_is_registered(subdomain_name, domain_name) && domains::name_is_expired( + subdomain_name, domain_name); let register_name_event_v1_event_count_before = domains::get_register_name_event_v1_count(); let set_name_address_event_v1_event_count_before = domains::get_set_name_address_event_v1_count(); let set_reverse_lookup_event_v1_event_count_before = domains::get_set_reverse_lookup_event_v1_count(); - let years = (time_helper::seconds_to_years(registration_duration_secs) as u8); + let years = + (time_helper::seconds_to_years(registration_duration_secs) as u8); if (option::is_none(&subdomain_name)) { - if (vector::length(&signature)== 0) { + if (vector::length(&signature) == 0) { domains::register_domain(user, domain_name, years); } else { domains::register_domain_with_signature(user, domain_name, years, signature); } } else { - domains::register_subdomain(user, *option::borrow(&subdomain_name), domain_name, registration_duration_secs); + domains::register_subdomain(user, *option::borrow(&subdomain_name), domain_name, + registration_duration_secs); }; // It should now be: not expired, registered, and not registerable @@ -100,38 +112,49 @@ module aptos_names::test_helper { assert!(!domains::name_is_registerable(subdomain_name, domain_name), 13); assert!(domains::name_is_registered(subdomain_name, domain_name), 14); - let (is_owner, _) = domains::is_owner_of_name(user_addr, subdomain_name, domain_name); + let (is_owner, _) = + domains::is_owner_of_name(user_addr, subdomain_name, domain_name); assert!(is_owner, 3); - let (is_owner, token_id) = domains::is_token_owner(user_addr, subdomain_name, domain_name); - let (tdi_creator, tdi_collection, tdi_name, tdi_property_version) = token::get_token_id_fields(&token_id); + let (is_owner, token_id) = domains::is_token_owner(user_addr, subdomain_name, + domain_name); + let (tdi_creator, tdi_collection, tdi_name, tdi_property_version) = token::get_token_id_fields( + &token_id); assert!(is_owner, 3); assert!(!domains::name_is_expired(subdomain_name, domain_name), 3); assert!(tdi_creator == token_helper::get_token_signer_address(), 4); assert!(tdi_collection == config::collection_name_v1(), 5); - test_utils::print_actual_expected(b"tdi_name: ", tdi_name, expected_fq_domain_name, false); + test_utils::print_actual_expected(b"tdi_name: ", tdi_name, expected_fq_domain_name, + false); assert!(tdi_name == expected_fq_domain_name, 6); - test_utils::print_actual_expected(b"tdi_property_version: ", tdi_property_version, expected_property_version, false); + test_utils::print_actual_expected(b"tdi_property_version: ", tdi_property_version, + expected_property_version, false); assert!(tdi_property_version == expected_property_version, tdi_property_version); let expected_user_balance_after; let user_balance_after = coin::balance(user_addr); if (is_subdomain) { // If it's a subdomain, we only charge a nomincal fee - expected_user_balance_after = user_balance_before - price_model::price_for_subdomain_v1(registration_duration_secs); + expected_user_balance_after = user_balance_before - price_model::price_for_subdomain_v1( + registration_duration_secs); } else { - let domain_price = price_model::price_for_domain_v1(string::length(&domain_name), years); + let domain_price = + price_model::price_for_domain_v1(string::length(&domain_name), years); assert!(domain_price / config::octas() == 40, domain_price / config::octas()); expected_user_balance_after = user_balance_before - domain_price; }; - test_utils::print_actual_expected(b"user_balance_after: ", user_balance_after, expected_user_balance_after, false); - assert!(user_balance_after == expected_user_balance_after, expected_user_balance_after); + test_utils::print_actual_expected(b"user_balance_after: ", user_balance_after, + expected_user_balance_after, false); + assert!(user_balance_after == expected_user_balance_after, + expected_user_balance_after); // Ensure the name was registered correctly, with an expiration timestamp one year in the future - let (property_version, expiration_time_sec, target_address) = domains::get_name_record_v1_props_for_name(subdomain_name, domain_name); - assert!(time_helper::seconds_to_days(expiration_time_sec - timestamp::now_seconds()) == 365, 10); + let (property_version, expiration_time_sec, target_address) = + domains::get_name_record_v1_props_for_name(subdomain_name, domain_name); + assert!(time_helper::seconds_to_days(expiration_time_sec - timestamp::now_seconds()) == + 365, 10); if (is_subdomain) { if (option::is_none(&user_reverse_lookup_before)) { @@ -147,22 +170,29 @@ module aptos_names::test_helper { }; // And the property version is correct - test_utils::print_actual_expected(b"property_version: ", property_version, expected_property_version, false); + test_utils::print_actual_expected(b"property_version: ", property_version, + expected_property_version, false); assert!(property_version == expected_property_version, 12); // Ensure the properties were set correctly - let token_data_id = token_helper::build_tokendata_id(token_helper::get_token_signer_address(), subdomain_name, domain_name); + let token_data_id = + token_helper::build_tokendata_id(token_helper::get_token_signer_address(), + subdomain_name, domain_name); let (creator, collection_name, token_name) = token::get_token_data_id_fields(&token_data_id); assert!(creator == token_helper::get_token_signer_address(), 20); assert!(collection_name == string::utf8(b"Aptos Names V1"), 21); assert!(token_name == token_name, 22); // Assert events have been correctly emmitted - let register_name_event_v1_num_emitted = domains::get_register_name_event_v1_count() - register_name_event_v1_event_count_before; - let set_name_address_event_v1_num_emitted = domains::get_set_name_address_event_v1_count() - set_name_address_event_v1_event_count_before; - let set_reverse_lookup_event_v1_num_emitted = domains::get_set_reverse_lookup_event_v1_count() - set_reverse_lookup_event_v1_event_count_before; - - test_utils::print_actual_expected(b"register_name_event_v1_num_emitted: ", register_name_event_v1_num_emitted, 1, false); + let register_name_event_v1_num_emitted = + domains::get_register_name_event_v1_count() - register_name_event_v1_event_count_before; + let set_name_address_event_v1_num_emitted = + domains::get_set_name_address_event_v1_count() - set_name_address_event_v1_event_count_before; + let set_reverse_lookup_event_v1_num_emitted = + domains::get_set_reverse_lookup_event_v1_count() - set_reverse_lookup_event_v1_event_count_before; + + test_utils::print_actual_expected(b"register_name_event_v1_num_emitted: ", + register_name_event_v1_num_emitted, 1, false); assert!(register_name_event_v1_num_emitted == 1, register_name_event_v1_num_emitted); // Reverse lookup should be set if user did not have one before @@ -170,7 +200,8 @@ module aptos_names::test_helper { let maybe_reverse_lookup_after = domains::get_reverse_lookup(user_addr); if (option::is_some(&maybe_reverse_lookup_after)) { let reverse_lookup_after = option::borrow(&maybe_reverse_lookup_after); - assert!(*reverse_lookup_after == domains::create_name_record_key_v1(subdomain_name, domain_name), 36); + assert!(*reverse_lookup_after + == domains::create_name_record_key_v1(subdomain_name, domain_name), 36); } else { // Reverse lookup is not set, even though user did not have a reverse lookup before. assert!(false, 37); @@ -178,47 +209,65 @@ module aptos_names::test_helper { // If we are registering over a name that is already registered but expired and was a primary name, // that name should be removed from being a primary name. if (option::is_some(&name_reverse_lookup_before) && is_expired_before) { - assert!(set_reverse_lookup_event_v1_num_emitted == 2, set_reverse_lookup_event_v1_num_emitted); + assert!(set_reverse_lookup_event_v1_num_emitted == 2, + set_reverse_lookup_event_v1_num_emitted); } else { - assert!(set_reverse_lookup_event_v1_num_emitted == 1, set_reverse_lookup_event_v1_num_emitted); + assert!(set_reverse_lookup_event_v1_num_emitted == 1, + set_reverse_lookup_event_v1_num_emitted); } } else { // If we are registering over a name that is already registered but expired and was the user's primary name, // that name should be removed from being a primary name and the new one should be set. if (option::is_some(&name_reverse_lookup_before) && option::is_some(&user_reverse_lookup_before) - && *option::borrow(&name_reverse_lookup_before) == *option::borrow(&user_reverse_lookup_before) - && is_expired_before - ) { - assert!(set_reverse_lookup_event_v1_num_emitted == 2, set_reverse_lookup_event_v1_num_emitted); + && *option::borrow(&name_reverse_lookup_before) + == *option::borrow(&user_reverse_lookup_before) + && is_expired_before) { + assert!(set_reverse_lookup_event_v1_num_emitted == 2, + set_reverse_lookup_event_v1_num_emitted); } else if (option::is_some(&name_reverse_lookup_before) && is_expired_before) { // If we are registering over a name that is already registered but expired and was a primary name, // that name should be removed from being a primary name. - assert!(set_reverse_lookup_event_v1_num_emitted == 1, set_reverse_lookup_event_v1_num_emitted); + assert!(set_reverse_lookup_event_v1_num_emitted == 1, + set_reverse_lookup_event_v1_num_emitted); } else { - assert!(set_reverse_lookup_event_v1_num_emitted == 0, set_reverse_lookup_event_v1_num_emitted); + assert!(set_reverse_lookup_event_v1_num_emitted == 0, + set_reverse_lookup_event_v1_num_emitted); } }; if (is_subdomain) { if (option::is_none(&user_reverse_lookup_before)) { // Should automatically point to the users address - test_utils::print_actual_expected(b"set_name_address_event_v1_num_emitted: ", set_name_address_event_v1_num_emitted, 1, false); - assert!(set_name_address_event_v1_num_emitted == 1, set_name_address_event_v1_num_emitted); + test_utils::print_actual_expected( + b"set_name_address_event_v1_num_emitted: ", + set_name_address_event_v1_num_emitted, 1, false); + assert!(set_name_address_event_v1_num_emitted == 1, + set_name_address_event_v1_num_emitted); } else { // We haven't set a target address yet! - test_utils::print_actual_expected(b"set_name_address_event_v1_num_emitted: ", set_name_address_event_v1_num_emitted, 0, false); - assert!(set_name_address_event_v1_num_emitted == 0, set_name_address_event_v1_num_emitted); + test_utils::print_actual_expected( + b"set_name_address_event_v1_num_emitted: ", + set_name_address_event_v1_num_emitted, 0, false); + assert!(set_name_address_event_v1_num_emitted == 0, + set_name_address_event_v1_num_emitted); } } else { // Should automatically point to the users address - test_utils::print_actual_expected(b"set_name_address_event_v1_num_emitted: ", set_name_address_event_v1_num_emitted, 1, false); - assert!(set_name_address_event_v1_num_emitted == 1, set_name_address_event_v1_num_emitted); + test_utils::print_actual_expected(b"set_name_address_event_v1_num_emitted: ", + set_name_address_event_v1_num_emitted, 1, false); + assert!(set_name_address_event_v1_num_emitted == 1, + set_name_address_event_v1_num_emitted); }; } /// Set the domain address, and verify the address was set correctly - public fun set_name_address(user: &signer, subdomain_name: Option, domain_name: String, expected_target_address: address) { + public fun set_name_address( + user: &signer, + subdomain_name: Option, + domain_name: String, + expected_target_address: address + ) { let user_addr = signer::address_of(user); let register_name_event_v1_event_count_before = domains::get_register_name_event_v1_count(); @@ -227,8 +276,10 @@ module aptos_names::test_helper { let maybe_reverse_lookup_before = domains::get_reverse_lookup(user_addr); domains::set_name_address(user, subdomain_name, domain_name, expected_target_address); - let (_property_version, _expiration_time_sec, target_address) = domains::get_name_record_v1_props_for_name(subdomain_name, domain_name); - test_utils::print_actual_expected(b"set_domain_address: ", target_address, option::some(expected_target_address), false); + let (_property_version, _expiration_time_sec, target_address) = + domains::get_name_record_v1_props_for_name(subdomain_name, domain_name); + test_utils::print_actual_expected(b"set_domain_address: ", target_address, + option::some(expected_target_address), false); assert!(target_address == option::some(expected_target_address), 33); // When setting the target address to an address that is *not* the owner's, the reverse lookup should also be cleared @@ -238,27 +289,39 @@ module aptos_names::test_helper { }; // Assert events have been correctly emmitted - let register_name_event_v1_num_emitted = domains::get_register_name_event_v1_count() - register_name_event_v1_event_count_before; - let set_name_address_event_v1_num_emitted = domains::get_set_name_address_event_v1_count() - set_name_address_event_v1_event_count_before; - let set_reverse_lookup_event_v1_num_emitted = domains::get_set_reverse_lookup_event_v1_count() - set_reverse_lookup_event_v1_event_count_before; - - test_utils::print_actual_expected(b"register_name_event_v1_num_emitted: ", register_name_event_v1_num_emitted, 0, false); + let register_name_event_v1_num_emitted = + domains::get_register_name_event_v1_count() - register_name_event_v1_event_count_before; + let set_name_address_event_v1_num_emitted = + domains::get_set_name_address_event_v1_count() - set_name_address_event_v1_event_count_before; + let set_reverse_lookup_event_v1_num_emitted = + domains::get_set_reverse_lookup_event_v1_count() - set_reverse_lookup_event_v1_event_count_before; + + test_utils::print_actual_expected(b"register_name_event_v1_num_emitted: ", + register_name_event_v1_num_emitted, 0, false); assert!(register_name_event_v1_num_emitted == 0, register_name_event_v1_num_emitted); - test_utils::print_actual_expected(b"set_name_address_event_v1_num_emitted: ", set_name_address_event_v1_num_emitted, 1, false); - assert!(set_name_address_event_v1_num_emitted == 1, set_name_address_event_v1_num_emitted); + test_utils::print_actual_expected(b"set_name_address_event_v1_num_emitted: ", + set_name_address_event_v1_num_emitted, 1, false); + assert!(set_name_address_event_v1_num_emitted == 1, + set_name_address_event_v1_num_emitted); // If the signer had a reverse lookup before, and set his reverse lookup name to a different address, it should be cleared if (option::is_some(&maybe_reverse_lookup_before)) { - let (maybe_reverse_subdomain, reverse_domain) = domains::get_name_record_key_v1_props(option::borrow(&maybe_reverse_lookup_before)); - if (maybe_reverse_subdomain == subdomain_name && reverse_domain == domain_name && signer::address_of(user) != expected_target_address) { - assert!(set_reverse_lookup_event_v1_num_emitted == 1, set_reverse_lookup_event_v1_num_emitted); + let (maybe_reverse_subdomain, reverse_domain) = + domains::get_name_record_key_v1_props(option::borrow(&maybe_reverse_lookup_before)); + if (maybe_reverse_subdomain == subdomain_name + && reverse_domain == domain_name + && signer::address_of(user) != expected_target_address) { + assert!(set_reverse_lookup_event_v1_num_emitted == 1, + set_reverse_lookup_event_v1_num_emitted); }; }; } /// Clear the domain address, and verify the address was cleared - public fun clear_name_address(user: &signer, subdomain_name: Option, domain_name: String) { + public fun clear_name_address( + user: &signer, subdomain_name: Option, domain_name: String + ) { let user_addr = signer::address_of(user); let register_name_event_v1_event_count_before = domains::get_register_name_event_v1_count(); let set_name_address_event_v1_event_count_before = domains::get_set_name_address_event_v1_count(); @@ -269,35 +332,48 @@ module aptos_names::test_helper { if (option::is_none(&subdomain_name)) { domains::clear_domain_address(user, domain_name); } else { - domains::clear_subdomain_address(user, *option::borrow(&subdomain_name), domain_name); + domains::clear_subdomain_address(user, *option::borrow(&subdomain_name), + domain_name); }; - let (_property_version, _expiration_time_sec, target_address) = domains::get_name_record_v1_props_for_name(subdomain_name, domain_name); - test_utils::print_actual_expected(b"clear_domain_address: ", target_address, option::none(), false); + let (_property_version, _expiration_time_sec, target_address) = + domains::get_name_record_v1_props_for_name(subdomain_name, domain_name); + test_utils::print_actual_expected(b"clear_domain_address: ", target_address, + option::none(), false); assert!(target_address == option::none(), 32); if (option::is_some(&maybe_reverse_lookup_before)) { let reverse_lookup_before = option::borrow(&maybe_reverse_lookup_before); - if (*reverse_lookup_before == domains::create_name_record_key_v1(subdomain_name, domain_name)) { + if (*reverse_lookup_before + == domains::create_name_record_key_v1(subdomain_name, domain_name)) { let reverse_lookup_after = domains::get_reverse_lookup(user_addr); assert!(option::is_none(&reverse_lookup_after), 35); - let set_reverse_lookup_event_v1_num_emitted = domains::get_set_reverse_lookup_event_v1_count() - set_reverse_lookup_event_v1_event_count_before; - assert!(set_reverse_lookup_event_v1_num_emitted == 1, set_reverse_lookup_event_v1_num_emitted); + let set_reverse_lookup_event_v1_num_emitted = + domains::get_set_reverse_lookup_event_v1_count() - set_reverse_lookup_event_v1_event_count_before; + assert!(set_reverse_lookup_event_v1_num_emitted == 1, + set_reverse_lookup_event_v1_num_emitted); }; }; // Assert events have been correctly emmitted - let register_name_event_v1_num_emitted = domains::get_register_name_event_v1_count() - register_name_event_v1_event_count_before; - let set_name_address_event_v1_num_emitted = domains::get_set_name_address_event_v1_count() - set_name_address_event_v1_event_count_before; + let register_name_event_v1_num_emitted = + domains::get_register_name_event_v1_count() - register_name_event_v1_event_count_before; + let set_name_address_event_v1_num_emitted = + domains::get_set_name_address_event_v1_count() - set_name_address_event_v1_event_count_before; - test_utils::print_actual_expected(b"register_name_event_v1_num_emitted: ", register_name_event_v1_num_emitted, 0, false); + test_utils::print_actual_expected(b"register_name_event_v1_num_emitted: ", + register_name_event_v1_num_emitted, 0, false); assert!(register_name_event_v1_num_emitted == 0, register_name_event_v1_num_emitted); - test_utils::print_actual_expected(b"set_name_address_event_v1_num_emitted: ", set_name_address_event_v1_num_emitted, 1, false); - assert!(set_name_address_event_v1_num_emitted == 1, set_name_address_event_v1_num_emitted); + test_utils::print_actual_expected(b"set_name_address_event_v1_num_emitted: ", + set_name_address_event_v1_num_emitted, 1, false); + assert!(set_name_address_event_v1_num_emitted == 1, + set_name_address_event_v1_num_emitted); } - public fun setup_and_fund_accounts(aptos: &signer, foundation: &signer, users: vector): vector { + public fun setup_and_fund_accounts( + aptos: &signer, foundation: &signer, users: vector + ): vector { let (burn_cap, mint_cap) = aptos_framework::aptos_coin::initialize_for_test(aptos); let len = vector::length(&users); diff --git a/core/sources/test_utils.move b/core/sources/test_utils.move index 1406596a..565cabea 100644 --- a/core/sources/test_utils.move +++ b/core/sources/test_utils.move @@ -14,22 +14,18 @@ module aptos_names::test_utils { expected: T, } - public fun print_actual_expected(label: vector, actual: T, expected: T, always: bool) { - if (!always && &actual == &expected) { - return - }; - let expected_actual = ActualExpectedDebug { - actual, - expected, - }; + public fun print_actual_expected( + label: vector, actual: T, expected: T, always: bool + ) { + if (!always && &actual == &expected) { return }; + let expected_actual = + ActualExpectedDebug { actual, expected, }; print_trace(label, expected_actual); } public fun print(label: vector, value: T) { - let print_debug = PrintDebug { - label: string::utf8(label), - value, - }; + let print_debug = + PrintDebug { label: string::utf8(label), value, }; debug::print(&print_debug); let PrintDebug { label: _, value: _ } = print_debug; } diff --git a/core/sources/time_helper.move b/core/sources/time_helper.move index e6ec86b1..2d0d6eaa 100644 --- a/core/sources/time_helper.move +++ b/core/sources/time_helper.move @@ -34,10 +34,8 @@ module aptos_names::time_helper { SECONDS_PER_YEAR * years } - #[test] - fun test_time_conversion() - { + fun test_time_conversion() { assert!(minutes_to_seconds(1) == 60, minutes_to_seconds(1)); assert!(minutes_to_seconds(60) == hours_to_seconds(1), minutes_to_seconds(1)); @@ -47,6 +45,7 @@ module aptos_names::time_helper { assert!(years_to_seconds(1) == days_to_seconds(1) * 365, years_to_seconds(1)); - assert!(1 == seconds_to_years(years_to_seconds(1)), seconds_to_years(years_to_seconds(1))); + assert!(1 == seconds_to_years(years_to_seconds(1)), + seconds_to_years(years_to_seconds(1))); } } diff --git a/core/sources/token_helper.move b/core/sources/token_helper.move index 6abae49f..0bb9d1ae 100644 --- a/core/sources/token_helper.move +++ b/core/sources/token_helper.move @@ -16,18 +16,19 @@ module aptos_names::token_helper { /// The collection does not exist. This should never happen. const ECOLLECTION_NOT_EXISTS: u64 = 1; - /// Tokens require a signer to create, so this is the signer for the collection struct CollectionCapabilityV1 has key, drop { capability: SignerCapability, } public fun get_token_signer_address(): address acquires CollectionCapabilityV1 { - account::get_signer_capability_address(&borrow_global(@aptos_names).capability) + account::get_signer_capability_address(&borrow_global( + @aptos_names).capability) } fun get_token_signer(): signer acquires CollectionCapabilityV1 { - account::create_signer_with_capability(&borrow_global(@aptos_names).capability) + account::create_signer_with_capability(&borrow_global( + @aptos_names).capability) } /// In the event of requiring operations via script, this allows root to get the registry signer @@ -38,13 +39,13 @@ module aptos_names::token_helper { public(friend) fun initialize(framework: &signer) { // Create the resource account for token creation, so we can get it as a signer later - let registry_seed = utf8_utils::u128_to_string((timestamp::now_microseconds() as u128)); + let registry_seed = + utf8_utils::u128_to_string((timestamp::now_microseconds() as u128)); string::append(&mut registry_seed, string::utf8(b"registry_seed")); - let (token_resource, token_signer_cap) = account::create_resource_account(framework, *string::bytes(®istry_seed)); + let (token_resource, token_signer_cap) = + account::create_resource_account(framework, *string::bytes(®istry_seed)); - move_to(framework, CollectionCapabilityV1 { - capability: token_signer_cap, - }); + move_to(framework, CollectionCapabilityV1 { capability: token_signer_cap, }); // Set up NFT collection let description = string::utf8(b".apt names from Aptos Labs"); @@ -54,19 +55,26 @@ module aptos_names::token_helper { // collection description mutable: true // collection URI mutable: true // collection max mutable: false - let mutate_setting = vector[ true, true, false ]; - token::create_collection(&token_resource, config::collection_name_v1(), description, collection_uri, maximum_supply, mutate_setting); + let mutate_setting = vector[true, true, false]; + token::create_collection(&token_resource, + config::collection_name_v1(), + description, + collection_uri, + maximum_supply, + mutate_setting); } - public fun get_fully_qualified_domain_name(subdomain_name: Option, domain_name: String): String { + public fun get_fully_qualified_domain_name( + subdomain_name: Option, domain_name: String + ): String { let (domain_is_allowed, _length) = utf8_utils::string_is_allowed(&domain_name); assert!(domain_is_allowed, 1); - let subdomain_is_allowed = if (option::is_some(&subdomain_name)) { - let (subdomain_is_allowed, _length) = utf8_utils::string_is_allowed(option::borrow(&subdomain_name)); - subdomain_is_allowed - } else { - true - }; + let subdomain_is_allowed = + if (option::is_some(&subdomain_name)) { + let (subdomain_is_allowed, _length) = utf8_utils::string_is_allowed(option::borrow( + &subdomain_name)); + subdomain_is_allowed + } else { true }; assert!(subdomain_is_allowed, 2); let combined = combine_sub_and_domain_str(subdomain_name, domain_name); string::append_utf8(&mut combined, DOMAIN_SUFFIX); @@ -74,26 +82,33 @@ module aptos_names::token_helper { } public fun tokendata_exists(token_data_id: &TokenDataId): bool { - let (creator, collection_name, token_name) = token::get_token_data_id_fields(token_data_id); + let (creator, collection_name, token_name) = token::get_token_data_id_fields( + token_data_id); token::check_tokendata_exists(creator, collection_name, token_name) } - public fun build_tokendata_id(token_resource_address: address, subdomain_name: Option, domain_name: String): TokenDataId { + public fun build_tokendata_id( + token_resource_address: address, subdomain_name: Option, domain_name: String + ): TokenDataId { let collection_name = config::collection_name_v1(); let fq_domain_name = get_fully_qualified_domain_name(subdomain_name, domain_name); token::create_token_data_id(token_resource_address, collection_name, fq_domain_name) } public fun latest_token_id(token_data_id: &TokenDataId): TokenId { - let (creator, _collection_name, _token_name) = token::get_token_data_id_fields(token_data_id); - let largest_tokendata_property_version = token::get_tokendata_largest_property_version(creator, *token_data_id); + let (creator, _collection_name, _token_name) = token::get_token_data_id_fields( + token_data_id); + let largest_tokendata_property_version = + token::get_tokendata_largest_property_version(creator, *token_data_id); token::create_token_id(*token_data_id, largest_tokendata_property_version) } /// Combines a subdomain and domain into a new string, separated by a `.` /// Used for building fully qualified domain names (Ex: `{subdomain_name}.{domain_name}.apt`) /// If there is no subdomain, just returns the domain name - public fun combine_sub_and_domain_str(subdomain_name: Option, domain_name: String): String { + public fun combine_sub_and_domain_str( + subdomain_name: Option, domain_name: String + ): String { if (option::is_none(&subdomain_name)) { return domain_name }; @@ -105,21 +120,28 @@ module aptos_names::token_helper { } /// gets or creates the token data for the given domain name - public(friend) fun ensure_token_data(subdomain_name: Option, domain_name: String, type: String): TokenDataId acquires CollectionCapabilityV1 { + public(friend) fun ensure_token_data( + subdomain_name: Option, domain_name: String, type: String + ): TokenDataId acquires CollectionCapabilityV1 { let token_resource = &get_token_signer(); - let token_data_id = build_tokendata_id(signer::address_of(token_resource), subdomain_name, domain_name); - if (tokendata_exists(&token_data_id)) { - token_data_id - } else { + let token_data_id = + build_tokendata_id(signer::address_of(token_resource), subdomain_name, + domain_name); + if (tokendata_exists(&token_data_id)) { token_data_id } + else { create_token_data(token_resource, subdomain_name, domain_name, type) } } - fun create_token_data(token_resource: &signer, subdomain_name: Option, domain_name: String, type: String): TokenDataId { + fun create_token_data( + token_resource: &signer, subdomain_name: Option, domain_name: String, type: String + ): TokenDataId { // Set up the NFT let collection_name = config::collection_name_v1(); - assert!(token::check_collection_exists(signer::address_of(token_resource), collection_name), ECOLLECTION_NOT_EXISTS); + assert!(token::check_collection_exists(signer::address_of(token_resource), + collection_name), + ECOLLECTION_NOT_EXISTS); let fq_domain_name = get_fully_qualified_domain_name(subdomain_name, domain_name); @@ -135,17 +157,18 @@ module aptos_names::token_helper { // token description mutable: true // token royalty mutable: false // token properties mutable: true - let token_mutate_config = token::create_token_mutability_config(&vector[ false, true, true, false, true ]); + let token_mutate_config = + token::create_token_mutability_config(&vector[false, true, true, false, true]); let type = property_map::create_property_value(&type); let now = property_map::create_property_value(×tamp::now_seconds()); let property_keys: vector = vector[config::config_key_creation_time_sec(), config::config_key_type()]; - let property_values: vector> = vector[property_map::borrow_value(&now), property_map::borrow_value(&type)]; - let property_types: vector = vector[property_map::borrow_type(&now), property_map::borrow_type(&type)]; - + let property_values: vector> = vector[property_map::borrow_value(&now), property_map::borrow_value( + &type)]; + let property_types: vector = vector[property_map::borrow_type(&now), property_map::borrow_type( + &type)]; - token::create_tokendata( - token_resource, + token::create_tokendata(token_resource, collection_name, fq_domain_name, description, @@ -157,8 +180,7 @@ module aptos_names::token_helper { token_mutate_config, property_keys, property_values, - property_types - ) + property_types) } public(friend) fun create_token(tokendata_id: TokenDataId): TokenId acquires CollectionCapabilityV1 { @@ -166,24 +188,29 @@ module aptos_names::token_helper { // At this point, property_version is 0 let (_creator, collection_name, _name) = token::get_token_data_id_fields(&tokendata_id); - assert!(token::check_collection_exists(signer::address_of(&token_resource), collection_name), 125); + assert!(token::check_collection_exists(signer::address_of(&token_resource), + collection_name), 125); token::mint_token(&token_resource, tokendata_id, 1) } - public(friend) fun set_token_props(token_owner: address, property_keys: vector, property_values: vector>, property_types: vector, token_id: TokenId): TokenId acquires CollectionCapabilityV1 { + public(friend) fun set_token_props( + token_owner: address, + property_keys: vector, + property_values: vector>, + property_types: vector, + token_id: TokenId + ): TokenId acquires CollectionCapabilityV1 { let token_resource = get_token_signer(); // At this point, property_version is 0 // This will create a _new_ token with property_version == max_property_version of the tokendata, and with the properties we just set - token::mutate_one_token( - &token_resource, + token::mutate_one_token(&token_resource, token_owner, token_id, property_keys, property_values, - property_types - ) + property_types) } public(friend) fun transfer_token_to(sign: &signer, token_id: TokenId) acquires CollectionCapabilityV1 { @@ -196,17 +223,28 @@ module aptos_names::token_helper { #[test] fun test_get_fully_qualified_domain_name() { - assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"test")) == string::utf8(b"test.apt"), 1); - assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"wowthisislong")) == string::utf8(b"wowthisislong.apt"), 2); - assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"123")) == string::utf8(b"123.apt"), 2); - assert!(get_fully_qualified_domain_name(option::some(string::utf8(b"sub")), string::utf8(b"test")) == string::utf8(b"sub.test.apt"), 2); + assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"test")) + == string::utf8(b"test.apt"), + 1); + assert!(get_fully_qualified_domain_name(option::none(), + string::utf8(b"wowthisislong")) + == string::utf8(b"wowthisislong.apt"), + 2); + assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"123")) + == string::utf8(b"123.apt"), + 2); + assert!(get_fully_qualified_domain_name(option::some(string::utf8(b"sub")), + string::utf8(b"test")) + == string::utf8(b"sub.test.apt"), + 2); } #[test] fun test_combine_sub_and_domain_str() { let subdomain_name = string::utf8(b"sub"); let domain_name = string::utf8(b"dom"); - let combined = combine_sub_and_domain_str(option::some(subdomain_name), domain_name); + let combined = + combine_sub_and_domain_str(option::some(subdomain_name), domain_name); assert!(combined == string::utf8(b"sub.dom"), 1); } diff --git a/core/sources/utf8_utils.move b/core/sources/utf8_utils.move index 039531cf..cb8284a6 100644 --- a/core/sources/utf8_utils.move +++ b/core/sources/utf8_utils.move @@ -28,7 +28,7 @@ module aptos_names::utf8_utils { if (c == 45) { if (i == 0 || i == len - 1) { // hyphen at beginning or end is not allowed - return (false, len) + return(false, len) }; // We ignore hyphens from the character set count, it's easy to determine later } @@ -41,7 +41,7 @@ module aptos_names::utf8_utils { // these are valid } else { // uknown character set: this is not valid - return (false, len) + return(false, len) }; i = i + 1; }; @@ -87,7 +87,7 @@ module aptos_names::utf8_utils { let char1 = (char1 as u64); let char2 = (*vector::borrow(bytes, i + 1) as u64); let char3 = (*vector::borrow(bytes, i + 2) as u64); - vector::push_back(&mut result, (char1 << 16) | (char2 << 8) | char3); + vector::push_back(&mut result, (char1 << 16) |(char2 << 8) | char3); i = i + 2; } else if (prefix == 15) { // 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx @@ -95,7 +95,7 @@ module aptos_names::utf8_utils { let char2 = (*vector::borrow(bytes, i + 1) as u64); let char3 = (*vector::borrow(bytes, i + 2) as u64); let char4 = (*vector::borrow(bytes, i + 3) as u64); - vector::push_back(&mut result, (char1 << 24) | (char2 << 16) | (char3 << 8) | char4); + vector::push_back(&mut result, (char1 << 24) |(char2 << 16) |(char3 << 8) | char4); i = i + 3; } else { assert!(char1 <= 14u8, EINVALID_UTF8_START); @@ -131,8 +131,7 @@ module aptos_names::utf8_utils { Example { text: b"01234-56789", length: 11, }, Example { text: b"abcdefgh-ijklmnopqrstuvwxyz", length: 27, }, Example { text: b"a", length: 1, }, - Example { text: b"", length: 0, }, - ]; + Example { text: b"", length: 0, },]; // Reverse it so the errors are in order vector::reverse(&mut allowed_tests); let i = 0; @@ -153,8 +152,7 @@ module aptos_names::utf8_utils { Example { text: b"-", length: 1, }, Example { text: b"_", length: 1, }, Example { text: b"a!b", length: 3, }, - Example { text: b"A", length: 1, }, - ]; + Example { text: b"A", length: 1, },]; // Reverse it so the errors are in order vector::reverse(&mut not_allowed); let i = 0; diff --git a/core/sources/verify.move b/core/sources/verify.move index 64087048..71b4c017 100644 --- a/core/sources/verify.move +++ b/core/sources/verify.move @@ -16,18 +16,23 @@ module aptos_names::verify { const EINVALID_PROOF_OF_KNOWLEDGE: u64 = 1; - public(friend) fun assert_register_domain_signature_verifies(signature: vector, account_address: address, domain_name: string::String) { + public(friend) fun assert_register_domain_signature_verifies( + signature: vector, account_address: address, domain_name: string::String + ) { let chain_id = chain_id::get(); let sequence_number = account::get_sequence_number(account_address); - let register_domain_proof_challenge = RegisterDomainProofChallenge { - sequence_number, - register_address: account_address, - domain_name, - chain_id - }; + let register_domain_proof_challenge = + RegisterDomainProofChallenge { + sequence_number, + register_address: account_address, + domain_name, + chain_id + }; let captcha_public_key = config::captcha_public_key(); let sig = ed25519::new_signature_from_bytes(signature); - assert!(ed25519::signature_verify_strict_t(&sig, &captcha_public_key, register_domain_proof_challenge), std::error::invalid_argument(EINVALID_PROOF_OF_KNOWLEDGE)); + assert!(ed25519::signature_verify_strict_t(&sig, &captcha_public_key, + register_domain_proof_challenge), + std::error::invalid_argument(EINVALID_PROOF_OF_KNOWLEDGE)); } } diff --git a/core_v2/sources/tests/v2_1_domain_e2e_tests.move b/core_v2/sources/tests/v2_1_domain_e2e_tests.move index 205e2754..641c8d85 100644 --- a/core_v2/sources/tests/v2_1_domain_e2e_tests.move +++ b/core_v2/sources/tests/v2_1_domain_e2e_tests.move @@ -15,14 +15,7 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { const SECONDS_PER_DAY: u64 = 60 * 60 * 24; const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_happy_path_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -31,37 +24,42 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Set an address and verify it - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(),option::none(), user_addr); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), user_addr); // Ensure the owner can clear the address - v2_1_test_helper::clear_target_address(user, option::none(), v2_1_test_helper::domain_name()); + v2_1_test_helper::clear_target_address(user, option::none(), + v2_1_test_helper::domain_name()); // And also can clear if the user is the registered address, but not owner - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::none(), signer::address_of(rando)); - v2_1_test_helper::clear_target_address(rando, option::none(), v2_1_test_helper::domain_name()); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), signer::address_of(rando)); + v2_1_test_helper::clear_target_address(rando, option::none(), + v2_1_test_helper::domain_name()); // Set it back for following tests - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::none(), user_addr); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), user_addr); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_renew_domain_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -70,41 +68,49 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); // Set the time is early than max remaining time for renewal from expiration time - timestamp::update_global_time_for_test_secs(expiration_time_sec - MAX_REMAINING_TIME_FOR_RENEWAL_SEC - 5); - assert!(!v2_1_domains::is_domain_in_renewal_window(v2_1_test_helper::domain_name()), 1); + timestamp::update_global_time_for_test_secs(expiration_time_sec - MAX_REMAINING_TIME_FOR_RENEWAL_SEC + - 5); + assert!(!v2_1_domains::is_domain_in_renewal_window(v2_1_test_helper::domain_name()), + 1); - timestamp::update_global_time_for_test_secs(expiration_time_sec - MAX_REMAINING_TIME_FOR_RENEWAL_SEC + 5); - assert!(v2_1_domains::is_domain_in_renewal_window(v2_1_test_helper::domain_name()), 2); + timestamp::update_global_time_for_test_secs(expiration_time_sec - MAX_REMAINING_TIME_FOR_RENEWAL_SEC + + 5); + assert!(v2_1_domains::is_domain_in_renewal_window(v2_1_test_helper::domain_name()), + 2); // Renew the domain v2_1_domains::renew_domain(user, v2_1_test_helper::domain_name(), SECONDS_PER_YEAR); // Ensure the domain is still registered after the original expiration time timestamp::update_global_time_for_test_secs(expiration_time_sec + 5); - assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 4); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 4); - let new_expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + let new_expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); // Ensure the domain is still expired after the new expiration time timestamp::update_global_time_for_test_secs(new_expiration_time_sec + 5); - assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()), 5); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()), 5); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_names_are_registerable_after_expiry_and_past_grace_period( router_signer: &signer, aptos_names_v2_1: &signer, @@ -113,49 +119,72 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Set the time past the domain's expiration time and past grace period - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); - timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + 5); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + + 5); // It should now be: expired, registered, AND registerable - assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()), 80); - assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 81); - assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), option::none()), 82); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()), 80); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 81); + assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), + option::none()), 82); // Lets try to register it again, now that it is expired - v2_1_test_helper::register_name(router_signer, rando, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 2); + v2_1_test_helper::register_name(router_signer, + rando, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 2); // Reverse lookup for |user| should be none. - assert!(option::is_none(&v2_1_domains::get_reverse_lookup(signer::address_of(user))), 85); + assert!(option::is_none(&v2_1_domains::get_reverse_lookup(signer::address_of(user))), + 85); // And again! - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); - timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + 5); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + + 5); // It should now be: expired, registered, AND registerable - assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()), 80); - assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 81); - assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), option::none()), 82); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()), 80); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 81); + assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), + option::none()), 82); // Lets try to register it again, now that it is expired - v2_1_test_helper::register_name(router_signer, rando, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 3); + v2_1_test_helper::register_name(router_signer, + rando, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 3); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 196611, location = aptos_names_v2_1::v2_1_domains)] fun test_no_double_domain_registrations( router_signer: &signer, @@ -165,23 +194,29 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Ensure we can't register it again - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327689, location = aptos_names_v2_1::v2_1_domains)] fun test_non_owner_can_not_set_target_address( router_signer: &signer, @@ -191,24 +226,25 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Ensure we can't set it as a rando. The expected target address doesn't matter as it won't get hit - v2_1_test_helper::set_target_address(rando, v2_1_test_helper::domain_name(), option::none(), @aptos_names_v2_1); + v2_1_test_helper::set_target_address(rando, v2_1_test_helper::domain_name(), + option::none(), @aptos_names_v2_1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327682, location = aptos_names_v2_1::v2_1_domains)] fun test_non_owner_can_not_clear_target_address( router_signer: &signer, @@ -218,26 +254,28 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain, and set its address - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::none(),signer::address_of(user)); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), signer::address_of(user)); // Ensure we can't clear it as a rando - v2_1_test_helper::clear_target_address(rando, option::none(), v2_1_test_helper::domain_name()); + v2_1_test_helper::clear_target_address(rando, option::none(), + v2_1_test_helper::domain_name()); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_owner_can_clear_domain_address( router_signer: &signer, aptos_names_v2_1: &signer, @@ -246,26 +284,28 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain, and set its address - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::none(), signer::address_of(rando)); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), signer::address_of(rando)); // Ensure we can clear as owner - v2_1_test_helper::clear_target_address(user, option::none(), v2_1_test_helper::domain_name()); + v2_1_test_helper::clear_target_address(user, option::none(), + v2_1_test_helper::domain_name()); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_target_addr_owner_can_clear_target_address( router_signer: &signer, aptos_names_v2_1: &signer, @@ -274,26 +314,28 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain, and set its address - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::none(), signer::address_of(rando)); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), signer::address_of(rando)); // Ensure we can clear as owner - v2_1_test_helper::clear_target_address(rando, option::none(), v2_1_test_helper::domain_name()); + v2_1_test_helper::clear_target_address(rando, option::none(), + v2_1_test_helper::domain_name()); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_get_target_address_for_domain( router_signer: &signer, aptos_names_v2_1: &signer, @@ -302,29 +344,32 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(),option::none(), user_addr); - let target_address = v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), user_addr); + let target_address = + v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::none()); assert!(target_address == option::some(user_addr), 2); timestamp::update_global_time_for_test_secs(v2_1_test_helper::one_year_secs() + 5); - let target_address = v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::none()); + let target_address = + v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::none()); assert!(option::is_none(&target_address), 3); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_get_expiration_for_domain( router_signer: &signer, aptos_names_v2_1: &signer, @@ -333,26 +378,27 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(),option::none(), user_addr); - let expiration_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), user_addr); + let expiration_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); assert!(expiration_sec == v2_1_test_helper::one_year_secs(), 1); } - - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_get_reverse_lookup_for_domain( router_signer: &signer, aptos_names_v2_1: &signer, @@ -361,28 +407,31 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - aptos_names_v2_1::v2_1_domains::set_reverse_lookup(user, option::none(), v2_1_test_helper::domain_name()); - let token_addr = v2_1_domains::get_token_addr(v2_1_test_helper::domain_name(), option::none()); - assert!(v2_1_domains::get_reverse_lookup(user_addr) == option::some(token_addr), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + aptos_names_v2_1::v2_1_domains::set_reverse_lookup(user, option::none(), + v2_1_test_helper::domain_name()); + let token_addr = + v2_1_domains::get_token_addr(v2_1_test_helper::domain_name(), option::none()); + assert!(v2_1_domains::get_reverse_lookup(user_addr) + == option::some(token_addr), 1); timestamp::update_global_time_for_test_secs(v2_1_test_helper::one_year_secs() + 5); assert!(option::is_none(&v2_1_domains::get_reverse_lookup(user_addr)), 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_admin_can_force_set_target_address_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -391,7 +440,8 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); @@ -404,23 +454,18 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1, - ); - - v2_1_domains::force_set_target_address(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::none(), rando_addr); - let target_address = v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::none()); - v2_1_test_utils::print_actual_expected(b"set_domain_address: ", target_address, option::some(rando_addr), false); + 1,); + + v2_1_domains::force_set_target_address(aptos_names_v2_1, + v2_1_test_helper::domain_name(), option::none(), rando_addr); + let target_address = + v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_utils::print_actual_expected(b"set_domain_address: ", target_address, + option::some(rando_addr), false); assert!(target_address == option::some(rando_addr), 33); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names_v2_1::v2_1_config)] fun test_rando_cant_force_set_target_address_e2e( router_signer: &signer, @@ -430,27 +475,28 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); let rando_addr = signer::address_of(rando); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Rando is not allowed to do this - v2_1_domains::force_set_target_address(rando, v2_1_test_helper::domain_name(), option::none(), rando_addr); + v2_1_domains::force_set_target_address(rando, v2_1_test_helper::domain_name(), + option::none(), rando_addr); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_admin_can_force_renew_domain_name( router_signer: &signer, aptos_names_v2_1: &signer, @@ -459,36 +505,41 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(user), v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(user), + v2_1_test_helper::domain_name(), option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 1); - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); - assert!( - expiration_time_sec / SECONDS_PER_YEAR == 1, expiration_time_sec / SECONDS_PER_YEAR); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + assert!(expiration_time_sec / SECONDS_PER_YEAR == 1, expiration_time_sec / SECONDS_PER_YEAR); // renew the domain by admin outside of renewal window - v2_1_domains::force_set_name_expiration(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::none(), timestamp::now_seconds() + 2 * v2_1_test_helper::one_year_secs()); + v2_1_domains::force_set_name_expiration(aptos_names_v2_1, + v2_1_test_helper::domain_name(), + option::none(), + timestamp::now_seconds() + 2 * v2_1_test_helper::one_year_secs()); - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); - assert!( - expiration_time_sec / SECONDS_PER_YEAR == 2, expiration_time_sec / SECONDS_PER_YEAR); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + assert!(expiration_time_sec / SECONDS_PER_YEAR == 2, expiration_time_sec / SECONDS_PER_YEAR); } - - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_admin_can_force_seize_domain_name( router_signer: &signer, aptos_names_v2_1: &signer, @@ -497,38 +548,48 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(user), v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(user), + v2_1_test_helper::domain_name(), option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 1); // Take the domain name for much longer than users are allowed to register it for - v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::none(), v2_1_test_helper::two_hundred_year_secs()); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(aptos_names_v2_1), v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, + v2_1_test_helper::domain_name(), + option::none(), + v2_1_test_helper::two_hundred_year_secs()); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(aptos_names_v2_1), + v2_1_test_helper::domain_name(), option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 2); // Ensure the expiration_time_sec is set to the new far future value - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); - assert!( - expiration_time_sec / SECONDS_PER_YEAR == 200, expiration_time_sec / SECONDS_PER_YEAR); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + assert!(expiration_time_sec / SECONDS_PER_YEAR == 200, expiration_time_sec / SECONDS_PER_YEAR); // Ensure that the user's primary name is no longer set. assert!(option::is_none(&v2_1_domains::get_reverse_lookup(user_addr)), 1); } - #[test( - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_admin_can_force_create_domain_name( aptos_names_v2_1: &signer, user: signer, @@ -536,36 +597,40 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let _ = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let _ = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); // No domain is registered yet - assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 1); + assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 1); // Take the domain name for much longer than users are allowed to register it for - v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::none(), v2_1_test_helper::two_hundred_year_secs()); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(aptos_names_v2_1), v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, + v2_1_test_helper::domain_name(), + option::none(), + v2_1_test_helper::two_hundred_year_secs()); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(aptos_names_v2_1), + v2_1_test_helper::domain_name(), option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 2); // Ensure the expiration_time_sec is set to the new far future value - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); - assert!( - expiration_time_sec / SECONDS_PER_YEAR == 200, expiration_time_sec / SECONDS_PER_YEAR); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + assert!(expiration_time_sec / SECONDS_PER_YEAR == 200, expiration_time_sec / SECONDS_PER_YEAR); // Try to nuke the domain - assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 3); - v2_1_domains::force_clear_registration(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::none()); - assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 4); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 3); + v2_1_domains::force_clear_registration(aptos_names_v2_1, + v2_1_test_helper::domain_name(), option::none()); + assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 4); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names_v2_1::v2_1_config)] fun test_rando_cant_force_seize_domain_name( router_signer: &signer, @@ -575,27 +640,34 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(user), v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(user), + v2_1_test_helper::domain_name(), option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 1); // Take the domain name for much longer than users are allowed to register it for - v2_1_domains::force_create_or_seize_name(rando, v2_1_test_helper::domain_name(), option::none(), v2_1_test_helper::two_hundred_year_secs()); + v2_1_domains::force_create_or_seize_name(rando, + v2_1_test_helper::domain_name(), + option::none(), + v2_1_test_helper::two_hundred_year_secs()); } - #[test( - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names_v2_1::v2_1_config)] fun test_rando_cant_force_create_domain_name( aptos_names_v2_1: &signer, @@ -604,24 +676,22 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let rando = vector::borrow(&users, 1); // No domain is registered yet - assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 1); + assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 1); // Take the domain name for much longer than users are allowed to register it for - v2_1_domains::force_create_or_seize_name(rando, v2_1_test_helper::domain_name(), option::none(), v2_1_test_helper::two_hundred_year_secs()); + v2_1_domains::force_create_or_seize_name(rando, + v2_1_test_helper::domain_name(), + option::none(), + v2_1_test_helper::two_hundred_year_secs()); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_clear_name_happy_path_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -630,12 +700,19 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Clear my reverse lookup. v2_1_domains::clear_reverse_lookup(user); @@ -643,14 +720,7 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { assert!(option::is_none(&v2_1_domains::get_reverse_lookup(user_addr)), 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_owner_of_expired_name_is_not_owner( router_signer: &signer, aptos_names_v2_1: &signer, @@ -659,33 +729,40 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - let is_owner = v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + let is_owner = + v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 1); // Set the time past the domain's expiration time - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); timestamp::update_global_time_for_test_secs(expiration_time_sec + 5); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(user), v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(user), + v2_1_test_helper::domain_name(), option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && is_expired, 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_transfer( router_signer: &signer, aptos_names_v2_1: &signer, @@ -694,7 +771,8 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); let rando = vector::borrow(&users, 1); @@ -707,34 +785,36 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1, - ); + 1,); // user is owner { - let is_owner = v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()); assert!(is_owner && !is_expired, 1); }; - let token_addr = v2_1_domains::get_token_addr(v2_1_test_helper::domain_name(), option::none()); + let token_addr = + v2_1_domains::get_token_addr(v2_1_test_helper::domain_name(), option::none()); object::transfer_raw(user, token_addr, rando_addr); // rando is owner { - let is_owner = v2_1_domains::is_token_owner(rando_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(rando_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()); assert!(is_owner && !is_expired, 1); }; } - #[test( - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_nonregistered_record_expiry( aptos_names_v2_1: &signer, user: signer, @@ -746,28 +826,22 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { // Non-registered domain should be expired { - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()); assert!(is_expired, 1); }; // Non-registered subdomain should be expired { - let is_expired = v2_1_domains::is_name_expired( - v2_1_test_helper::domain_name(), - option::some(v2_1_test_helper::subdomain_name()), - ); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()),); assert!(is_expired, 1); }; } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 393221, location = aptos_names_v2_1::v2_1_domains)] fun test_cannot_set_unregistered_name_as_primary_name( router_signer: &signer, @@ -777,32 +851,25 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1 - ); + 1); // Set a not exist domain as primary name, should trigger ENAME_NOT_EXIST error - aptos_names_v2_1::v2_1_domains::set_reverse_lookup(user, option::none(), string::utf8(b"notexist")); + aptos_names_v2_1::v2_1_domains::set_reverse_lookup(user, option::none(), + string::utf8(b"notexist")); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 196611, location = aptos_names_v2_1::v2_1_domains)] fun test_register_during_reregistration_grace( router_signer: &signer, @@ -812,7 +879,8 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); @@ -820,49 +888,45 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { v2_1_config::set_reregistration_grace_sec(aptos_names_v2_1, 30 * SECONDS_PER_DAY); // Register the domain - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1 - ); + 1); - let is_owner = v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 1); // Set the time right before the domain's expiration time + grace period - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec()); // Is still owner but name has expired - let is_owner = v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && is_expired, 1); // Register the domain again. Should fail because it's still in the grace period - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1 - ); + 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_register_after_reregistration_grace( router_signer: &signer, aptos_names_v2_1: &signer, @@ -871,7 +935,8 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); @@ -879,38 +944,42 @@ module aptos_names_v2_1::v2_1_domain_e2e_tests { v2_1_config::set_reregistration_grace_sec(aptos_names_v2_1, 30 * SECONDS_PER_DAY); // Register the domain - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1 - ); + 1); - let is_owner = v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 1); // Set the time right before the domain's expiration time + grace period - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); - timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + 1); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + + 1); // Is still owner but name has expired - let is_owner = v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && is_expired, 1); // Register the domain again. Should succeeds because it's out of the grace period - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1 - ); + 1); } } diff --git a/core_v2/sources/tests/v2_1_subdomain_e2e_tests.move b/core_v2/sources/tests/v2_1_subdomain_e2e_tests.move index b9047e05..022ac669 100644 --- a/core_v2/sources/tests/v2_1_subdomain_e2e_tests.move +++ b/core_v2/sources/tests/v2_1_subdomain_e2e_tests.move @@ -12,14 +12,7 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { const MAX_REMAINING_TIME_FOR_RENEWAL_SEC: u64 = 15552000; const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun happy_path_e2e_test( router_signer: &signer, aptos_names_v2_1: &signer, @@ -28,52 +21,71 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Set an address and verify it - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::none(), user_addr); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), user_addr); // Ensure the owner can clear the address - v2_1_test_helper::clear_target_address(user, option::none(), v2_1_test_helper::domain_name()); + v2_1_test_helper::clear_target_address(user, option::none(), + v2_1_test_helper::domain_name()); // And also can clear if the user is the registered address, but not owner - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::none(), signer::address_of(rando)); - v2_1_test_helper::clear_target_address(rando, option::none(), v2_1_test_helper::domain_name()); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), signer::address_of(rando)); + v2_1_test_helper::clear_target_address(rando, option::none(), + v2_1_test_helper::domain_name()); // Set it back for following tests - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::none(), user_addr); + v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), + option::none(), user_addr); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); // Set a subdomain address and verify it - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), user_addr); + v2_1_test_helper::set_target_address(user, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + user_addr); // Ensure these also work :-) - v2_1_test_helper::clear_target_address(user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name()); + v2_1_test_helper::clear_target_address(user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name()); // And also can clear if is registered address, but not owner - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), signer::address_of(rando)); - v2_1_test_helper::clear_target_address(rando, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name()); + v2_1_test_helper::set_target_address(user, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + signer::address_of(rando)); + v2_1_test_helper::clear_target_address(rando, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name()); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_renew_domain_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -82,41 +94,49 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); // Set the time is early than max remaining time for renewal from expiration time - timestamp::update_global_time_for_test_secs(expiration_time_sec - MAX_REMAINING_TIME_FOR_RENEWAL_SEC - 5); - assert!(!v2_1_domains::is_domain_in_renewal_window(v2_1_test_helper::domain_name()), 1); + timestamp::update_global_time_for_test_secs(expiration_time_sec - MAX_REMAINING_TIME_FOR_RENEWAL_SEC + - 5); + assert!(!v2_1_domains::is_domain_in_renewal_window(v2_1_test_helper::domain_name()), + 1); - timestamp::update_global_time_for_test_secs(expiration_time_sec - MAX_REMAINING_TIME_FOR_RENEWAL_SEC + 5); - assert!(v2_1_domains::is_domain_in_renewal_window(v2_1_test_helper::domain_name()), 2); + timestamp::update_global_time_for_test_secs(expiration_time_sec - MAX_REMAINING_TIME_FOR_RENEWAL_SEC + + 5); + assert!(v2_1_domains::is_domain_in_renewal_window(v2_1_test_helper::domain_name()), + 2); // Renew the domain v2_1_domains::renew_domain(user, v2_1_test_helper::domain_name(), SECONDS_PER_YEAR); // Ensure the domain is still registered after the original expiration time timestamp::update_global_time_for_test_secs(expiration_time_sec + 5); - assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 4); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 4); - let new_expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + let new_expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); // Ensure the domain is still expired after the new expiration time timestamp::update_global_time_for_test_secs(new_expiration_time_sec + 5); - assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()), 5); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()), 5); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 131083, location = aptos_names_v2_1::v2_1_domains)] fun test_register_subdomain_with_invalid_string( router_signer: &signer, @@ -126,25 +146,31 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain with an invalid string! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::invalid_subdomain_name()), v2_1_test_helper::domain_name(), timestamp::now_seconds() + v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::invalid_subdomain_name()), + v2_1_test_helper::domain_name(), + timestamp::now_seconds() + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_auto_renew_subdomain_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -153,39 +179,51 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), timestamp::now_seconds() + v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + timestamp::now_seconds() + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); // The subdomain auto-renewal policy is true by default - assert!( - v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name()) == 0, 2); + assert!(v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name()) == 0, + 2); // The subdomain auto-renewal policy is set to auto_renew - v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), 1); + v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), 1); // Renew the domain (and the subdomain should be auto renewed) - let original_expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); + let original_expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); timestamp::update_global_time_for_test_secs(original_expiration_time_sec - 5); v2_1_domains::renew_domain(user, v2_1_test_helper::domain_name(), SECONDS_PER_YEAR); // Set the time past the domain's expiration time timestamp::update_global_time_for_test_secs(original_expiration_time_sec + 5); // Both domain and subdomain are not expired - assert!(!v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()), 80); - assert!(!v2_1_domains::is_name_expired( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 80); - } - - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + assert!(!v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()), 80); + assert!(!v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 80); + } + + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 65562, location = aptos_names_v2_1::v2_1_domains)] fun test_set_subdomain_expiration_policy( router_signer: &signer, @@ -195,32 +233,42 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); - assert!( - v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name()) == 0, 2); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); + assert!(v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name()) == 0, + 2); // test set the policy to auto-renewal - v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), 1); - assert!( - v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name()) == 1, 3); + v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), 1); + assert!(v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name()) == 1, + 3); // test set the policy to something not exist - v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), 100); + v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), 100); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_manual_renew_subdomain_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -229,38 +277,50 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); - v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), 0); - assert!( - v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name()) == 0, 2); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); + v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), 0); + assert!(v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name()) == 0, + 2); // Set the time past the domain's expiration time - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); // Renew the domain before it's expired timestamp::update_global_time_for_test_secs(expiration_time_sec - 5); v2_1_domains::renew_domain(user, v2_1_test_helper::domain_name(), SECONDS_PER_YEAR); // Set the time past the domain's expiration time timestamp::update_global_time_for_test_secs(expiration_time_sec + 5); // Ensure the subdomain is still expired after domain renewal - assert!(!v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()), 80); - assert!( - v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 80); + assert!(!v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()), 80); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 80); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_admin_can_force_renew_subdomain_name( router_signer: &signer, aptos_names_v2_1: &signer, @@ -269,32 +329,41 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); // renew the domain by admin outside of renewal window - v2_1_domains::force_set_name_expiration(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), timestamp::now_seconds() + 2 * v2_1_test_helper::one_year_secs()); + v2_1_domains::force_set_name_expiration(aptos_names_v2_1, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + timestamp::now_seconds() + 2 * v2_1_test_helper::one_year_secs()); - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); - assert!( - expiration_time_sec / SECONDS_PER_YEAR == 2, expiration_time_sec / SECONDS_PER_YEAR); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + assert!(expiration_time_sec / SECONDS_PER_YEAR == 2, expiration_time_sec / SECONDS_PER_YEAR); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_transfer_subdomain( router_signer: &signer, aptos_names_v2_1: &signer, @@ -303,83 +372,69 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, 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); // create the domain - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1 - ); - v2_1_test_helper::register_name( - router_signer, + 1); + v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1 - ); + 1); // user is the owner of domain - let is_owner = v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 1); // transfer the subdomain to rando - v2_1_domains::transfer_subdomain_owner( - user, + v2_1_domains::transfer_subdomain_owner(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), rando_addr, - option::some(rando_addr) - ); + option::some(rando_addr)); // rando owns the subdomain - let is_owner = v2_1_domains::is_token_owner( - rando_addr, - v2_1_test_helper::domain_name(), - option::some(v2_1_test_helper::subdomain_name()) - ); - let is_expired = v2_1_domains::is_name_expired( - v2_1_test_helper::domain_name(), - option::some(v2_1_test_helper::subdomain_name()) - ); + let is_owner = + v2_1_domains::is_token_owner(rando_addr, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(is_owner && !is_expired, 2); { // when rando owns the subdomain and user owns the domain, user can still transfer the subdomain. - v2_1_domains::transfer_subdomain_owner( - user, + v2_1_domains::transfer_subdomain_owner(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), user_addr, - option::some(user_addr) - ); - let is_owner = v2_1_domains::is_token_owner( - user_addr, - v2_1_test_helper::domain_name(), - option::some(v2_1_test_helper::subdomain_name()), - ); + option::some(user_addr)); + let is_owner = + v2_1_domains::is_token_owner(user_addr, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()),); assert!(is_owner, 1); } } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327686, location = aptos_names_v2_1::v2_1_domains)] fun test_non_domain_owner_transfer_subdomain( router_signer: &signer, @@ -389,49 +444,54 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, 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); // create the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // user is the owner of domain - let is_owner = v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), option::none()); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); + let is_owner = + v2_1_domains::is_token_owner(user_addr, v2_1_test_helper::domain_name(), + option::none()); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()); assert!(is_owner && !is_expired, 1); // transfer the subdomain to rando - v2_1_domains::transfer_subdomain_owner( - user, + v2_1_domains::transfer_subdomain_owner(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), rando_addr, - option::some(rando_addr) - ); + option::some(rando_addr)); { // when rando owns the subdomain but not the domain, rando can't transfer subdomain ownership. - v2_1_domains::transfer_subdomain_owner( - rando, + v2_1_domains::transfer_subdomain_owner(rando, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), user_addr, - option::some(user_addr) - ); + option::some(user_addr)); } } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 196632, location = aptos_names_v2_1::v2_1_domains)] fun test_set_expiration_date_for_subdomain( router_signer: &signer, @@ -441,30 +501,44 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); // Set the auto-renewal flag as false - v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), 0); + v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), 0); - v2_1_domains::set_subdomain_expiration(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), timestamp::now_seconds() + 10); - let domain_expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + v2_1_domains::set_subdomain_expiration(user, + v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), + timestamp::now_seconds() + 10); + let domain_expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); // expect error when the expiration date pass the domain expiration date - v2_1_domains::set_subdomain_expiration(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), domain_expiration_time_sec + 5); + v2_1_domains::set_subdomain_expiration(user, + v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), + domain_expiration_time_sec + 5); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 65561, location = aptos_names_v2_1::v2_1_domains)] fun test_register_domain_less_than_a_year( router_signer: &signer, @@ -474,20 +548,20 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), 100, v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + 100, + v2_1_test_helper::fq_domain_name(), + 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 65561, location = aptos_names_v2_1::v2_1_domains)] fun test_register_domain_duration_not_whole_years( router_signer: &signer, @@ -497,20 +571,20 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs()+5, v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs() + 5, + v2_1_test_helper::fq_domain_name(), + 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_names_are_registerable_after_expiry_past_grace_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -519,94 +593,142 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), timestamp::now_seconds() + v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + timestamp::now_seconds() + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); // Set the subdomain auto-renewal policy to false - v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), 0); + v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), 0); // Set the time past the domain's expiration time and past grace period - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); - timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + 5); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + + 5); // The domain should now be: expired, registered, AND registerable - assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()), 80); - assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 81); - assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), option::none()), 82); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()), 80); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 81); + assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), + option::none()), 82); // The subdomain now be: expired, registered, AND NOT registerable (because the domain is expired, too) - assert!( - v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 90); - assert!( - v2_1_domains::is_name_registered( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 91); - assert!(!v2_1_domains::is_name_registerable( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 92); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 90); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 91); + assert!(!v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 92); // Lets try to register it again, now that it is expired - v2_1_test_helper::register_name(router_signer, rando, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 2); + v2_1_test_helper::register_name(router_signer, + rando, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 2); // The subdomain should now be registerable: it's both expired AND the domain is registered - assert!( - v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 93); - assert!( - v2_1_domains::is_name_registered( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 94); - assert!( - v2_1_domains::is_name_registerable( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 95); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 93); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 94); + assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 95); // and likewise for the subdomain - v2_1_test_helper::register_name(router_signer, rando, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 2); + v2_1_test_helper::register_name(router_signer, + rando, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 2); // And again! - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); - timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + 5); - + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + timestamp::update_global_time_for_test_secs(expiration_time_sec + v2_1_config::reregistration_grace_sec() + + 5); // The domain should now be: expired, registered, AND registerable - assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::none()), 80); - assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), option::none()), 81); - assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), option::none()), 82); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::none()), 80); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::none()), 81); + assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), + option::none()), 82); // The subdomain now be: expired, registered, AND NOT registerable (because the domain is expired, too) - assert!( - v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 90); - assert!( - v2_1_domains::is_name_registered( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 91); - assert!(!v2_1_domains::is_name_registerable( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 92); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 90); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 91); + assert!(!v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 92); // Lets try to register it again, now that it is expired - v2_1_test_helper::register_name(router_signer, rando, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 3); + v2_1_test_helper::register_name(router_signer, + rando, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 3); // The subdomain should now be registerable: it's both expired AND the domain is registered - assert!( - v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 93); - assert!( - v2_1_domains::is_name_registered( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 94); - assert!( - v2_1_domains::is_name_registerable( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 95); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 93); + assert!(v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 94); + assert!(v2_1_domains::is_name_registerable(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 95); // and likewise for the subdomain - v2_1_test_helper::register_name(router_signer, rando, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 3); + v2_1_test_helper::register_name(router_signer, + rando, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 3); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 196611, location = aptos_names_v2_1::v2_1_domains)] fun test_dont_allow_double_subdomain_registrations_e2e( router_signer: &signer, @@ -616,24 +738,36 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Try to register a subdomain twice (ensure we can't) - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_get_target_address_for_subdomain( router_signer: &signer, aptos_names_v2_1: &signer, @@ -642,32 +776,44 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(),option::some(v2_1_test_helper::subdomain_name()), user_addr); - let target_address = v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); + v2_1_test_helper::set_target_address(user, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + user_addr); + let target_address = + v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(target_address == option::some(user_addr), 2); timestamp::update_global_time_for_test_secs(v2_1_test_helper::one_year_secs() + 5); - let target_address = v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::none()); + let target_address = + v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::none()); assert!(option::is_none(&target_address), 3); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_get_expiration_sec_for_subdomain( router_signer: &signer, aptos_names_v2_1: &signer, @@ -676,39 +822,56 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); // Register a subdomain! - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); - assert!( - v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name()) == 0, 2); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); + assert!(v2_1_domains::get_subdomain_renewal_policy(v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name()) == 0, + 2); // set the subdomain's renewal policy to manual - v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), 0); + v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), 0); // set the subdomain's expiration date to now - v2_1_domains::set_subdomain_expiration(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), timestamp::now_seconds()); + v2_1_domains::set_subdomain_expiration(user, + v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), + timestamp::now_seconds()); // check that the subdomain's expiration date is now - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(expiration_time_sec == timestamp::now_seconds(), 3); // set the subdomain's renewal policy to auto renewal - v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), v2_1_test_helper::subdomain_name(), 1); - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); - let domain_expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); + v2_1_domains::set_subdomain_expiration_policy(user, v2_1_test_helper::domain_name(), + v2_1_test_helper::subdomain_name(), 1); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + let domain_expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::none()); assert!(expiration_time_sec == domain_expiration_time_sec, 4); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327689, location = aptos_names_v2_1::v2_1_domains)] fun test_dont_allow_rando_to_set_subdomain_address_e2e( router_signer: &signer, @@ -718,26 +881,34 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain and subdomain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); // Ensure we can't clear it as a rando. The expected target address doesn't matter as it won't get hit - v2_1_test_helper::set_target_address(rando, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), @aptos_names_v2_1); + v2_1_test_helper::set_target_address(rando, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + @aptos_names_v2_1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327689, location = aptos_names_v2_1::v2_1_domains)] fun test_dont_allow_rando_to_clear_subdomain_address_e2e( router_signer: &signer, @@ -747,28 +918,38 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain and subdomain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); - v2_1_test_helper::set_target_address(user, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), signer::address_of(user)); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); + v2_1_test_helper::set_target_address(user, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + signer::address_of(user)); // Ensure we can't clear it as a rando. The expected target address doesn't matter as it won't get hit - v2_1_test_helper::set_target_address(rando, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), @aptos_names_v2_1); + v2_1_test_helper::set_target_address(rando, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + @aptos_names_v2_1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_admin_can_force_set_subdomain_address_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -777,31 +958,42 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); let rando_addr = signer::address_of(rando); // Register the domain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); - v2_1_domains::force_set_target_address(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), rando_addr); - let target_address = v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); - v2_1_test_utils::print_actual_expected(b"set_subdomain_address: ", target_address, option::some(rando_addr), false); + v2_1_domains::force_set_target_address(aptos_names_v2_1, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + rando_addr); + let target_address = + v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + v2_1_test_utils::print_actual_expected(b"set_subdomain_address: ", target_address, + option::some(rando_addr), false); assert!(target_address == option::some(rando_addr), 33); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names_v2_1::v2_1_config)] fun test_rando_cant_force_set_subdomain_address_e2e( router_signer: &signer, @@ -811,7 +1003,8 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); @@ -819,22 +1012,29 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { let rando_addr = signer::address_of(rando); // Register the domain and subdomain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); // Rando is not allowed to do this - v2_1_domains::force_set_target_address(rando, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), rando_addr); + v2_1_domains::force_set_target_address(rando, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + rando_addr); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_admin_can_force_seize_subdomain_name_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -843,41 +1043,56 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // Register the domain and subdomain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(user), v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name())); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name())); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(user), + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(is_owner && !is_expired, 1); // Take the subdomain name for much longer than users are allowed to register it for - v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), v2_1_test_helper::one_year_secs()); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(aptos_names_v2_1), v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name())); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name())); + v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::one_year_secs()); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(aptos_names_v2_1), + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(is_owner && !is_expired, 2); // Ensure the expiration_time_sec is set to the new far future value - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); - assert!( - expiration_time_sec / SECONDS_PER_YEAR == 1, expiration_time_sec / SECONDS_PER_YEAR); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + assert!(expiration_time_sec / SECONDS_PER_YEAR == 1, expiration_time_sec / SECONDS_PER_YEAR); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_admin_can_force_create_subdomain_name_e2e( router_signer: &signer, aptos_names_v2_1: &signer, @@ -886,37 +1101,44 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // No subdomain is registered yet - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - assert!(!v2_1_domains::is_name_registered( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 1); // Take the subdomain name - v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), v2_1_test_helper::one_year_secs()); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(aptos_names_v2_1), v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name())); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name())); + v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::one_year_secs()); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(aptos_names_v2_1), + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(is_owner && !is_expired, 2); // Ensure the expiration_time_sec is set to the new far future value - let expiration_time_sec = v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); - assert!( - expiration_time_sec / SECONDS_PER_YEAR == 1, expiration_time_sec / SECONDS_PER_YEAR); + let expiration_time_sec = + v2_1_domains::get_expiration(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + assert!(expiration_time_sec / SECONDS_PER_YEAR == 1, expiration_time_sec / SECONDS_PER_YEAR); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 131096, location = aptos_names_v2_1::v2_1_domains)] fun test_admin_cant_force_create_subdomain_more_than_domain_time_e2e( router_signer: &signer, @@ -926,27 +1148,30 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); // No subdomain is registered yet- domain is registered for 1 year - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - assert!(!v2_1_domains::is_name_registered( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 1); // Take the subdomain name for longer than domain: this should explode - v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), v2_1_test_helper::one_year_secs() + 1); + v2_1_domains::force_create_or_seize_name(aptos_names_v2_1, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::one_year_secs() + 1); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names_v2_1::v2_1_config)] fun test_rando_cant_force_seize_subdomain_name_e2e( router_signer: &signer, @@ -956,32 +1181,43 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register the domain and subdomain - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), 1); - let is_owner = v2_1_domains::is_token_owner(signer::address_of(user), v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name())); - let is_expired = v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name())); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + v2_1_test_helper::register_name(router_signer, + user, + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_subdomain_name(), + 1); + let is_owner = + v2_1_domains::is_token_owner(signer::address_of(user), + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); + let is_expired = + v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(is_owner && !is_expired, 1); // Attempt (and fail) to take the subdomain name for much longer than users are allowed to register it for - v2_1_domains::force_create_or_seize_name(rando, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), v2_1_test_helper::two_hundred_year_secs()); + v2_1_domains::force_create_or_seize_name(rando, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::two_hundred_year_secs()); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327681, location = aptos_names_v2_1::v2_1_config)] fun test_rando_cant_force_create_subdomain_name_e2e( router_signer: &signer, @@ -991,28 +1227,31 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let rando = vector::borrow(&users, 1); // Register a domain, and ensure no subdomain is registered yet - v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), 1); - assert!(!v2_1_domains::is_name_registered( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 1); + v2_1_test_helper::register_name(router_signer, + user, + option::none(), + v2_1_test_helper::domain_name(), + v2_1_test_helper::one_year_secs(), + v2_1_test_helper::fq_domain_name(), + 1); + assert!(!v2_1_domains::is_name_registered(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 1); // Attempt (and fail) to take the subdomain name for much longer than users are allowed to register it for - v2_1_domains::force_create_or_seize_name(rando, v2_1_test_helper::domain_name(), option::some( - v2_1_test_helper::subdomain_name()), v2_1_test_helper::two_hundred_year_secs()); + v2_1_domains::force_create_or_seize_name(rando, + v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::two_hundred_year_secs()); } - #[test( - router_signer = @router_signer, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router_signer = @router_signer, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_subdomain_reset( router_signer: &signer, aptos_names_v2_1: &signer, @@ -1021,89 +1260,91 @@ module aptos_names_v2_1::v2_1_subdomain_e2e_tests { rando: signer, foundation: signer, ) { - let users = v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + v2_1_test_helper::e2e_test_setup(aptos_names_v2_1, user, &aptos, rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); // Register the domain - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 1 - ); + 1); // Register a subdomain! - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), - 1 - ); - assert!(!v2_1_domains::is_name_expired( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 1); + 1); + assert!(!v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 1); // Let the domain expire and re-register it timestamp::update_global_time_for_test_secs(SECONDS_PER_YEAR * 2); - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::none(), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_domain_name(), - 2 - ); + 2); // The subdomain should be clear (expired, no target addr, no owner) { - assert!(v2_1_domains::is_name_expired( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 3); - let owner_addr = v2_1_domains::get_name_owner_addr( - option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name()); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 3); + let owner_addr = + v2_1_domains::get_name_owner_addr(option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name()); assert!(owner_addr == option::none(), 4); - let target_addr = v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); + let target_addr = + v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(target_addr == option::none(), 5); }; // Even if the admin force changes the expiration time, the subdomain should still be clear - v2_1_domains::force_set_name_expiration( - aptos_names_v2_1, + v2_1_domains::force_set_name_expiration(aptos_names_v2_1, v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name()), - timestamp::now_seconds() + v2_1_test_helper::one_year_secs() - ); + timestamp::now_seconds() + v2_1_test_helper::one_year_secs()); { - assert!(v2_1_domains::is_name_expired( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 3); - let owner_addr = v2_1_domains::get_name_owner_addr( - option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name()); + assert!(v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 3); + let owner_addr = + v2_1_domains::get_name_owner_addr(option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name()); assert!(owner_addr == option::none(), 4); - let target_addr = v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())); + let target_addr = + v2_1_domains::get_target_address(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())); assert!(target_addr == option::none(), 5); }; // The subdomain can be re-registered - v2_1_test_helper::register_name( - router_signer, + v2_1_test_helper::register_name(router_signer, user, option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name(), v2_1_test_helper::one_year_secs(), v2_1_test_helper::fq_subdomain_name(), - 3 - ); + 3); { - assert!(!v2_1_domains::is_name_expired( - v2_1_test_helper::domain_name(), option::some(v2_1_test_helper::subdomain_name())), 3); - let owner_addr = v2_1_domains::get_name_owner_addr( - option::some(v2_1_test_helper::subdomain_name()), v2_1_test_helper::domain_name()); + assert!(!v2_1_domains::is_name_expired(v2_1_test_helper::domain_name(), + option::some(v2_1_test_helper::subdomain_name())), + 3); + let owner_addr = + v2_1_domains::get_name_owner_addr(option::some(v2_1_test_helper::subdomain_name()), + v2_1_test_helper::domain_name()); assert!(*option::borrow(&owner_addr) == user_addr, 4); }; } diff --git a/core_v2/sources/tests/v2_1_test_helper.move b/core_v2/sources/tests/v2_1_test_helper.move index 4dddf32c..abcf30da 100644 --- a/core_v2/sources/tests/v2_1_test_helper.move +++ b/core_v2/sources/tests/v2_1_test_helper.move @@ -86,15 +86,14 @@ module aptos_names_v2_1::v2_1_test_helper { let set_target_address_event_event_count_before = v2_1_domains::get_set_target_address_event_count(); if (option::is_none(&subdomain_name)) { - v2_1_domains::register_domain(router_signer, user, domain_name, registration_duration_secs); + v2_1_domains::register_domain(router_signer, user, domain_name, + registration_duration_secs); } else { - v2_1_domains::register_subdomain( - router_signer, + v2_1_domains::register_subdomain(router_signer, user, domain_name, *option::borrow(&subdomain_name), - timestamp::now_seconds() + registration_duration_secs - ); + timestamp::now_seconds() + registration_duration_secs); }; // It should now be: not expired, registered, and not registerable @@ -102,7 +101,8 @@ module aptos_names_v2_1::v2_1_test_helper { assert!(!v2_1_domains::is_name_registerable(domain_name, subdomain_name), 13); assert!(v2_1_domains::is_name_registered(domain_name, subdomain_name), 14); - let is_owner = v2_1_domains::is_token_owner(user_addr, domain_name, subdomain_name); + let is_owner = + v2_1_domains::is_token_owner(user_addr, domain_name, subdomain_name); let is_expired = v2_1_domains::is_name_expired(domain_name, subdomain_name); // TODO: Re-enable / Re-write // let (tdi_creator, tdi_collection, tdi_name, tdi_property_version) = token::get_token_id_fields(&token_id); @@ -114,24 +114,19 @@ module aptos_names_v2_1::v2_1_test_helper { if (is_subdomain) { // If it's a subdomain, we only charge a nomincal fee expected_user_balance_after = user_balance_before - v2_1_price_model::price_for_subdomain( - registration_duration_secs - ); + registration_duration_secs); } else { - let domain_price = v2_1_price_model::price_for_domain( - string::length(&domain_name), - registration_duration_secs - ); + let domain_price = + v2_1_price_model::price_for_domain(string::length(&domain_name), + registration_duration_secs); assert!(domain_price / v2_1_config::octas() == 10, domain_price / v2_1_config::octas()); expected_user_balance_after = user_balance_before - domain_price; }; - v2_1_test_utils::print_actual_expected( - b"user_balance_after: ", - user_balance_after, - expected_user_balance_after, - false - ); - assert!(user_balance_after == expected_user_balance_after, expected_user_balance_after); + v2_1_test_utils::print_actual_expected(b"user_balance_after: ", user_balance_after, + expected_user_balance_after, false); + assert!(user_balance_after == expected_user_balance_after, + expected_user_balance_after); // Ensure the name was registered correctly, with an expiration timestamp one year in the future let expiration_time_sec = v2_1_domains::get_expiration(domain_name, subdomain_name); @@ -146,25 +141,17 @@ module aptos_names_v2_1::v2_1_test_helper { // assert!(token_name == token_name, 22); // Assert events have been correctly emmitted - let register_name_event_num_emitted = v2_1_domains::get_register_name_event_count( - ) - register_name_event_event_count_before; - let set_target_address_event_num_emitted = v2_1_domains::get_set_target_address_event_count( - ) - set_target_address_event_event_count_before; - - v2_1_test_utils::print_actual_expected( - b"register_name_event_num_emitted: ", - register_name_event_num_emitted, - 1, - false - ); + let register_name_event_num_emitted = + v2_1_domains::get_register_name_event_count() - register_name_event_event_count_before; + let set_target_address_event_num_emitted = + v2_1_domains::get_set_target_address_event_count() - set_target_address_event_event_count_before; + + v2_1_test_utils::print_actual_expected(b"register_name_event_num_emitted: ", + register_name_event_num_emitted, 1, false); assert!(register_name_event_num_emitted == 1, register_name_event_num_emitted); - v2_1_test_utils::print_actual_expected( - b"set_target_address_event_num_emitted: ", - set_target_address_event_num_emitted, - 1, - false - ); + v2_1_test_utils::print_actual_expected(b"set_target_address_event_num_emitted: ", + set_target_address_event_num_emitted, 1, false); } /// Set the domain address, and verify the address was set correctly @@ -181,14 +168,11 @@ module aptos_names_v2_1::v2_1_test_helper { let set_reverse_lookup_event_event_count_before = v2_1_domains::get_set_reverse_lookup_event_count(); let maybe_reverse_lookup_before = v2_1_domains::get_reverse_lookup(user_addr); - v2_1_domains::set_target_address(user, domain_name, subdomain_name, expected_target_address); + v2_1_domains::set_target_address(user, domain_name, subdomain_name, + expected_target_address); let target_address = v2_1_domains::get_target_address(domain_name, subdomain_name); - v2_1_test_utils::print_actual_expected( - b"set_domain_address: ", - target_address, - option::some(expected_target_address), - false - ); + v2_1_test_utils::print_actual_expected(b"set_domain_address: ", target_address, + option::some(expected_target_address), false); assert!(target_address == option::some(expected_target_address), 33); // When setting the target address to an address that is *not* the owner's, the reverse lookup should also be cleared @@ -198,44 +182,39 @@ module aptos_names_v2_1::v2_1_test_helper { }; // Assert events have been correctly emmitted - let register_name_event_num_emitted = v2_1_domains::get_register_name_event_count( - ) - register_name_event_event_count_before; - let set_target_address_event_num_emitted = v2_1_domains::get_set_target_address_event_count( - ) - set_target_address_event_event_count_before; - let set_reverse_lookup_event_num_emitted = v2_1_domains::get_set_reverse_lookup_event_count( - ) - set_reverse_lookup_event_event_count_before; - - v2_1_test_utils::print_actual_expected( - b"register_name_event_num_emitted: ", - register_name_event_num_emitted, - 0, - false - ); + let register_name_event_num_emitted = + v2_1_domains::get_register_name_event_count() - register_name_event_event_count_before; + let set_target_address_event_num_emitted = + v2_1_domains::get_set_target_address_event_count() - set_target_address_event_event_count_before; + let set_reverse_lookup_event_num_emitted = + v2_1_domains::get_set_reverse_lookup_event_count() - set_reverse_lookup_event_event_count_before; + + v2_1_test_utils::print_actual_expected(b"register_name_event_num_emitted: ", + register_name_event_num_emitted, 0, false); assert!(register_name_event_num_emitted == 0, register_name_event_num_emitted); - v2_1_test_utils::print_actual_expected( - b"set_target_address_event_num_emitted: ", - set_target_address_event_num_emitted, - 1, - false - ); - assert!(set_target_address_event_num_emitted == 1, set_target_address_event_num_emitted); + v2_1_test_utils::print_actual_expected(b"set_target_address_event_num_emitted: ", + set_target_address_event_num_emitted, 1, false); + assert!(set_target_address_event_num_emitted == 1, + set_target_address_event_num_emitted); // If the signer had a reverse lookup before, and set his reverse lookup name to a different address, it should be cleared if (option::is_some(&maybe_reverse_lookup_before)) { - let (maybe_reverse_subdomain, reverse_domain) = v2_1_domains::get_name_props_from_token_addr( - *option::borrow(&maybe_reverse_lookup_before) - ); - if (maybe_reverse_subdomain == subdomain_name && reverse_domain == domain_name && signer::address_of( - user - ) != expected_target_address) { - assert!(set_reverse_lookup_event_num_emitted == 1, set_reverse_lookup_event_num_emitted); + let (maybe_reverse_subdomain, reverse_domain) = + v2_1_domains::get_name_props_from_token_addr(*option::borrow(&maybe_reverse_lookup_before)); + if (maybe_reverse_subdomain == subdomain_name + && reverse_domain == domain_name + && signer::address_of(user) != expected_target_address) { + assert!(set_reverse_lookup_event_num_emitted == 1, + set_reverse_lookup_event_num_emitted); }; }; } /// Clear the domain address, and verify the address was cleared - public fun clear_target_address(user: &signer, subdomain_name: Option, domain_name: String) { + public fun clear_target_address( + user: &signer, subdomain_name: Option, domain_name: String + ) { let user_addr = signer::address_of(user); let register_name_event_event_count_before = v2_1_domains::get_register_name_event_count(); let set_target_address_event_event_count_before = v2_1_domains::get_set_target_address_event_count(); @@ -244,45 +223,43 @@ module aptos_names_v2_1::v2_1_test_helper { v2_1_domains::clear_target_address(user, subdomain_name, domain_name); let target_address = v2_1_domains::get_target_address(domain_name, subdomain_name); - v2_1_test_utils::print_actual_expected(b"clear_domain_address: ", target_address, option::none(), false); + v2_1_test_utils::print_actual_expected(b"clear_domain_address: ", target_address, + option::none(), false); assert!(target_address == option::none(), 32); if (option::is_some(&maybe_reverse_lookup_before)) { let reverse_lookup_before = option::borrow(&maybe_reverse_lookup_before); - if (*reverse_lookup_before == v2_1_domains::get_token_addr(domain_name, subdomain_name)) { + if (*reverse_lookup_before + == v2_1_domains::get_token_addr(domain_name, subdomain_name)) { let reverse_lookup_after = v2_1_domains::get_reverse_lookup(user_addr); assert!(option::is_none(&reverse_lookup_after), 35); - let set_reverse_lookup_event_num_emitted = v2_1_domains::get_set_reverse_lookup_event_count( - ) - set_reverse_lookup_event_event_count_before; - assert!(set_reverse_lookup_event_num_emitted == 1, set_reverse_lookup_event_num_emitted); + let set_reverse_lookup_event_num_emitted = + v2_1_domains::get_set_reverse_lookup_event_count() - set_reverse_lookup_event_event_count_before; + assert!(set_reverse_lookup_event_num_emitted == 1, + set_reverse_lookup_event_num_emitted); }; }; // Assert events have been correctly emmitted - let register_name_event_num_emitted = v2_1_domains::get_register_name_event_count( - ) - register_name_event_event_count_before; - let set_target_address_event_num_emitted = v2_1_domains::get_set_target_address_event_count( - ) - set_target_address_event_event_count_before; - - v2_1_test_utils::print_actual_expected( - b"register_name_event_num_emitted: ", - register_name_event_num_emitted, - 0, - false - ); + let register_name_event_num_emitted = + v2_1_domains::get_register_name_event_count() - register_name_event_event_count_before; + let set_target_address_event_num_emitted = + v2_1_domains::get_set_target_address_event_count() - set_target_address_event_event_count_before; + + v2_1_test_utils::print_actual_expected(b"register_name_event_num_emitted: ", + register_name_event_num_emitted, 0, false); assert!(register_name_event_num_emitted == 0, register_name_event_num_emitted); - v2_1_test_utils::print_actual_expected( - b"set_target_address_event_num_emitted: ", - set_target_address_event_num_emitted, - 1, - false - ); - assert!(set_target_address_event_num_emitted == 1, set_target_address_event_num_emitted); + v2_1_test_utils::print_actual_expected(b"set_target_address_event_num_emitted: ", + set_target_address_event_num_emitted, 1, false); + assert!(set_target_address_event_num_emitted == 1, + set_target_address_event_num_emitted); } - public fun setup_and_fund_accounts(aptos: &signer, foundation: &signer, users: vector): vector { + public fun setup_and_fund_accounts( + aptos: &signer, foundation: &signer, users: vector + ): vector { let (burn_cap, mint_cap) = aptos_framework::aptos_coin::initialize_for_test(aptos); let len = vector::length(&users); diff --git a/core_v2/sources/tests/v2_1_test_utils.move b/core_v2/sources/tests/v2_1_test_utils.move index bf4f5ee9..ba9053ba 100644 --- a/core_v2/sources/tests/v2_1_test_utils.move +++ b/core_v2/sources/tests/v2_1_test_utils.move @@ -13,22 +13,18 @@ module aptos_names_v2_1::v2_1_test_utils { expected: T, } - public fun print_actual_expected(label: vector, actual: T, expected: T, always: bool) { - if (!always && &actual == &expected) { - return - }; - let expected_actual = ActualExpectedDebug { - actual, - expected, - }; + public fun print_actual_expected( + label: vector, actual: T, expected: T, always: bool + ) { + if (!always && &actual == &expected) { return }; + let expected_actual = + ActualExpectedDebug { actual, expected, }; print_trace(label, expected_actual); } public fun print(label: vector, value: T) { - let print_debug = PrintDebug { - label: string::utf8(label), - value, - }; + let print_debug = + PrintDebug { label: string::utf8(label), value, }; debug::print(&print_debug); let PrintDebug { label: _, value: _ } = print_debug; } diff --git a/core_v2/sources/v2_1_config.move b/core_v2/sources/v2_1_config.move index 79576d07..32e7241a 100644 --- a/core_v2/sources/v2_1_config.move +++ b/core_v2/sources/v2_1_config.move @@ -49,28 +49,29 @@ module aptos_names_v2_1::v2_1_config { } public(friend) fun initialize_config( - deployer: &signer, - admin_address: address, - fund_destination_address: address + deployer: &signer, admin_address: address, fund_destination_address: address ) { - move_to(deployer, Config { - enabled: true, - admin_address, - fund_destination_address, - max_number_of_seconds_registered: SECONDS_PER_YEAR, - max_domain_length: 63, - min_domain_length: 3, - tokendata_description: string::utf8(b"This is an official Aptos Labs Name Service Name"), - tokendata_url_prefix: string::utf8(b"https://www.aptosnames.com/api/mainnet/v2/metadata/"), - domain_price_length_3: 20 * octas(), - domain_price_length_4: 10 * octas(), - domain_price_length_5: 5 * octas(), - domain_price_length_6_and_above: octas(), - // 0.2 APT - subdomain_price: 0, - // The number of seconds after a name expires that it can be re-registered - reregistration_grace_sec: 30 * SECONDS_PER_DAY, - }) + move_to(deployer, + Config { + enabled: true, + admin_address, + fund_destination_address, + max_number_of_seconds_registered: SECONDS_PER_YEAR, + max_domain_length: 63, + min_domain_length: 3, + tokendata_description: string::utf8( + b"This is an official Aptos Labs Name Service Name"), + tokendata_url_prefix: string::utf8( + b"https://www.aptosnames.com/api/mainnet/v2/metadata/"), + domain_price_length_3: 20 * octas(), + domain_price_length_4: 10 * octas(), + domain_price_length_5: 5 * octas(), + domain_price_length_6_and_above: octas(), + // 0.2 APT + subdomain_price: 0, + // The number of seconds after a name expires that it can be re-registered + reregistration_grace_sec: 30 * SECONDS_PER_DAY, + }) } // @@ -159,7 +160,8 @@ module aptos_names_v2_1::v2_1_config { /// The account will be used to manage names that are being used in a way that is harmful to others. /// Alternatively, the deployer can be used to perform admin actions. public fun signer_is_admin(sign: &signer): bool acquires Config { - signer::address_of(sign) == admin_address() || signer::address_of(sign) == @aptos_names_v2_1 + signer::address_of(sign) == admin_address() || signer::address_of(sign) == + @aptos_names_v2_1 } public fun assert_signer_is_admin(sign: &signer) acquires Config { @@ -187,7 +189,9 @@ module aptos_names_v2_1::v2_1_config { borrow_global_mut(@aptos_names_v2_1).admin_address = addr } - public entry fun set_max_number_of_seconds_registered(sign: &signer, max_seconds_registered: u64) acquires Config { + public entry fun set_max_number_of_seconds_registered( + sign: &signer, max_seconds_registered: u64 + ) acquires Config { assert_signer_is_admin(sign); assert!(max_seconds_registered > 0, error::invalid_argument(EINVALID_VALUE)); borrow_global_mut(@aptos_names_v2_1).max_number_of_seconds_registered = max_seconds_registered @@ -205,12 +209,16 @@ module aptos_names_v2_1::v2_1_config { borrow_global_mut(@aptos_names_v2_1).min_domain_length = domain_length } - public entry fun set_tokendata_description(sign: &signer, description: String) acquires Config { + public entry fun set_tokendata_description( + sign: &signer, description: String + ) acquires Config { assert_signer_is_admin(sign); borrow_global_mut(@aptos_names_v2_1).tokendata_description = description } - public entry fun set_tokendata_url_prefix(sign: &signer, url_prefix: String) acquires Config { + public entry fun set_tokendata_url_prefix( + sign: &signer, url_prefix: String + ) acquires Config { assert_signer_is_admin(sign); borrow_global_mut(@aptos_names_v2_1).tokendata_url_prefix = url_prefix } @@ -220,7 +228,9 @@ module aptos_names_v2_1::v2_1_config { borrow_global_mut(@aptos_names_v2_1).subdomain_price = price } - public entry fun set_domain_price_for_length(sign: &signer, price: u64, length: u64) acquires Config { + public entry fun set_domain_price_for_length( + sign: &signer, price: u64, length: u64 + ) acquires Config { assert_signer_is_admin(sign); assert!(length >= 3, error::invalid_argument(EINVALID_DOMAIN_LENGTH)); assert!(length >= 3, length); @@ -235,7 +245,9 @@ module aptos_names_v2_1::v2_1_config { } } - public entry fun set_reregistration_grace_sec(sign: &signer, reregistration_grace_sec: u64) acquires Config { + public entry fun set_reregistration_grace_sec( + sign: &signer, reregistration_grace_sec: u64 + ) acquires Config { assert_signer_is_admin(sign); borrow_global_mut(@aptos_names_v2_1).reregistration_grace_sec = reregistration_grace_sec } @@ -339,10 +351,11 @@ module aptos_names_v2_1::v2_1_config { assert!(admin_address() == signer::address_of(rando), 6); } - #[test(myself = @aptos_names_v2_1, rando = @0x266f, aptos = @0x1)] #[expected_failure(abort_code = 393218, location = aptos_framework::aptos_account)] - fun test_cant_set_foundation_address_without_coin(myself: &signer, rando: &signer, aptos: &signer) acquires Config { + fun test_cant_set_foundation_address_without_coin( + myself: &signer, rando: &signer, aptos: &signer + ) acquires Config { account::create_account_for_test(signer::address_of(myself)); account::create_account_for_test(signer::address_of(rando)); account::create_account_for_test(signer::address_of(aptos)); @@ -358,7 +371,9 @@ module aptos_names_v2_1::v2_1_config { #[test(myself = @aptos_names_v2_1, rando = @0x266f, aptos = @0x1)] #[expected_failure(abort_code = 327681, location = aptos_names_v2_1::v2_1_config)] - fun test_foundation_config_requires_admin(myself: &signer, rando: &signer, aptos: &signer) acquires Config { + fun test_foundation_config_requires_admin( + myself: &signer, rando: &signer, aptos: &signer + ) acquires Config { account::create_account_for_test(signer::address_of(myself)); account::create_account_for_test(signer::address_of(rando)); account::create_account_for_test(signer::address_of(aptos)); @@ -372,7 +387,9 @@ module aptos_names_v2_1::v2_1_config { #[test(myself = @aptos_names_v2_1, rando = @0x266f, aptos = @0x1)] #[expected_failure(abort_code = 327681, location = aptos_names_v2_1::v2_1_config)] - fun test_admin_config_requires_admin(myself: &signer, rando: &signer, aptos: &signer) acquires Config { + fun test_admin_config_requires_admin( + myself: &signer, rando: &signer, aptos: &signer + ) acquires Config { account::create_account_for_test(signer::address_of(myself)); account::create_account_for_test(signer::address_of(rando)); account::create_account_for_test(signer::address_of(aptos)); diff --git a/core_v2/sources/v2_1_domains.move b/core_v2/sources/v2_1_domains.move index fa58e83b..f3d00966 100644 --- a/core_v2/sources/v2_1_domains.move +++ b/core_v2/sources/v2_1_domains.move @@ -81,7 +81,7 @@ module aptos_names_v2_1::v2_1_domains { const ECANNOT_RENEW_NAME_THAT_IS_EXPIRED_AND_PAST_GRACE_PERIOD: u64 = 31; #[resource_group(scope = global)] - struct ObjectGroup { } + struct ObjectGroup {} /// Tokens require a signer to create and we want to store global resources. We use object to achieve both struct DomainObject has key { @@ -198,42 +198,41 @@ module aptos_names_v2_1::v2_1_domains { v2_1_config::initialize_config(account, admin_address, funds_address); // Create collection + token_resource - let constructor_ref = object::create_named_object( - account, - APP_OBJECT_SEED, - ); + let constructor_ref = + object::create_named_object(account, APP_OBJECT_SEED,); let extend_ref = object::generate_extend_ref(&constructor_ref); let app_signer = &object::generate_signer(&constructor_ref); - collection::create_unlimited_collection( - app_signer, + collection::create_unlimited_collection(app_signer, utf8(COLLECTION_DESCRIPTION), v2_1_config::domain_collection_name(), option::none(), - utf8(COLLECTION_URI), - ); - collection::create_unlimited_collection( - app_signer, + utf8(COLLECTION_URI),); + collection::create_unlimited_collection(app_signer, utf8(SUBDOMAIN_COLLECTION_DESCRIPTION), v2_1_config::subdomain_collection_name(), option::none(), - utf8(COLLECTION_URI), - ); + utf8(COLLECTION_URI),); aptos_account::create_account(signer::address_of(app_signer)); - move_to(app_signer, SetTargetAddressEvents { - set_name_events: account::new_event_handle(app_signer), - }); - move_to(app_signer, RegisterNameEvents { - register_name_events: account::new_event_handle(app_signer), - }); - move_to(app_signer, RenewNameEvents { - renew_name_events: account::new_event_handle(app_signer), - }); - move_to(app_signer, SetReverseLookupEvents { - set_reverse_lookup_events: account::new_event_handle(app_signer), - }); - move_to(app_signer, DomainObject { - extend_ref, - }); + move_to(app_signer, + SetTargetAddressEvents { + set_name_events: account::new_event_handle( + app_signer), + }); + move_to(app_signer, + RegisterNameEvents { + register_name_events: account::new_event_handle( + app_signer), + }); + move_to(app_signer, + RenewNameEvents { + renew_name_events: account::new_event_handle(app_signer), + }); + move_to(app_signer, + SetReverseLookupEvents { + set_reverse_lookup_events: account::new_event_handle( + app_signer), + }); + move_to(app_signer, DomainObject { extend_ref, }); } /// Creates a token for the name. @@ -244,38 +243,41 @@ module aptos_names_v2_1::v2_1_domains { subdomain_name: Option, expiration_time_sec: u64, ) acquires DomainObject { - let name = v2_1_token_helper::get_fully_qualified_domain_name(subdomain_name, domain_name); + let name = + v2_1_token_helper::get_fully_qualified_domain_name(subdomain_name, domain_name); let description = v2_1_config::tokendata_description(); let uri = v2_1_config::tokendata_url_prefix(); string::append(&mut uri, name); - let constructor_ref = token::create_named_token( - &get_app_signer(), - get_collection_name(is_subdomain(subdomain_name)), - description, - name, - option::none(), - uri, - ); + let constructor_ref = + token::create_named_token(&get_app_signer(), + get_collection_name(is_subdomain(subdomain_name)), + description, + name, + option::none(), + uri,); let token_signer = object::generate_signer(&constructor_ref); // creating subdomain - let record = NameRecord { - domain_name, - expiration_time_sec, - target_address: option::none(), - transfer_ref: object::generate_transfer_ref(&constructor_ref), - registration_time_sec: timestamp::now_seconds(), - extend_ref: object::generate_extend_ref(&constructor_ref), - }; + let record = + NameRecord { + domain_name, + expiration_time_sec, + target_address: option::none(), + transfer_ref: object::generate_transfer_ref(&constructor_ref), + registration_time_sec: timestamp::now_seconds(), + extend_ref: object::generate_extend_ref(&constructor_ref), + }; move_to(&token_signer, record); if (option::is_some(&subdomain_name)) { - let subdomain_ext = SubdomainExt { - subdomain_name: *option::borrow(&subdomain_name), - subdomain_expiration_policy: SUBDOMAIN_POLICY_MANUAL_SET_EXPIRATION, - }; + let subdomain_ext = + SubdomainExt { + subdomain_name: *option::borrow(&subdomain_name), + subdomain_expiration_policy: SUBDOMAIN_POLICY_MANUAL_SET_EXPIRATION, + }; move_to(&token_signer, subdomain_ext); }; - let record_obj = object::object_from_constructor_ref(&constructor_ref); + let record_obj = + object::object_from_constructor_ref(&constructor_ref); object::transfer(&get_app_signer(), record_obj, to_addr); } @@ -289,21 +291,25 @@ module aptos_names_v2_1::v2_1_domains { domain_name: String, registration_duration_secs: u64, ) acquires DomainObject, NameRecord, SubdomainExt, RegisterNameEvents, ReverseRecord, SetReverseLookupEvents { - assert!(address_of(router_signer) == @router_signer, error::permission_denied(ENOT_ROUTER)); + assert!(address_of(router_signer) == @router_signer, + error::permission_denied(ENOT_ROUTER)); assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); validate_registration_duration(registration_duration_secs); let subdomain_name = option::none(); - assert!(is_name_registerable(domain_name, subdomain_name), error::invalid_state(ENAME_NOT_AVAILABLE)); + assert!(is_name_registerable(domain_name, subdomain_name), + error::invalid_state(ENAME_NOT_AVAILABLE)); let length = validate_name_string(domain_name); - let price = v2_1_price_model::price_for_domain(length, registration_duration_secs); + let price = + v2_1_price_model::price_for_domain(length, registration_duration_secs); coin::transfer(sign, v2_1_config::fund_destination_address(), price); - register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, price); + register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, + price); } /// A wrapper around `register_name` as an entry function. @@ -316,34 +322,34 @@ module aptos_names_v2_1::v2_1_domains { subdomain_name: String, expiration_time_sec: u64 ) acquires DomainObject, NameRecord, SubdomainExt, RegisterNameEvents, ReverseRecord, SetReverseLookupEvents { - assert!(address_of(router_signer) == @router_signer, error::permission_denied(ENOT_ROUTER)); + assert!(address_of(router_signer) == @router_signer, + error::permission_denied(ENOT_ROUTER)); assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); - assert!( - is_name_registerable(domain_name, option::some(subdomain_name)), - error::invalid_state(ENAME_NOT_AVAILABLE) - ); + assert!(is_name_registerable(domain_name, option::some(subdomain_name)), + error::invalid_state(ENAME_NOT_AVAILABLE)); // We are registering a subdomain name: this has no cost, but is only doable by the owner of the domain validate_name_string(subdomain_name); // Ensure signer owns the domain we're registering a subdomain for let signer_addr = signer::address_of(sign); - assert!( - is_token_owner(signer_addr, domain_name, option::none()), - error::permission_denied(ENOT_OWNER_OF_DOMAIN) - ); - assert!( - !is_name_expired(domain_name, option::none()), - error::permission_denied(ECANNOT_REGISTER_SUBDOMAIN_WHILE_DOMAIN_HAS_EXPIRED) - ); + assert!(is_token_owner(signer_addr, domain_name, option::none()), + error::permission_denied(ENOT_OWNER_OF_DOMAIN)); + assert!(!is_name_expired(domain_name, option::none()), + error::permission_denied(ECANNOT_REGISTER_SUBDOMAIN_WHILE_DOMAIN_HAS_EXPIRED)); let registration_duration_secs = expiration_time_sec - timestamp::now_seconds(); - let price = v2_1_price_model::price_for_subdomain(registration_duration_secs); + let price = + v2_1_price_model::price_for_subdomain(registration_duration_secs); coin::transfer(sign, v2_1_config::fund_destination_address(), price); - register_name_internal(sign, option::some(subdomain_name), domain_name, registration_duration_secs, price); + register_name_internal(sign, + option::some(subdomain_name), + domain_name, + registration_duration_secs, + price); } /// Router-only registration that does not take registration fees. Should only be used for v1=>v2 migrations. @@ -356,15 +362,18 @@ module aptos_names_v2_1::v2_1_domains { registration_duration_secs: u64, ) acquires DomainObject, NameRecord, SubdomainExt, RegisterNameEvents, ReverseRecord, SetReverseLookupEvents { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); - assert!(address_of(router_signer) == @router_signer, error::permission_denied(ENOT_ROUTER)); + assert!(address_of(router_signer) == @router_signer, + error::permission_denied(ENOT_ROUTER)); // For subdomains, this will check that the domain exists first - assert!(is_name_registerable(domain_name, subdomain_name), error::invalid_state(ENAME_NOT_AVAILABLE)); + assert!(is_name_registerable(domain_name, subdomain_name), + error::invalid_state(ENAME_NOT_AVAILABLE)); if (option::is_some(&subdomain_name)) { validate_name_string(*option::borrow(&subdomain_name)); } else { validate_name_string(domain_name); }; - register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, 0); + register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, + 0); // No automatic assignment of primary name / target_addr. These are handled by the router } @@ -391,10 +400,8 @@ module aptos_names_v2_1::v2_1_domains { // This is done here so that any governance moderation activities must abide by the same invariant if (is_subdomain(subdomain_name)) { let domain_record = get_record(domain_name, option::none()); - assert!( - name_expiration_time_secs <= domain_record.expiration_time_sec, - error::out_of_range(ESUBDOMAIN_EXPIRATION_PASS_DOMAIN_EXPIRATION) - ); + assert!(name_expiration_time_secs <= domain_record.expiration_time_sec, + error::out_of_range(ESUBDOMAIN_EXPIRATION_PASS_DOMAIN_EXPIRATION)); }; // If the token already exists, transfer it to the signer @@ -406,67 +413,63 @@ module aptos_names_v2_1::v2_1_domains { record.expiration_time_sec = name_expiration_time_secs; record.target_address = option::none(); record.registration_time_sec = timestamp::now_seconds(); - object::transfer_with_ref(object::generate_linear_transfer_ref(&record.transfer_ref), account_addr); + object::transfer_with_ref(object::generate_linear_transfer_ref(&record.transfer_ref), + account_addr); } else { - create_token( - account_addr, - domain_name, - subdomain_name, - name_expiration_time_secs, - ); + create_token(account_addr, domain_name, subdomain_name, + name_expiration_time_secs,); }; - event::emit_event( - &mut borrow_global_mut(get_app_signer_addr()).register_name_events, + event::emit_event(&mut borrow_global_mut( + get_app_signer_addr()).register_name_events, RegisterNameEvent { domain_name, subdomain_name, registration_fee_octas: price, expiration_time_secs: name_expiration_time_secs, - }, - ); + },); } // === RENEW DOMAIN === public fun renew_domain( - sign: &signer, - domain_name: String, - renewal_duration_secs: u64, + sign: &signer, domain_name: String, renewal_duration_secs: u64, ) acquires NameRecord, SubdomainExt, RenewNameEvents, ReverseRecord { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); // check the domain eligibility let length = validate_name_string(domain_name); validate_registration_duration(renewal_duration_secs); - assert!(is_domain_in_renewal_window(domain_name), error::invalid_state(EDOMAIN_NOT_AVAILABLE_TO_RENEW)); - let price = v2_1_price_model::price_for_domain(length, renewal_duration_secs); + assert!(is_domain_in_renewal_window(domain_name), + error::invalid_state(EDOMAIN_NOT_AVAILABLE_TO_RENEW)); + let price = + v2_1_price_model::price_for_domain(length, renewal_duration_secs); // pay the price coin::transfer(sign, v2_1_config::fund_destination_address(), price); let record = get_record_mut(domain_name, option::none()); record.expiration_time_sec = record.expiration_time_sec + renewal_duration_secs; // Idea here is that if this is a primary name, then the target_addr's reverse lookup should point back to this domain - let is_primary_name = if (option::is_some(&record.target_address)) { - let maybe_reverse_record = if (exists(*option::borrow(&record.target_address))) { - let reverse_record = borrow_global(*option::borrow(&record.target_address)); - reverse_record.token_addr - } else { - option::none() - }; - if (option::is_some(&maybe_reverse_record)) { - let reverse_record_addr = *option::borrow(&maybe_reverse_record); - get_token_addr_inline(domain_name, option::none()) == reverse_record_addr - } else { - false - } - } else { - false - }; + let is_primary_name = + if (option::is_some(&record.target_address)) { + let maybe_reverse_record = + if (exists(*option::borrow(&record.target_address))) { + let reverse_record = + borrow_global(*option::borrow(&record.target_address)); + reverse_record.token_addr + } else { + option::none() + }; + if (option::is_some(&maybe_reverse_record)) { + let reverse_record_addr = *option::borrow(&maybe_reverse_record); + get_token_addr_inline(domain_name, option::none()) + == reverse_record_addr + } else { false } + } else { false }; // log the event - event::emit_event( - &mut borrow_global_mut(get_app_signer_addr()).renew_name_events, + event::emit_event(&mut borrow_global_mut( + get_app_signer_addr()).renew_name_events, RenewNameEvent { domain_name, subdomain_name: option::none(), @@ -474,8 +477,7 @@ module aptos_names_v2_1::v2_1_domains { expiration_time_secs: record.expiration_time_sec, target_address: record.target_address, is_primary_name, - }, - ); + },); } // === SUBDOMAIN MANAGEMENT === @@ -489,8 +491,10 @@ module aptos_names_v2_1::v2_1_domains { transferrable: bool ) acquires NameRecord, SubdomainExt { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); - assert!(address_of(router_signer) == @router_signer, error::permission_denied(ENOT_ROUTER)); - validate_subdomain_registered_and_domain_owned_by_signer(sign, domain_name, subdomain_name); + assert!(address_of(router_signer) == @router_signer, + error::permission_denied(ENOT_ROUTER)); + validate_subdomain_registered_and_domain_owned_by_signer(sign, domain_name, + subdomain_name); let name_record_address = get_token_addr(domain_name, option::some(subdomain_name)); let transfer_ref = &borrow_global_mut(name_record_address).transfer_ref; if (transferrable) { @@ -510,19 +514,16 @@ module aptos_names_v2_1::v2_1_domains { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); // validate user own the domain let signer_addr = signer::address_of(sign); - assert!( - is_token_owner(signer_addr, domain_name, option::none()), - error::permission_denied(ENOT_OWNER_OF_DOMAIN) - ); - assert!( - !is_name_expired(domain_name, option::none()), - error::permission_denied(ECANNOT_TRANSFER_SUBDOMAIN_WHILE_DOMAIN_HAS_EXPIRED) - ); + assert!(is_token_owner(signer_addr, domain_name, option::none()), + error::permission_denied(ENOT_OWNER_OF_DOMAIN)); + assert!(!is_name_expired(domain_name, option::none()), + error::permission_denied(ECANNOT_TRANSFER_SUBDOMAIN_WHILE_DOMAIN_HAS_EXPIRED)); let token_addr = get_token_addr_inline(domain_name, option::some(subdomain_name)); let record = borrow_global_mut(token_addr); record.target_address = new_target_address; - object::transfer_with_ref(object::generate_linear_transfer_ref(&record.transfer_ref), new_owner_address); + object::transfer_with_ref(object::generate_linear_transfer_ref(&record.transfer_ref), + new_owner_address); // clear the primary name clear_reverse_lookup_for_name(option::some(subdomain_name), domain_name); } @@ -535,24 +536,23 @@ module aptos_names_v2_1::v2_1_domains { expiration_time_sec: u64, ) acquires NameRecord, SubdomainExt { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); - validate_subdomain_registered_and_domain_owned_by_signer(domain_admin, domain_name, subdomain_name); + validate_subdomain_registered_and_domain_owned_by_signer(domain_admin, domain_name, + subdomain_name); // check if the expiration time is valid let domain_record = get_record(domain_name, option::none()); - assert!( - domain_record.expiration_time_sec >= expiration_time_sec, - error::invalid_state(ESUBDOMAIN_EXPIRATION_PASS_DOMAIN_EXPIRATION) - ); + assert!(domain_record.expiration_time_sec >= expiration_time_sec, + error::invalid_state(ESUBDOMAIN_EXPIRATION_PASS_DOMAIN_EXPIRATION)); // check the auto-renew flag let subdomain_name_opt = option::some(subdomain_name); let token_addr = get_token_addr_inline(domain_name, subdomain_name_opt); - let record = borrow_global_mut(get_token_addr_inline(domain_name, subdomain_name_opt)); + let record = + borrow_global_mut(get_token_addr_inline(domain_name, + subdomain_name_opt)); assert!(exists(token_addr), error::invalid_state(ENOT_A_SUBDOMAIN)); let subdomain_ext = borrow_global(token_addr); - assert!( - subdomain_ext.subdomain_expiration_policy != SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION, - error::invalid_state(ESUBDOMAIN_IS_AUTO_RENEW) - ); + assert!(subdomain_ext.subdomain_expiration_policy != SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION, + error::invalid_state(ESUBDOMAIN_IS_AUTO_RENEW)); // manually set the expiration date record.expiration_time_sec = expiration_time_sec; @@ -565,7 +565,8 @@ module aptos_names_v2_1::v2_1_domains { subdomain_expiration_policy: u8, ) acquires NameRecord, SubdomainExt { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); - validate_subdomain_registered_and_domain_owned_by_signer(domain_admin, domain_name, subdomain_name); + validate_subdomain_registered_and_domain_owned_by_signer(domain_admin, domain_name, + subdomain_name); validate_subdomain_expiration_policy(subdomain_expiration_policy); // if manually set the expiration date let token_addr = get_token_addr_inline(domain_name, option::some(subdomain_name)); @@ -575,8 +576,7 @@ module aptos_names_v2_1::v2_1_domains { } public fun get_subdomain_renewal_policy( - domain_name: String, - subdomain_name: String, + domain_name: String, subdomain_name: String, ): u8 acquires SubdomainExt { let token_addr = get_token_addr_inline(domain_name, option::some(subdomain_name)); assert!(exists(token_addr), error::invalid_state(ESUBDOMAIN_NOT_EXIST)); @@ -587,24 +587,17 @@ module aptos_names_v2_1::v2_1_domains { // === TARGET ADDRESS FUNCTIONS === public fun set_target_address( - sign: &signer, - domain_name: String, - subdomain_name: Option, - new_address: address + sign: &signer, domain_name: String, subdomain_name: Option, new_address: address ) acquires NameRecord, SubdomainExt, ReverseRecord, SetTargetAddressEvents, SetReverseLookupEvents { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); // If the domain name is a primary name, clear it. clear_reverse_lookup_for_name(subdomain_name, domain_name); let signer_addr = signer::address_of(sign); - assert!( - is_token_owner(signer_addr, domain_name, subdomain_name), - error::permission_denied(ENOT_OWNER_OF_NAME) - ); - assert!( - !is_name_expired(domain_name, subdomain_name), - error::permission_denied(ENAME_EXPIRED) - ); + assert!(is_token_owner(signer_addr, domain_name, subdomain_name), + error::permission_denied(ENOT_OWNER_OF_NAME)); + assert!(!is_name_expired(domain_name, subdomain_name), + error::permission_denied(ENAME_EXPIRED)); set_target_address_internal(subdomain_name, domain_name, new_address); @@ -615,45 +608,38 @@ module aptos_names_v2_1::v2_1_domains { // The new state should be bob.apt points to @b, and the reverse lookup of @a should be none. // if current state is true, then we must clear let maybe_reverse_lookup = get_reverse_lookup(signer_addr); - if (option::is_none(&maybe_reverse_lookup)) { - return - }; + if (option::is_none(&maybe_reverse_lookup)) { return }; let reverse_name_record_addr = *option::borrow(&maybe_reverse_lookup); let reverse_name_record = borrow_global(reverse_name_record_addr); let reverse_name_record_subdomain = extract_subdomain_name(reverse_name_record_addr); - if (reverse_name_record.domain_name == domain_name && - reverse_name_record_subdomain == subdomain_name && - signer_addr != new_address - ) { + if (reverse_name_record.domain_name == domain_name + && reverse_name_record_subdomain == subdomain_name + && signer_addr != new_address) { clear_reverse_lookup(sign); }; } fun set_target_address_internal( - subdomain_name: Option, - domain_name: String, - new_address: address + subdomain_name: Option, domain_name: String, new_address: address ) acquires NameRecord, SetTargetAddressEvents { - assert!(is_name_registered(domain_name, subdomain_name), error::not_found(ENAME_NOT_EXIST)); + assert!(is_name_registered(domain_name, subdomain_name), + error::not_found(ENAME_NOT_EXIST)); let record = get_record_mut(domain_name, subdomain_name); record.target_address = option::some(new_address); - emit_set_target_address_event( - subdomain_name, + emit_set_target_address_event(subdomain_name, domain_name, record.expiration_time_sec, - record.target_address, - ); + record.target_address,); } /// This is a shared entry point for clearing the address of a domain or subdomain /// It enforces owner permissions public fun clear_target_address( - sign: &signer, - subdomain_name: Option, - domain_name: String + sign: &signer, subdomain_name: Option, domain_name: String ) acquires NameRecord, SubdomainExt, ReverseRecord, SetTargetAddressEvents, SetReverseLookupEvents { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); - assert!(is_name_registered(domain_name, subdomain_name), error::not_found(ENAME_NOT_EXIST)); + assert!(is_name_registered(domain_name, subdomain_name), + error::not_found(ENAME_NOT_EXIST)); let signer_addr = signer::address_of(sign); @@ -669,20 +655,19 @@ module aptos_names_v2_1::v2_1_domains { // Only the owner or the registered address can clear the address let is_owner = is_token_owner(signer_addr, domain_name, subdomain_name); let is_expired = is_name_expired(domain_name, subdomain_name); - let is_target_address = get_target_address(domain_name, subdomain_name) == option::some
( - signer_addr - ); + let is_target_address = + get_target_address(domain_name, subdomain_name) + == option::some
(signer_addr); - assert!((is_owner && !is_expired) || is_target_address, error::permission_denied(ENOT_AUTHORIZED)); + assert!((is_owner && !is_expired) + || is_target_address, error::permission_denied(ENOT_AUTHORIZED)); let record = get_record_mut(domain_name, subdomain_name); record.target_address = option::none(); - emit_set_target_address_event( - subdomain_name, + emit_set_target_address_event(subdomain_name, domain_name, record.expiration_time_sec, - record.target_address, - ); + record.target_address,); } // === PRIMARY NAMES === @@ -690,31 +675,26 @@ module aptos_names_v2_1::v2_1_domains { /// Sets the |account|'s reverse lookup, aka "primary name". This allows a user to specify which of their Aptos Names /// is their "primary", so that dapps can display the user's primary name rather than their address. public entry fun set_reverse_lookup( - account: &signer, - subdomain_name: Option, - domain_name: String + account: &signer, subdomain_name: Option, domain_name: String ) acquires NameRecord, SubdomainExt, ReverseRecord, SetTargetAddressEvents, SetReverseLookupEvents { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); // Name must be registered before assigning reverse lookup - assert!(is_name_registered(domain_name, subdomain_name), error::not_found(ENAME_NOT_EXIST)); + assert!(is_name_registered(domain_name, subdomain_name), + error::not_found(ENAME_NOT_EXIST)); let token_addr = get_token_addr_inline(domain_name, subdomain_name); set_target_address(account, domain_name, subdomain_name, address_of(account)); set_reverse_lookup_internal(account, token_addr); } /// Clears the user's reverse lookup. - public fun clear_reverse_lookup( - account: &signer - ) acquires NameRecord, SubdomainExt, ReverseRecord, SetReverseLookupEvents { + public fun clear_reverse_lookup(account: &signer) acquires NameRecord, SubdomainExt, ReverseRecord, SetReverseLookupEvents { assert!(v2_1_config::is_enabled(), error::unavailable(ENOT_ENABLED)); let account_addr = signer::address_of(account); clear_reverse_lookup_internal(account_addr); } /// Returns the reverse lookup (the token addr) for an address if any. - public fun get_reverse_lookup( - account_addr: address - ): Option
acquires ReverseRecord, NameRecord { + public fun get_reverse_lookup(account_addr: address): Option
acquires ReverseRecord, NameRecord { if (!exists(account_addr)) { return option::none() }; @@ -737,21 +717,17 @@ module aptos_names_v2_1::v2_1_domains { exists(account_addr) } - fun set_reverse_lookup_internal( - account: &signer, - token_addr: address, - ) acquires NameRecord, SubdomainExt, ReverseRecord, SetReverseLookupEvents { + fun set_reverse_lookup_internal(account: &signer, token_addr: address,) acquires NameRecord, SubdomainExt, ReverseRecord, SetReverseLookupEvents { let account_addr = signer::address_of(account); let record_obj = object::address_to_object(token_addr); - assert!(object::owns(record_obj, account_addr), error::permission_denied(ENOT_AUTHORIZED)); + assert!(object::owns(record_obj, account_addr), + error::permission_denied(ENOT_AUTHORIZED)); let prev_subdomain_name = option::none(); let prev_domain_name = option::none(); let prev_expiration_time_secs = option::none(); if (!exists(account_addr)) { - move_to(account, ReverseRecord { - token_addr: option::some(token_addr) - }) + move_to(account, ReverseRecord { token_addr: option::some(token_addr) }) } else { let reverse_record = borrow_global_mut(account_addr); @@ -768,24 +744,18 @@ module aptos_names_v2_1::v2_1_domains { }; let record = borrow_global(token_addr); - emit_set_reverse_lookup_event( - account_addr, + emit_set_reverse_lookup_event(account_addr, prev_subdomain_name, prev_domain_name, prev_expiration_time_secs, extract_subdomain_name(token_addr), option::some(record.domain_name), - option::some(record.expiration_time_sec) - ); + option::some(record.expiration_time_sec)); } - fun clear_reverse_lookup_internal( - account_addr: address - ) acquires NameRecord, SubdomainExt, ReverseRecord, SetReverseLookupEvents { + fun clear_reverse_lookup_internal(account_addr: address) acquires NameRecord, SubdomainExt, ReverseRecord, SetReverseLookupEvents { let maybe_reverse_lookup = get_reverse_lookup(account_addr); - if (option::is_none(&maybe_reverse_lookup)) { - return - }; + if (option::is_none(&maybe_reverse_lookup)) { return }; // Lookup the previous reverse lookup let token_addr = *option::borrow(&maybe_reverse_lookup); @@ -798,20 +768,17 @@ module aptos_names_v2_1::v2_1_domains { let reverse_record = borrow_global_mut(account_addr); reverse_record.token_addr = option::none(); - emit_set_reverse_lookup_event( - account_addr, + emit_set_reverse_lookup_event(account_addr, prev_subdomain_name, prev_domain_name, prev_expiration_time_secs, option::none(), option::none(), - option::none() - ); + option::none()); } fun clear_reverse_lookup_for_name( - subdomain_name: Option, - domain_name: String + subdomain_name: Option, domain_name: String ) acquires NameRecord, SubdomainExt, ReverseRecord, SetReverseLookupEvents { if (!is_name_registered(domain_name, subdomain_name)) return; @@ -835,10 +802,7 @@ module aptos_names_v2_1::v2_1_domains { /// This is a privileged operation, used via governance, to forcefully set a domain address /// This can be used, for example, to forcefully set the domain for a system address domain public entry fun force_set_target_address( - sign: &signer, - domain_name: String, - subdomain_name: Option, - new_owner: address + sign: &signer, domain_name: String, subdomain_name: Option, new_owner: address ) acquires NameRecord, SubdomainExt, ReverseRecord, SetTargetAddressEvents, SetReverseLookupEvents { v2_1_config::assert_signer_is_admin(sign); // If the domain name is a primary name, clear it. @@ -859,29 +823,24 @@ module aptos_names_v2_1::v2_1_domains { ) acquires DomainObject, NameRecord, SubdomainExt, RegisterNameEvents, ReverseRecord, SetReverseLookupEvents { v2_1_config::assert_signer_is_admin(sign); // Register the name - register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, 0); + register_name_internal(sign, subdomain_name, domain_name, registration_duration_secs, + 0); } /// This removes a name mapping from the registry; functionally this 'expires' it. /// This is a privileged operation, used via governance. public entry fun force_clear_registration( - sign: &signer, - domain_name: String, - subdomain_name: Option, + sign: &signer, domain_name: String, subdomain_name: Option, ) acquires NameRecord { v2_1_config::assert_signer_is_admin(sign); let record = get_record_mut(domain_name, subdomain_name); - object::transfer_with_ref( - object::generate_linear_transfer_ref(&record.transfer_ref), - get_app_signer_addr(), - ); + object::transfer_with_ref(object::generate_linear_transfer_ref(&record.transfer_ref), + get_app_signer_addr(),); record.target_address = option::none(); } public entry fun force_set_name_expiration( - sign: &signer, - domain_name: String, - subdomain_name: Option, + sign: &signer, domain_name: String, subdomain_name: Option, new_expiration_secs: u64 ) acquires NameRecord { // check the signer eligibility @@ -891,30 +850,26 @@ module aptos_names_v2_1::v2_1_domains { record.expiration_time_sec = new_expiration_secs; } - // === HELPER FUNCTIONS === - fun validate_name_string( - name: String, - ): u64 { + fun validate_name_string(name: String,): u64 { let (is_valid, length) = v2_1_string_validator::string_is_allowed(&name); assert!(is_valid, error::invalid_argument(ENAME_HAS_INVALID_CHARACTERS)); - assert!(length <= v2_1_config::max_domain_length(), error::out_of_range(ENAME_TOO_LONG)); - assert!(length >= v2_1_config::min_domain_length(), error::out_of_range(ENAME_TOO_SHORT)); + assert!(length <= v2_1_config::max_domain_length(), + error::out_of_range(ENAME_TOO_LONG)); + assert!(length >= v2_1_config::min_domain_length(), + error::out_of_range(ENAME_TOO_SHORT)); return length } - public fun is_domain_in_renewal_window( - domain_name: String, - ): bool acquires NameRecord, SubdomainExt { + public fun is_domain_in_renewal_window(domain_name: String,): bool acquires NameRecord, SubdomainExt { // check if the domain is registered - assert!(is_name_registered(domain_name, option::none()), error::not_found(ENAME_NOT_EXIST)); + assert!(is_name_registered(domain_name, option::none()), + error::not_found(ENAME_NOT_EXIST)); // check if the domain is expired and past gract period already - assert!( - !is_name_expired_past_grace(domain_name, option::none()), - error::invalid_state(ECANNOT_RENEW_NAME_THAT_IS_EXPIRED_AND_PAST_GRACE_PERIOD) - ); + assert!(!is_name_expired_past_grace(domain_name, option::none()), + error::invalid_state(ECANNOT_RENEW_NAME_THAT_IS_EXPIRED_AND_PAST_GRACE_PERIOD)); let record = get_record_mut(domain_name, option::none()); record.expiration_time_sec <= timestamp::now_seconds() + MAX_REMAINING_TIME_FOR_RENEWAL_SEC @@ -929,48 +884,39 @@ module aptos_names_v2_1::v2_1_domains { } fun get_app_signer(): signer acquires DomainObject { - object::generate_signer_for_extending(&borrow_global(get_app_signer_addr()).extend_ref) + object::generate_signer_for_extending(&borrow_global( + get_app_signer_addr()).extend_ref) } inline fun get_token_addr_inline( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): address { - token::create_token_address( - &get_app_signer_addr(), + token::create_token_address(&get_app_signer_addr(), &get_collection_name(is_subdomain(subdomain_name)), - &v2_1_token_helper::get_fully_qualified_domain_name(subdomain_name, domain_name), - ) + &v2_1_token_helper::get_fully_qualified_domain_name(subdomain_name, domain_name),) } public fun get_token_addr( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): address { - token::create_token_address( - &get_app_signer_addr(), + token::create_token_address(&get_app_signer_addr(), &get_collection_name(is_subdomain(subdomain_name)), - &v2_1_token_helper::get_fully_qualified_domain_name(subdomain_name, domain_name), - ) + &v2_1_token_helper::get_fully_qualified_domain_name(subdomain_name, domain_name),) } - fun get_record_obj( - domain_name: String, - subdomain_name: Option, - ): Object { + fun get_record_obj(domain_name: String, subdomain_name: Option,) + : Object { object::address_to_object(get_token_addr_inline(domain_name, subdomain_name)) } inline fun get_record( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): &NameRecord acquires NameRecord { borrow_global(get_token_addr_inline(domain_name, subdomain_name)) } inline fun get_record_mut( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): &mut NameRecord acquires NameRecord { borrow_global_mut(get_token_addr_inline(domain_name, subdomain_name)) } @@ -992,50 +938,38 @@ module aptos_names_v2_1::v2_1_domains { } } - fun validate_registration_duration( - registration_duration_secs: u64, - ) { - assert!(registration_duration_secs != 0, error::invalid_argument(EDURATION_MUST_BE_WHOLE_YEARS)); - assert!( - registration_duration_secs % SECONDS_PER_YEAR == 0, - error::invalid_argument(EDURATION_MUST_BE_WHOLE_YEARS) - ); + fun validate_registration_duration(registration_duration_secs: u64,) { + assert!(registration_duration_secs != 0, + error::invalid_argument(EDURATION_MUST_BE_WHOLE_YEARS)); + assert!(registration_duration_secs % SECONDS_PER_YEAR == 0, + error::invalid_argument(EDURATION_MUST_BE_WHOLE_YEARS)); - assert!( - registration_duration_secs <= v2_1_config::max_number_of_seconds_registered(), - error::out_of_range(EINVALID_NUMBER_YEARS) - ); + assert!(registration_duration_secs <= v2_1_config::max_number_of_seconds_registered(), + error::out_of_range(EINVALID_NUMBER_YEARS)); } - fun validate_subdomain_expiration_policy( subdomain_expiration_policy: u8, ) { // revise the function when adding more policies // SUBDOMAIN_POLICY_NEXT_ENUM = 2 - assert!( - subdomain_expiration_policy == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION - || subdomain_expiration_policy == SUBDOMAIN_POLICY_MANUAL_SET_EXPIRATION, - error::invalid_argument(ESUBDOMAIN_EXPIRATION_POLICY_INVALID) - ); + assert!(subdomain_expiration_policy + == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION || subdomain_expiration_policy + == SUBDOMAIN_POLICY_MANUAL_SET_EXPIRATION, + error::invalid_argument(ESUBDOMAIN_EXPIRATION_POLICY_INVALID)); } fun validate_subdomain_registered_and_domain_owned_by_signer( - sign: &signer, - domain_name: String, - subdomain_name: String, + sign: &signer, domain_name: String, subdomain_name: String, ) acquires NameRecord, SubdomainExt { - assert!(is_name_registered(domain_name, option::some(subdomain_name)), error::not_found(ESUBDOMAIN_NOT_EXIST)); + assert!(is_name_registered(domain_name, option::some(subdomain_name)), + error::not_found(ESUBDOMAIN_NOT_EXIST)); // Ensure signer owns the domain we're registering a subdomain for - assert!( - is_token_owner(signer::address_of(sign), domain_name, option::none()), - error::permission_denied(ENOT_OWNER_OF_DOMAIN) - ); + assert!(is_token_owner(signer::address_of(sign), domain_name, option::none()), + error::permission_denied(ENOT_OWNER_OF_DOMAIN)); // Ensure name is not expired - assert!( - !is_name_expired(domain_name, option::none()), - error::permission_denied(EDOMAIN_EXPIRED) - ); + assert!(!is_name_expired(domain_name, option::none()), + error::permission_denied(EDOMAIN_EXPIRED)); } /// Checks for the name not existing, or being expired @@ -1043,8 +977,7 @@ module aptos_names_v2_1::v2_1_domains { /// if this is a subdomain, and the domain doesn't exist, returns false /// Doesn't use the `name_is_expired` or `name_is_registered` internally to share the borrow public fun is_name_registerable( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): bool acquires DomainObject, NameRecord, SubdomainExt { // If this is a subdomain, ensure the domain also exists, and is not expired: i.e not registerable // So if the domain name is registerable, we return false, as the subdomain is not registerable @@ -1082,23 +1015,19 @@ module aptos_names_v2_1::v2_1_domains { /// 2. The name is a subdomain AND subdomain was registered before the domain OR /// 3. The name is registered AND is expired and past grace period public fun is_name_expired_past_grace( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): bool acquires NameRecord, SubdomainExt { - if (!is_name_registered(domain_name, subdomain_name)) { - true - } else if (option::is_some(&subdomain_name) && is_subdomain_registered_before_domain( - domain_name, - *option::borrow(&subdomain_name) - )) { - true - } else { + if (!is_name_registered(domain_name, subdomain_name)) { true } + else if (option::is_some(&subdomain_name) && is_subdomain_registered_before_domain(domain_name, *option::borrow( + &subdomain_name))) { true } + else { let token_addr = get_token_addr_inline(domain_name, subdomain_name); let record = borrow_global(token_addr); // check the auto-renew flag if (exists(token_addr)) { let subdomain_ext = borrow_global(token_addr); - if (subdomain_ext.subdomain_expiration_policy == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION) { + if (subdomain_ext.subdomain_expiration_policy + == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION) { // refer to the expiration date of the domain let domain_record = get_record(domain_name, option::none()); return is_time_expired(domain_record.expiration_time_sec + v2_1_config::reregistration_grace_sec()) @@ -1113,23 +1042,19 @@ module aptos_names_v2_1::v2_1_domains { /// 2. The name is a subdomain AND subdomain was registered before the domain OR /// 3. The name is registered AND is expired public fun is_name_expired( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): bool acquires NameRecord, SubdomainExt { - if (!is_name_registered(domain_name, subdomain_name)) { - true - } else if (option::is_some(&subdomain_name) && is_subdomain_registered_before_domain( - domain_name, - *option::borrow(&subdomain_name) - )) { - true - } else { + if (!is_name_registered(domain_name, subdomain_name)) { true } + else if (option::is_some(&subdomain_name) && is_subdomain_registered_before_domain(domain_name, *option::borrow( + &subdomain_name))) { true } + else { let token_addr = get_token_addr_inline(domain_name, subdomain_name); let record = borrow_global(token_addr); // check the auto-renew flag if (exists(token_addr)) { let subdomain_ext = borrow_global(token_addr); - if (subdomain_ext.subdomain_expiration_policy == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION) { + if (subdomain_ext.subdomain_expiration_policy + == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION) { // refer to the expiration date of the domain let domain_record = get_record(domain_name, option::none()); return is_time_expired(domain_record.expiration_time_sec) @@ -1141,50 +1066,48 @@ module aptos_names_v2_1::v2_1_domains { /// Returns true if the object exists AND the owner is not the `token_resource` account public fun is_name_registered( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): bool { - object::is_object(get_token_addr_inline(domain_name, subdomain_name)) && - !object::is_owner(get_record_obj(domain_name, subdomain_name), get_app_signer_addr()) + object::is_object(get_token_addr_inline(domain_name, subdomain_name)) && !object::is_owner( + get_record_obj(domain_name, subdomain_name), get_app_signer_addr()) } /// Check if the address is the owner of the given aptos_name /// If the name does not exist returns false public fun is_token_owner( - owner_addr: address, - domain_name: String, - subdomain_name: Option, + owner_addr: address, domain_name: String, subdomain_name: Option, ): bool { - if (!is_name_registered(domain_name, subdomain_name)) - return false; - let record_obj = object::address_to_object(get_token_addr_inline(domain_name, subdomain_name)); + if (!is_name_registered(domain_name, subdomain_name)) return false; + let record_obj = + object::address_to_object(get_token_addr_inline(domain_name, + subdomain_name)); object::owns(record_obj, owner_addr) } /// Returns a name's owner address. Returns option::none() if there is no owner. public fun get_name_owner_addr( - subdomain_name: Option, - domain_name: String, + subdomain_name: Option, domain_name: String, ): Option
acquires NameRecord, SubdomainExt { // check if the name is registered - if (!is_name_registered(domain_name, subdomain_name) || is_name_expired( - domain_name, - subdomain_name, - )) return option::none(); - let record_obj = object::address_to_object(get_token_addr_inline(domain_name, subdomain_name)); + if (!is_name_registered(domain_name, subdomain_name) || is_name_expired(domain_name, + subdomain_name,)) + return option::none(); + let record_obj = + object::address_to_object(get_token_addr_inline(domain_name, + subdomain_name)); option::some(object::owner(record_obj)) } public fun get_expiration( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): u64 acquires NameRecord, SubdomainExt { let token_addr = get_token_addr_inline(domain_name, subdomain_name); let record = borrow_global(token_addr); if (exists(token_addr)) { // check the expiration policy if it's subdomain let subdomain_ext = borrow_global(token_addr); - if (subdomain_ext.subdomain_expiration_policy == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION) { + if (subdomain_ext.subdomain_expiration_policy + == SUBDOMAIN_POLICY_LOOKUP_DOMAIN_EXPIRATION) { // refer to the expiration date of the domain let domain_record = get_record(domain_name, option::none()); @@ -1195,8 +1118,7 @@ module aptos_names_v2_1::v2_1_domains { } public fun get_target_address( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): Option
acquires NameRecord, SubdomainExt { // check the expiration sec if the name is a domain let expiration_sec = get_expiration(domain_name, subdomain_name); @@ -1208,9 +1130,7 @@ module aptos_names_v2_1::v2_1_domains { } } - public fun get_name_props_from_token_addr( - token_addr: address - ): (Option, String) acquires NameRecord, SubdomainExt { + public fun get_name_props_from_token_addr(token_addr: address): (Option, String) acquires NameRecord, SubdomainExt { let record = borrow_global(token_addr); (extract_subdomain_name(token_addr), record.domain_name) } @@ -1221,12 +1141,10 @@ module aptos_names_v2_1::v2_1_domains { } fun is_subdomain_registered_before_domain( - domain_name: String, - subdomain_name: String, + domain_name: String, subdomain_name: String, ): bool acquires NameRecord { - if(!is_name_registered(domain_name, option::some(subdomain_name))) { - false - } else { + if (!is_name_registered(domain_name, option::some(subdomain_name))) { false } + else { let domain_record = get_record(domain_name, option::none()); let subdomain_record = get_record(domain_name, option::some(subdomain_name)); subdomain_record.registration_time_sec < domain_record.registration_time_sec @@ -1241,17 +1159,17 @@ module aptos_names_v2_1::v2_1_domains { expiration_time_secs: u64, new_address: Option
) acquires SetTargetAddressEvents { - let event = SetTargetAddressEvent { - domain_name, - subdomain_name, - expiration_time_secs, - new_address, - }; + let event = + SetTargetAddressEvent { + domain_name, + subdomain_name, + expiration_time_secs, + new_address, + }; - event::emit_event( - &mut borrow_global_mut(get_app_signer_addr()).set_name_events, - event, - ); + event::emit_event(&mut borrow_global_mut< + SetTargetAddressEvents>(get_app_signer_addr()).set_name_events, + event,); } fun emit_set_reverse_lookup_event( @@ -1263,22 +1181,22 @@ module aptos_names_v2_1::v2_1_domains { curr_domain_name: Option, curr_expiration_time_secs: Option, ) acquires SetReverseLookupEvents { - let event = SetReverseLookupEvent { - account_addr, + let event = + SetReverseLookupEvent { + account_addr, - prev_domain_name, - prev_subdomain_name, - prev_expiration_time_secs, + prev_domain_name, + prev_subdomain_name, + prev_expiration_time_secs, - curr_domain_name, - curr_subdomain_name, - curr_expiration_time_secs, - }; + curr_domain_name, + curr_subdomain_name, + curr_expiration_time_secs, + }; - event::emit_event( - &mut borrow_global_mut(get_app_signer_addr()).set_reverse_lookup_events, - event, - ); + event::emit_event(&mut borrow_global_mut< + SetReverseLookupEvents>(get_app_signer_addr()).set_reverse_lookup_events, + event,); } // ==== TIME HELPERS ==== diff --git a/core_v2/sources/v2_1_price_model.move b/core_v2/sources/v2_1_price_model.move index 4b0935c6..7c3f0e30 100644 --- a/core_v2/sources/v2_1_price_model.move +++ b/core_v2/sources/v2_1_price_model.move @@ -3,7 +3,6 @@ module aptos_names_v2_1::v2_1_price_model { use aptos_std::math64; use std::error; - /// The domain length is too short- currently the minimum is 2 characters const EDOMAIN_TOO_SHORT: u64 = 1; const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; @@ -65,7 +64,8 @@ module aptos_names_v2_1::v2_1_price_model { let price = price_for_domain(15, SECONDS_PER_YEAR) / v2_1_config::octas(); assert!(price == 5, price); - let price = price_for_domain(15, 10 * SECONDS_PER_YEAR) / v2_1_config::octas(); + let price = + price_for_domain(15, 10 * SECONDS_PER_YEAR) / v2_1_config::octas(); assert!(price == 50, price); } diff --git a/core_v2/sources/v2_1_string_validator.move b/core_v2/sources/v2_1_string_validator.move index 06969f51..e2fa5450 100644 --- a/core_v2/sources/v2_1_string_validator.move +++ b/core_v2/sources/v2_1_string_validator.move @@ -30,7 +30,7 @@ module aptos_names_v2_1::v2_1_string_validator { if (c == 45) { if (i == 0 || i == len - 1) { // hyphen at beginning or end is not allowed - return (false, len) + return(false, len) }; // We ignore hyphens from the character set count, it's easy to determine later } @@ -43,7 +43,7 @@ module aptos_names_v2_1::v2_1_string_validator { // these are valid } else { // uknown character set: this is not valid - return (false, len) + return(false, len) }; i = i + 1; }; @@ -89,7 +89,7 @@ module aptos_names_v2_1::v2_1_string_validator { let char1 = (char1 as u64); let char2 = (*vector::borrow(bytes, i + 1) as u64); let char3 = (*vector::borrow(bytes, i + 2) as u64); - vector::push_back(&mut result, (char1 << 16) | (char2 << 8) | char3); + vector::push_back(&mut result, (char1 << 16) |(char2 << 8) | char3); i = i + 2; } else if (prefix == 15) { // 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx @@ -97,7 +97,7 @@ module aptos_names_v2_1::v2_1_string_validator { let char2 = (*vector::borrow(bytes, i + 1) as u64); let char3 = (*vector::borrow(bytes, i + 2) as u64); let char4 = (*vector::borrow(bytes, i + 3) as u64); - vector::push_back(&mut result, (char1 << 24) | (char2 << 16) | (char3 << 8) | char4); + vector::push_back(&mut result, (char1 << 24) |(char2 << 16) |(char3 << 8) | char4); i = i + 3; } else { assert!(char1 <= 14u8, EINVALID_UTF8_START); @@ -133,8 +133,7 @@ module aptos_names_v2_1::v2_1_string_validator { Example { text: b"01234-56789", length: 11, }, Example { text: b"abcdefgh-ijklmnopqrstuvwxyz", length: 27, }, Example { text: b"a", length: 1, }, - Example { text: b"", length: 0, }, - ]; + Example { text: b"", length: 0, },]; // Reverse it so the errors are in order vector::reverse(&mut allowed_tests); let i = 0; @@ -155,8 +154,7 @@ module aptos_names_v2_1::v2_1_string_validator { Example { text: b"-", length: 1, }, Example { text: b"_", length: 1, }, Example { text: b"a!b", length: 3, }, - Example { text: b"A", length: 1, }, - ]; + Example { text: b"A", length: 1, },]; // Reverse it so the errors are in order vector::reverse(&mut not_allowed); let i = 0; diff --git a/core_v2/sources/v2_1_token_helper.move b/core_v2/sources/v2_1_token_helper.move index 952f50eb..ed3eab15 100644 --- a/core_v2/sources/v2_1_token_helper.move +++ b/core_v2/sources/v2_1_token_helper.move @@ -16,15 +16,17 @@ module aptos_names_v2_1::v2_1_token_helper { /// The subdomain name is not a valid name const ESUBDOMAIN_NAME_INVALID: u64 = 3; - public(friend) fun get_fully_qualified_domain_name(subdomain_name: Option, domain_name: String): String { + public(friend) fun get_fully_qualified_domain_name( + subdomain_name: Option, domain_name: String + ): String { let (domain_is_allowed, _length) = v2_1_string_validator::string_is_allowed(&domain_name); assert!(domain_is_allowed, error::invalid_argument(EDOMAIN_NAME_INVALID)); - let subdomain_is_allowed = if (option::is_some(&subdomain_name)) { - let (subdomain_is_allowed, _length) = v2_1_string_validator::string_is_allowed(option::borrow(&subdomain_name)); - subdomain_is_allowed - } else { - true - }; + let subdomain_is_allowed = + if (option::is_some(&subdomain_name)) { + let (subdomain_is_allowed, _length) = + v2_1_string_validator::string_is_allowed(option::borrow(&subdomain_name)); + subdomain_is_allowed + } else { true }; assert!(subdomain_is_allowed, error::invalid_argument(ESUBDOMAIN_NAME_INVALID)); let combined = combine_sub_and_domain_str(subdomain_name, domain_name); string::append_utf8(&mut combined, DOMAIN_SUFFIX); @@ -34,7 +36,9 @@ module aptos_names_v2_1::v2_1_token_helper { /// Combines a subdomain and domain into a new string, separated by a `.` /// Used for building fully qualified domain names (Ex: `{subdomain_name}.{domain_name}.apt`) /// If there is no subdomain, just returns the domain name - public(friend) fun combine_sub_and_domain_str(subdomain_name: Option, domain_name: String): String { + public(friend) fun combine_sub_and_domain_str( + subdomain_name: Option, domain_name: String + ): String { if (option::is_none(&subdomain_name)) { return domain_name }; @@ -47,17 +51,28 @@ module aptos_names_v2_1::v2_1_token_helper { #[test] fun test_get_fully_qualified_domain_name() { - assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"test")) == string::utf8(b"test.apt"), 1); - assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"wowthisislong")) == string::utf8(b"wowthisislong.apt"), 2); - assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"123")) == string::utf8(b"123.apt"), 2); - assert!(get_fully_qualified_domain_name(option::some(string::utf8(b"sub")), string::utf8(b"test")) == string::utf8(b"sub.test.apt"), 2); + assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"test")) + == string::utf8(b"test.apt"), + 1); + assert!(get_fully_qualified_domain_name(option::none(), + string::utf8(b"wowthisislong")) + == string::utf8(b"wowthisislong.apt"), + 2); + assert!(get_fully_qualified_domain_name(option::none(), string::utf8(b"123")) + == string::utf8(b"123.apt"), + 2); + assert!(get_fully_qualified_domain_name(option::some(string::utf8(b"sub")), + string::utf8(b"test")) + == string::utf8(b"sub.test.apt"), + 2); } #[test] fun test_combine_sub_and_domain_str() { let subdomain_name = string::utf8(b"sub"); let domain_name = string::utf8(b"dom"); - let combined = combine_sub_and_domain_str(option::some(subdomain_name), domain_name); + let combined = + combine_sub_and_domain_str(option::some(subdomain_name), domain_name); assert!(combined == string::utf8(b"sub.dom"), 1); } diff --git a/distribute/sources/script.move b/distribute/sources/script.move index 73aeef1f..3a699619 100644 --- a/distribute/sources/script.move +++ b/distribute/sources/script.move @@ -2,15 +2,9 @@ script { use aptos_names::token_helper; fun main(offerer: &signer) { - let names = vector [ - b"name0", - b"name1", - ]; + let names = vector[b"name0", b"name1",]; - let recipients = vector [ - @0x1, - @0x2, - ]; + let recipients = vector[@0x1, @0x2,]; assert!(std::vector::length(&names) == std::vector::length(&recipients), 1); @@ -18,11 +12,9 @@ script { let name = std::vector::pop_back(&mut names); let recipient = std::vector::pop_back(&mut recipients); - let token_data_id = token_helper::build_tokendata_id( - token_helper::get_token_signer_address(), - std::option::none(), - std::string::utf8(name), - ); + let token_data_id = + token_helper::build_tokendata_id(token_helper::get_token_signer_address(), + std::option::none(), std::string::utf8(name),); let token_id = token_helper::latest_token_id(&token_data_id); aptos_token::token_transfers::offer(offerer, recipient, token_id, 1); } diff --git a/register/sources/script.move b/register/sources/script.move index e6180f91..a82bc5c6 100644 --- a/register/sources/script.move +++ b/register/sources/script.move @@ -2,10 +2,7 @@ script { use aptos_names::token_helper; fun main(admin: &signer) { - let names = vector [ - b"name0", - b"name1", - ]; + let names = vector[b"name0", b"name1",]; let one_year_secs = 365 * 24 * 60 * 60; @@ -13,20 +10,17 @@ script { while (!std::vector::is_empty(&names)) { let name = std::string::utf8(std::vector::pop_back(&mut names)); - aptos_names::domains::force_create_or_seize_domain_name(admin, name, one_year_secs); + aptos_names::domains::force_create_or_seize_domain_name(admin, name, + one_year_secs); - if (!transfer) { - continue - }; + if (!transfer) { continue }; - let token_data_id = token_helper::build_tokendata_id( - token_helper::get_token_signer_address(), - std::option::none(), - name, - ); + let token_data_id = + token_helper::build_tokendata_id(token_helper::get_token_signer_address(), + std::option::none(), name,); let token_id = token_helper::latest_token_id(&token_data_id); - aptos_token::token::transfer(admin, token_id, @repository, 1); + aptos_token::token::transfer(admin, token_id, @repository, 1); } } } diff --git a/router/sources/router.move b/router/sources/router.move index 87a8441d..47d51ab2 100644 --- a/router/sources/router.move +++ b/router/sources/router.move @@ -61,49 +61,45 @@ module router::router { } fun init_module(deployer: &signer) { - let (_, signer_cap) = account::create_resource_account( - deployer, - ROUTER_SIGNER_SEED, - ); - move_to(deployer, RouterConfig { - pending_admin_addr: option::none(), - admin_addr: signer::address_of(deployer), - mode: MODE_V1, - signer_cap, - }); + let (_, signer_cap) = + account::create_resource_account(deployer, ROUTER_SIGNER_SEED,); + move_to(deployer, + RouterConfig { + pending_admin_addr: option::none(), + admin_addr: signer::address_of(deployer), + mode: MODE_V1, + signer_cap, + }); } // == ROUTER MANAGEMENT WRITE FUNCTIONS == /// Sets the pending admin address. Caller must be the admin public entry fun set_pending_admin( - router_admin: &signer, - pending_admin_addr: address, + router_admin: &signer, pending_admin_addr: address, ) acquires RouterConfig { let router_config = borrow_global_mut(@router); - assert!(router_config.admin_addr == signer::address_of(router_admin), error::permission_denied(ENOT_ADMIN)); + assert!(router_config.admin_addr == signer::address_of(router_admin), + error::permission_denied(ENOT_ADMIN)); router_config.pending_admin_addr = option::some(pending_admin_addr); } /// Accept to become admin. Caller must be the pending admin public entry fun accept_pending_admin(pending_admin: &signer) acquires RouterConfig { let router_config = borrow_global_mut(@router); - assert!( - router_config.pending_admin_addr == option::some(signer::address_of(pending_admin)), - error::permission_denied(ENOT_PENDING_ADMIN) - ); + assert!(router_config.pending_admin_addr + == option::some(signer::address_of(pending_admin)), + error::permission_denied(ENOT_PENDING_ADMIN)); router_config.admin_addr = *option::borrow(&router_config.pending_admin_addr); router_config.pending_admin_addr = option::none(); } /// Change the router mode. See ROUTER MODE ENUMS - public entry fun set_mode( - router_admin: &signer, - mode: u8, - ) acquires RouterConfig { + public entry fun set_mode(router_admin: &signer, mode: u8,) acquires RouterConfig { assert!(is_valid_mode(mode), error::invalid_argument(EINVALID_MODE)); let router_config = borrow_global_mut(@router); - assert!(router_config.admin_addr == signer::address_of(router_admin), error::permission_denied(ENOT_ADMIN)); + assert!(router_config.admin_addr == signer::address_of(router_admin), + error::permission_denied(ENOT_ADMIN)); router_config.mode = mode; } @@ -143,22 +139,24 @@ module router::router { /// If the name is registerable in v1, the name can only be registered if it is also available in v2. /// Else the name is registered and active in v1, then the name can only be registered if we have burned the token /// (sent it to the router_signer) - fun can_register_in_v2(domain_name: String, subdomain_name: Option): bool acquires RouterConfig { - let registerable_in_v1 = domains::name_is_expired_past_grace(subdomain_name, domain_name); + fun can_register_in_v2( + domain_name: String, subdomain_name: Option + ): bool acquires RouterConfig { + let registerable_in_v1 = domains::name_is_expired_past_grace(subdomain_name, + domain_name); if (registerable_in_v1) { v2_1_domains::is_name_registerable(domain_name, subdomain_name) } else { - let (is_burned, _token_id) = domains::is_token_owner( - router_signer_addr(), - subdomain_name, - domain_name - ); + let (is_burned, _token_id) = + domains::is_token_owner(router_signer_addr(), subdomain_name, domain_name); is_burned } } #[view] - public fun can_register(domain_name: String, subdomain_name: Option): bool acquires RouterConfig { + public fun can_register( + domain_name: String, subdomain_name: Option + ): bool acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { domains::name_is_expired_past_grace(subdomain_name, domain_name) @@ -184,53 +182,38 @@ module router::router { ) acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { - assert!( - registration_duration_secs % SECONDS_PER_YEAR == 0, - error::invalid_argument(ENOT_MULTIPLE_OF_SECONDS_PER_YEAR) - ); - domains::register_domain( - user, - domain_name, - ((registration_duration_secs / SECONDS_PER_YEAR) as u8) - ); + assert!(registration_duration_secs % SECONDS_PER_YEAR == 0, + error::invalid_argument(ENOT_MULTIPLE_OF_SECONDS_PER_YEAR)); + domains::register_domain(user, domain_name, ( + (registration_duration_secs / SECONDS_PER_YEAR) as u8 + )); } else if (mode == MODE_V1_AND_V2) { - assert!(can_register_in_v2(domain_name, option::none()), error::unavailable(ENAME_NOT_AVAILABLE)); - v2_1_domains::register_domain( - get_router_signer(), - user, - domain_name, - registration_duration_secs, - ); + assert!(can_register_in_v2(domain_name, option::none()), + error::unavailable(ENAME_NOT_AVAILABLE)); + v2_1_domains::register_domain(get_router_signer(), user, domain_name, + registration_duration_secs,); // Clear the name in v1 - domains::force_clear_registration(get_router_signer(), option::none(), domain_name) + domains::force_clear_registration(get_router_signer(), option::none(), + domain_name) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) }; // Common operations that handle modes via the router - let target_addr_with_default = if (option::is_some(&target_addr)) { - *option::borrow(&target_addr) - } else { - signer::address_of(user) - }; - set_target_addr( - user, - domain_name, - option::none(), - target_addr_with_default - ); + let target_addr_with_default = + if (option::is_some(&target_addr)) { + *option::borrow(&target_addr) + } else { + signer::address_of(user) + }; + set_target_addr(user, domain_name, option::none(), target_addr_with_default); if (option::is_some(&to_addr)) { transfer_name(user, domain_name, option::none(), *option::borrow(&to_addr)); }; // This will set primary name and target address - set_primary_name_when_register( - user, - target_addr, - to_addr, - domain_name, - option::none(), - ); + set_primary_name_when_register(user, target_addr, to_addr, domain_name, + option::none(),); } fun set_primary_name_when_register( @@ -243,14 +226,10 @@ module router::router { let owner_addr = signer::address_of(user); // if the owner address is not the buyer address - if (option::is_some(&to_addr) && to_addr != option::some(owner_addr)) { - return - }; + if (option::is_some(&to_addr) && to_addr != option::some(owner_addr)) { return }; // if the target address is not the buyer address - if (option::is_some(&target_addr) && target_addr != option::some(owner_addr)) { - return - }; + if (option::is_some(&target_addr) && target_addr != option::some(owner_addr)) { return }; if (!has_primary_name(user)) { set_primary_name(user, domain_name, subdomain_name); @@ -278,72 +257,51 @@ module router::router { ) acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { - domains::register_subdomain(user, subdomain_name, domain_name, expiration_time_sec); + domains::register_subdomain(user, subdomain_name, domain_name, + expiration_time_sec); } else if (mode == MODE_V1_AND_V2) { - assert!( - can_register_in_v2(domain_name, option::some(subdomain_name)), - error::unavailable(ENAME_NOT_AVAILABLE) - ); - v2_1_domains::register_subdomain( - get_router_signer(), + assert!(can_register_in_v2(domain_name, option::some(subdomain_name)), + error::unavailable(ENAME_NOT_AVAILABLE)); + v2_1_domains::register_subdomain(get_router_signer(), user, domain_name, subdomain_name, - expiration_time_sec, - ); - v2_1_domains::set_subdomain_expiration_policy( - user, - domain_name, - subdomain_name, - expiration_policy, - ); - domains::force_clear_registration(get_router_signer(), option::some(subdomain_name), domain_name) + expiration_time_sec,); + v2_1_domains::set_subdomain_expiration_policy(user, domain_name, subdomain_name, + expiration_policy,); + domains::force_clear_registration(get_router_signer(), + option::some(subdomain_name), domain_name) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) }; // Common operations that handle modes via the router - let target_addr_with_default = if (option::is_some(&target_addr)) { - *option::borrow(&target_addr) - } else { - signer::address_of(user) - }; - set_target_addr( - user, - domain_name, - option::some(subdomain_name), - target_addr_with_default - ); + let target_addr_with_default = + if (option::is_some(&target_addr)) { + *option::borrow(&target_addr) + } else { + signer::address_of(user) + }; + set_target_addr(user, domain_name, option::some(subdomain_name), + target_addr_with_default); if (option::is_some(&to_addr)) { transfer_name(user, domain_name, option::some(subdomain_name), *option::borrow(&to_addr)); }; if (mode == MODE_V1_AND_V2) { - v2_1_domains::set_subdomain_transferability_as_domain_owner( - get_router_signer(), - user, - domain_name, - subdomain_name, - transferrable - ); + v2_1_domains::set_subdomain_transferability_as_domain_owner(get_router_signer(), user, + domain_name, subdomain_name, transferrable); }; // This will set primary name and target address - set_primary_name_when_register( - user, - target_addr, - to_addr, - domain_name, - option::some(subdomain_name), - ); + set_primary_name_when_register(user, target_addr, to_addr, domain_name, + option::some(subdomain_name),); } // ==== MIGRATION ==== /// @notice Migrates a name to the current router mode public entry fun migrate_name( - user: &signer, - domain_name: String, - subdomain_name: Option, + user: &signer, domain_name: String, subdomain_name: Option, ) acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { @@ -351,65 +309,41 @@ module router::router { } else if (mode == MODE_V1_AND_V2) { let user_addr = signer::address_of(user); // Check name is not already migrated - assert!( - !exists_in_v2(domain_name, subdomain_name), - error::invalid_state(ENAME_ALREADY_MIGRATED) - ); + assert!(!exists_in_v2(domain_name, subdomain_name), + error::invalid_state(ENAME_ALREADY_MIGRATED)); - let (is_v1_owner, _token_id) = domains::is_token_owner( - user_addr, - subdomain_name, - domain_name, - ); + let (is_v1_owner, _token_id) = + domains::is_token_owner(user_addr, subdomain_name, domain_name,); assert!(is_v1_owner, error::permission_denied(ENOT_NAME_OWNER)); - assert!( - !domains::name_is_expired_past_grace(subdomain_name, domain_name), - error::invalid_state(EMIGRATION_ALREADY_EXPIRED) - ); + assert!(!domains::name_is_expired_past_grace(subdomain_name, domain_name), + error::invalid_state(EMIGRATION_ALREADY_EXPIRED)); // Check primary name status let maybe_primary_name = domains::get_reverse_lookup(user_addr); - let is_primary_name = if (option::is_some(&maybe_primary_name)) { - let (primary_subdomain_name, primary_domain_name) = domains::get_name_record_key_v1_props( - &option::extract(&mut maybe_primary_name) - ); - subdomain_name == primary_subdomain_name && domain_name == primary_domain_name - } else { - false - }; + let is_primary_name = + if (option::is_some(&maybe_primary_name)) { + let (primary_subdomain_name, primary_domain_name) = + domains::get_name_record_key_v1_props(&option::extract(&mut maybe_primary_name)); + subdomain_name == primary_subdomain_name && domain_name == primary_domain_name + } else { false }; // Get the v1 token info - let ( - _property_version, - expiration_time_sec, - target_addr - ) = domains::get_name_record_v1_props_for_name( - subdomain_name, - domain_name, - ); - let tokendata_id = aptos_names::token_helper::build_tokendata_id( - aptos_names::token_helper::get_token_signer_address(), - subdomain_name, - domain_name, - ); + let (_property_version, expiration_time_sec, target_addr) = + domains::get_name_record_v1_props_for_name(subdomain_name, domain_name,); + let tokendata_id = + aptos_names::token_helper::build_tokendata_id(aptos_names::token_helper::get_token_signer_address(), + subdomain_name, domain_name,); let token_id = aptos_names::token_helper::latest_token_id(&tokendata_id); // Domain must migrate before subdomain, throw error if this is a subdomain but domain has not been migrated if (option::is_some(&subdomain_name)) { - assert!( - exists_in_v2(domain_name, option::none()), - error::invalid_state(ECANNOT_MIGRATE_SUBDOMAIN_BEFORE_MIGRATE_DOMAIN) - ) + assert!(exists_in_v2(domain_name, option::none()), + error::invalid_state(ECANNOT_MIGRATE_SUBDOMAIN_BEFORE_MIGRATE_DOMAIN)) }; // Burn by sending to `router_signer` let router_signer = get_router_signer(); - aptos_token::token::direct_transfer( - user, - router_signer, - token_id, - 1, - ); + aptos_token::token::direct_transfer(user, router_signer, token_id, 1,); // Calculate new expiration. Cases: // 1. Name is a subdomain. Migrate the name with the same expiration @@ -417,46 +351,37 @@ module router::router { // a. it expires before AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC. Migrate the name with an extra year to its existing expiration // b. it expires after AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC. Migrate the name with the same expiration let now = timestamp::now_seconds(); - let new_expiration_time_sec = if (option::is_some(&subdomain_name)) { - expiration_time_sec - } else { - if (expiration_time_sec <= AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC) { - expiration_time_sec + SECONDS_PER_YEAR - } else { - expiration_time_sec - } - }; + let new_expiration_time_sec = + if (option::is_some(&subdomain_name)) { expiration_time_sec } + else { + if (expiration_time_sec <= AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC) { + expiration_time_sec + SECONDS_PER_YEAR + } else { expiration_time_sec } + }; // Mint token in v2 // Names past the cutoff date will end up with a negative // registration duration. The following logic ensures that duration // is >= 1 - let registration_duration_secs = if (new_expiration_time_sec > now) - { - new_expiration_time_sec - now - } else { - // Must be non-zero so that the name is not considered expired - 1 - }; - v2_1_domains::register_name_with_router( - router_signer, + let registration_duration_secs = + if (new_expiration_time_sec > now) { + new_expiration_time_sec - now + } else { + // Must be non-zero so that the name is not considered expired + 1 }; + v2_1_domains::register_name_with_router(router_signer, user, domain_name, subdomain_name, - registration_duration_secs, - ); + registration_duration_secs,); // If the name was a primary name, carry it over (`target_addr` gets automatically carried over too) // Else, if there was a target_addr in v1, just carry over the target_addr if (is_primary_name) { v2_1_domains::set_reverse_lookup(user, subdomain_name, domain_name) } else if (option::is_some(&target_addr)) { - v2_1_domains::set_target_address( - user, - domain_name, - subdomain_name, - *option::borrow(&target_addr) - ); + v2_1_domains::set_target_address(user, domain_name, subdomain_name, *option::borrow( + &target_addr)); }; // Clear the name in v1. Will also clear the primary name if it was a primary name @@ -470,9 +395,7 @@ module router::router { /// @notice Renews the domain. NOTE 1: Not available in MODE_V1. NOTE 2: Will attempt to migrate the domain. For subdomains, the call may fail unless `migrate_name` is called directly on the subdomain first public entry fun renew_domain( - user: &signer, - domain_name: String, - renewal_duration_secs: u64, + user: &signer, domain_name: String, renewal_duration_secs: u64, ) acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { @@ -487,17 +410,12 @@ module router::router { } fun migrate_if_eligible( - user: &signer, - domain_name: String, - subdomain_name: Option, + user: &signer, domain_name: String, subdomain_name: Option, ) acquires RouterConfig { // Migrate if the name is still in v1 and is a domain. // We do not migrate the subdomain because it might fail due to domain hasn't been migrated - if (!exists_in_v2(domain_name, subdomain_name) && is_v1_name_owner( - signer::address_of(user), - domain_name, - subdomain_name - )) { + if (!exists_in_v2(domain_name, subdomain_name) && is_v1_name_owner(signer::address_of(user), + domain_name, subdomain_name)) { if (option::is_none(&subdomain_name)) { migrate_name(user, domain_name, subdomain_name); } else { @@ -508,17 +426,16 @@ module router::router { // ==== REVERSE REGISTRATION ==== - fun has_primary_name( - user: &signer, - ): bool acquires RouterConfig { + fun has_primary_name(user: &signer,): bool acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { let reverse_lookup_result = domains::get_reverse_lookup(signer::address_of(user)); - return (option::is_some(&reverse_lookup_result)) + return(option::is_some(&reverse_lookup_result)) } else if (mode == MODE_V1_AND_V2) { // Returns true if the user has a primary name in v1 or v2. We are essentially accepting that a v1 primary name is valid while in MODE_V1_AND_V2. // That said, as long as v1 is read-only and changes to v2 names will clear the v1 name, this is acceptable - return (option::is_some(&domains::get_reverse_lookup(signer::address_of(user))) || option::is_some(&v2_1_domains::get_reverse_lookup(signer::address_of(user)))) + return(option::is_some(&domains::get_reverse_lookup(signer::address_of(user))) || option::is_some( + &v2_1_domains::get_reverse_lookup(signer::address_of(user)))) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } @@ -526,16 +443,12 @@ module router::router { /// @notice Updates a user's primary name. NOTE: Will attempt to migrate the domain. For subdomains, the call may fail unless `migrate_name` is called directly on the subdomain first public entry fun set_primary_name( - user: &signer, - domain_name: String, - subdomain_name: Option, + user: &signer, domain_name: String, subdomain_name: Option, ) acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { - let record = domains::create_name_record_key_v1( - subdomain_name, - domain_name, - ); + let record = + domains::create_name_record_key_v1(subdomain_name, domain_name,); domains::set_reverse_lookup(user, &record); } else if (mode == MODE_V1_AND_V2) { migrate_if_eligible(user, domain_name, subdomain_name); @@ -545,11 +458,7 @@ module router::router { if (option::is_some(&v1_primary_domain_name)) { domains::force_clear_reverse_lookup(get_router_signer(), user_addr); }; - v2_1_domains::set_reverse_lookup( - user, - subdomain_name, - domain_name, - ); + v2_1_domains::set_reverse_lookup(user, subdomain_name, domain_name,); } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } @@ -562,11 +471,13 @@ module router::router { domains::clear_reverse_lookup(user); } else if (mode == MODE_V1_AND_V2) { // Clear primary name in v1 if exists so we do not have primary name in both v1 and v2 - let (v1_primary_subdomain_name, v1_primary_domain_name) = get_v1_primary_name(signer::address_of(user)); + let (v1_primary_subdomain_name, v1_primary_domain_name) = get_v1_primary_name(signer::address_of( + user)); if (option::is_some(&v1_primary_domain_name)) { // If v1 primary name is a domain, migrate it to v2, this will automatically clear it as primary name in v1 and set again in v2 if (option::is_none(&v1_primary_subdomain_name)) { - migrate_name(user, *option::borrow(&v1_primary_domain_name), v1_primary_subdomain_name); + migrate_name(user, *option::borrow(&v1_primary_domain_name), + v1_primary_subdomain_name); } else { // else v1 primary name is a subdomain, we only clear it but not migrate it, as migration could fail if its domain has not been migrated domains::clear_reverse_lookup(user); @@ -589,20 +500,10 @@ module router::router { ) acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { - domains::set_name_address( - user, - subdomain_name, - domain_name, - target_addr, - ) + domains::set_name_address(user, subdomain_name, domain_name, target_addr,) } else if (mode == MODE_V1_AND_V2) { migrate_if_eligible(user, domain_name, subdomain_name); - v2_1_domains::set_target_address( - user, - domain_name, - subdomain_name, - target_addr, - ) + v2_1_domains::set_target_address(user, domain_name, subdomain_name, target_addr,) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } @@ -610,30 +511,19 @@ module router::router { /// @notice Clear a name's target address. NOTE: Will attempt to migrate the domain. For subdomains, the call may fail unless `migrate_name` is called directly on the subdomain first public entry fun clear_target_addr( - user: &signer, - domain_name: String, - subdomain_name: Option, + user: &signer, domain_name: String, subdomain_name: Option, ) acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { - domains::clear_name_address( - user, - subdomain_name, - domain_name, - ) + domains::clear_name_address(user, subdomain_name, domain_name,) } else if (mode == MODE_V1_AND_V2) { migrate_if_eligible(user, domain_name, subdomain_name); - v2_1_domains::clear_target_address( - user, - subdomain_name, - domain_name, - ) + v2_1_domains::clear_target_address(user, subdomain_name, domain_name,) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } } - // ==== DOMAIN ADMIN ==== /// @notice Transfer a subdomain as the domain admin. NOTE: Not available in MODE_V1 @@ -648,13 +538,8 @@ module router::router { if (mode == MODE_V1) { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } else if (mode == MODE_V1_AND_V2) { - v2_1_domains::transfer_subdomain_owner( - domain_admin, - domain_name, - subdomain_name, - to_addr, - target_addr, - ) + v2_1_domains::transfer_subdomain_owner(domain_admin, domain_name, subdomain_name, + to_addr, target_addr,) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } @@ -671,13 +556,11 @@ module router::router { if (mode == MODE_V1) { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } else if (mode == MODE_V1_AND_V2) { - v2_1_domains::set_subdomain_transferability_as_domain_owner( - get_router_signer(), + v2_1_domains::set_subdomain_transferability_as_domain_owner(get_router_signer(), domain_admin, domain_name, subdomain_name, - transferable - ) + transferable) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } @@ -695,12 +578,8 @@ module router::router { // Will not be implemented in v1 abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } else if (mode == MODE_V1_AND_V2) { - v2_1_domains::set_subdomain_expiration_policy( - domain_admin, - domain_name, - subdomain_name, - expiration_policy, - ) + v2_1_domains::set_subdomain_expiration_policy(domain_admin, domain_name, + subdomain_name, expiration_policy,) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } @@ -718,12 +597,8 @@ module router::router { // Will not be implemented in v1 abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } else if (mode == MODE_V1_AND_V2) { - v2_1_domains::set_subdomain_expiration( - domain_admin, - domain_name, - subdomain_name, - expiration_time_sec, - ) + v2_1_domains::set_subdomain_expiration(domain_admin, domain_name, subdomain_name, + expiration_time_sec,) } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } @@ -732,29 +607,28 @@ module router::router { // == ROUTER READ FUNCTIONS == /// Returns true if the name is tracked in v2 - inline fun exists_in_v2(domain_name: String, subdomain_name: Option): bool { + inline fun exists_in_v2( + domain_name: String, subdomain_name: Option + ): bool { object::is_object(v2_1_domains::get_token_addr(domain_name, subdomain_name)) } inline fun get_v1_target_addr( - domain_name: String, - subdomain_name: Option + domain_name: String, subdomain_name: Option ): Option
{ if (!aptos_names::domains::name_is_registered(subdomain_name, domain_name)) { option::none() } else { - let (_property_version, _expiration_time_sec, target_addr) = aptos_names::domains::get_name_record_v1_props_for_name( - subdomain_name, - domain_name, - ); + let (_property_version, _expiration_time_sec, target_addr) = + aptos_names::domains::get_name_record_v1_props_for_name(subdomain_name, + domain_name,); target_addr } } #[view] public fun get_target_addr( - domain_name: String, - subdomain_name: Option + domain_name: String, subdomain_name: Option ): Option
acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { @@ -763,10 +637,8 @@ module router::router { if (!exists_in_v2(domain_name, subdomain_name)) { get_v1_target_addr(domain_name, subdomain_name) } else { - let target_addr = v2_1_domains::get_target_address( - domain_name, - subdomain_name, - ); + let target_addr = + v2_1_domains::get_target_address(domain_name, subdomain_name,); target_addr } } else { @@ -775,19 +647,16 @@ module router::router { } inline fun is_v1_name_owner( - owner_addr: address, - domain_name: String, - subdomain_name: Option, + owner_addr: address, domain_name: String, subdomain_name: Option, ): bool { - let (is_owner, _token_id) = domains::is_token_owner(owner_addr, subdomain_name, domain_name); + let (is_owner, _token_id) = domains::is_token_owner(owner_addr, subdomain_name, + domain_name); is_owner && !domains::name_is_expired_past_grace(subdomain_name, domain_name) } #[view] public fun is_name_owner( - owner_addr: address, - domain_name: String, - subdomain_name: Option, + owner_addr: address, domain_name: String, subdomain_name: Option, ): bool acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { @@ -797,9 +666,7 @@ module router::router { is_v1_name_owner(owner_addr, domain_name, subdomain_name) } else { v2_1_domains::is_token_owner(owner_addr, domain_name, subdomain_name) && !v2_1_domains::is_name_expired( - domain_name, - subdomain_name - ) + domain_name, subdomain_name) } } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) @@ -810,8 +677,7 @@ module router::router { /// Returns a name's owner address. Returns option::none() if there is no owner. /// Not available in MODE_v1 public fun get_owner_addr( - domain_name: String, - subdomain_name: Option, + domain_name: String, subdomain_name: Option, ): Option
acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { @@ -825,20 +691,16 @@ module router::router { } inline fun get_v1_expiration( - domain_name: String, - subdomain_name: Option + domain_name: String, subdomain_name: Option ): u64 { - let (_property_version, expiration_time_sec, _target_addr) = domains::get_name_record_v1_props_for_name( - subdomain_name, - domain_name, - ); + let (_property_version, expiration_time_sec, _target_addr) = + domains::get_name_record_v1_props_for_name(subdomain_name, domain_name,); expiration_time_sec } #[view] public fun get_expiration( - domain_name: String, - subdomain_name: Option + domain_name: String, subdomain_name: Option ): u64 acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { @@ -847,10 +709,8 @@ module router::router { if (!exists_in_v2(domain_name, subdomain_name)) { get_v1_expiration(domain_name, subdomain_name) } else { - let expiration_time_sec = v2_1_domains::get_expiration( - domain_name, - subdomain_name, - ); + let expiration_time_sec = + v2_1_domains::get_expiration(domain_name, subdomain_name,); expiration_time_sec } } else { @@ -861,8 +721,7 @@ module router::router { #[view] /// Not available in MODE_v1 public fun get_subdomain_expiration_policy( - domain_name: String, - subdomain_name: String, + domain_name: String, subdomain_name: String, ): u8 acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { @@ -875,16 +734,12 @@ module router::router { } } - inline fun get_v1_primary_name( - user_addr: address - ): (Option, Option) { + inline fun get_v1_primary_name(user_addr: address): (Option, Option) { let record = domains::get_reverse_lookup(user_addr); - if (option::is_none(&record)) { - (option::none(), option::none()) - } else { - let (subdomain_name, domain_name) = domains::get_name_record_key_v1_props( - option::borrow(&record) - ); + if (option::is_none(&record)) { (option::none(), option::none()) } + else { + let (subdomain_name, domain_name) = + domains::get_name_record_key_v1_props(option::borrow(&record)); (subdomain_name, option::some(domain_name)) } } @@ -900,12 +755,10 @@ module router::router { get_v1_primary_name(user_addr) } else { let token_addr = v2_1_domains::get_reverse_lookup(user_addr); - if (option::is_none(&token_addr)) { - (option::none(), option::none()) - } else { - let (subdomain_name, domain_name) = v2_1_domains::get_name_props_from_token_addr( - *option::borrow(&token_addr) - ); + if (option::is_none(&token_addr)) { (option::none(), option::none()) } + else { + let (subdomain_name, domain_name) = + v2_1_domains::get_name_props_from_token_addr(*option::borrow(&token_addr)); (subdomain_name, option::some(domain_name)) } } @@ -916,43 +769,24 @@ module router::router { // == Transfer helper == fun transfer_name( - user: &signer, - domain_name: String, - subdomain_name: Option, - to_addr: address + user: &signer, domain_name: String, subdomain_name: Option, to_addr: address ) acquires RouterConfig { let mode = get_mode(); if (mode == MODE_V1) { // Get the v1 token info - let ( - _property_version, - _expiration_time_sec, - _target_addr - ) = domains::get_name_record_v1_props_for_name( - subdomain_name, - domain_name, - ); - let tokendata_id = aptos_names::token_helper::build_tokendata_id( - aptos_names::token_helper::get_token_signer_address(), - subdomain_name, - domain_name, - ); + let (_property_version, _expiration_time_sec, _target_addr) = + domains::get_name_record_v1_props_for_name(subdomain_name, domain_name,); + let tokendata_id = + aptos_names::token_helper::build_tokendata_id(aptos_names::token_helper::get_token_signer_address(), + subdomain_name, domain_name,); let token_id = aptos_names::token_helper::latest_token_id(&tokendata_id); - aptos_token::token::transfer( - user, - token_id, - to_addr, - 1, - ); + aptos_token::token::transfer(user, token_id, to_addr, 1,); // TODO: Probably good idea to clear entries in v1 } else if (mode == MODE_V1_AND_V2) { let token_addr = v2_1_domains::get_token_addr(domain_name, subdomain_name); - object::transfer( - user, - object::address_to_object(token_addr), - to_addr, - ); + object::transfer(user, + object::address_to_object(token_addr), to_addr,); } else { abort error::not_implemented(ENOT_IMPLEMENTED_IN_MODE) } diff --git a/router/sources/tests/domain_admin_tests.move b/router/sources/tests/domain_admin_tests.move index f0bc04bd..d3ce4d80 100644 --- a/router/sources/tests/domain_admin_tests.move +++ b/router/sources/tests/domain_admin_tests.move @@ -9,15 +9,7 @@ module router::domain_admin_tests { const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_domain_admin_transfer_subdomain( router: &signer, aptos_names: &signer, @@ -28,7 +20,9 @@ module router::domain_admin_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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); @@ -40,32 +34,26 @@ module router::domain_admin_tests { // Register with v1 let domain_name = utf8(b"test1"); let subdomain_name = utf8(b"sub1"); - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user1, + 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() - ); - assert!(router::is_name_owner(user1_addr, domain_name, option::some(subdomain_name)), 1); + option::none()); + assert!(router::is_name_owner(user1_addr, domain_name, option::some(subdomain_name)), + 1); - router::domain_admin_transfer_subdomain(user1, domain_name, subdomain_name, user2_addr, option::none()); - assert!(router::is_name_owner(user2_addr, domain_name, option::some(subdomain_name)), 1); + router::domain_admin_transfer_subdomain(user1, domain_name, subdomain_name, + user2_addr, option::none()); + assert!(router::is_name_owner(user2_addr, domain_name, option::some(subdomain_name)), + 1); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_domain_admin_set_subdomain_expiration_policy( router: &signer, aptos_names: &signer, @@ -76,7 +64,9 @@ module router::domain_admin_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user1 = vector::borrow(&users, 0); // Bump mode @@ -85,47 +75,33 @@ module router::domain_admin_tests { // Register with v1 let domain_name = utf8(b"test1"); let subdomain_name = utf8(b"sub1"); - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user1, + 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() - ); - assert!(router::get_subdomain_expiration_policy(domain_name, subdomain_name) == 0, 1); + option::none()); + assert!(router::get_subdomain_expiration_policy(domain_name, subdomain_name) == 0, + 1); // Set it to 1 - router::domain_admin_set_subdomain_expiration_policy( - user1, - domain_name, - subdomain_name, - 1, - ); - assert!(router::get_subdomain_expiration_policy(domain_name, subdomain_name) == 1, 2); + router::domain_admin_set_subdomain_expiration_policy(user1, domain_name, + subdomain_name, 1,); + assert!(router::get_subdomain_expiration_policy(domain_name, subdomain_name) == 1, + 2); // Set it to 0 - router::domain_admin_set_subdomain_expiration_policy( - user1, - domain_name, - subdomain_name, - 0, - ); - assert!(router::get_subdomain_expiration_policy(domain_name, subdomain_name) == 0, 2); + router::domain_admin_set_subdomain_expiration_policy(user1, domain_name, + subdomain_name, 0,); + assert!(router::get_subdomain_expiration_policy(domain_name, subdomain_name) == 0, + 2); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_domain_admin_set_subdomain_expiration( router: &signer, aptos_names: &signer, @@ -136,7 +112,9 @@ module router::domain_admin_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user1 = vector::borrow(&users, 0); // Bump mode @@ -146,35 +124,27 @@ module router::domain_admin_tests { let domain_name = utf8(b"test1"); let subdomain_name = utf8(b"sub1"); let subdomain_name_opt = option::some(subdomain_name); - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user1, + 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() - ); - assert!(router::get_expiration(domain_name, subdomain_name_opt) == SECONDS_PER_YEAR, 1); + option::none()); + assert!(router::get_expiration(domain_name, subdomain_name_opt) == SECONDS_PER_YEAR, + 1); // Set it to 0 - router::domain_admin_set_subdomain_expiration( - user1, - domain_name, - subdomain_name, - 0, - ); + router::domain_admin_set_subdomain_expiration(user1, domain_name, subdomain_name, + 0,); assert!(router::get_expiration(domain_name, subdomain_name_opt) == 0, 2); // Set it to 5 - router::domain_admin_set_subdomain_expiration( - user1, - domain_name, - subdomain_name, - 5, - ); + router::domain_admin_set_subdomain_expiration(user1, domain_name, subdomain_name, + 5,); assert!(router::get_expiration(domain_name, subdomain_name_opt) == 5, 2); } } diff --git a/router/sources/tests/migration_tests.move b/router/sources/tests/migration_tests.move index 17aa4c2f..671a126d 100644 --- a/router/sources/tests/migration_tests.move +++ b/router/sources/tests/migration_tests.move @@ -11,15 +11,7 @@ module router::migration_tests { const MAX_MODE: u8 = 1; const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_migrate_domain( router: &signer, aptos_names: &signer, @@ -30,19 +22,25 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name = utf8(b"test"); // Register with v1 let now = timestamp::now_seconds(); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); assert!(router::is_name_owner(user_addr, domain_name, option::none()), 1); - assert!(*option::borrow(&router::get_target_addr(domain_name, option::none())) == user_addr, 2); - assert!(router::get_expiration(domain_name, option::none()) == now + SECONDS_PER_YEAR, 3); + assert!(*option::borrow(&router::get_target_addr(domain_name, option::none())) == user_addr, + 2); + assert!(router::get_expiration(domain_name, option::none()) + == now + SECONDS_PER_YEAR, 3); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 4); assert!(option::is_none(&primary_subdomain_name), 5); }; @@ -52,10 +50,13 @@ module router::migration_tests { // Attributes should still be the same assert!(router::is_name_owner(user_addr, domain_name, option::none()), 7); - assert!(*option::borrow(&router::get_target_addr(domain_name, option::none())) == user_addr, 8); - assert!(router::get_expiration(domain_name, option::none()) == now + SECONDS_PER_YEAR, 9); + assert!(*option::borrow(&router::get_target_addr(domain_name, option::none())) == user_addr, + 8); + assert!(router::get_expiration(domain_name, option::none()) + == now + SECONDS_PER_YEAR, 9); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 10); assert!(option::is_none(&primary_subdomain_name), 11); }; @@ -66,32 +67,29 @@ module router::migration_tests { // Migrate to v2 router::migrate_name(user, domain_name, option::none()); assert!(router::is_name_owner(user_addr, domain_name, option::none()), 12); - assert!(*option::borrow(&router::get_target_addr(domain_name, option::none())) == user_addr, 13); + assert!(*option::borrow(&router::get_target_addr(domain_name, option::none())) == user_addr, + 13); // Auto-renewal is on because the expiration is 2 years from epoch - assert!(router::get_expiration(domain_name, option::none()) == now + SECONDS_PER_YEAR * 2, 14); + assert!(router::get_expiration(domain_name, option::none()) + == now + SECONDS_PER_YEAR * 2, 14); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 15); assert!(option::is_none(&primary_subdomain_name), 16); }; // v1 target is cleared - assert!(option::is_none(&aptos_names::domains::name_resolved_address(option::none(), domain_name)), 17); + assert!(option::is_none(&aptos_names::domains::name_resolved_address(option::none(), + domain_name)), + 17); // v1 primary name is cleared assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(user_addr)), 17); // v1 registration is cleared assert!(!aptos_names::domains::name_is_registered(option::none(), domain_name), 18); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 327688, location = router)] fun test_migrate_domain_as_non_owner( router: &signer, @@ -103,13 +101,16 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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 domain_name = utf8(b"test"); // Register with v1 - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Bump mode router::set_mode(router, 1); @@ -118,15 +119,7 @@ module router::migration_tests { router::migrate_name(user2, domain_name, option::none()); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_migrate_domain_no_autorenewal( router: &signer, aptos_names: &signer, @@ -137,7 +130,9 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); @@ -146,7 +141,8 @@ module router::migration_tests { let now = timestamp::now_seconds(); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Bump mode router::set_mode(router, 1); @@ -157,25 +153,21 @@ module router::migration_tests { router::migrate_name(user, domain_name, option::none()); // Auto-renewal is off because the expiration is after 2024/03/07 - assert!(router::get_expiration(domain_name, option::none()) == now + SECONDS_PER_YEAR, 14); + assert!(router::get_expiration(domain_name, option::none()) + == now + SECONDS_PER_YEAR, 14); // v1 target is cleared - assert!(option::is_none(&aptos_names::domains::name_resolved_address(option::none(), domain_name)), 17); + assert!(option::is_none(&aptos_names::domains::name_resolved_address(option::none(), + domain_name)), + 17); // v1 primary name is cleared - assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(address_of(user))), 17); + assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(address_of(user))), + 17); // v1 registration is cleared assert!(!aptos_names::domains::name_is_registered(option::none(), domain_name), 18); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_migrate_subdomain( router: &signer, aptos_names: &signer, @@ -186,7 +178,9 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name = utf8(b"test"); @@ -195,23 +189,25 @@ module router::migration_tests { // Register with v1 let now = timestamp::now_seconds(); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); router::set_primary_name(user, domain_name, subdomain_name_opt); assert!(router::is_name_owner(user_addr, domain_name, subdomain_name_opt), 7); - assert!(*option::borrow(&router::get_target_addr(domain_name, subdomain_name_opt)) == user_addr, 8); - assert!(router::get_expiration(domain_name, option::none()) == now + SECONDS_PER_YEAR, 9); + assert!(*option::borrow(&router::get_target_addr(domain_name, subdomain_name_opt)) == + user_addr, 8); + assert!(router::get_expiration(domain_name, option::none()) + == now + SECONDS_PER_YEAR, 9); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 10); assert!(*option::borrow(&primary_subdomain_name) == subdomain_name, 11); }; @@ -224,11 +220,15 @@ module router::migration_tests { // Attribtes should be the same assert!(router::is_name_owner(user_addr, domain_name, subdomain_name_opt), 7); - assert!(*option::borrow(&router::get_target_addr(domain_name, subdomain_name_opt)) == user_addr, 8); - assert!(router::get_expiration(domain_name, option::none()) == now + SECONDS_PER_YEAR, 9); - assert!(router::get_expiration(domain_name, subdomain_name_opt) == now + SECONDS_PER_YEAR, 9); + assert!(*option::borrow(&router::get_target_addr(domain_name, subdomain_name_opt)) == + user_addr, 8); + assert!(router::get_expiration(domain_name, option::none()) + == now + SECONDS_PER_YEAR, 9); + assert!(router::get_expiration(domain_name, subdomain_name_opt) + == now + SECONDS_PER_YEAR, 9); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 10); assert!(*option::borrow(&primary_subdomain_name) == subdomain_name, 11); }; @@ -237,37 +237,35 @@ module router::migration_tests { router::migrate_name(user, domain_name, option::none()); router::migrate_name(user, domain_name, subdomain_name_opt); assert!(router::is_name_owner(user_addr, domain_name, subdomain_name_opt), 7); - assert!(*option::borrow(&router::get_target_addr(domain_name, subdomain_name_opt)) == user_addr, 8); + assert!(*option::borrow(&router::get_target_addr(domain_name, subdomain_name_opt)) == + user_addr, 8); // Auto-renewal will not happen for subdomain. Its expiration remains the same - assert!( - router::get_expiration(domain_name, subdomain_name_opt) == now + SECONDS_PER_YEAR, - 9 - ); + assert!(router::get_expiration(domain_name, subdomain_name_opt) + == now + SECONDS_PER_YEAR, 9); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 10); assert!(*option::borrow(&primary_subdomain_name) == subdomain_name, 11); }; // v1 target is cleared - assert!(option::is_none(&aptos_names::domains::name_resolved_address(option::none(), domain_name)), 12); - assert!(option::is_none(&aptos_names::domains::name_resolved_address(subdomain_name_opt, domain_name)), 13); + assert!(option::is_none(&aptos_names::domains::name_resolved_address(option::none(), + domain_name)), + 12); + assert!(option::is_none(&aptos_names::domains::name_resolved_address( + subdomain_name_opt, domain_name)), + 13); // v1 primary name is cleared - assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(address_of(user))), 14); + assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(address_of(user))), + 14); // v1 registration is cleared assert!(!aptos_names::domains::name_is_registered(option::none(), domain_name), 15); - assert!(!aptos_names::domains::name_is_registered(subdomain_name_opt, domain_name), 16); + assert!(!aptos_names::domains::name_is_registered(subdomain_name_opt, domain_name), + 16); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 327688, location = router)] fun test_cannot_migrate_subdomain_as_non_owner( router: &signer, @@ -279,7 +277,9 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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 domain_name = utf8(b"test"); @@ -287,17 +287,16 @@ module router::migration_tests { 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, + 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(), - ); + option::none(),); // Bump mode router::set_mode(router, 1); @@ -309,15 +308,7 @@ module router::migration_tests { router::migrate_name(user2, domain_name, subdomain_name_opt); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 196618, location = router)] fun test_cannot_migrate_subdomain_before_domain( router: &signer, @@ -329,24 +320,25 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); let subdomain_name = utf8(b"sub"); let subdomain_name_opt = option::some(subdomain_name); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); // Bump mode router::set_mode(router, 1); @@ -355,15 +347,7 @@ module router::migration_tests { router::migrate_name(user, domain_name, subdomain_name_opt); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 196619, location = router)] fun test_cannot_migrate_twice( router: &signer, @@ -375,12 +359,15 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Bump mode router::set_mode(router, 1); @@ -390,15 +377,7 @@ module router::migration_tests { router::migrate_name(user, domain_name, option::none()); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_migrate_expired_but_still_in_grace_period_name( router: &signer, aptos_names: &signer, @@ -409,12 +388,15 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Bump mode router::set_mode(router, 1); @@ -427,25 +409,21 @@ module router::migration_tests { timestamp::update_global_time_for_test_secs(SECONDS_PER_YEAR + 100); router::migrate_name(user, domain_name, option::none()); // New expiration date is 1 year after original expiration date - assert!(router::get_expiration(domain_name, option::none()) == SECONDS_PER_YEAR * 2, 2); + assert!(router::get_expiration(domain_name, option::none()) + == SECONDS_PER_YEAR * 2, 2); // v1 target is cleared - assert!(option::is_none(&aptos_names::domains::name_resolved_address(option::none(), domain_name)), 12); + assert!(option::is_none(&aptos_names::domains::name_resolved_address(option::none(), + domain_name)), + 12); // v1 primary name is cleared - assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(address_of(user))), 14); + assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(address_of(user))), + 14); // v1 registration is cleared assert!(!aptos_names::domains::name_is_registered(option::none(), domain_name), 15); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 196615, location = router)] fun test_cannot_migrate_expired_past_grace_period_name( router: &signer, @@ -457,12 +435,15 @@ module router::migration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Bump mode router::set_mode(router, 1); diff --git a/router/sources/tests/primary_name_tests.move b/router/sources/tests/primary_name_tests.move index 56e0e692..bf078b13 100644 --- a/router/sources/tests/primary_name_tests.move +++ b/router/sources/tests/primary_name_tests.move @@ -11,48 +11,36 @@ module router::primary_name_tests { const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; - inline fun get_v1_primary_name( - user_addr: address - ): (Option, Option) { + inline fun get_v1_primary_name(user_addr: address): (Option, Option) { let record = aptos_names::domains::get_reverse_lookup(user_addr); - if (option::is_none(&record)) { - (option::none(), option::none()) - } else { - let (subdomain_name, domain_name) = aptos_names::domains::get_name_record_key_v1_props( - option::borrow(&record) - ); + if (option::is_none(&record)) { (option::none(), option::none()) } + else { + let (subdomain_name, domain_name) = + aptos_names::domains::get_name_record_key_v1_props(option::borrow(&record)); (subdomain_name, option::some(domain_name)) } } /// Returns true if the name is tracked in v2 - inline fun exists_in_v2(domain_name: String, subdomain_name: Option): bool { - object::is_object(aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, subdomain_name)) + inline fun exists_in_v2( + domain_name: String, subdomain_name: Option + ): bool { + object::is_object(aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, + subdomain_name)) } - inline fun get_v2_primary_name( - user_addr: address - ): (Option, Option) { + inline fun get_v2_primary_name(user_addr: address): (Option, Option) { let token_addr = aptos_names_v2_1::v2_1_domains::get_reverse_lookup(user_addr); - if (option::is_none(&token_addr)) { - (option::none(), option::none()) - } else { - let (subdomain_name, domain_name) = aptos_names_v2_1::v2_1_domains::get_name_props_from_token_addr( - *option::borrow(&token_addr) - ); + if (option::is_none(&token_addr)) { (option::none(), option::none()) } + else { + let (subdomain_name, domain_name) = + aptos_names_v2_1::v2_1_domains::get_name_props_from_token_addr(*option::borrow( + &token_addr)); (subdomain_name, option::some(domain_name)) } } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_set_primary_name_when_register( router: &signer, aptos_names: &signer, @@ -63,14 +51,18 @@ module router::primary_name_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name = utf8(b"test"); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 1); assert!(option::is_none(&primary_subdomain_name), 2); @@ -81,25 +73,20 @@ module router::primary_name_tests { let user_addr = address_of(user); let domain_name = utf8(b"test1"); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 1); assert!(option::is_none(&primary_subdomain_name), 2); // v1 primary name is cleared - assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(address_of(user))), 14); + assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(address_of(user))), + 14); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_set_primary_name( router: &signer, aptos_names: &signer, @@ -110,7 +97,9 @@ module router::primary_name_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name = utf8(b"test"); @@ -118,22 +107,22 @@ module router::primary_name_tests { let subdomain_name_opt = option::some(subdomain_name); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); // Set domain as primary router::set_primary_name(user, domain_name, option::none()); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 1); assert!(option::is_none(&primary_subdomain_name), 2); }; @@ -141,7 +130,8 @@ module router::primary_name_tests { // Set subdomain as primary router::set_primary_name(user, domain_name, subdomain_name_opt); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 3); assert!(*option::borrow(&primary_subdomain_name) == subdomain_name, 4); }; @@ -149,7 +139,8 @@ module router::primary_name_tests { // Clear primary name router::clear_primary_name(user); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(option::is_none(&primary_domain_name), 5); assert!(option::is_none(&primary_subdomain_name), 6); }; @@ -159,7 +150,8 @@ module router::primary_name_tests { // Primary name should still be cleared after version bump { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(option::is_none(&primary_domain_name), 5); assert!(option::is_none(&primary_subdomain_name), 6); }; @@ -171,7 +163,8 @@ module router::primary_name_tests { // Set domain as primary router::set_primary_name(user, domain_name, option::none()); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 7); assert!(option::is_none(&primary_subdomain_name), 8); }; @@ -179,7 +172,8 @@ module router::primary_name_tests { // Set subdomain as primary router::set_primary_name(user, domain_name, subdomain_name_opt); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(*option::borrow(&primary_domain_name) == domain_name, 9); assert!(*option::borrow(&primary_subdomain_name) == subdomain_name, 10); }; @@ -187,21 +181,14 @@ module router::primary_name_tests { // Clear primary name router::clear_primary_name(user); { - let (primary_subdomain_name, primary_domain_name) = router::get_primary_name(user_addr); + let (primary_subdomain_name, primary_domain_name) = router::get_primary_name( + user_addr); assert!(option::is_none(&primary_domain_name), 11); assert!(option::is_none(&primary_subdomain_name), 12); }; } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 65545, location = router::router)] fun test_set_primary_name_should_trigger_auto_migration( router: &signer, @@ -213,7 +200,9 @@ module router::primary_name_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name = utf8(b"test"); @@ -223,29 +212,27 @@ module router::primary_name_tests { let subdomain_name_opt2 = option::some(subdomain_name2); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_domain(user, domain_name2, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_domain(user, domain_name2, SECONDS_PER_YEAR, option::none(), + option::none()); - router::register_subdomain( - user, + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); - router::register_subdomain( - user, + option::none(),); + router::register_subdomain(user, domain_name2, subdomain_name2, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); router::set_primary_name(user, domain_name, option::none()); @@ -256,13 +243,16 @@ module router::primary_name_tests { router::set_primary_name(user, domain_name2, option::none()); { // domain2 should be successfully migrated to v2 - assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name2, option::none()), 2); - assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name2, option::none()), 3); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name2, + option::none()), 2); + assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name2, + option::none()), 3); // v1 primary name should be cleared let (_, v1_primary_domain_name) = get_v1_primary_name(user_addr); assert!(option::is_none(&v1_primary_domain_name), 2); // v2 primary name should be properly set to domain2 - let (v2_primary_subdomain_name, v2_primary_domain_name) = get_v2_primary_name(user_addr); + let (v2_primary_subdomain_name, v2_primary_domain_name) = get_v2_primary_name( + user_addr); assert!(v2_primary_domain_name == option::some(domain_name2), 3); assert!(option::is_none(&v2_primary_subdomain_name), 4); }; @@ -272,15 +262,7 @@ module router::primary_name_tests { router::set_primary_name(user, domain_name2, subdomain_name_opt2); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_clear_domain_primary_name_should_trigger_auto_migration( router: &signer, aptos_names: &signer, @@ -291,25 +273,26 @@ module router::primary_name_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name = utf8(b"test"); let subdomain_name = utf8(b"test"); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); - router::register_subdomain( - user, + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); router::set_primary_name(user, domain_name, option::none()); @@ -320,30 +303,27 @@ module router::primary_name_tests { router::clear_primary_name(user); { // domain should be successfully migrated to v2 - let (is_owner_of_v1_name, _) = aptos_names::domains::is_token_owner(user_addr, option::none(), domain_name); + let (is_owner_of_v1_name, _) = + aptos_names::domains::is_token_owner(user_addr, option::none(), domain_name); assert!(!is_owner_of_v1_name, 1); - assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, option::none()), 2); - assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, option::none()), 2); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, + option::none()), 2); + assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, + option::none()), 2); // v1 primary name should be cleared - let (v1_primary_subdomain_name, v1_primary_domain_name) = get_v1_primary_name(user_addr); + let (v1_primary_subdomain_name, v1_primary_domain_name) = get_v1_primary_name( + user_addr); assert!(option::is_none(&v1_primary_domain_name), 3); assert!(option::is_none(&v1_primary_subdomain_name), 4); // v2 primary name should be empty - let (v2_primary_subdomain_name, v2_primary_domain_name) = get_v2_primary_name(user_addr); + let (v2_primary_subdomain_name, v2_primary_domain_name) = get_v2_primary_name( + user_addr); assert!(option::is_none(&v2_primary_domain_name), 5); assert!(option::is_none(&v2_primary_subdomain_name), 6); }; } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_clear_subdomain_primary_name_should_not_trigger_auto_migration( router: &signer, aptos_names: &signer, @@ -354,7 +334,9 @@ module router::primary_name_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name = utf8(b"test"); @@ -362,18 +344,17 @@ module router::primary_name_tests { let subdomain_name_opt = option::some(subdomain_name); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); - router::register_subdomain( - user, + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); router::set_primary_name(user, domain_name, subdomain_name_opt); @@ -385,17 +366,25 @@ module router::primary_name_tests { router::clear_primary_name(user); { // subdomain should still remain in v1 - let (is_owner_of_v1_name, _) = aptos_names::domains::is_token_owner(user_addr, subdomain_name_opt, domain_name); - assert!(!aptos_names::domains::name_is_expired(subdomain_name_opt, domain_name), 1); + let (is_owner_of_v1_name, _) = + aptos_names::domains::is_token_owner(user_addr, subdomain_name_opt, + domain_name); + assert!(!aptos_names::domains::name_is_expired(subdomain_name_opt, domain_name), + 1); assert!(is_owner_of_v1_name, 1); - assert!(!aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, subdomain_name_opt), 2); - assert!(aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, subdomain_name_opt), 2); + assert!(!aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, + subdomain_name_opt), + 2); + assert!(aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, + subdomain_name_opt), 2); // v1 primary name should be cleared - let (v1_primary_subdomain_name, v1_primary_domain_name) = get_v1_primary_name(user_addr); + let (v1_primary_subdomain_name, v1_primary_domain_name) = get_v1_primary_name( + user_addr); assert!(option::is_none(&v1_primary_domain_name), 2); assert!(option::is_none(&v1_primary_subdomain_name), 3); // v2 primary name should be empty - let (v2_primary_subdomain_name, v2_primary_domain_name) = get_v2_primary_name(user_addr); + let (v2_primary_subdomain_name, v2_primary_domain_name) = get_v2_primary_name( + user_addr); assert!(option::is_none(&v2_primary_domain_name), 4); assert!(option::is_none(&v2_primary_subdomain_name), 5); }; diff --git a/router/sources/tests/registration_tests.move b/router/sources/tests/registration_tests.move index 9790841c..27503db3 100644 --- a/router/sources/tests/registration_tests.move +++ b/router/sources/tests/registration_tests.move @@ -12,15 +12,7 @@ module router::registration_tests { // == DOMAIN REGISTRATION == - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_register_domain( router: &signer, aptos_names: &signer, @@ -31,41 +23,39 @@ module router::registration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name1 = utf8(b"test1"); let domain_name2 = utf8(b"test2"); // Register with v1 - router::register_domain(user, domain_name1, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name1, SECONDS_PER_YEAR, option::none(), + option::none()); assert!(router::is_name_owner(user_addr, domain_name1, option::none()), 1); // Bump mode router::set_mode(router, 1); // Register with v2 - router::register_domain(user, domain_name2, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name2, SECONDS_PER_YEAR, option::none(), + option::none()); assert!(router::is_name_owner(user_addr, domain_name1, option::none()), 2); assert!(router::is_name_owner(user_addr, domain_name2, option::none()), 3); // v1 primary name is not cleared. v1 primary name only gets unset for explicit change of primary name. - assert!(option::is_some(&aptos_names::domains::get_reverse_lookup(address_of(user))), 4); + assert!(option::is_some(&aptos_names::domains::get_reverse_lookup(address_of(user))), + 4); // v2 primary name is properly set - let (primary_subdomain_name, primary_domain_name) = router::router::get_primary_name(address_of(user)); + let (primary_subdomain_name, primary_domain_name) = router::router::get_primary_name( + address_of(user)); assert!(option::is_none(&primary_subdomain_name), 5); assert!(option::some(domain_name1) == primary_domain_name, 6); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 851974, location = router)] fun test_register_same_domain_in_v1_and_v2( router: &signer, @@ -77,29 +67,25 @@ module router::registration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test1"); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Bump mode router::set_mode(router, 1); // Fail to register with v2 because name is still active in v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_register_diff_domain_in_v1_and_v2( router: &signer, aptos_names: &signer, @@ -110,13 +96,16 @@ module router::registration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name1 = utf8(b"test1"); // Register with v1 - router::register_domain(user, domain_name1, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name1, SECONDS_PER_YEAR, option::none(), + option::none()); { // Primary name should be `domain_name1` let (primary_subdomain, primary_domain) = router::get_primary_name(user_addr); @@ -129,7 +118,8 @@ module router::registration_tests { router::set_mode(router, 1); let domain_name = utf8(b"test2"); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); { // Primary name should still be `domain_name1` let (primary_subdomain, primary_domain) = router::get_primary_name(user_addr); @@ -138,15 +128,7 @@ module router::registration_tests { }; } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_register_domain_with_target_addr_and_to_addr( router: &signer, aptos_names: &signer, @@ -157,7 +139,9 @@ module router::registration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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); @@ -167,15 +151,14 @@ module router::registration_tests { // Register with v1 aptos_token::token::opt_in_direct_transfer(user2, true); - router::register_domain( - user1, + router::register_domain(user1, domain_name1, SECONDS_PER_YEAR, option::some(user2_addr), - option::some(user2_addr) - ); + option::some(user2_addr)); assert!(router::is_name_owner(user2_addr, domain_name1, option::none()), 1); - assert!(*option::borrow(&router::get_target_addr(domain_name1, option::none())) == user2_addr, 2); + assert!(*option::borrow(&router::get_target_addr(domain_name1, option::none())) == user2_addr, + 2); { // Primary name should be unset for user1 now that `target_addr` has been changed. let (primary_subdomain, primary_domain) = router::get_primary_name(user1_addr); @@ -187,15 +170,14 @@ module router::registration_tests { router::set_mode(router, 1); // Register with v2 - router::register_domain( - user1, + router::register_domain(user1, domain_name2, SECONDS_PER_YEAR, option::some(user2_addr), - option::some(user2_addr) - ); + option::some(user2_addr)); assert!(router::is_name_owner(user2_addr, domain_name2, option::none()), 1); - assert!(*option::borrow(&router::get_target_addr(domain_name2, option::none())) == user2_addr, 2); + assert!(*option::borrow(&router::get_target_addr(domain_name2, option::none())) == user2_addr, + 2); { // Primary name should be unset for user1 now that `target_addr` has been changed. let (primary_subdomain, primary_domain) = router::get_primary_name(user1_addr); @@ -206,15 +188,7 @@ module router::registration_tests { // == SUBDOMAIN REGISTRATION == - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_register_subdomain( router: &signer, aptos_names: &signer, @@ -225,25 +199,27 @@ module router::registration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); // Register with v1 let domain_name1 = utf8(b"test1"); let subdomain_name1 = utf8(b"sub1"); - router::register_domain(user, domain_name1, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name1, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name1, subdomain_name1, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); - assert!(router::is_name_owner(user_addr, domain_name1, option::some(subdomain_name1)), 1); + option::none(),); + assert!(router::is_name_owner(user_addr, domain_name1, option::some(subdomain_name1)), + 1); // Bump mode router::set_mode(router, 1); @@ -251,45 +227,38 @@ module router::registration_tests { // Register with v2 let domain_name2 = utf8(b"test2"); let subdomain_name2 = utf8(b"sub2"); - router::register_domain(user, domain_name2, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name2, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name2, subdomain_name2, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); - assert!(router::is_name_owner(user_addr, domain_name2, option::some(subdomain_name2)), 2); - assert!(router::get_subdomain_expiration_policy(domain_name2, subdomain_name2) == 0, 3); + option::none(),); + assert!(router::is_name_owner(user_addr, domain_name2, option::some(subdomain_name2)), + 2); + assert!(router::get_subdomain_expiration_policy(domain_name2, subdomain_name2) == + 0, 3); // Register another subdomain with a different subdomain expiration policy let subdomain_name3 = utf8(b"sub3"); - router::register_subdomain( - user, + router::register_subdomain(user, domain_name2, subdomain_name3, SECONDS_PER_YEAR, 1, false, option::none(), - option::none(), - ); - assert!(router::is_name_owner(user_addr, domain_name2, option::some(subdomain_name3)), 2); - assert!(router::get_subdomain_expiration_policy(domain_name2, subdomain_name3) == 1, 3); + option::none(),); + assert!(router::is_name_owner(user_addr, domain_name2, option::some(subdomain_name3)), + 2); + assert!(router::get_subdomain_expiration_policy(domain_name2, subdomain_name3) == + 1, 3); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 851974, location = router)] fun test_register_same_subdomain_in_v1_and_v2( router: &signer, @@ -301,23 +270,24 @@ module router::registration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); let subdomain_name = utf8(b"sub"); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); // Bump mode router::set_mode(router, 1); @@ -326,27 +296,17 @@ module router::registration_tests { router::migrate_name(user, domain_name, option::none()); // Fail to register with v2 because name is still active in v1 - router::register_subdomain( - user, + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 851974, location = router)] fun test_register_subdomain_whose_domain_is_not_in_v2( router: &signer, @@ -358,49 +318,40 @@ module router::registration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); let subdomain_name = utf8(b"sub"); // Register domain with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); // Bump mode router::set_mode(router, 1); // Fail to register with v2 because domain does not yet exist in v2 - router::register_subdomain( - user, + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_register_subdomain_with_target_addr_and_to_addr( router: &signer, aptos_names: &signer, @@ -411,7 +362,9 @@ module router::registration_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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); @@ -423,19 +376,22 @@ module router::registration_tests { // Register with v1 aptos_token::token::opt_in_direct_transfer(user2, true); - router::register_domain(user1, domain_name1, SECONDS_PER_YEAR, option::some(user2_addr), option::none()); - router::register_subdomain( - user1, + router::register_domain(user1, + domain_name1, + SECONDS_PER_YEAR, + option::some(user2_addr), + option::none()); + router::register_subdomain(user1, domain_name1, subdomain_name, SECONDS_PER_YEAR, 0, false, option::some(user2_addr), - option::some(user2_addr), - ); + option::some(user2_addr),); assert!(router::is_name_owner(user2_addr, domain_name1, subdomain_name_opt), 1); - assert!(*option::borrow(&router::get_target_addr(domain_name1, subdomain_name_opt)) == user2_addr, 2); + assert!(*option::borrow(&router::get_target_addr(domain_name1, subdomain_name_opt)) == + user2_addr, 2); { // Primary name should be unset for user1 now that `target_addr` has been changed. let (primary_subdomain, primary_domain) = router::get_primary_name(user1_addr); @@ -447,19 +403,22 @@ module router::registration_tests { router::set_mode(router, 1); // Register with v2 - router::register_domain(user1, domain_name2, SECONDS_PER_YEAR, option::some(user2_addr), option::none()); - router::register_subdomain( - user1, + router::register_domain(user1, + domain_name2, + SECONDS_PER_YEAR, + option::some(user2_addr), + option::none()); + router::register_subdomain(user1, domain_name2, subdomain_name, SECONDS_PER_YEAR, 0, false, option::some(user2_addr), - option::some(user2_addr), - ); + option::some(user2_addr),); assert!(router::is_name_owner(user2_addr, domain_name2, subdomain_name_opt), 1); - assert!(*option::borrow(&router::get_target_addr(domain_name2, subdomain_name_opt)) == user2_addr, 2); + assert!(*option::borrow(&router::get_target_addr(domain_name2, subdomain_name_opt)) == + user2_addr, 2); { // Primary name should be unset for user1 now that `target_addr` has been changed. let (primary_subdomain, primary_domain) = router::get_primary_name(user1_addr); diff --git a/router/sources/tests/renewal_domain_tests.move b/router/sources/tests/renewal_domain_tests.move index aed48bbc..e463e7d1 100644 --- a/router/sources/tests/renewal_domain_tests.move +++ b/router/sources/tests/renewal_domain_tests.move @@ -14,33 +14,23 @@ module router::renewal_domain_tests { const AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC: u64 = 1709855999; inline fun get_v1_expiration( - domain_name: String, - subdomain_name: Option + domain_name: String, subdomain_name: Option ): u64 { - let (_property_version, expiration_time_sec, _target_addr) = aptos_names::domains::get_name_record_v1_props_for_name( - subdomain_name, - domain_name, - ); + let (_property_version, expiration_time_sec, _target_addr) = + aptos_names::domains::get_name_record_v1_props_for_name(subdomain_name, + domain_name,); expiration_time_sec } inline fun get_v2_expiration( - domain_name: String, - subdomain_name: Option + domain_name: String, subdomain_name: Option ): u64 { - let expiration_time_sec = aptos_names_v2_1::v2_1_domains::get_expiration(domain_name, subdomain_name); + let expiration_time_sec = + aptos_names_v2_1::v2_1_domains::get_expiration(domain_name, subdomain_name); expiration_time_sec } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = ENOT_IMPLEMENTED_IN_MODE, location = router)] fun test_renew_domain_in_v1( router: &signer, @@ -52,22 +42,16 @@ module router::renewal_domain_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); router::renew_domain(user, domain_name, SECONDS_PER_YEAR); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_renew_domain_in_v2( router: &signer, aptos_names: &signer, @@ -78,31 +62,27 @@ module router::renewal_domain_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); // Bump mode to v2 router::set_mode(router, 1); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); assert!(router::get_expiration(domain_name, option::none()) == SECONDS_PER_YEAR, 1); // Renewals only allowed within 6 months of expiration. Move time to 100 seconds before expiry. timestamp::update_global_time_for_test_secs(SECONDS_PER_YEAR - 100); router::renew_domain(user, domain_name, SECONDS_PER_YEAR); - assert!(router::get_expiration(domain_name, option::none()) == SECONDS_PER_YEAR * 2, 2); + assert!(router::get_expiration(domain_name, option::none()) + == SECONDS_PER_YEAR * 2, 2); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_renew_v1_name_not_eligible_for_free_extension_should_trigger_auto_migration( router: &signer, aptos_names: &signer, @@ -113,14 +93,17 @@ module router::renewal_domain_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = signer::address_of(user); let domain_name = utf8(b"test"); // update global time to next year so domain is not eligibal for free 1 year extension timestamp::update_global_time_for_test_secs(AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Bump mode to v2 router::set_mode(router, 1); @@ -129,36 +112,28 @@ module router::renewal_domain_tests { aptos_names::config::set_is_enabled(aptos_names, false); // Renewals only allowed within 6 months of expiration. Move time to 100 seconds before expiry. - timestamp::update_global_time_for_test_secs(AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC + SECONDS_PER_YEAR - 100); + timestamp::update_global_time_for_test_secs(AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC + SECONDS_PER_YEAR + - 100); router::renew_domain(user, domain_name, SECONDS_PER_YEAR); // Domain should be auto migrated to v2 and renewed with 1 year { // v1 name should be burnt now, i.e. not owned by the user now - let (is_v1_owner, _) = aptos_names::domains::is_token_owner(user_addr, option::none(), domain_name); + let (is_v1_owner, _) = + aptos_names::domains::is_token_owner(user_addr, option::none(), domain_name); assert!(!is_v1_owner, 1); // v2 name should be owned by user - assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, option::none()), 2); - assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, option::none()), 3); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, + option::none()), 2); + assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, + option::none()), 3); // v2 name expiration should be 1 year after original expiration - assert!( - get_v2_expiration( - domain_name, - option::none() - ) == AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC + SECONDS_PER_YEAR * 2, - get_v2_expiration(domain_name, option::none()) - ); + assert!(get_v2_expiration(domain_name, option::none()) + == AUTO_RENEWAL_EXPIRATION_CUTOFF_SEC + SECONDS_PER_YEAR * 2, + get_v2_expiration(domain_name, option::none())); } } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 196626, location = aptos_names_v2_1::v2_1_domains)] fun test_renew_v1_name_eligible_for_free_extension_should_trigger_auto_migration_and_fail( router: &signer, @@ -170,31 +145,26 @@ module router::renewal_domain_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); // Do not update system time so domain is eligibal for free 1 year extension - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Bump mode to v2 router::set_mode(router, 1); // Renewals only allowed within 6 months of expiration. Move time to 100 seconds before expiry. - timestamp::update_global_time_for_test_secs( SECONDS_PER_YEAR - 100); + timestamp::update_global_time_for_test_secs(SECONDS_PER_YEAR - 100); // Expect to fail due to EDOMAIN_NOT_AVAILABLE_TO_RENEW during renew because migration already renew for free 1 year extension router::renew_domain(user, domain_name, SECONDS_PER_YEAR); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_renew_expired_but_still_in_grace_period_domain_in_v2( router: &signer, aptos_names: &signer, @@ -205,14 +175,17 @@ module router::renewal_domain_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); // Bump mode to v2 router::set_mode(router, 1); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); assert!(router::get_expiration(domain_name, option::none()) == SECONDS_PER_YEAR, 1); // Renewals only allowed [expiration - 6 month, expiration + grace period]. Move time to 100 seconds after expiry. @@ -220,18 +193,11 @@ module router::renewal_domain_tests { timestamp::update_global_time_for_test_secs(SECONDS_PER_YEAR + 100); router::renew_domain(user, domain_name, SECONDS_PER_YEAR); // New expiration date is 1 year after original expiration date - assert!(router::get_expiration(domain_name, option::none()) == SECONDS_PER_YEAR * 2, 2); + assert!(router::get_expiration(domain_name, option::none()) + == SECONDS_PER_YEAR * 2, 2); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 196639, location = aptos_names_v2_1::v2_1_domains)] fun test_cannot_renew_expired_past_grace_period_domain_in_v2( router: &signer, @@ -243,14 +209,17 @@ module router::renewal_domain_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let domain_name = utf8(b"test"); // Bump mode to v2 router::set_mode(router, 1); - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); assert!(router::get_expiration(domain_name, option::none()) == SECONDS_PER_YEAR, 1); // Renewals only allowed [expiration - 6 month, expiration + grace period]. Move time to 1 year after expiry. diff --git a/router/sources/tests/router_management_tests.move b/router/sources/tests/router_management_tests.move index ca8d3baa..bdbb92fa 100644 --- a/router/sources/tests/router_management_tests.move +++ b/router/sources/tests/router_management_tests.move @@ -8,15 +8,7 @@ module router::router_management_tests { const MAX_MODE: u8 = 1; - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_initialization( router: &signer, aptos_names: &signer, @@ -27,21 +19,14 @@ module router::router_management_tests { foundation: signer ) { router::init_module_for_test(router); - router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); assert!(router::get_admin_addr() == @router, 0); assert!(router::get_pending_admin_addr() == option::none(), 1); assert!(router::get_mode() == 0, 2) } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_accept_admin( router: &signer, aptos_names: &signer, @@ -52,7 +37,9 @@ module router::router_management_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); @@ -65,15 +52,7 @@ module router::router_management_tests { assert!(router::get_pending_admin_addr() == option::none(), 1); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327682, location = router)] fun test_accept_admin_only_pending_admin( router: &signer, @@ -85,7 +64,9 @@ module router::router_management_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); @@ -96,15 +77,7 @@ module router::router_management_tests { router::accept_pending_admin(router); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327680, location = router)] fun test_set_pending_admin_only_admin( router: &signer, @@ -116,21 +89,15 @@ module router::router_management_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let user = vector::borrow(&users, 0); router::set_pending_admin(user, address_of(user)); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_set_mode( router: &signer, aptos_names: &signer, @@ -141,7 +108,8 @@ module router::router_management_tests { foundation: signer ) { router::init_module_for_test(router); - router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let i = 0; while (i <= MAX_MODE) { @@ -151,15 +119,7 @@ module router::router_management_tests { } } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327680, location = router)] fun test_set_mode_admin_only( router: &signer, @@ -171,21 +131,15 @@ module router::router_management_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let user = vector::borrow(&users, 0); router::set_mode(user, 0); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 65539, location = router)] fun test_set_mode_invalid_mode( router: &signer, @@ -197,7 +151,8 @@ module router::router_management_tests { foundation: signer ) { router::init_module_for_test(router); - router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); router::set_mode(router, MAX_MODE + 1); } diff --git a/router/sources/tests/router_test_helper.move b/router/sources/tests/router_test_helper.move index 519d945d..52cfbf77 100644 --- a/router/sources/tests/router_test_helper.move +++ b/router/sources/tests/router_test_helper.move @@ -34,14 +34,20 @@ module router::router_test_helper { timestamp::set_time_has_started_for_testing(aptos); aptos_names::domains::init_module_for_test(aptos_names); aptos_names_v2_1::v2_1_domains::init_module_for_test(aptos_names_v2_1); - aptos_names::config::set_fund_destination_address_test_only(signer::address_of(foundation)); - aptos_names_v2_1::config::set_reregistration_grace_sec(aptos_names, ONE_MONTH_IN_SECONDS); - aptos_names_v2_1::v2_1_config::set_fund_destination_address_test_only(signer::address_of(foundation)); - aptos_names_v2_1::v2_1_config::set_reregistration_grace_sec(aptos_names_v2_1, ONE_MONTH_IN_SECONDS); + aptos_names::config::set_fund_destination_address_test_only(signer::address_of( + foundation)); + aptos_names_v2_1::config::set_reregistration_grace_sec(aptos_names, + ONE_MONTH_IN_SECONDS); + aptos_names_v2_1::v2_1_config::set_fund_destination_address_test_only(signer::address_of( + foundation)); + aptos_names_v2_1::v2_1_config::set_reregistration_grace_sec(aptos_names_v2_1, + ONE_MONTH_IN_SECONDS); new_accounts } - public fun setup_and_fund_accounts(aptos: &signer, foundation: &signer, users: vector): vector { + public fun setup_and_fund_accounts( + aptos: &signer, foundation: &signer, users: vector + ): vector { let (burn_cap, mint_cap) = aptos_framework::aptos_coin::initialize_for_test(aptos); let len = vector::length(&users); diff --git a/router/sources/tests/router_tests.move b/router/sources/tests/router_tests.move index 1c63665d..af6b91df 100644 --- a/router/sources/tests/router_tests.move +++ b/router/sources/tests/router_tests.move @@ -8,15 +8,7 @@ module router::router_tests { const MAX_MODE: u8 = 1; - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_initialization( router: &signer, aptos_names: &signer, @@ -27,21 +19,14 @@ module router::router_tests { foundation: signer ) { router::init_module_for_test(router); - router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); assert!(router::get_admin_addr() == @router, 0); assert!(option::is_none(&router::get_pending_admin_addr()), 1); assert!(router::get_mode() == 0, 2) } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_accept_admin( router: &signer, aptos_names: &signer, @@ -52,7 +37,9 @@ module router::router_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); @@ -65,15 +52,7 @@ module router::router_tests { assert!(option::is_none(&router::get_pending_admin_addr()), 1); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327682, location = router)] fun test_accept_admin_only_pending_admin( router: &signer, @@ -85,7 +64,9 @@ module router::router_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); @@ -96,15 +77,7 @@ module router::router_tests { router::accept_pending_admin(router); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327680, location = router)] fun test_set_pending_admin_only_admin( router: &signer, @@ -116,21 +89,15 @@ module router::router_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let user = vector::borrow(&users, 0); router::set_pending_admin(user, address_of(user)); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] fun test_set_mode( router: &signer, aptos_names: &signer, @@ -141,7 +108,8 @@ module router::router_tests { foundation: signer ) { router::init_module_for_test(router); - router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let i = 0; while (i <= MAX_MODE) { @@ -151,15 +119,7 @@ module router::router_tests { } } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 327680, location = router)] fun test_set_mode_admin_only( router: &signer, @@ -171,21 +131,15 @@ module router::router_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); let user = vector::borrow(&users, 0); router::set_mode(user, 0); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user = @0x077, - aptos = @0x1, - rando = @0x266f, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user = @0x077, aptos = @0x1, rando = @0x266f, foundation = @0xf01d)] #[expected_failure(abort_code = 65539, location = router)] fun test_set_mode_invalid_mode( router: &signer, @@ -197,7 +151,8 @@ module router::router_tests { foundation: signer ) { router::init_module_for_test(router); - router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, rando, &foundation); + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user, &aptos, + rando, &foundation); router::set_mode(router, MAX_MODE + 1); } diff --git a/router/sources/tests/subdomain_transfer_tests.move b/router/sources/tests/subdomain_transfer_tests.move index 5893bb96..13e0893c 100644 --- a/router/sources/tests/subdomain_transfer_tests.move +++ b/router/sources/tests/subdomain_transfer_tests.move @@ -11,15 +11,7 @@ module router::subdomain_transfer_tests { const MAX_MODE: u8 = 1; const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 327683, location = aptos_framework::object)] fun test_register_subdomain_with_subdomain_owner_transfer_disabled( router: &signer, @@ -31,7 +23,9 @@ module router::subdomain_transfer_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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); @@ -43,37 +37,28 @@ module router::subdomain_transfer_tests { router::set_mode(router, 1); // Register domain - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Register subdomain and disable owner transfer - router::register_subdomain( - user1, + router::register_subdomain(user1, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::some(user2_addr), - option::some(user2_addr), - ); + option::some(user2_addr),); assert!(router::is_name_owner(user2_addr, domain_name, subdomain_name_opt), 0); // Subdomain owner should not be able to transfer it now - let token_addr = aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, subdomain_name_opt); - object::transfer( - user2, - object::address_to_object(token_addr), - user1_addr, - ); + let token_addr = + aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, subdomain_name_opt); + object::transfer(user2, + object::address_to_object( + token_addr), + user1_addr,); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 327683, location = aptos_framework::object)] fun test_register_subdomain_with_subdomain_owner_transfer_enabled_and_disable_subdomain_owner_transfer( router: &signer, @@ -85,7 +70,9 @@ module router::subdomain_transfer_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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); @@ -97,39 +84,31 @@ module router::subdomain_transfer_tests { router::set_mode(router, 1); // Register domain - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Register subdomain and disable owner transfer - router::register_subdomain( - user1, + router::register_subdomain(user1, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, true, option::some(user2_addr), - option::some(user2_addr), - ); + option::some(user2_addr),); assert!(router::is_name_owner(user2_addr, domain_name, subdomain_name_opt), 0); // Disable owner transfer as domain admin - router::domain_admin_set_subdomain_transferability(user1, domain_name, subdomain_name, false); + router::domain_admin_set_subdomain_transferability(user1, domain_name, + subdomain_name, false); // Subdomain owner should not be able to transfer it now - let token_addr = aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, subdomain_name_opt); - object::transfer( - user2, - object::address_to_object(token_addr), - user1_addr, - ); + let token_addr = + aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, subdomain_name_opt); + object::transfer(user2, + object::address_to_object( + token_addr), + user1_addr,); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_register_subdomain_with_subdomain_owner_transfer_disabled_and_enable_subdomain_owner_transfer( router: &signer, aptos_names: &signer, @@ -140,7 +119,9 @@ module router::subdomain_transfer_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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); @@ -152,40 +133,32 @@ module router::subdomain_transfer_tests { router::set_mode(router, 1); // Register domain - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Register subdomain and disable owner transfer - router::register_subdomain( - user1, + router::register_subdomain(user1, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::some(user2_addr), - option::some(user2_addr), - ); + option::some(user2_addr),); assert!(router::is_name_owner(user2_addr, domain_name, subdomain_name_opt), 0); // Enable owner transfer as domain admin - router::domain_admin_set_subdomain_transferability(user1, domain_name, subdomain_name, true); + router::domain_admin_set_subdomain_transferability(user1, domain_name, + subdomain_name, true); // Subdomain owner should be able to transfer it now - let token_addr = aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, subdomain_name_opt); - object::transfer( - user2, - object::address_to_object(token_addr), - user1_addr, - ); + let token_addr = + aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, subdomain_name_opt); + object::transfer(user2, + object::address_to_object( + token_addr), + user1_addr,); assert!(router::is_name_owner(user1_addr, domain_name, subdomain_name_opt), 1); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_register_subdomain_with_subdomain_owner_transfer_disabled_and_domain_admin_can_still_transfer( router: &signer, aptos_names: &signer, @@ -196,7 +169,9 @@ module router::subdomain_transfer_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + 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); @@ -208,27 +183,24 @@ module router::subdomain_transfer_tests { router::set_mode(router, 1); // Register domain - router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); + router::register_domain(user1, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); // Register subdomain and disable owner transfer - router::register_subdomain( - user1, + router::register_subdomain(user1, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::some(user2_addr), - option::some(user2_addr), - ); + option::some(user2_addr),); assert!(router::is_name_owner(user2_addr, domain_name, subdomain_name_opt), 0); // Domain admin should still be able to transfer subdomain - router::domain_admin_transfer_subdomain( - user1, + router::domain_admin_transfer_subdomain(user1, domain_name, subdomain_name, user1_addr, - option::some(user1_addr) - ); + option::some(user1_addr)); assert!(router::is_name_owner(user1_addr, domain_name, subdomain_name_opt), 0); } } diff --git a/router/sources/tests/target_address_tests.move b/router/sources/tests/target_address_tests.move index ed77bbf7..0f393ebd 100644 --- a/router/sources/tests/target_address_tests.move +++ b/router/sources/tests/target_address_tests.move @@ -12,45 +12,37 @@ module router::target_address_tests { const SECONDS_PER_YEAR: u64 = 60 * 60 * 24 * 365; inline fun get_v1_target_addr( - domain_name: String, - subdomain_name: Option + domain_name: String, subdomain_name: Option ): Option
{ if (!aptos_names::domains::name_is_registered(subdomain_name, domain_name)) { option::none() } else { - let (_property_version, _expiration_time_sec, target_addr) = aptos_names::domains::get_name_record_v1_props_for_name( - subdomain_name, - domain_name, - ); + let (_property_version, _expiration_time_sec, target_addr) = + aptos_names::domains::get_name_record_v1_props_for_name(subdomain_name, + domain_name,); target_addr } } /// Returns true if the name is tracked in v2 - inline fun exists_in_v2(domain_name: String, subdomain_name: Option): bool { - object::is_object(aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, subdomain_name)) + inline fun exists_in_v2( + domain_name: String, subdomain_name: Option + ): bool { + object::is_object(aptos_names_v2_1::v2_1_domains::get_token_addr(domain_name, + subdomain_name)) } inline fun get_v2_target_addr( - domain_name: String, - subdomain_name: Option + domain_name: String, subdomain_name: Option ): Option
{ if (!exists_in_v2(domain_name, subdomain_name)) { option::none() - }else { + } else { aptos_names_v2_1::v2_1_domains::get_target_address(domain_name, subdomain_name) } } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[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_set_target_address( router: &signer, aptos_names: &signer, @@ -61,7 +53,9 @@ module router::target_address_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user2 = vector::borrow(&users, 1); let user_addr = address_of(user); @@ -71,17 +65,16 @@ module router::target_address_tests { let subdomain_name_opt = option::some(subdomain_name); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); // Domain target address should be default to user_addr { @@ -166,15 +159,7 @@ module router::target_address_tests { assert!(option::is_none(&aptos_names::domains::get_reverse_lookup(user_addr)), 7); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 65545, location = router::router)] fun test_set_target_address_should_trigger_auto_migration( router: &signer, @@ -186,7 +171,9 @@ module router::target_address_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let user2 = vector::borrow(&users, 1); @@ -196,17 +183,16 @@ module router::target_address_tests { let subdomain_name_opt = option::some(subdomain_name); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); // Bump mode router::set_mode(router, 1); @@ -214,8 +200,10 @@ module router::target_address_tests { // Set domain target address to user2_addr, this should trigger auto migration router::set_target_addr(user, domain_name, option::none(), user2_addr); { - assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, option::none()), 1); - assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, option::none()), 1); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, + option::none()), 1); + assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, + option::none()), 1); let v1_target_address = get_v1_target_addr(domain_name, option::none()); assert!(option::is_none(&v1_target_address), 2); let v2_target_address = get_v2_target_addr(domain_name, option::none()); @@ -227,15 +215,7 @@ module router::target_address_tests { router::set_target_addr(user, domain_name, subdomain_name_opt, user2_addr); } - #[test( - router = @router, - aptos_names = @aptos_names, - aptos_names_v2_1 = @aptos_names_v2_1, - user1 = @0x077, - user2 = @0x266f, - aptos = @0x1, - foundation = @0xf01d - )] + #[test(router = @router, aptos_names = @aptos_names, aptos_names_v2_1 = @aptos_names_v2_1, user1 = @0x077, user2 = @0x266f, aptos = @0x1, foundation = @0xf01d)] #[expected_failure(abort_code = 65545, location = router::router)] fun test_clear_target_address_should_trigger_auto_migration( router: &signer, @@ -247,7 +227,9 @@ module router::target_address_tests { foundation: signer ) { router::init_module_for_test(router); - let users = router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, user2, &foundation); + let users = + router_test_helper::e2e_test_setup(aptos_names, aptos_names_v2_1, user1, &aptos, + user2, &foundation); let user = vector::borrow(&users, 0); let user_addr = address_of(user); let domain_name = utf8(b"test"); @@ -255,17 +237,16 @@ module router::target_address_tests { let subdomain_name_opt = option::some(subdomain_name); // Register with v1 - router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), option::none()); - router::register_subdomain( - user, + router::register_domain(user, domain_name, SECONDS_PER_YEAR, option::none(), + option::none()); + router::register_subdomain(user, domain_name, subdomain_name, SECONDS_PER_YEAR, 0, false, option::none(), - option::none(), - ); + option::none(),); // Bump mode router::set_mode(router, 1); @@ -273,8 +254,10 @@ module router::target_address_tests { // Clear domain target address, this should trigger auto migration router::clear_target_addr(user, domain_name, option::none()); { - assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, option::none()), 1); - assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, option::none()), 1); + assert!(aptos_names_v2_1::v2_1_domains::is_token_owner(user_addr, domain_name, + option::none()), 1); + assert!(!aptos_names_v2_1::v2_1_domains::is_name_expired(domain_name, + option::none()), 1); let v1_target_address = get_v1_target_addr(domain_name, option::none()); assert!(option::is_none(&v1_target_address), 1); let v2_target_address = get_v2_target_addr(domain_name, option::none()); diff --git a/transfer/sources/script.move b/transfer/sources/script.move index 9367fbdb..e0ae7fa6 100644 --- a/transfer/sources/script.move +++ b/transfer/sources/script.move @@ -2,14 +2,8 @@ script { use aptos_names::token_helper; fun main(offerer: &signer) { - let names = vector [ - b"name0", - b"name1", - ]; - let recipients = vector [ - @0x1, - @0x2, - ]; + let names = vector[b"name0", b"name1",]; + let recipients = vector[@0x1, @0x2,]; assert!(std::vector::length(&names) == std::vector::length(&recipients), 1); @@ -17,13 +11,11 @@ script { let name = std::vector::pop_back(&mut names); let recipient = std::vector::pop_back(&mut recipients); - let token_data_id = token_helper::build_tokendata_id( - token_helper::get_token_signer_address(), - std::option::none(), - std::string::utf8(name), - ); + let token_data_id = + token_helper::build_tokendata_id(token_helper::get_token_signer_address(), + std::option::none(), std::string::utf8(name),); let token_id = token_helper::latest_token_id(&token_data_id); - aptos_token::token::transfer(offerer, token_id, recipient, 1); + aptos_token::token::transfer(offerer, token_id, recipient, 1); } } }