Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
GotenJBZ committed Jun 7, 2024
1 parent a5b7c3b commit 3dab86a
Show file tree
Hide file tree
Showing 40 changed files with 4,199 additions and 3,690 deletions.
31 changes: 11 additions & 20 deletions bulk/sources/bulk.move
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module bulk::bulk {

/// Domains only
public entry fun bulk_migrate_domain(
user: &signer,
domain_names: vector<String>
user: &signer, domain_names: vector<String>
) {
let idx = 0;
while (idx < vector::length(&domain_names)) {
Expand All @@ -28,14 +27,11 @@ module bulk::bulk {

/// Subdomains only
public entry fun bulk_migrate_subdomain(
user: &signer,
domain_names: vector<String>,
subdomain_names: vector<Option<String>>,
user: &signer, domain_names: vector<String>, subdomain_names: vector<Option<String>>,
) {
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);
Expand All @@ -49,14 +45,11 @@ module bulk::bulk {

/// Domains only
public entry fun bulk_renew_domain(
user: &signer,
domain_names: vector<String>,
renewal_duration_secs: vector<u64>,
user: &signer, domain_names: vector<String>, renewal_duration_secs: vector<u64>,
) {
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);
Expand Down Expand Up @@ -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
}
}
Expand Down
136 changes: 51 additions & 85 deletions bulk/sources/bulk_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
Expand All @@ -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,
Expand All @@ -152,20 +115,23 @@ 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");

// Bump mode
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());
Expand Down
34 changes: 4 additions & 30 deletions bulk_clear/sources/script.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<string::String>(), name);
aptos_names::domains::force_clear_registration(admin,
option::none<string::String>(), name);
}
}
}
11 changes: 3 additions & 8 deletions bulk_force_renewal/sources/script.move
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
}
}
}
5 changes: 1 addition & 4 deletions bulk_migrate/sources/script.move
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 3dab86a

Please sign in to comment.