Skip to content

Commit

Permalink
[ans] adding bulk_force_renew
Browse files Browse the repository at this point in the history
  • Loading branch information
angieyth committed Oct 3, 2023
1 parent 84d0167 commit 8e4b564
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
31 changes: 29 additions & 2 deletions bulk/sources/bulk.move
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module bulk::bulk {
use aptos_framework::timestamp;
use aptos_names_v2_1::v2_1_domains;
use router::router;
use std::error;
use std::option;
use std::option::Option;
use std::option;
use std::string::String;
use std::vector;
use router::router;

/// For bulk migrate endpoint, domain names vector must have same length as subdomain names vector
const EDOMAIN_AND_SUBDOMAIN_MUST_HAVE_SAME_LENGTH: u64 = 1;
Expand Down Expand Up @@ -78,4 +80,29 @@ module bulk::bulk {
bulk_migrate_domain(user, migrate_domain_names);
bulk_renew_domain(user, renew_domain_names, renewal_duration_secs);
}


// === Force Renewal ===
/// Domains only
public entry fun bulk_force_renew_domain(
v2_1_admin: &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)
);

let idx = 0;
while (idx < vector::length(&domain_names)) {
let domain_name = *vector::borrow(&domain_names, idx);
let renewal_duration_sec = *vector::borrow(&renewal_duration_secs, idx);
let new_expiration = timestamp::now_seconds() + renewal_duration_sec;

v2_1_domains::force_set_name_expiration(v2_1_admin, domain_name, option::none(), new_expiration);
idx = idx + 1
}
}

}
39 changes: 38 additions & 1 deletion bulk/sources/bulk_tests.move
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[test_only]
module bulk::bulk_tests {
use aptos_framework::timestamp;
use bulk::bulk::{bulk_renew_domain, bulk_migrate_domain, bulk_migrate_subdomain};
use bulk::bulk::{bulk_renew_domain, bulk_migrate_domain, bulk_migrate_subdomain, bulk_force_renew_domain};
use router::router;
use router::router_test_helper;
use std::option;
Expand Down Expand Up @@ -171,4 +171,41 @@ module bulk::bulk_tests {
let expiration = router::get_expiration(domain_name, option::none());
assert!(expiration == SECONDS_PER_YEAR * 2, 1);
}

#[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_force_renew_happy_path(
router: &signer,
aptos_names: &signer,
aptos_names_v2_1: &signer,
user1: signer,
user2: signer,
aptos: signer,
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 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());

// renew domain for 10 years. not in the renewal window. exceed the max expiration
bulk_force_renew_domain(aptos_names_v2_1, vector [ domain_name ], vector [ SECONDS_PER_YEAR * 10]);

// Verify names new expiration
let expiration = router::get_expiration(domain_name, option::none());
assert!(expiration == SECONDS_PER_YEAR * 10, 1);
}
}
24 changes: 12 additions & 12 deletions sh_scripts/move_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ APTOS_NAMES_V2_1="0x867ed1f6bf916171b1de3ee92849b8978b7d1b9e0a8cc982a3d19d535dfd
ADMIN="0x91945b4672607a327019e768dd6045d1254d1102d882df434ca734250bb3581d"
FUNDS="0x78ee3915e67ef5d19fa91d1e05e60ae08751efd12ce58e23fc1109de87ea7865"
ROUTER="0x867ed1f6bf916171b1de3ee92849b8978b7d1b9e0a8cc982a3d19d535dfd9c0c"
ROUTER_SIGNER=0x$(./aptos account derive-resource-account-address \
ROUTER_SIGNER=0x$(aptos account derive-resource-account-address \
--address $ROUTER \
--seed "ANS ROUTER" \
--seed-encoding utf8 | \
grep "Result" | \
sed -n 's/.*"Result": "\([^"]*\)".*/\1/p')
BULK="0x53febacc40e549ced4132bf3c3313076c3a81c631c8deda28cad871e34f6de0b"

./aptos move test \
--package-dir core \
--named-addresses aptos_names=$APTOS_NAMES,aptos_names_admin=$ADMIN,aptos_names_funds=$FUNDS,router_signer=$ROUTER_SIGNER
./aptos move test \
--package-dir core_v2 \
--named-addresses aptos_names=$APTOS_NAMES,aptos_names_v2_1=$APTOS_NAMES_V2_1,aptos_names_admin=$ADMIN,aptos_names_funds=$FUNDS,router=$ROUTER,router_signer=$ROUTER_SIGNER
./aptos move test \
--package-dir router \
--named-addresses aptos_names=$APTOS_NAMES,aptos_names_v2_1=$APTOS_NAMES_V2_1,aptos_names_admin=$ADMIN,aptos_names_funds=$FUNDS,router=$ROUTER,router_signer=$ROUTER_SIGNER
./aptos move test \
--package-dir bulk \
aptos move test \
--package-dir core \
--named-addresses aptos_names=$APTOS_NAMES,aptos_names_admin=$ADMIN,aptos_names_funds=$FUNDS,router_signer=$ROUTER_SIGNER
aptos move test \
--package-dir core_v2 \
--named-addresses aptos_names=$APTOS_NAMES,aptos_names_v2_1=$APTOS_NAMES_V2_1,aptos_names_admin=$ADMIN,aptos_names_funds=$FUNDS,router=$ROUTER,router_signer=$ROUTER_SIGNER
aptos move test \
--package-dir router \
--named-addresses aptos_names=$APTOS_NAMES,aptos_names_v2_1=$APTOS_NAMES_V2_1,aptos_names_admin=$ADMIN,aptos_names_funds=$FUNDS,router=$ROUTER,router_signer=$ROUTER_SIGNER
aptos move test \
--package-dir bulk \
--named-addresses aptos_names=$APTOS_NAMES,aptos_names_v2_1=$APTOS_NAMES_V2_1,aptos_names_admin=$ADMIN,aptos_names_funds=$FUNDS,router=$ROUTER,router_signer=$ROUTER_SIGNER,bulk=$BULK

0 comments on commit 8e4b564

Please sign in to comment.