From 607388f3779ae8168c13d02c4b070a1d6143c8d6 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Thu, 28 Mar 2024 16:27:47 -0400 Subject: [PATCH 01/38] reference update --- packages/coupons/sources/coupons.move | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index 976617cd..4f0650d9 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -101,7 +101,7 @@ module coupons::coupons { ): SuinsRegistration { assert_version_is_valid(self); // Validate that specified coupon is valid. - assert!(table::contains(&mut self.data.coupons, coupon_code), ECouponNotExists); + assert!(table::contains(&self.data.coupons, coupon_code), ECouponNotExists); // Verify coupon house is authorized to buy names. suins::assert_app_is_authorized(suins); @@ -155,7 +155,7 @@ module coupons::coupons { // Nor does it calculate the original price. This is part of the Frontend anyways. public fun calculate_sale_price(self: &mut CouponHouse, price: u64, coupon_code: String): u64 { // Validate that specified coupon is valid. - assert!(table::contains(&mut self.data.coupons, coupon_code), ECouponNotExists); + assert!(table::contains(&self.data.coupons, coupon_code), ECouponNotExists); // Borrow coupon from the table. let coupon = table::borrow_mut(&mut self.data.coupons, coupon_code); internal_calculate_sale_price(price, coupon) @@ -262,7 +262,7 @@ module coupons::coupons { code: String, coupon: Coupon ) { - assert!(!table::contains(&mut self.coupons, code), ECouponAlreadyExists); + assert!(!table::contains(&self.coupons, code), ECouponAlreadyExists); table::add(&mut self.coupons, code, coupon); } From fda792cd4e57df60f39330c92f0ca19311c1e10a Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Thu, 28 Mar 2024 16:41:27 -0400 Subject: [PATCH 02/38] test changes --- packages/coupons/sources/coupons.move | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index 4f0650d9..b1c5006e 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -41,12 +41,7 @@ module coupons::coupons { /// Our versioning of the coupons package. const VERSION: u8 = 1; - // use suins::config; - use suins::domain; - use suins::suins::{Self, AdminCap, SuiNS}; // re-use AdminCap for creating new coupons. - use suins::suins_registration::SuinsRegistration; - use suins::config::{Self, Config}; - use suins::registry::{Self, Registry}; + use suins::{domain, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, config::{Self, Config}, registry::{Self, Registry}}; // Authorization for the Coupons on SuiNS, to be able to register names on the app. public struct CouponsApp has drop {} @@ -99,7 +94,7 @@ module coupons::coupons { clock: &Clock, ctx: &mut TxContext ): SuinsRegistration { - assert_version_is_valid(self); + self.assert_version_is_valid(); // Validate that specified coupon is valid. assert!(table::contains(&self.data.coupons, coupon_code), ECouponNotExists); @@ -111,12 +106,12 @@ module coupons::coupons { let config = suins::get_config(suins); let domain = domain::new(domain_name); - let label = domain::sld(&domain); + let label = domain.sld(); - let domain_length = (string::length(label) as u8); + let domain_length = (label.length() as u8); // Borrow coupon from the table. - let coupon = table::borrow_mut(&mut self.data.coupons, coupon_code); + let coupon = self.data.coupons.borrow_mut(coupon_code); // We need to do a total of 5 checks, based on `CouponRules` // Our checks work with `AND`, all of the conditions must pass for a coupon to be used. From f633d8e32cde94d0526b91782639c0ae194a0cdf Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Thu, 28 Mar 2024 16:51:29 -0400 Subject: [PATCH 03/38] test function --- packages/coupons/sources/coupons.move | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index b1c5006e..d8f88b17 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -9,7 +9,7 @@ /// Each coupon is validated towards a list of rules. View `rules` module for explanation. /// The app is authorized on `SuiNS` to be able to claim names and add earnings to the registry. module coupons::coupons { - use std::string::{Self, String}; + use std::string::String; use sui::table::{Self, Table}; use sui::tx_context::{TxContext, sender}; @@ -22,6 +22,7 @@ module coupons::coupons { use coupons::rules::{Self, CouponRules}; use coupons::constants; + use suins::{domain, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, config::Self, registry::{Self, Registry}}; /// Coupon already exists const ECouponAlreadyExists: u64 = 0; @@ -41,7 +42,6 @@ module coupons::coupons { /// Our versioning of the coupons package. const VERSION: u8 = 1; - use suins::{domain, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, config::{Self, Config}, registry::{Self, Registry}}; // Authorization for the Coupons on SuiNS, to be able to register names on the app. public struct CouponsApp has drop {} @@ -96,7 +96,7 @@ module coupons::coupons { ): SuinsRegistration { self.assert_version_is_valid(); // Validate that specified coupon is valid. - assert!(table::contains(&self.data.coupons, coupon_code), ECouponNotExists); + assert!(self.data.coupons.contains(coupon_code), ECouponNotExists); // Verify coupon house is authorized to buy names. suins::assert_app_is_authorized(suins); @@ -104,8 +104,8 @@ module coupons::coupons { // Validate registration years are in [0,5] range. assert!(no_years > 0 && no_years <= 5, EInvalidYearsArgument); - let config = suins::get_config(suins); - let domain = domain::new(domain_name); + let config = suins.get_config(); + let domain = domain::new(domain_name); //update? let label = domain.sld(); let domain_length = (label.length() as u8); @@ -136,7 +136,7 @@ module coupons::coupons { suins::app_add_balance(CouponsApp {}, suins, coin::into_balance(payment)); // Clean up our registry by removing the coupon if no more available claims! - if(!rules::has_available_claims(&coupon.rules)){ + if(!coupon.rules.has_available_claims()){ // remove the coupon, since it's no longer usable. internal_remove_coupon(&mut self.data, coupon_code); }; From f4bfa2776ba0033492b1a7933581c89d9fdcbc69 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Thu, 28 Mar 2024 16:54:41 -0400 Subject: [PATCH 04/38] update --- packages/coupons/sources/coupons.move | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index d8f88b17..0ed2c106 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -152,7 +152,7 @@ module coupons::coupons { // Validate that specified coupon is valid. assert!(table::contains(&self.data.coupons, coupon_code), ECouponNotExists); // Borrow coupon from the table. - let coupon = table::borrow_mut(&mut self.data.coupons, coupon_code); + let coupon = self.data.coupons.borrow_mut(coupon_code); internal_calculate_sale_price(price, coupon) } @@ -258,7 +258,7 @@ module coupons::coupons { coupon: Coupon ) { assert!(!table::contains(&self.coupons, code), ECouponAlreadyExists); - table::add(&mut self.coupons, code, coupon); + self.coupons.add(code, coupon); } /// An internal function to create a coupon object. @@ -277,7 +277,7 @@ module coupons::coupons { // A function to remove a coupon from the system. fun internal_remove_coupon(self: &mut Data, code: String) { - table::remove(&mut self.coupons, code); + self.coupons.remove(code); } // test only functions. From 8b97910b6b0cdece95b10e60bc9bb876762cabb0 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Thu, 28 Mar 2024 16:57:15 -0400 Subject: [PATCH 05/38] coupons.move finished --- packages/coupons/sources/coupons.move | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index 0ed2c106..8c8fe5b1 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -150,7 +150,7 @@ module coupons::coupons { // Nor does it calculate the original price. This is part of the Frontend anyways. public fun calculate_sale_price(self: &mut CouponHouse, price: u64, coupon_code: String): u64 { // Validate that specified coupon is valid. - assert!(table::contains(&self.data.coupons, coupon_code), ECouponNotExists); + assert!(self.data.coupons.contains(coupon_code), ECouponNotExists); // Borrow coupon from the table. let coupon = self.data.coupons.borrow_mut(coupon_code); internal_calculate_sale_price(price, coupon) From 46610e2711a8b9ba5c3bea171acf33fa945895f4 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Thu, 28 Mar 2024 17:07:40 -0400 Subject: [PATCH 06/38] coupons migrated --- packages/coupons/sources/range.move | 6 ++-- packages/coupons/sources/rules.move | 44 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/packages/coupons/sources/range.move b/packages/coupons/sources/range.move index 4643fc86..508f5a75 100644 --- a/packages/coupons/sources/range.move +++ b/packages/coupons/sources/range.move @@ -4,8 +4,6 @@ /// A module to introduce `range` checks for the rules. module coupons::range { - use std::vector; - /// Invalid [from, to] setup in the range! /// `to` parameter has to be >= `from` const EInvalidRange: u64 = 0; @@ -31,12 +29,12 @@ module coupons::range { /// Get floor limit for the range. public fun from(range: &Range): u8 { - *vector::borrow(&range.vec, 0) + *range.vec.borrow(0) } /// Get upper limit for the range. public fun to(range: &Range): u8 { - *vector::borrow(&range.vec, 1) + *range.vec.borrow(1) } } diff --git a/packages/coupons/sources/rules.move b/packages/coupons/sources/rules.move index 59504e23..b243e481 100644 --- a/packages/coupons/sources/rules.move +++ b/packages/coupons/sources/rules.move @@ -5,13 +5,11 @@ // validation of names etc. module coupons::rules { - use std::vector; use std::option::{Self, Option}; - use sui::clock::{Self, Clock}; + use sui::clock::Clock; - use coupons::constants; - use coupons::range::{Self, Range}; + use coupons::{constants, range::Range}; use suins::constants::{Self as suins_constants}; // Errors @@ -64,7 +62,7 @@ module coupons::rules { ): CouponRules { assert!(is_valid_years_range(&years), EInvalidYears); assert!(is_valid_length_range(&length), EInvalidLengthRule); - assert!(option::is_none(&available_claims) || (*option::borrow(&available_claims) > 0), EInvalidAvailableClaims); + assert!(available_claims.is_none() || (*available_claims.borrow() > 0), EInvalidAvailableClaims); CouponRules { length, available_claims, user, expiration, years } @@ -90,8 +88,8 @@ module coupons::rules { if(option::is_some(&rules.available_claims)){ assert!(has_available_claims(rules), ENoMoreAvailableClaims); // Decrease available claims by 1. - let available_claims = *option::borrow(&rules.available_claims); - option::swap(&mut rules.available_claims, available_claims - 1); + let available_claims = *rules.available_claims.borrow(); + rules.available_claims.swap(available_claims - 1); } } @@ -99,7 +97,7 @@ module coupons::rules { // Returns true if the rule is not set OR it has used all the available claims. public fun has_available_claims(rules: &CouponRules): bool { if(option::is_none(&rules.available_claims)) return true; - *option::borrow(&rules.available_claims) > 0 + *rules.available_claims.borrow() > 0 } // Assertion helper for the validity of years. @@ -113,13 +111,13 @@ module coupons::rules { // 1. Exact years (e.g. 2 years, by passing [2,2]) // 2. Range of years (e.g. [1,3]) public fun is_coupon_valid_for_domain_years(rules: &CouponRules, target: u8): bool { - if(option::is_none(&rules.years)) return true; + if(rules.years.is_none()) return true; - range::is_in_range(option::borrow(&rules.years), target) + rules.years.borrow().is_in_range(target) } public fun assert_is_valid_discount_type(`type`: u8) { - assert!(vector::contains(&constants::discount_rule_types(), &`type`), EInvalidType); + assert!(constants::discount_rule_types().contains(&`type`), EInvalidType); } // verify that we are creating the coupons correctly (based on amount & type). @@ -139,9 +137,9 @@ module coupons::rules { /// We check the length of the name based on the domain length rule public fun is_coupon_valid_for_domain_size(rules: &CouponRules, length: u8): bool { // If the vec is not set, we pass this rule test. - if(option::is_none(&rules.length)) return true; + if(rules.length.is_none()) return true; - range::is_in_range(option::borrow(&rules.length), length) + rules.length.borrow().is_in_range(length) } @@ -152,8 +150,8 @@ module coupons::rules { } /// Check that the domain is valid for the specified address public fun is_coupon_valid_for_address(rules: &CouponRules, user: address): bool { - if(option::is_none(&rules.user)) return true; - *option::borrow(&rules.user) == user + if(rules.user.is_none()) return true; + rules.user.borrow() == user } /// Simple assertion for the coupon expiration. @@ -164,23 +162,23 @@ module coupons::rules { /// Check whether a coupon has expired public fun is_coupon_expired(rules: &CouponRules, clock: &Clock): bool { - if(option::is_none(&rules.expiration)){ + if(rules.expiration.is_none()){ return false }; - clock::timestamp_ms(clock) > *option::borrow(&rules.expiration) + clock.timestamp_ms() > *rules.expiration.borrow() } fun is_valid_years_range(range: &Option): bool { - if(option::is_none(range)) return true; - let range = option::borrow(range); - range::from(range) >= 1 && range::to(range) <= 5 + if(range.is_none()) return true; + let range = range.borrow(); + range.from() >= 1 && range.to() <= 5 } fun is_valid_length_range(range: &Option): bool { - if(option::is_none(range)) return true; - let range = option::borrow(range); - range::from(range) >= suins_constants::min_domain_length() && range::to(range) <= suins_constants::max_domain_length() + if(range.is_none()) return true; + let range = range.borrow(); + range.from() >= suins_constants::min_domain_length() && range.to() <= suins_constants::max_domain_length() } } From 5ba98a6d082cd7cb3b01e1d063492e83434c35d5 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Thu, 28 Mar 2024 17:09:12 -0400 Subject: [PATCH 07/38] remove comments --- packages/coupons/sources/coupons.move | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index 8c8fe5b1..80cb2ef0 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -105,7 +105,7 @@ module coupons::coupons { assert!(no_years > 0 && no_years <= 5, EInvalidYearsArgument); let config = suins.get_config(); - let domain = domain::new(domain_name); //update? + let domain = domain::new(domain_name); let label = domain.sld(); let domain_length = (label.length() as u8); From 4554736b5ed779d17f148beefd2752402050f9f5 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Thu, 28 Mar 2024 17:12:09 -0400 Subject: [PATCH 08/38] update small syntax --- packages/coupons/sources/coupons.move | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index 80cb2ef0..da3e8cab 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -257,7 +257,7 @@ module coupons::coupons { code: String, coupon: Coupon ) { - assert!(!table::contains(&self.coupons, code), ECouponAlreadyExists); + assert!(!self.coupons.contains(code), ECouponAlreadyExists); self.coupons.add(code, coupon); } From 3b7d82d0d7f7c9868f8499e62b495b2c0f4b85c7 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 10:03:37 -0400 Subject: [PATCH 09/38] debug and update test --- .../coupons/tests/authorization_tests.move | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/packages/coupons/tests/authorization_tests.move b/packages/coupons/tests/authorization_tests.move index 631e5ac7..2057274d 100644 --- a/packages/coupons/tests/authorization_tests.move +++ b/packages/coupons/tests/authorization_tests.move @@ -5,61 +5,58 @@ #[test_only] module coupons::app_authorization_tests { - // use std::string::{utf8, String}; - use sui::test_scenario::{Self}; + use sui::test_scenario::{return_shared, return_to_sender, end}; - use coupons::coupons::{Self, CouponHouse}; - use suins::suins::{AdminCap}; - use coupons::setup::{Self, UnauthorizedTestApp, TestApp, admin, user}; + use coupons::{coupons::{app_data_mut, deauthorize_app}, setup::{Self, UnauthorizedTestApp, TestApp, admin, user, test_init, unauthorized_test_app}}; #[test] fun admin_get_app_success() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; // auth style as authorized app { - test_scenario::next_tx(scenario, user()); - let mut coupon_house = test_scenario::take_shared(scenario); - coupons::app_data_mut(setup::test_app(), &mut coupon_house); - test_scenario::return_shared(coupon_house); + scenario.next_tx(user()); + let mut coupon_house = scenario.take_shared(); + app_data_mut(setup::test_app(), &mut coupon_house); + return_shared(coupon_house); }; - test_scenario::end(scenario_val); + end(scenario_val); } #[test] fun authorized_app_get_app_success(){ - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; { - test_scenario::next_tx(scenario, admin()); + scenario.next_tx(admin()); - let mut coupon_house = test_scenario::take_shared(scenario); - let admin_cap = test_scenario::take_from_sender(scenario); + let mut coupon_house = scenario.take_shared(); + let admin_cap = scenario.take_from_sender(); // test app deauthorization. - coupons::deauthorize_app(&admin_cap, &mut coupon_house); + deauthorize_app(&admin_cap, &mut coupon_house); // test that the app is indeed non authorized - assert!(!coupons::is_app_authorized(&coupon_house), 0); + assert!(!coupon_house.is_app_authorized(), 0); - test_scenario::return_to_sender(scenario, admin_cap); - test_scenario::return_shared(coupon_house); + return_to_sender(scenario, admin_cap); + return_shared(coupon_house); }; - test_scenario::end(scenario_val); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::coupons::EAppNotAuthorized)] fun unauthorized_app_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; { - test_scenario::next_tx(scenario, user()); - let mut coupon_house = test_scenario::take_shared(scenario); - coupons::app_data_mut(setup::unauthorized_test_app(), &mut coupon_house); - test_scenario::return_shared(coupon_house); + scenario.next_tx(user()); + let mut coupon_house = scenario.take_shared(); + app_data_mut(unauthorized_test_app(), &mut coupon_house); + return_shared(coupon_house); }; - test_scenario::end(scenario_val); + end(scenario_val); } } From 9213d956cf089487043daf302c71a50ed808809d Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 10:38:22 -0400 Subject: [PATCH 10/38] coupon tests --- packages/coupons/tests/coupons_tests.move | 134 +++++++++++----------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/packages/coupons/tests/coupons_tests.move b/packages/coupons/tests/coupons_tests.move index 3204a791..13622ea2 100644 --- a/packages/coupons/tests/coupons_tests.move +++ b/packages/coupons/tests/coupons_tests.move @@ -6,10 +6,10 @@ module coupons::coupon_tests { use std::option; use std::string::{utf8}; - use sui::test_scenario::{Self, Scenario, ctx}; + use sui::test_scenario::{Self, Scenario, ctx, return_shared, end}; // test dependencies. - use coupons::setup::{Self, TestApp, user, user_two, mist_per_sui}; + use coupons::setup::{Self, TestApp, user, user_two, mist_per_sui, test_app, admin_add_coupon, register_with_coupon, test_init}; use coupons::coupons::{Self, CouponHouse}; use coupons::constants::{Self}; use coupons::rules; @@ -18,54 +18,54 @@ module coupons::coupon_tests { // populate a lot of coupons with different cases. // This populates the coupon as an authorized app fun populate_coupons(scenario: &mut Scenario) { - test_scenario::next_tx(scenario, user()); - let mut coupon_house = test_scenario::take_shared(scenario); + scenario.next_tx(user()); + let mut coupon_house = scenario.take_shared(); - let data_mut = coupons::app_data_mut(setup::test_app(), &mut coupon_house); + let data_mut = coupons::app_data_mut(test_app(), &mut coupon_house); setup::populate_coupons(data_mut, ctx(scenario)); - test_scenario::return_shared(coupon_house); + return_shared(coupon_house); } // Please look up at `setup` file to see all the coupon names and their respective logic. // Tests the e2e experience for coupons (a list of different coupons with different rules) #[test] fun test_e2e() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; // populate all coupons. populate_coupons(scenario); // 5 SUI discount coupon. - setup::register_with_coupon(utf8(b"5_SUI_DISCOUNT"), utf8(b"test.sui"), 1, 195 * mist_per_sui(), 0, user(), scenario); + register_with_coupon(utf8(b"5_SUI_DISCOUNT"), utf8(b"test.sui"), 1, 195 * mist_per_sui(), 0, user(), scenario); // original price would be 400 (200*2 years). 25% discount should bring it down to 300. - setup::register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_MAX_2_YEARS"), utf8(b"jest.sui"), 2, 300 * mist_per_sui(), 0, user(), scenario); + register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_MAX_2_YEARS"), utf8(b"jest.sui"), 2, 300 * mist_per_sui(), 0, user(), scenario); // Test that this user-specific coupon works as expected - setup::register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"fest.sui"), 2, 300 * mist_per_sui(), 0, user(), scenario); + register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"fest.sui"), 2, 300 * mist_per_sui(), 0, user(), scenario); // 50% discount only on names 5+ digits - setup::register_with_coupon(utf8(b"50_PERCENT_5_PLUS_NAMES"), utf8(b"testo.sui"), 1, 25 * mist_per_sui(), 0, user(), scenario); + register_with_coupon(utf8(b"50_PERCENT_5_PLUS_NAMES"), utf8(b"testo.sui"), 1, 25 * mist_per_sui(), 0, user(), scenario); // 50% discount only on names 3 digit names. - setup::register_with_coupon(utf8(b"50_PERCENT_3_DIGITS"), utf8(b"tes.sui"), 1, 600 * mist_per_sui(), 0, user(), scenario); + register_with_coupon(utf8(b"50_PERCENT_3_DIGITS"), utf8(b"tes.sui"), 1, 600 * mist_per_sui(), 0, user(), scenario); // 50% DISCOUNT, with all possible rules involved. - setup::register_with_coupon(utf8(b"50_DISCOUNT_SALAD"), utf8(b"teso.sui"), 1, 100 * mist_per_sui(), 0, user(), scenario); + register_with_coupon(utf8(b"50_DISCOUNT_SALAD"), utf8(b"teso.sui"), 1, 100 * mist_per_sui(), 0, user(), scenario); - test_scenario::end(scenario_val); + end(scenario_val); } #[test] fun zero_fee_purchase(){ - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; // populate all coupons. populate_coupons(scenario); // 5 SUI discount coupon. - setup::admin_add_coupon(utf8(b"100_SUI_OFF"), constants::fixed_price_discount_type(), 100 * mist_per_sui(), scenario); + admin_add_coupon(utf8(b"100_SUI_OFF"), constants::fixed_price_discount_type(), 100 * mist_per_sui(), scenario); // Buy a name for free using the 100 SUI OFF coupon! - setup::register_with_coupon(utf8(b"100_SUI_OFF"), utf8(b"testo.sui"), 1, 0 * mist_per_sui(), 0, user(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"100_SUI_OFF"), utf8(b"testo.sui"), 1, 0 * mist_per_sui(), 0, user(), scenario); + end(scenario_val); } #[test] fun specific_max_years(){ @@ -100,7 +100,7 @@ module coupons::coupon_tests { #[test] fun test_price_calculation(){ - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); { @@ -111,146 +111,146 @@ module coupons::coupon_tests { assert!(sale_price == 50, 1); test_scenario::return_shared(coupon_house); }; - test_scenario::end(scenario_val); + end(scenario_val); } // Tests the e2e experience for coupons (a list of different coupons with different rules) #[test, expected_failure(abort_code=::coupons::coupons::EIncorrectAmount)] fun test_invalid_coin_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; // populate all coupons. populate_coupons(scenario); // 5 SUI discount coupon. - setup::register_with_coupon(utf8(b"5_SUI_DISCOUNT"), utf8(b"test.sui"), 1, 200 * mist_per_sui(), 0, user(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"5_SUI_DISCOUNT"), utf8(b"test.sui"), 1, 200 * mist_per_sui(), 0, user(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::coupons::ECouponNotExists)] fun no_more_available_claims_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"test.sui"), 1, 150 * mist_per_sui(), 0, user(), scenario); - setup::register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"tost.sui"), 1, 150 * mist_per_sui(), 0, user(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"test.sui"), 1, 150 * mist_per_sui(), 0, user(), scenario); + register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"tost.sui"), 1, 150 * mist_per_sui(), 0, user(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::coupons::EInvalidYearsArgument)] fun invalid_years_claim_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"test.sui"), 6, 150 * mist_per_sui(), 0, user(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"test.sui"), 6, 150 * mist_per_sui(), 0, user(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::coupons::EInvalidYearsArgument)] fun invalid_years_claim_1_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"test.sui"), 0, 150 * mist_per_sui(), 0, user(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"test.sui"), 0, 150 * mist_per_sui(), 0, user(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::EInvalidUser)] fun invalid_user_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"test.sui"), 1, 150 * mist_per_sui(), 0, user_two(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"25_PERCENT_DISCOUNT_USER_ONLY"), utf8(b"test.sui"), 1, 150 * mist_per_sui(), 0, user_two(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::ECouponExpired)] fun coupon_expired_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::register_with_coupon(utf8(b"50_PERCENT_3_DIGITS"), utf8(b"tes.sui"), 1, 150 * mist_per_sui(), 2, user_two(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"50_PERCENT_3_DIGITS"), utf8(b"tes.sui"), 1, 150 * mist_per_sui(), 2, user_two(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::ENotValidYears)] fun coupon_not_valid_for_years_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::register_with_coupon(utf8(b"50_DISCOUNT_SALAD"), utf8(b"tes.sui"), 3, 150 * mist_per_sui(), 0, user(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"50_DISCOUNT_SALAD"), utf8(b"tes.sui"), 3, 150 * mist_per_sui(), 0, user(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::EInvalidForDomainLength)] fun coupon_invalid_length_1_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::register_with_coupon(utf8(b"50_PERCENT_3_DIGITS"), utf8(b"test.sui"), 1, 150 * mist_per_sui(), 2, user_two(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"50_PERCENT_3_DIGITS"), utf8(b"test.sui"), 1, 150 * mist_per_sui(), 2, user_two(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::EInvalidForDomainLength)] fun coupon_invalid_length_2_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); // Tries to use 5 digit name for a <=4 digit one. - setup::register_with_coupon(utf8(b"50_DISCOUNT_SALAD"), utf8(b"testo.sui"), 1, 150 * mist_per_sui(), 2, user(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"50_DISCOUNT_SALAD"), utf8(b"testo.sui"), 1, 150 * mist_per_sui(), 2, user(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::EInvalidForDomainLength)] fun coupon_invalid_length_3_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); // Tries to use 4 digit name for a 5+ chars coupon. - setup::register_with_coupon(utf8(b"50_PERCENT_5_PLUS_NAMES"), utf8(b"test.sui"), 1, 150 * mist_per_sui(), 2, user(), scenario); - test_scenario::end(scenario_val); + register_with_coupon(utf8(b"50_PERCENT_5_PLUS_NAMES"), utf8(b"test.sui"), 1, 150 * mist_per_sui(), 2, user(), scenario); + end(scenario_val); } #[test] fun add_coupon_as_admin() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); // add a no rule coupon as an admin - setup::admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::fixed_price_discount_type(), 100 * mist_per_sui(), scenario); + admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::fixed_price_discount_type(), 100 * mist_per_sui(), scenario); setup::admin_remove_coupon(utf8(b"TEST_SUCCESS_ADDITION"), scenario); - test_scenario::end(scenario_val); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::EInvalidType)] fun add_coupon_invalid_type_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), 5, 100 * mist_per_sui(), scenario); - test_scenario::end(scenario_val); + admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), 5, 100 * mist_per_sui(), scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::EInvalidAmount)] fun add_coupon_invalid_amount_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::percentage_discount_type(), 101, scenario); - test_scenario::end(scenario_val); + admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::percentage_discount_type(), 101, scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::rules::EInvalidAmount)] fun add_coupon_invalid_amount_2_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::percentage_discount_type(), 0, scenario); - test_scenario::end(scenario_val); + admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::percentage_discount_type(), 0, scenario); + end(scenario_val); } #[test, expected_failure(abort_code=::coupons::coupons::ECouponAlreadyExists)] fun add_coupon_twice_failure() { - let mut scenario_val = setup::test_init(); + let mut scenario_val = test_init(); let scenario = &mut scenario_val; populate_coupons(scenario); - setup::admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::percentage_discount_type(), 100, scenario); - setup::admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::percentage_discount_type(), 100, scenario); - test_scenario::end(scenario_val); + admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::percentage_discount_type(), 100, scenario); + admin_add_coupon(utf8(b"TEST_SUCCESS_ADDITION"), constants::percentage_discount_type(), 100, scenario); + end(scenario_val); } } From 28877dccb34820c608cdc8538218c003079c2426 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 10:45:15 -0400 Subject: [PATCH 11/38] setup --- packages/coupons/tests/setup.move | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/coupons/tests/setup.move b/packages/coupons/tests/setup.move index fb04be92..8c1f3d77 100644 --- a/packages/coupons/tests/setup.move +++ b/packages/coupons/tests/setup.move @@ -44,12 +44,12 @@ module coupons::setup { clock::share_for_testing(clock); }; { - test_scenario::next_tx(scenario, ADMIN_ADDRESS); - let mut coupon_house = test_scenario::take_shared(scenario); + scenario.next_tx(ADMIN_ADDRESS); + let mut coupon_house = scenario.take_shared(); // get admin cap - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario)); // authorize TestApp to CouponHouse. coupons::authorize_app(&admin_cap, &mut coupon_house); @@ -194,9 +194,9 @@ module coupons::setup { // Adds a 0 rule coupon that gives 15% discount to test admin additions. public fun admin_add_coupon(code_name: String, `type`: u8, value: u64, scenario: &mut Scenario) { - test_scenario::next_tx(scenario, admin()); - let mut coupon_house = test_scenario::take_shared(scenario); - let cap = test_scenario::take_from_sender(scenario); + scenario.next_tx(admin()); + let mut coupon_house = scenario.take_shared(); + let cap = scenario.take_from_sender(); coupons::admin_add_coupon( &cap, &mut coupon_house, @@ -211,9 +211,9 @@ module coupons::setup { } // Adds a 0 rule coupon that gives 15% discount to test admin additions. public fun admin_remove_coupon(code_name: String, scenario: &mut Scenario) { - test_scenario::next_tx(scenario, admin()); - let mut coupon_house = test_scenario::take_shared(scenario); - let cap = test_scenario::take_from_sender(scenario); + scenario.next_tx(admin()); + let mut coupon_house = scenario.take_shared(); + let cap = scenario.take_from_sender(); coupons::admin_remove_coupon( &cap, &mut coupon_house, @@ -230,16 +230,15 @@ module coupons::setup { // 5 digit -> 50 // A helper to easily register a name with a coupon code. public fun register_with_coupon(coupon_code: String, domain_name: String, no_years: u8, amount: u64, clock_value: u64, user: address, scenario: &mut Scenario) { - test_scenario::next_tx(scenario, user); - let mut clock = test_scenario::take_shared(scenario); - clock::increment_for_testing(&mut clock, clock_value); - let mut coupon_house = test_scenario::take_shared(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(user); + let mut clock = scenario.take_shared(); + clock.increment_for_testing(clock_value); + let mut coupon_house = scenario.take_shared(); + let mut suins = scenario.take_shared(); let payment = coin::mint_for_testing(amount, ctx(scenario)); - let nft = coupons::register_with_coupon( - &mut coupon_house, + let nft = coupon_house.register_with_coupon( &mut suins, coupon_code, domain_name, From c48b28c2c0d05e30ecb7da2b85d18609003c7e0f Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 13:26:43 -0400 Subject: [PATCH 12/38] denylist --- packages/denylist/sources/denylist.move | 23 ++++---- packages/denylist/tests/denylist_tests.move | 60 ++++++++++----------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/packages/denylist/sources/denylist.move b/packages/denylist/sources/denylist.move index 97cfd89b..13ddfc26 100644 --- a/packages/denylist/sources/denylist.move +++ b/packages/denylist/sources/denylist.move @@ -3,7 +3,6 @@ module denylist::denylist { use std::string::String; - use std::vector; use sui::tx_context::{TxContext}; use sui::table::{Self, Table}; @@ -35,12 +34,12 @@ module denylist::denylist { /// Check for a reserved name public fun is_reserved_name(suins: &SuiNS, name: String): bool { - table::contains(&denylist(suins).reserved, name) + denylist(suins).reserved.contains(name) } /// Checks for a blocked name. public fun is_blocked_name(suins: &SuiNS, name: String): bool { - table::contains(&denylist(suins).blocked, name) + denylist(suins).blocked.contains(name) } /// Add a list of reserved names to the list as admin. @@ -65,7 +64,7 @@ module denylist::denylist { /// Get immutable access to the registry. fun denylist(suins: &SuiNS): &Denylist { - suins::registry(suins) + suins.registry() } /// Internal helper to get access to the BlockedNames object @@ -75,27 +74,27 @@ module denylist::denylist { /// Internal helper to batch add words to a table. fun internal_add_names_to_list(table: &mut Table, words: vector) { - assert!(vector::length(&words) > 0, ENoWordsInList); + assert!(words.length() > 0, ENoWordsInList); - let mut i = vector::length(&words); + let mut i = words.length(); while (i > 0) { i = i - 1; - let word = *vector::borrow(&words, i); - table::add(table, word, true); + let word = *words.borrow(i); + table.add(word, true); }; } /// Internal helper to remove words from a table. fun internal_remove_names_from_list(table: &mut Table, words: vector) { - assert!(vector::length(&words) > 0, ENoWordsInList); + assert!(words.length() > 0, ENoWordsInList); - let mut i = vector::length(&words); + let mut i = words.length(); while (i > 0) { i = i - 1; - let word = *vector::borrow(&words, i); - table::remove(table, word); + let word = *words.borrow(i); + table.remove(word); }; } diff --git a/packages/denylist/tests/denylist_tests.move b/packages/denylist/tests/denylist_tests.move index a0c71c2a..7dc7c63d 100644 --- a/packages/denylist/tests/denylist_tests.move +++ b/packages/denylist/tests/denylist_tests.move @@ -5,7 +5,7 @@ module denylist::denylist_tests { use std::vector; use std::string::{utf8, String}; - use sui::test_scenario::{Self as ts, ctx, Scenario}; + use sui::test_scenario::{Self as ts, Scenario}; use suins::suins::{Self, SuiNS}; @@ -18,9 +18,9 @@ module denylist::denylist_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - ts::next_tx(scenario, ADDR); - let mut suins = ts::take_shared(scenario); - let cap = suins::create_admin_cap_for_testing(ctx(scenario)); + scenario.next_tx(ADDR); + let mut suins = scenario.take_shared(); + let cap = suins::create_admin_cap_for_testing(scenario.ctx()); denylist::add_reserved_names(&mut suins, &cap, some_reserved_names()); denylist::add_blocked_names(&mut suins, &cap, some_offensive_names()); @@ -38,7 +38,7 @@ module denylist::denylist_tests { suins::burn_admin_cap_for_testing(cap); ts::return_shared(suins); - ts::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::denylist::denylist::ENoWordsInList)] @@ -46,9 +46,9 @@ module denylist::denylist_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - ts::next_tx(scenario, ADDR); - let mut suins = ts::take_shared(scenario); - let cap = suins::create_admin_cap_for_testing(ctx(scenario)); + scenario.next_tx(ADDR); + let mut suins = scenario.take_shared(); + let cap = suins::create_admin_cap_for_testing(scenario.ctx()); denylist::add_reserved_names(&mut suins, &cap, vector[]); @@ -61,9 +61,9 @@ module denylist::denylist_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - ts::next_tx(scenario, ADDR); - let mut suins = ts::take_shared(scenario); - let cap = suins::create_admin_cap_for_testing(ctx(scenario)); + scenario.next_tx(ADDR); + let mut suins = scenario.take_shared(); + let cap = suins::create_admin_cap_for_testing(scenario.ctx()); denylist::add_blocked_names(&mut suins, &cap, vector[]); @@ -75,9 +75,9 @@ module denylist::denylist_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - ts::next_tx(scenario, ADDR); - let mut suins = ts::take_shared(scenario); - let cap = suins::create_admin_cap_for_testing(ctx(scenario)); + scenario.next_tx(ADDR); + let mut suins = scenario.take_shared(); + let cap = suins::create_admin_cap_for_testing(scenario.ctx()); denylist::add_blocked_names(&mut suins, &cap, some_offensive_names()); @@ -90,7 +90,7 @@ module denylist::denylist_tests { suins::burn_admin_cap_for_testing(cap); ts::return_shared(suins); - ts::end(scenario_val); + scenario_val.end(); } #[test] @@ -98,9 +98,9 @@ module denylist::denylist_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - ts::next_tx(scenario, ADDR); - let mut suins = ts::take_shared(scenario); - let cap = suins::create_admin_cap_for_testing(ctx(scenario)); + scenario.next_tx(ADDR); + let mut suins = scenario.take_shared(); + let cap = suins::create_admin_cap_for_testing(scenario.ctx()); denylist::add_reserved_names(&mut suins, &cap, some_reserved_names()); @@ -115,7 +115,7 @@ module denylist::denylist_tests { suins::burn_admin_cap_for_testing(cap); ts::return_shared(suins); - ts::end(scenario_val); + scenario_val.end(); } // data preparation @@ -123,15 +123,15 @@ module denylist::denylist_tests { public fun test_init(): (Scenario) { let mut scenario = ts::begin(ADDR); { - ts::next_tx(&mut scenario, ADDR); + scenario.next_tx(ADDR); - let (mut suins, cap) = suins::new_for_testing(ctx(&mut scenario)); + let (mut suins, cap) = suins::new_for_testing(scenario.ctx()); - suins::authorize_app_for_testing(&mut suins); + suins.authorize_app_for_testing(); - denylist::setup(&mut suins, &cap, ctx(&mut scenario)); + denylist::setup(&mut suins, &cap, scenario.ctx()); - suins::share_for_testing(suins); + suins.share_for_testing(); suins::burn_admin_cap_for_testing(cap); }; @@ -142,17 +142,17 @@ module denylist::denylist_tests { fun some_reserved_names(): vector { let mut vec: vector = vector::empty(); - vector::push_back(&mut vec, utf8(b"test")); - vector::push_back(&mut vec, utf8(b"test2")); - vector::push_back(&mut vec, utf8(b"test3")); + vec.push_back(utf8(b"test")); + vec.push_back(utf8(b"test2")); + vec.push_back(utf8(b"test3")); vec } fun some_offensive_names(): vector { let mut vec: vector = vector::empty(); - vector::push_back(&mut vec, utf8(b"bad_test")); - vector::push_back(&mut vec, utf8(b"bad_test2")); - vector::push_back(&mut vec, utf8(b"bad_test3")); + vec.push_back(utf8(b"bad_test")); + vec.push_back(utf8(b"bad_test2")); + vec.push_back(utf8(b"bad_test3")); vec } } From 0808d81e541ac063b2af50f01cad94f91ab7db18 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 14:38:24 -0400 Subject: [PATCH 13/38] discounts --- packages/discounts/sources/discounts.move | 16 ++-- packages/discounts/sources/free_claims.move | 47 ++++++------ packages/discounts/sources/house.move | 8 +- packages/discounts/tests/discount_tests.move | 74 +++++++++---------- .../discounts/tests/free_claims_test.move | 52 ++++++------- 5 files changed, 97 insertions(+), 100 deletions(-) diff --git a/packages/discounts/sources/discounts.move b/packages/discounts/sources/discounts.move index 24e71fae..65fb7f9b 100644 --- a/packages/discounts/sources/discounts.move +++ b/packages/discounts/sources/discounts.move @@ -9,13 +9,13 @@ /// Activation / deactivation happens through PTBs. module discounts::discounts { use std::option::{Option}; - use std::string::{Self, String}; + use std::string::String; use std::type_name::{Self as `type`}; use sui::tx_context::{TxContext}; use sui::dynamic_field::{Self as df}; use sui::clock::{Clock}; - use sui::coin::{Self, Coin}; + use sui::coin::Coin; use sui::sui::SUI; use suins::domain::{Self}; @@ -105,7 +105,7 @@ module discounts::discounts { four_char_price: u64, five_plus_char_price: u64 ) { - house::assert_version_is_valid(self); + self.assert_version_is_valid(); assert!(!df::exists_(house::uid_mut(self), DiscountKey {}), EConfigExists); df::add(house::uid_mut(self), DiscountKey{}, DiscountConfig { @@ -117,9 +117,9 @@ module discounts::discounts { /// An admin action to deauthorize type T from getting discounts. public fun deauthorize_type(_: &AdminCap, self: &mut DiscountHouse) { - house::assert_version_is_valid(self); + self.assert_version_is_valid(); assert_config_exists(self); - df::remove, DiscountConfig>(house::uid_mut(self), DiscountKey{}); + df::remove, DiscountConfig>(self.uid_mut(), DiscountKey{}); } /// Internal helper to handle the registration process @@ -136,10 +136,10 @@ module discounts::discounts { assert_config_exists(self); let domain = domain::new(domain_name); - let price = calculate_price(df::borrow(house::uid_mut(self), DiscountKey{}), (string::length(domain::sld(&domain)) as u8)); + let price = calculate_price(df::borrow(house::uid_mut(self), DiscountKey{}), (domain.sld().length() as u8)); - assert!(coin::value(&payment) == price, EIncorrectAmount); - suins::app_add_balance(house::suins_app_auth(), suins, coin::into_balance(payment)); + assert!(payment.value() == price, EIncorrectAmount); + suins::app_add_balance(house::suins_app_auth(), suins, payment.into_balance()); house::friend_add_registry_entry(suins, domain, clock, ctx) } diff --git a/packages/discounts/sources/free_claims.move b/packages/discounts/sources/free_claims.move index 89b94248..b3bef7c6 100644 --- a/packages/discounts/sources/free_claims.move +++ b/packages/discounts/sources/free_claims.move @@ -9,9 +9,6 @@ /// Activation / deactivation happens through PTBs. module discounts::free_claims { - use std::vector; - use std::string; - use std::string::{String}; use std::type_name::{Self as `type`}; @@ -97,7 +94,7 @@ module discounts::free_claims { object: &T, ctx: &mut TxContext ): SuinsRegistration { - house::assert_version_is_valid(self); + self.assert_version_is_valid(); // validate that there's a configuration for type T. assert_config_exists(self); @@ -106,11 +103,11 @@ module discounts::free_claims { let id = object::id(object); // validate that the supplied object hasn't been used to claim a free name. - let config = df::borrow_mut, FreeClaimsConfig>(house::uid_mut(self), FreeClaimsKey{}); - assert!(!linked_table::contains(&config.used_objects, id), EAlreadyClaimed); + let config = df::borrow_mut, FreeClaimsConfig>(self.uid_mut(), FreeClaimsKey{}); + assert!(!config.used_objects.contains(id), EAlreadyClaimed); // add the supplied object's id to the used objects list. - linked_table::push_back(&mut config.used_objects, id, true); + config.used_objects.push_back(id, true); // Now validate the domain, and that the rule applies here. let domain = domain::new(domain_name); @@ -127,13 +124,13 @@ module discounts::free_claims { domain_length_range: vector, ctx: &mut TxContext ) { - house::assert_version_is_valid(self); - assert!(!df::exists_(house::uid_mut(self), FreeClaimsKey {}), EConfigExists); + self.assert_version_is_valid(); + assert!(!df::exists_(self.uid_mut(), FreeClaimsKey {}), EConfigExists); // validate the range is valid. assert_valid_length_setup(&domain_length_range); - df::add(house::uid_mut(self), FreeClaimsKey{}, FreeClaimsConfig { + df::add(self.uid_mut(), FreeClaimsKey{}, FreeClaimsConfig { domain_length_range, used_objects: linked_table::new(ctx) }); @@ -143,37 +140,37 @@ module discounts::free_claims { /// Deauthorization also brings storage rebates by destroying the table of used objects. /// If we re-authorize a type, objects can be re-used, but that's considered a separate promotion. public fun deauthorize_type(_: &AdminCap, self: &mut DiscountHouse) { - house::assert_version_is_valid(self); + self.assert_version_is_valid(); assert_config_exists(self); - let FreeClaimsConfig { mut used_objects, domain_length_range: _ } = df::remove, FreeClaimsConfig>(house::uid_mut(self), FreeClaimsKey{}); + let FreeClaimsConfig { mut used_objects, domain_length_range: _ } = df::remove, FreeClaimsConfig>(self.uid_mut(), FreeClaimsKey{}); // parse each entry and remove it. Gives us storage rebates. - while(linked_table::length(&used_objects) > 0) { - linked_table::pop_front(&mut used_objects); + while(used_objects.length() > 0) { + used_objects.pop_front(); }; - linked_table::destroy_empty(used_objects); + used_objects.destroy_empty(); } /// Worried by the 1000 DFs load limit, I introduce a `drop_type` function now /// to make sure we can force-finish a promotion for type `T`. public fun force_deauthorize_type(_: &AdminCap, self: &mut DiscountHouse) { - house::assert_version_is_valid(self); + self.assert_version_is_valid(); assert_config_exists(self); - let FreeClaimsConfig { used_objects, domain_length_range: _ } = df::remove, FreeClaimsConfig>(house::uid_mut(self), FreeClaimsKey{}); - linked_table::drop(used_objects); + let FreeClaimsConfig { used_objects, domain_length_range: _ } = df::remove, FreeClaimsConfig>(self.uid_mut(), FreeClaimsKey{}); + used_objects.drop(); } // Validate that there is a config for `T` fun assert_config_exists(self: &mut DiscountHouse) { - assert!(df::exists_with_type, FreeClaimsConfig>(house::uid_mut(self), FreeClaimsKey {}), EConfigNotExists); + assert!(df::exists_with_type, FreeClaimsConfig>(self.uid_mut(), FreeClaimsKey {}), EConfigNotExists); } /// Validate that the domain length is valid for the passed configuration. fun assert_domain_length_eligible(domain: &Domain, config: &FreeClaimsConfig) { - let domain_length = (string::length(domain::sld(domain)) as u8); - let from = *vector::borrow(&config.domain_length_range, 0); - let to = *vector::borrow(&config.domain_length_range, 1); + let domain_length = (domain.sld().length() as u8); + let from = *config.domain_length_range.borrow(0); + let to = *config.domain_length_range.borrow(1); assert!(domain_length >= from && domain_length <= to, EInvalidCharacterRange); } @@ -181,10 +178,10 @@ module discounts::free_claims { // Validate that our range setup is right. fun assert_valid_length_setup(domain_length_range: &vector) { - assert!(vector::length(domain_length_range) == 2, EInvalidCharacterRange); + assert!(domain_length_range.length() == 2, EInvalidCharacterRange); - let from = *vector::borrow(domain_length_range, 0); - let to = *vector::borrow(domain_length_range, 1); + let from = *domain_length_range.borrow(0); + let to = *domain_length_range.borrow(1); assert!(to >= from, EInvalidCharacterRange); } diff --git a/packages/discounts/sources/house.move b/packages/discounts/sources/house.move index 6b475a78..372261e8 100644 --- a/packages/discounts/sources/house.move +++ b/packages/discounts/sources/house.move @@ -10,8 +10,8 @@ module discounts::house { use sui::transfer; use sui::clock::{Clock}; - use suins::domain::{Domain}; - use suins::registry::{Self, Registry}; + use suins::domain::Domain; + use suins::registry::Registry; use suins::suins::{Self, AdminCap, SuiNS}; use suins::config; use suins::suins_registration::SuinsRegistration; @@ -68,13 +68,13 @@ module discounts::house { ctx: &mut TxContext ): SuinsRegistration { // Verify that app is authorized to register names. - suins::assert_app_is_authorized(suins); + suins.assert_app_is_authorized(); // Validate that the name can be registered. config::assert_valid_user_registerable_domain(&domain); let registry = suins::app_registry_mut(DiscountHouseApp {}, suins); - registry::add_record(registry, domain, REGISTRATION_YEARS, clock, ctx) + registry.add_record(domain, REGISTRATION_YEARS, clock, ctx) } /// Returns the UID of the shared object so we can add custom configuration. diff --git a/packages/discounts/tests/discount_tests.move b/packages/discounts/tests/discount_tests.move index cdfbeebd..3ca1067b 100644 --- a/packages/discounts/tests/discount_tests.move +++ b/packages/discounts/tests/discount_tests.move @@ -38,18 +38,18 @@ module discounts::discount_tests { let mut scenario_val = ts::begin(SUINS_ADDRESS); let scenario = &mut scenario_val; { - let mut suins = suins::init_for_testing(ctx(scenario)); - suins::authorize_app_for_testing(&mut suins); - suins::share_for_testing(suins); - house::init_for_testing(ctx(scenario)); - let clock = clock::create_for_testing(ctx(scenario)); - clock::share_for_testing(clock); + let mut suins = suins::init_for_testing(scenario.ctx()); + suins.authorize_app_for_testing(); + suins.share_for_testing(); + house::init_for_testing(scenario.ctx()); + let clock = clock::create_for_testing(scenario.ctx()); + clock.share_for_testing(); }; { - ts::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = ts::take_from_sender(scenario); - let mut suins = ts::take_shared(scenario); - let mut discount_house = ts::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); + let mut discount_house = scenario.take_shared(); // a more expensive alternative. discounts::authorize_type(&admin_cap, &mut discount_house, 3*MIST_PER_SUI, 2*MIST_PER_SUI, 1*MIST_PER_SUI); @@ -57,7 +57,7 @@ module discounts::discount_tests { discounts::authorize_type(&admin_cap, &mut discount_house, MIST_PER_SUI / 20, MIST_PER_SUI / 10, MIST_PER_SUI / 5); discounts::authorize_type(&admin_cap, &mut discount_house, MIST_PER_SUI, MIST_PER_SUI, MIST_PER_SUI); - registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario)); + registry::init_for_testing(&admin_cap, &mut suins, scenario.ctx()); ts::return_shared(discount_house); ts::return_shared(suins); @@ -73,12 +73,12 @@ module discounts::discount_tests { payment: Coin, user: address ) { - ts::next_tx(scenario, user); - let mut suins = ts::take_shared(scenario); - let mut discount_house = ts::take_shared(scenario); - let clock = ts::take_shared(scenario); + scenario.next_tx(user); + let mut suins = scenario.take_shared(); + let mut discount_house = scenario.take_shared(); + let clock = scenario.take_shared(); - let name = discounts::register(&mut discount_house, &mut suins, item, domain_name, payment, &clock, option::none(), ctx(scenario)); + let name = discounts::register(&mut discount_house, &mut suins, item, domain_name, payment, &clock, option::none(), scenario.ctx()); transfer::public_transfer(name, user); @@ -94,12 +94,12 @@ module discounts::discount_tests { payment: Coin, user: address ) { - ts::next_tx(scenario, user); - let mut suins = ts::take_shared(scenario); - let mut discount_house = ts::take_shared(scenario); - let clock = ts::take_shared(scenario); + scenario.next_tx(user); + let mut suins = scenario.take_shared(); + let mut discount_house = scenario.take_shared(); + let clock = scenario.take_shared(); - let name = discounts::register_with_day_one(&mut discount_house, &mut suins, item, domain_name, payment, &clock, option::none(), ctx(scenario)); + let name = discounts::register_with_day_one(&mut discount_house, &mut suins, item, domain_name, payment, &clock, option::none(), scenario.ctx()); transfer::public_transfer(name, user); @@ -114,7 +114,7 @@ module discounts::discount_tests { let scenario = &mut scenario_val; let test_item = TestAuthorized {}; - let payment: Coin = coin::mint_for_testing(2*MIST_PER_SUI, ctx(scenario)); + let payment: Coin = coin::mint_for_testing(2*MIST_PER_SUI, scenario.ctx()); register_with_type( &test_item, @@ -124,7 +124,7 @@ module discounts::discount_tests { USER_ADDRESS ); - ts::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::discounts::discounts::EConfigNotExists)] @@ -133,7 +133,7 @@ module discounts::discount_tests { let scenario = &mut scenario_val; let test_item = TestUnauthorized {}; - let payment: Coin = coin::mint_for_testing(2*MIST_PER_SUI, ctx(scenario)); + let payment: Coin = coin::mint_for_testing(2*MIST_PER_SUI, scenario.ctx()); register_with_type( &test_item, @@ -142,7 +142,7 @@ module discounts::discount_tests { payment, USER_ADDRESS ); - ts::end(scenario_val); + scenario_val.end(); } #[test] @@ -150,9 +150,9 @@ module discounts::discount_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - let mut day_one = day_one::mint_for_testing(ctx(scenario)); + let mut day_one = day_one::mint_for_testing(scenario.ctx()); day_one::set_is_active_for_testing(&mut day_one, true); - let payment: Coin = coin::mint_for_testing(MIST_PER_SUI, ctx(scenario)); + let payment: Coin = coin::mint_for_testing(MIST_PER_SUI, scenario.ctx()); register_with_day_one( &day_one, @@ -162,8 +162,8 @@ module discounts::discount_tests { USER_ADDRESS ); - day_one::burn_for_testing(day_one); - ts::end(scenario_val); + day_one.burn_for_testing(); + scenario_val.end(); } #[test, expected_failure(abort_code = ::discounts::discounts::ENotValidForDayOne)] @@ -171,9 +171,9 @@ module discounts::discount_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - let mut day_one = day_one::mint_for_testing(ctx(scenario)); + let mut day_one = day_one::mint_for_testing(scenario.ctx()); day_one::set_is_active_for_testing(&mut day_one, true); - let payment: Coin = coin::mint_for_testing(MIST_PER_SUI, ctx(scenario)); + let payment: Coin = coin::mint_for_testing(MIST_PER_SUI, scenario.ctx()); register_with_type( &day_one, @@ -183,8 +183,8 @@ module discounts::discount_tests { USER_ADDRESS ); - day_one::burn_for_testing(day_one); - ts::end(scenario_val); + day_one.burn_for_testing(); + scenario_val.end(); } #[test, expected_failure(abort_code = ::discounts::discounts::ENotActiveDayOne)] @@ -192,8 +192,8 @@ module discounts::discount_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - let day_one = day_one::mint_for_testing(ctx(scenario)); - let payment: Coin = coin::mint_for_testing(MIST_PER_SUI, ctx(scenario)); + let day_one = day_one::mint_for_testing(scenario.ctx()); + let payment: Coin = coin::mint_for_testing(MIST_PER_SUI, scenario.ctx()); register_with_day_one( &day_one, @@ -203,7 +203,7 @@ module discounts::discount_tests { USER_ADDRESS ); - day_one::burn_for_testing(day_one); - ts::end(scenario_val); + day_one.burn_for_testing(); + scenario_val.end(); } } diff --git a/packages/discounts/tests/free_claims_test.move b/packages/discounts/tests/free_claims_test.move index 5367fe9a..9dc500cd 100644 --- a/packages/discounts/tests/free_claims_test.move +++ b/packages/discounts/tests/free_claims_test.move @@ -32,23 +32,23 @@ module discounts::free_claims_tests { let mut scenario_val = ts::begin(SUINS_ADDRESS); let scenario = &mut scenario_val; { - let mut suins = suins::init_for_testing(ctx(scenario)); - suins::authorize_app_for_testing(&mut suins); - suins::share_for_testing(suins); - house::init_for_testing(ctx(scenario)); - let clock = clock::create_for_testing(ctx(scenario)); - clock::share_for_testing(clock); + let mut suins = suins::init_for_testing(scenario.ctx()); + suins.authorize_app_for_testing(); + suins.share_for_testing(); + house::init_for_testing(scenario.ctx()); + let clock = clock::create_for_testing(scenario.ctx()); + clock.share_for_testing(); }; { ts::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = ts::take_from_sender(scenario); - let mut suins = ts::take_shared(scenario); - let mut discount_house = ts::take_shared(scenario); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); + let mut discount_house = scenario.take_shared(); // a more expensive alternative. - free_claims::authorize_type(&admin_cap, &mut discount_house, vector[10,63], ctx(scenario)); - free_claims::authorize_type(&admin_cap, &mut discount_house, vector[10,63], ctx(scenario)); - registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario)); + free_claims::authorize_type(&admin_cap, &mut discount_house, vector[10,63], scenario.ctx()); + free_claims::authorize_type(&admin_cap, &mut discount_house, vector[10,63], scenario.ctx()); + registry::init_for_testing(&admin_cap, &mut suins, scenario.ctx()); ts::return_shared(discount_house); ts::return_shared(suins); @@ -61,8 +61,8 @@ module discounts::free_claims_tests { let scenario = &mut scenario_val; { ts::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = ts::take_from_sender(scenario); - let mut discount_house = ts::take_shared(scenario); + let admin_cap = scenario.take_from_sender(); + let mut discount_house = scenario.take_shared(); free_claims::deauthorize_type(&admin_cap, &mut discount_house); free_claims::deauthorize_type(&admin_cap, &mut discount_house); ts::return_shared(discount_house); @@ -84,11 +84,11 @@ module discounts::free_claims_tests { user: address ) { ts::next_tx(scenario, user); - let mut suins = ts::take_shared(scenario); - let mut discount_house = ts::take_shared(scenario); - let clock = ts::take_shared(scenario); + let mut suins = scenario.take_shared(); + let mut discount_house = scenario.take_shared(); + let clock = scenario.take_shared(); - let name = free_claims::free_claim(&mut discount_house, &mut suins, item, domain_name, &clock, ctx(scenario)); + let name = free_claims::free_claim(&mut discount_house, &mut suins, item, domain_name, &clock, scenario.ctx()); transfer::public_transfer(name, user); @@ -108,7 +108,7 @@ module discounts::free_claims_tests { let mut discount_house = ts::take_shared(scenario); let clock = ts::take_shared(scenario); - let name = free_claims::free_claim_with_day_one(&mut discount_house, &mut suins, item, domain_name, &clock, ctx(scenario)); + let name = free_claims::free_claim_with_day_one(&mut discount_house, &mut suins, item, domain_name, &clock, scenario.ctx()); transfer::public_transfer(name, user); @@ -123,7 +123,7 @@ module discounts::free_claims_tests { let scenario = &mut scenario_val; let test_item = TestAuthorized { - id: object::new(ctx(scenario)) + id: object::new(scenario.ctx()) }; free_claim_with_type( @@ -142,8 +142,8 @@ module discounts::free_claims_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - let mut day_one = day_one::mint_for_testing(ctx(scenario)); - day_one::set_is_active_for_testing(&mut day_one, true); + let mut day_one = day_one::mint_for_testing(scenario.ctx()); + day_one.set_is_active_for_testing(true); free_claim_with_day_one( &day_one, @@ -152,7 +152,7 @@ module discounts::free_claims_tests { USER_ADDRESS ); - day_one::burn_for_testing(day_one); + day_one.burn_for_testing(); test_end(scenario_val); } @@ -162,7 +162,7 @@ module discounts::free_claims_tests { let scenario = &mut scenario_val; let test_item = TestAuthorized { - id: object::new(ctx(scenario)) + id: object::new(scenario.ctx()) }; free_claim_with_type( @@ -190,7 +190,7 @@ module discounts::free_claims_tests { let scenario = &mut scenario_val; let test_item = TestAuthorized { - id: object::new(ctx(scenario)) + id: object::new(scenario.ctx()) }; free_claim_with_type( @@ -210,7 +210,7 @@ module discounts::free_claims_tests { let scenario = &mut scenario_val; let test_item = TestUnauthorized { - id: object::new(ctx(scenario)) + id: object::new(scenario.ctx()) }; free_claim_with_type( From 957f9daa2266e963b3ed13753270b525a08267dc Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 15:38:52 -0400 Subject: [PATCH 14/38] managed_names --- packages/managed_names/sources/managed.move | 43 +++++------- .../managed_names/tests/managed_tests.move | 70 +++++++++---------- 2 files changed, 50 insertions(+), 63 deletions(-) diff --git a/packages/managed_names/sources/managed.move b/packages/managed_names/sources/managed.move index 5784d740..edc49607 100644 --- a/packages/managed_names/sources/managed.move +++ b/packages/managed_names/sources/managed.move @@ -16,7 +16,6 @@ /// we're also using it to store the managed names (to avoid using separate shared objects). /// module managed_names::managed { - use std::vector; use std::string::{String}; use std::option::{Self, Option}; @@ -27,7 +26,7 @@ module managed_names::managed { use sui::transfer; use suins::domain::{Self, Domain}; - use suins::suins_registration::{Self, SuinsRegistration}; + use suins::suins_registration::SuinsRegistration; use suins::suins::{Self, SuiNS, AdminCap}; /// Tries to add an NFT that has expired. @@ -83,11 +82,11 @@ module managed_names::managed { allowed_addresses: vector
, ctx: &mut TxContext ) { - assert!(!suins_registration::has_expired(&nft, clock), EExpiredNFT); + assert!(!nft.has_expired(clock), EExpiredNFT); let managed_names = managed_names_mut(suins); - let domain = suins_registration::domain(&nft); + let domain = nft.domain(); // if the name exists. We check if it's expired, and return it to the owner. if(table::contains(&managed_names.names, domain)) { @@ -97,13 +96,13 @@ module managed_names::managed { let existing_nft = option::destroy_some(nft); - assert!(suins_registration::has_expired(&existing_nft, clock), EAlreadyExists); + assert!(existing_nft.has_expired(clock), EAlreadyExists); // transfer it back to the owner. transfer::public_transfer(existing_nft, owner); }; // add the name to the managed names list. - table::add(&mut managed_names.names, domain, ManagedName { + managed_names.names.add(domain, ManagedName { owner: sender(ctx), allowed_addresses, nft: option::some(nft) @@ -120,7 +119,7 @@ module managed_names::managed { let domain = domain::new(name); assert!(table::contains(&managed_names.names, domain), ENameNotExists); - let existing = table::remove(&mut managed_names.names, domain); + let existing = managed_names.names.remove(domain); assert!(is_owner(&existing, sender(ctx)), ENotAuthorized); @@ -140,11 +139,11 @@ module managed_names::managed { let existing = internal_get_managed_name(managed_names_mut(suins), domain::new(name)); assert!(is_owner(existing, sender(ctx)), ENotAuthorized); - while(vector::length(&addresses) > 0) { - let addr = vector::pop_back(&mut addresses); + while(addresses.length() > 0) { + let addr = addresses.pop_back(); - if(!vector::contains(&existing.allowed_addresses, &addr)) { - vector::push_back(&mut existing.allowed_addresses, addr); + if(!existing.allowed_addresses.contains(&addr)) { + existing.allowed_addresses.push_back(addr); } } } @@ -159,13 +158,13 @@ module managed_names::managed { let existing = internal_get_managed_name(managed_names_mut(suins), domain::new(name)); assert!(is_owner(existing, sender(ctx)), ENotAuthorized); - while(vector::length(&addresses) > 0) { - let addr = vector::pop_back(&mut addresses); + while(addresses.length() > 0) { + let addr = addresses.pop_back(); - let (has_address, index) = vector::index_of(&existing.allowed_addresses, &addr); + let (has_address, index) = existing.allowed_addresses.index_of(&addr); if (has_address) { - vector::remove(&mut existing.allowed_addresses, index); + existing.allowed_addresses.remove(index); } } } @@ -197,7 +196,7 @@ module managed_names::managed { let ReturnPromise { id } = promise; assert!(object::id(&nft) == id, EInvalidReturnedNFT); - let existing = internal_get_managed_name(managed_names_mut(suins), suins_registration::domain(&nft)); + let existing = internal_get_managed_name(managed_names_mut(suins), nft.domain()); // return the NFT back. option::fill(&mut existing.nft, nft) @@ -205,9 +204,9 @@ module managed_names::managed { fun internal_get_managed_name(managed_names: &mut ManagedNames, domain: Domain): &mut ManagedName { - assert!(table::contains(&managed_names.names, domain), ENameNotExists); + assert!(managed_names.names.contains(domain), ENameNotExists); - table::borrow_mut(&mut managed_names.names, domain) + managed_names.names.borrow_mut(domain) } @@ -216,13 +215,7 @@ module managed_names::managed { } /// Check if an address is authorized for borrowing. fun is_authorized_address(self: &ManagedName, addr: address): bool { - self.owner == addr || vector::contains(&self.allowed_addresses, &addr) - } - - - /// an immutable reference to the registry. - fun managed_names(self: &SuiNS): &ManagedNames { - suins::registry(self) + self.owner == addr || self.allowed_addresses.contains(&addr) } /// a mutable reference to the registry diff --git a/packages/managed_names/tests/managed_tests.move b/packages/managed_names/tests/managed_tests.move index 279367c4..b5b8c5c5 100644 --- a/packages/managed_names/tests/managed_tests.move +++ b/packages/managed_names/tests/managed_tests.move @@ -37,8 +37,7 @@ module managed_names::managed_tests { let nft = remove_attached_name(domain_name, USER, scenario); transfer::public_transfer(nft, USER); - - ts::end(scenario_val); + scenario_val.end(); } #[test] @@ -65,7 +64,7 @@ module managed_names::managed_tests { // Since we attached the re-registered version for the name, // the original `owner` should have received back the expired NFT. { - ts::next_tx(scenario, USER); + scenario.next_tx(USER); let mut nft_transferred_back = ts::most_recent_id_for_address(USER); assert!(option::is_some(&nft_transferred_back), 0); @@ -75,7 +74,7 @@ module managed_names::managed_tests { suins_registration::burn_for_testing(random_nft); - ts::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code=managed_names::managed::EExpiredNFT)] @@ -227,19 +226,18 @@ module managed_names::managed_tests { /// public fun test_init(): (Scenario) { let mut scenario = ts::begin(USER); - { - ts::next_tx(&mut scenario, USER); + scenario.next_tx(USER); - let clock = clock::create_for_testing(ctx(&mut scenario)); + let clock = clock::create_for_testing(scenario.ctx()); clock::share_for_testing(clock); - let (mut suins, cap) = suins::new_for_testing(ctx(&mut scenario)); + let (mut suins, cap) = suins::new_for_testing(scenario.ctx()); - suins::authorize_app_for_testing(&mut suins); + suins.authorize_app_for_testing(); managed::setup(&mut suins, &cap, ctx(&mut scenario)); - suins::share_for_testing(suins); + suins.share_for_testing(); suins::burn_admin_cap_for_testing(cap); }; @@ -248,35 +246,35 @@ module managed_names::managed_tests { } public fun attach_name(nft: SuinsRegistration, addresses: vector
, addr: address, scenario: &mut Scenario) { - ts::next_tx(scenario, addr); - let mut suins = ts::take_shared(scenario); - let clock = ts::take_shared(scenario); + scenario.next_tx(addr); + let mut suins = scenario.take_shared(); + let clock = scenario.take_shared(); - managed::attach_managed_name(&mut suins, nft, &clock, addresses, ctx(scenario)); + managed::attach_managed_name(&mut suins, nft, &clock, addresses, scenario.ctx()); ts::return_shared(clock); ts::return_shared(suins); } public fun remove_attached_name(domain_name: String, addr: address, scenario: &mut Scenario): SuinsRegistration { - ts::next_tx(scenario, addr); - let mut suins = ts::take_shared(scenario); + scenario.next_tx(addr); + let mut suins = scenario.take_shared(); - let nft = managed::remove_attached_name(&mut suins, domain_name, ctx(scenario)); + let nft = managed::remove_attached_name(&mut suins, domain_name, scenario.ctx()); ts::return_shared(suins); nft } public fun add_or_remove_addresses(name: String, addresses: vector
, add: bool, addr: address, scenario: &mut Scenario) { - ts::next_tx(scenario, addr); - let mut suins = ts::take_shared(scenario); - let clock = ts::take_shared(scenario); + scenario.next_tx(addr); + let mut suins = scenario.take_shared(); + let clock = scenario.take_shared(); if(add){ - managed::allow_addresses(&mut suins, name, addresses, ctx(scenario)); + managed::allow_addresses(&mut suins, name, addresses, scenario.ctx()); }else { - managed::revoke_addresses(&mut suins, name, addresses, ctx(scenario)); + managed::revoke_addresses(&mut suins, name, addresses, scenario.ctx()); }; ts::return_shared(clock); @@ -284,12 +282,12 @@ module managed_names::managed_tests { } public fun simulate_borrow(domain_name: String, addr: address, scenario: &mut Scenario): (SuinsRegistration, ReturnPromise) { - ts::next_tx(scenario, addr); - let mut suins = ts::take_shared(scenario); + scenario.next_tx(addr); + let mut suins = scenario.take_shared(); - let (name, promise) = managed::borrow_val(&mut suins, domain_name, ctx(scenario)); + let (name, promise) = managed::borrow_val(&mut suins, domain_name, scenario.ctx()); - assert!(suins_registration::domain(&name) == domain::new(domain_name), 0); + assert!(name.domain() == domain::new(domain_name), 0); ts::return_shared(suins); @@ -297,8 +295,8 @@ module managed_names::managed_tests { } public fun simulate_return(nft: SuinsRegistration, promise: ReturnPromise, scenario: &mut Scenario) { - ts::next_tx(scenario, USER); - let mut suins = ts::take_shared(scenario); + scenario.next_tx(USER); + let mut suins = scenario.take_shared(); managed::return_val(&mut suins, nft, promise); @@ -313,18 +311,18 @@ module managed_names::managed_tests { } public fun advance_clock_post_expiration_of_nft(nft: &SuinsRegistration, scenario: &mut Scenario) { - ts::next_tx(scenario, USER); - let mut clock = ts::take_shared(scenario); + scenario.next_tx(USER); + let mut clock = scenario.take_shared(); // expire name - clock::increment_for_testing(&mut clock, suins_registration::expiration_timestamp_ms(nft) + 1); + clock.increment_for_testing(nft.expiration_timestamp_ms() + 1); ts::return_shared(clock); } // generates a SuinsRegistration NFT for testing public fun get_nft(name: String, addr: address, scenario: &mut Scenario): SuinsRegistration { - ts::next_tx(scenario, addr); - let suins = ts::take_shared(scenario); - let clock = ts::take_shared(scenario); + scenario.next_tx(addr); + let suins = scenario.take_shared(); + let clock = scenario.take_shared(); let nft = new_for_testing( domain::new(name), 1, @@ -335,8 +333,4 @@ module managed_names::managed_tests { ts::return_shared(suins); nft } - - - - } From 2ea7f2ac3e9fb16ce7beaaa5576aa6a9251a18b3 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 16:19:37 -0400 Subject: [PATCH 15/38] registration --- packages/registration/sources/register.move | 20 +-- .../registration/tests/register_tests.move | 142 +++++++++--------- 2 files changed, 81 insertions(+), 81 deletions(-) diff --git a/packages/registration/sources/register.move b/packages/registration/sources/register.move index 1fe43d78..b9022cae 100644 --- a/packages/registration/sources/register.move +++ b/packages/registration/sources/register.move @@ -2,14 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 module registration::register { - use std::string::{Self, String}; - use sui::coin::{Self, Coin}; + use std::string::String; + use sui::coin::Coin; use sui::tx_context::TxContext; use sui::clock::Clock; use sui::sui::SUI; use suins::domain; - use suins::registry::{Self, Registry}; + use suins::registry::Registry; use suins::suins::{Self, SuiNS}; use suins::config::{Self, Config}; use suins::suins_registration::SuinsRegistration; @@ -38,22 +38,22 @@ module registration::register { clock: &Clock, ctx: &mut TxContext ): SuinsRegistration { - suins::assert_app_is_authorized(suins); + suins.assert_app_is_authorized(); - let config = suins::get_config(suins); + let config = suins.get_config(); let domain = domain::new(domain_name); config::assert_valid_user_registerable_domain(&domain); assert!(0 < no_years && no_years <= 5, EInvalidYearsArgument); - let label = domain::sld(&domain); - let price = config::calculate_price(config, (string::length(label) as u8), no_years); + let label = domain.sld(); + let price = config.calculate_price((label.length() as u8), no_years); - assert!(coin::value(&payment) == price, EIncorrectAmount); + assert!(payment.value() == price, EIncorrectAmount); - suins::app_add_balance(Register {}, suins, coin::into_balance(payment)); + suins::app_add_balance(Register {}, suins, payment.into_balance()); let registry = suins::app_registry_mut(Register {}, suins); - registry::add_record(registry, domain, no_years, clock, ctx) + registry.add_record(domain, no_years, clock, ctx) } } \ No newline at end of file diff --git a/packages/registration/tests/register_tests.move b/packages/registration/tests/register_tests.move index 9899714c..d00fd832 100644 --- a/packages/registration/tests/register_tests.move +++ b/packages/registration/tests/register_tests.move @@ -30,22 +30,22 @@ module registration::register_tests { let mut scenario_val = test_scenario::begin(SUINS_ADDRESS); let scenario = &mut scenario_val; { - let mut suins = suins::init_for_testing(ctx(scenario)); - suins::authorize_app_for_testing(&mut suins); - suins::authorize_app_for_testing(&mut suins); - suins::share_for_testing(suins); - let clock = clock::create_for_testing(ctx(scenario)); + let mut suins = suins::init_for_testing(scenario.ctx()); + suins.authorize_app_for_testing(); + suins.authorize_app_for_testing(); + suins.share_for_testing(); + let clock = clock::create_for_testing(scenario.ctx()); clock::share_for_testing(clock); }; { test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); - registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario)); + registry::init_for_testing(&admin_cap, &mut suins, scenario.ctx()); test_scenario::return_shared(suins); - test_scenario::return_to_sender(scenario, admin_cap); + scenario.return_to_sender(admin_cap); }; scenario_val } @@ -57,13 +57,13 @@ module registration::register_tests { amount: u64, clock_tick: u64 ): SuinsRegistration { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let mut suins = test_scenario::take_shared(scenario); - let payment = coin::mint_for_testing(amount, ctx(scenario)); - let mut clock = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let mut suins = scenario.take_shared(); + let payment = coin::mint_for_testing(amount, scenario.ctx()); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); - let nft = register(&mut suins, domain_name, no_years, payment, &clock, ctx(scenario)); + clock.increment_for_testing(clock_tick); + let nft = register(&mut suins, domain_name, no_years, payment, &clock, scenario.ctx()); test_scenario::return_shared(clock); test_scenario::return_shared(suins); @@ -73,19 +73,19 @@ module registration::register_tests { fun deauthorize_app_util(scenario: &mut Scenario) { test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); suins::deauthorize_app(&admin_cap, &mut suins); test_scenario::return_shared(suins); - test_scenario::return_to_sender(scenario, admin_cap); + scenario.return_to_sender(admin_cap); } public fun assert_balance(scenario: &mut Scenario, amount: u64) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let auction_house = test_scenario::take_shared(scenario); - assert!(total_balance(&auction_house) == amount, 0); + scenario.next_tx(SUINS_ADDRESS); + let auction_house = scenario.take_shared(); + assert!(auction_house.total_balance() == amount, 0); test_scenario::return_shared(auction_house); } @@ -96,23 +96,23 @@ module registration::register_tests { let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == year_ms() + 10, 0); + nft.burn_for_testing(); let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 400 * mist_per_sui(), 20); assert_balance(scenario, 1600 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abcd.sui")), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 30, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(b"abcd.sui")), 0); + assert!(nft.expiration_timestamp_ms() == 2 * year_ms() + 30, 0); + nft.burn_for_testing(); let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 150 * mist_per_sui(), 30); assert_balance(scenario, 1750 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f12.sui")), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 60, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(b"abce-f12.sui")), 0); + assert!(nft.expiration_timestamp_ms() == 3 * year_ms() + 60, 0); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = config::EInvalidTld)] @@ -121,9 +121,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"abc.move"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = register::EIncorrectAmount)] @@ -132,9 +132,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1210 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = register::EIncorrectAmount)] @@ -143,9 +143,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 90 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = register::EInvalidYearsArgument)] @@ -154,9 +154,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(DOMAIN_NAME), 6, 6 * 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = register::EInvalidYearsArgument)] @@ -165,9 +165,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(DOMAIN_NAME), 0, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -177,9 +177,9 @@ module registration::register_tests { let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == year_ms() + 10, 0); + nft.burn_for_testing(); let nft = register_util( scenario, @@ -189,14 +189,14 @@ module registration::register_tests { year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 2400 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(nft.domain() == domain::new(utf8(DOMAIN_NAME)), 0); assert!( - suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + grace_period_ms() + 30, + nft.expiration_timestamp_ms() == 2 * year_ms() + grace_period_ms() + 30, 0 ); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ERecordNotExpired)] @@ -206,14 +206,14 @@ module registration::register_tests { let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == year_ms() + 10, 0); + nft.burn_for_testing(); let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 20); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -222,9 +222,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"-ab.sui"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -233,9 +233,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"ab-.sui"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -244,9 +244,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"Abc.com"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = config::ELabelTooShort)] @@ -255,9 +255,9 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"ab.sui"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = config::EInvalidDomain)] @@ -266,29 +266,29 @@ module registration::register_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"abc.xyz.sui"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ERecordNotExpired)] fun test_register_aborts_if_domain_name_went_through_auction() { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - auction::init_for_testing(ctx(scenario)); + auction::init_for_testing(scenario.ctx()); auction_tests::normal_auction_flow(scenario); let nft = register_util(scenario, utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] fun test_register_works_if_auctioned_domain_name_expired() { let mut scenario_val = test_init(); let scenario = &mut scenario_val; - auction::init_for_testing(ctx(scenario)); + auction::init_for_testing(scenario.ctx()); auction_tests::normal_auction_flow(scenario); let nft = register_util( @@ -300,9 +300,9 @@ module registration::register_tests { ); assert_balance(scenario, 50 * mist_per_sui()); assert!(suins_registration::domain(&nft) == domain::new(utf8(AUCTIONED_DOMAIN_NAME)), 0); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -312,8 +312,8 @@ module registration::register_tests { deauthorize_app_util(scenario); let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } } \ No newline at end of file From eb74bff268ed2882f6d858163a5713f5b3f510f8 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 16:42:13 -0400 Subject: [PATCH 16/38] renewal --- packages/renewal/sources/renew.move | 32 ++++++++++++------------- packages/renewal/tests/renew_tests.move | 12 +++++----- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/renewal/sources/renew.move b/packages/renewal/sources/renew.move index 0851f8bb..470117b1 100644 --- a/packages/renewal/sources/renew.move +++ b/packages/renewal/sources/renew.move @@ -6,22 +6,20 @@ /// /// The renewal is capped at 5 years. module renewal::renew { - use std::string; use std::option; use sui::coin::{Self, Coin}; - use sui::clock::{Self, Clock}; + use sui::clock::Clock; use sui::sui::SUI; use sui::object; use suins::constants; - use suins::domain::{Self, Domain}; - use suins::registry::{Self, Registry}; + use suins::domain::Domain; + use suins::registry::Registry; use suins::suins::{Self, SuiNS, AdminCap}; use suins::config::{Self, Config}; - use suins::suins_registration::{Self as nft, SuinsRegistration}; - use suins::name_record; + use suins::suins_registration::SuinsRegistration; /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; @@ -75,7 +73,7 @@ module renewal::renew { clock: &Clock ) { // authorization occurs inside the call. - let domain = nft::domain(nft); + let domain = nft.domain(); // check if the name is valid, for public registration // Also checks if the domain is not a subdomain, validates label lengths, TLD. config::assert_valid_user_registerable_domain(&domain); @@ -90,7 +88,7 @@ module renewal::renew { let target_expiration = target_expiration(registry, nft, domain, clock, no_years); // set the expiration of the NFT + the registry's name record. - registry::set_expiration_timestamp_ms(registry, nft, domain, target_expiration); + registry.set_expiration_timestamp_ms(nft, domain, target_expiration); sui::event::emit(NameRenewed { domain, amount: coin::value(&payment) }); suins::app_add_balance(Renew {}, suins, coin::into_balance(payment)); @@ -105,35 +103,35 @@ module renewal::renew { clock: &Clock, no_years: u8, ): u64 { - let name_record_option = registry::lookup(registry, domain); + let name_record_option = registry.lookup(domain); // validate that the name_record still exists in the registry. assert!(option::is_some(&name_record_option), ERecordNotFound); let name_record = option::destroy_some(name_record_option); // Validate that the name has not expired. If it has, we can only re-purchase (and that might involve different pricing). - assert!(!name_record::has_expired_past_grace_period(&name_record, clock), ERecordExpired); + assert!(!name_record.has_expired_past_grace_period(clock), ERecordExpired); // validate that the supplied NFT ID matches the NFT ID of the registry. - assert!(name_record::nft_id(&name_record) == object::id(nft), ERecordNftIDMismatch); + assert!(name_record.nft_id() == object::id(nft), ERecordNftIDMismatch); // Validate that the no_years supplied makes sense. (1-5). assert!(0 < no_years && no_years <= 5, EInvalidYearsArgument); // calcualate target expiration! - let target_expiration = name_record::expiration_timestamp_ms(&name_record) + (no_years as u64) * constants::year_ms(); + let target_expiration = name_record.expiration_timestamp_ms() + (no_years as u64) * constants::year_ms(); // validate that the target expiration is not more than 6 years in the future. - assert!(target_expiration < clock::timestamp_ms(clock) + (constants::year_ms() * 6), EMoreThanSixYears); + assert!(target_expiration < clock.timestamp_ms() + (constants::year_ms() * 6), EMoreThanSixYears); target_expiration } /// Validates that the payment Coin is correct for the domain + number of years fun validate_payment(suins: &SuiNS, payment: &Coin, domain: &Domain, no_years: u8){ - let config = suins::get_config(suins); - let label = domain::sld(domain); - let price = config::calculate_price(&config.config, (string::length(label) as u8), no_years); - assert!(coin::value(payment) == price, EIncorrectAmount); + let config = suins.get_config(); + let label = domain.sld(); + let price = config.config.calculate_price((label.length() as u8), no_years); + assert!(payment.value() == price, EIncorrectAmount); } } diff --git a/packages/renewal/tests/renew_tests.move b/packages/renewal/tests/renew_tests.move index 36e7e780..5961c7c2 100644 --- a/packages/renewal/tests/renew_tests.move +++ b/packages/renewal/tests/renew_tests.move @@ -30,14 +30,14 @@ module renewal::renew_tests { let mut clock = clock::create_for_testing(&mut ctx); - clock::increment_for_testing(&mut clock, 10); + clock.increment_for_testing(10); renew_util(&mut suins, &mut nft, 5, &clock, &mut ctx); // our fresh domain with 5 years renewal is now 6 years - assert!(nft::expiration_timestamp_ms(&nft) == clock::timestamp_ms(&clock) + (6 * year_ms()) - 10, 0); + assert!(nft.expiration_timestamp_ms() == clock.timestamp_ms() + (6 * year_ms()) - 10, 0); - clock::destroy_for_testing(clock); + clock.destroy_for_testing(); wrapup(suins); wrapup_name(nft); @@ -143,11 +143,11 @@ module renewal::renew_tests { renewal::setup(&cap, &mut suins, config); - let nft = registry::add_record(&mut registry, domain, 1,&clock, ctx); + let nft = registry.add_record(domain, 1,&clock, ctx); suins::add_registry(&cap, &mut suins, registry); suins::burn_admin_cap_for_testing(cap); - clock::destroy_for_testing(clock); + clock.destroy_for_testing(); (suins, nft) } @@ -157,6 +157,6 @@ module renewal::renew_tests { } public fun wrapup(suins: SuiNS) { - suins::share_for_testing(suins); + suins.share_for_testing(); } } From 653edbcd995e2f5a8d7f205ee970dbaf45ce37e4 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 17:00:51 -0400 Subject: [PATCH 17/38] subdomains --- packages/subdomains/sources/config.move | 15 ++-- packages/subdomains/sources/subdomains.move | 77 ++++++++++----------- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/packages/subdomains/sources/config.move b/packages/subdomains/sources/config.move index 702b75f0..0f201522 100644 --- a/packages/subdomains/sources/config.move +++ b/packages/subdomains/sources/config.move @@ -2,10 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 module subdomains::config { - use std::string::{Self, String}; - use std::vector; + use std::string::String; - use suins::domain::{Self, Domain, is_parent_of}; + use suins::domain::{Domain, is_parent_of}; use suins::constants::sui_tld; /// the minimum size a subdomain label can have. @@ -71,7 +70,7 @@ module subdomains::config { /// Validate that the depth of the subdomain is with the allowed range. public fun has_valid_depth(domain: &Domain, config: &SubDomainConfig): bool { - domain::number_of_levels(domain) <= (config.max_depth as u64) + domain.number_of_levels() <= (config.max_depth as u64) } /// Validates that the TLD of the domain is supported for subdomains. @@ -80,8 +79,8 @@ module subdomains::config { /// (E.g., with `.move` service, we might want to restrict how subdomains are created) public fun is_valid_tld(domain: &Domain, config: &SubDomainConfig): bool { let mut i=0; - while (i < vector::length(&config.allowed_tlds)) { - if (domain::tld(domain) == vector::borrow(&config.allowed_tlds, i)) { + while (i < config.allowed_tlds.length()) { + if (domain.tld() == config.allowed_tlds.borrow(i)) { return true }; i = i + 1; @@ -94,8 +93,8 @@ module subdomains::config { /// in the `Domain` construction. public fun is_valid_label(domain: &Domain, config: &SubDomainConfig): bool { // our label is the last vector element, as labels are stored in reverse order. - let label = domain::label(domain, domain::number_of_levels(domain) - 1); - string::length(label) >= (config.min_label_size as u64) + let label = domain.label(domain.number_of_levels() - 1); + label.length() >= (config.min_label_size as u64) } } diff --git a/packages/subdomains/sources/subdomains.move b/packages/subdomains/sources/subdomains.move index bddb2295..7d9bb252 100644 --- a/packages/subdomains/sources/subdomains.move +++ b/packages/subdomains/sources/subdomains.move @@ -30,17 +30,16 @@ module subdomains::subdomains { use sui::object::{Self, ID}; use sui::tx_context::{TxContext}; - use sui::clock::{Self, Clock}; + use sui::clock::Clock; use sui::dynamic_field as df; - use sui::vec_map::{Self, VecMap}; + use sui::vec_map::VecMap; use suins::domain::{Self, Domain, is_subdomain}; - use suins::registry::{Self, Registry}; + use suins::registry::Registry; use suins::suins::{Self, SuiNS, AdminCap}; - use suins::suins_registration::{Self, SuinsRegistration}; - use suins::subdomain_registration::{Self, SubDomainRegistration}; + use suins::suins_registration::SuinsRegistration; + use suins::subdomain_registration::SubDomainRegistration; use suins::constants::{subdomain_allow_extension_key, subdomain_allow_creation_key}; - use suins::name_record; use subdomains::config::{Self, SubDomainConfig}; @@ -97,7 +96,7 @@ module subdomains::subdomains { internal_validate_nft_can_manage_subdomain(suins, parent, clock, subdomain, true); // Aborts with `suins::registry::ERecordExists` if the subdomain already exists. - registry::add_leaf_record(registry_mut(suins), subdomain, clock, target, ctx) + registry_mut(suins).add_leaf_record(subdomain, clock, target, ctx) } /// Removes a `leaf` subdomain from the registry. @@ -115,7 +114,7 @@ module subdomains::subdomains { // we can still remove a leaf name (we just can't add a new one). internal_validate_nft_can_manage_subdomain(suins, parent, clock, subdomain, false); - registry::remove_leaf_record(registry_mut(suins), subdomain) + registry_mut(suins).remove_leaf_record(subdomain) } /// Creates a new `node` subdomain @@ -149,9 +148,9 @@ module subdomains::subdomains { internal_validate_nft_can_manage_subdomain(suins, parent, clock, subdomain, true); // Validate that the duration is at least the minimum duration. - assert!(expiration_timestamp_ms >= clock::timestamp_ms(clock) + config::minimum_duration(&app_config(suins).config), EInvalidExpirationDate); + assert!(expiration_timestamp_ms >= clock.timestamp_ms() + app_config(suins).config.minimum_duration(), EInvalidExpirationDate); // validate that the requested expiration timestamp is not greater than the parent's one. - assert!(expiration_timestamp_ms <= suins_registration::expiration_timestamp_ms(parent), EInvalidExpirationDate); + assert!(expiration_timestamp_ms <= parent.expiration_timestamp_ms(), EInvalidExpirationDate); // We register the subdomain (e.g. `subdomain.example.sui`) and return the SuinsRegistration object. // Aborts with `suins::registry::ERecordExists` if the subdomain already exists. @@ -178,29 +177,29 @@ module subdomains::subdomains { ) { let registry = registry(suins); - let nft = subdomain_registration::nft_mut(sub_nft); - let subdomain = suins_registration::domain(nft); - let parent_domain = domain::parent(&subdomain); + let nft = sub_nft.nft_mut(); + let subdomain = nft.domain(); + let parent_domain = subdomain.parent(); // Check if time extension is allowed for this subdomain. assert!(is_extension_allowed(&record_metadata(suins, subdomain)), EExtensionDisabledForSubDomain); - let existing_name_record = registry::lookup(registry, subdomain); - let parent_name_record = registry::lookup(registry, parent_domain); + let existing_name_record = registry.lookup(subdomain); + let parent_name_record = registry.lookup(parent_domain); // we need to make sure this name record exists (both child + parent), otherwise we don't have a valid object. assert!(option::is_some(&existing_name_record) && option::is_some(&parent_name_record), ESubdomainReplaced); // Validate that the parent of the name is the same as the actual parent // (to prevent cases where owner of the parent changed. When that happens, subdomains lose all abilities to renew / create subdomains) - assert!(parent(nft) == name_record::nft_id(option::borrow(&parent_name_record)), EParentChanged); + assert!(parent(nft) == option::borrow(&parent_name_record).nft_id(), EParentChanged); // validate that expiration date is > than the current. - assert!(expiration_timestamp_ms > suins_registration::expiration_timestamp_ms(nft), EInvalidExpirationDate); + assert!(expiration_timestamp_ms > nft.expiration_timestamp_ms(), EInvalidExpirationDate); // validate that the requested expiration timestamp is not greater than the parent's one. - assert!(expiration_timestamp_ms <= name_record::expiration_timestamp_ms(option::borrow(&parent_name_record)), EInvalidExpirationDate); + assert!(expiration_timestamp_ms <= option::borrow(&parent_name_record).expiration_timestamp_ms(), EInvalidExpirationDate); - registry::set_expiration_timestamp_ms(registry_mut(suins), nft, subdomain, expiration_timestamp_ms); + registry_mut(suins).set_expiration_timestamp_ms(nft, subdomain, expiration_timestamp_ms); } /// Called by the parent domain to edit a subdomain's settings. @@ -216,9 +215,9 @@ module subdomains::subdomains { allow_time_extension: bool ) { // validate that parent is a valid, non expired object. - registry::assert_nft_is_authorized(registry(suins), parent, clock); + registry(suins).assert_nft_is_authorized(parent, clock); - let parent_domain = suins_registration::domain(parent); + let parent_domain = parent.domain(); let subdomain = domain::new(subdomain_name); // validate that the subdomain is valid for the supplied parent @@ -237,12 +236,12 @@ module subdomains::subdomains { nft: SubDomainRegistration, clock: &Clock, ) { - registry::burn_subdomain_object(registry_mut(suins), nft, clock); + registry_mut(suins).burn_subdomain_object(nft, clock); } /// Parent ID of a subdomain public fun parent(subdomain: &SuinsRegistration): ID { - *df::borrow(suins_registration::uid(subdomain), ParentKey {}) + *df::borrow(subdomain.uid(), ParentKey {}) } // Sets/removes a (key,value) on the domain's NameRecord metadata (depending on cases). @@ -254,27 +253,27 @@ module subdomains::subdomains { enable: bool ) { let mut config = record_metadata(self, subdomain); - let is_enabled = vec_map::contains(&config, &key); + let is_enabled = config.contains(&key); if (enable && !is_enabled) { - vec_map::insert(&mut config, key, utf8(ACTIVE_METADATA_VALUE)); + config.insert(key, utf8(ACTIVE_METADATA_VALUE)); }; if(!enable && is_enabled) { - vec_map::remove(&mut config, &key); + config.remove(&key); }; - registry::set_data(registry_mut(self), subdomain, config); + registry_mut(self).set_data(subdomain, config); } /// Check if subdomain creation is allowed. fun is_creation_allowed(metadata: &VecMap): bool { - vec_map::contains(metadata, &subdomain_allow_creation_key()) + metadata.contains(&subdomain_allow_creation_key()) } /// Check if time extension is allowed. fun is_extension_allowed(metadata: &VecMap): bool { - vec_map::contains(metadata, &subdomain_allow_extension_key()) + metadata.contains(&subdomain_allow_extension_key()) } /// Get the name record's metadata for a subdomain. @@ -282,7 +281,7 @@ module subdomains::subdomains { self: &SuiNS, subdomain: Domain ): VecMap { - *registry::get_data(registry(self), subdomain) + *registry(self).get_data(subdomain) } /// Does all the regular checks for validating that a parent `SuinsRegistration` object @@ -301,15 +300,15 @@ module subdomains::subdomains { check_creation_auth: bool ) { // validate that parent is a valid, non expired object. - registry::assert_nft_is_authorized(registry(suins), parent, clock); + registry(suins).assert_nft_is_authorized(parent, clock); if (check_creation_auth) { // validate that the parent can create subdomains. - internal_assert_parent_can_create_subdomains(suins, suins_registration::domain(parent)); + internal_assert_parent_can_create_subdomains(suins, parent.domain()); }; // validate that the subdomain is valid for the supplied parent. - config::assert_is_valid_subdomain(&suins_registration::domain(parent), &subdomain, &app_config(suins).config); + config::assert_is_valid_subdomain(&parent.domain(), &subdomain, &app_config(suins).config); } /// Validate whether a `SuinsRegistration` object is eligible for creating a subdomain. @@ -341,21 +340,21 @@ module subdomains::subdomains { clock: &Clock, ctx: &mut TxContext, ): SubDomainRegistration { - let mut nft = registry::add_record_ignoring_grace_period(registry, subdomain, 1, clock, ctx); + let mut nft = registry.add_record_ignoring_grace_period(subdomain, 1, clock, ctx); // set the timestamp to the correct one. `add_record` only works with years but we can correct it easily here. - registry::set_expiration_timestamp_ms(registry, &mut nft, subdomain, expiration_timestamp_ms); + registry.set_expiration_timestamp_ms(&mut nft, subdomain, expiration_timestamp_ms); // attach the `ParentID` to the SuinsRegistration, so we validate that the parent who created this subdomain // is the same as the one currently holding the parent domain. - df::add(suins_registration::uid_mut(&mut nft), ParentKey {}, parent_nft_id); + df::add(nft.uid_mut(), ParentKey {}, parent_nft_id); - registry::wrap_subdomain(registry, nft, clock, ctx) + registry.wrap_subdomain(nft, clock, ctx) } // == Internal helper to access registry & app setup == fun registry(suins: &SuiNS): &Registry { - suins::registry(suins) + suins.registry() } fun registry_mut(suins: &mut SuiNS): &mut Registry { @@ -363,7 +362,7 @@ module subdomains::subdomains { } fun app_config(suins: &SuiNS): &App { - suins::registry(suins) + suins.registry() } #[test_only] From eae1f9fc502b1923611ab6ea1aeca4c9e8ba1316 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 17:03:01 -0400 Subject: [PATCH 18/38] subdomain proxy --- .../temp_subdomain_proxy/sources/subdomain_proxy.move | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/temp_subdomain_proxy/sources/subdomain_proxy.move b/packages/temp_subdomain_proxy/sources/subdomain_proxy.move index 1a5dbc4a..1310ef7d 100644 --- a/packages/temp_subdomain_proxy/sources/subdomain_proxy.move +++ b/packages/temp_subdomain_proxy/sources/subdomain_proxy.move @@ -15,7 +15,7 @@ module temp_subdomain_proxy::subdomain_proxy { use sui::clock::Clock; use suins::suins::SuiNS; - use suins::subdomain_registration::{Self, SubDomainRegistration}; + use suins::subdomain_registration::SubDomainRegistration; use subdomains::subdomains; use utils::direct_setup; @@ -32,7 +32,7 @@ module temp_subdomain_proxy::subdomain_proxy { ): SubDomainRegistration { subdomains::new( suins, - subdomain_registration::nft(subdomain), + subdomain.nft(), clock, subdomain_name, expiration_timestamp_ms, @@ -52,7 +52,7 @@ module temp_subdomain_proxy::subdomain_proxy { ){ subdomains::new_leaf( suins, - subdomain_registration::nft(subdomain), + subdomain.nft(), clock, subdomain_name, target, @@ -68,7 +68,7 @@ module temp_subdomain_proxy::subdomain_proxy { ) { subdomains::remove_leaf( suins, - subdomain_registration::nft(subdomain), + subdomain.nft(), clock, subdomain_name, ); @@ -82,7 +82,7 @@ module temp_subdomain_proxy::subdomain_proxy { ) { direct_setup::set_target_address( suins, - subdomain_registration::nft(subdomain), + subdomain.nft(), new_target, clock, ); From 9e62b89db6706d26ffa00b64694d75f13f5db929 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Fri, 29 Mar 2024 17:13:46 -0400 Subject: [PATCH 19/38] utils --- packages/utils/sources/direct_setup.move | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/utils/sources/direct_setup.move b/packages/utils/sources/direct_setup.move index f589f222..a8027de9 100644 --- a/packages/utils/sources/direct_setup.move +++ b/packages/utils/sources/direct_setup.move @@ -11,9 +11,9 @@ module utils::direct_setup { use sui::clock::Clock; use suins::domain; - use suins::registry::{Self, Registry}; + use suins::registry::Registry; use suins::suins::{Self, SuiNS}; - use suins::suins_registration::{Self as nft, SuinsRegistration}; + use suins::suins_registration::SuinsRegistration; /// Authorization token for the controller. public struct DirectSetup has drop {} @@ -26,16 +26,16 @@ module utils::direct_setup { clock: &Clock, ) { let registry = suins::app_registry_mut(DirectSetup {}, suins); - registry::assert_nft_is_authorized(registry, nft, clock); + registry.assert_nft_is_authorized(nft, clock); - let domain = nft::domain(nft); - registry::set_target_address(registry, domain, option::some(new_target)); + let domain = nft.domain(); + registry.set_target_address(domain, option::some(new_target)); } /// Set the reverse lookup address for the domain public fun set_reverse_lookup(suins: &mut SuiNS, domain_name: String, ctx: &TxContext) { let domain = domain::new(domain_name); let registry = suins::app_registry_mut(DirectSetup {}, suins); - registry::set_reverse_lookup(registry, sender(ctx), domain); + registry.set_reverse_lookup(sender(ctx), domain); } } From 5d30df43d1649ca9f671c112890fda4d6ffa4a8b Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Mon, 1 Apr 2024 13:17:44 -0400 Subject: [PATCH 20/38] part 1 suins --- .../suins/sources/actions/update_image.move | 28 +++---- packages/suins/sources/admin.move | 8 +- packages/suins/sources/auction.move | 84 +++++++++---------- packages/suins/sources/config.move | 10 +-- packages/suins/sources/controller.move | 38 ++++----- packages/suins/sources/domain.move | 50 +++++------ packages/suins/tests/auction_tests.move | 1 - 7 files changed, 109 insertions(+), 110 deletions(-) diff --git a/packages/suins/sources/actions/update_image.move b/packages/suins/sources/actions/update_image.move index b3a882c4..941cc953 100644 --- a/packages/suins/sources/actions/update_image.move +++ b/packages/suins/sources/actions/update_image.move @@ -32,23 +32,23 @@ module suins::update_image { signature: vector, clock: &Clock, ) { - suins::assert_app_is_authorized(suins); - let registry = suins::registry(suins); - registry::assert_nft_is_authorized(registry, nft, clock); + suins.assert_app_is_authorized(); + let registry = suins.registry(); + registry.assert_nft_is_authorized(nft, clock); - let config = suins::get_config(suins); + let config = suins.get_config(); assert!( - ecdsa_k1::secp256k1_verify(&signature, config::public_key(config), &raw_msg, 1), + ecdsa_k1::secp256k1_verify(&signature, config.public_key(), &raw_msg, 1), ESignatureNotMatch ); let (ipfs_hash, domain_name, expiration_timestamp_ms, _data) = image_data_from_bcs(raw_msg); - assert!(nft::expiration_timestamp_ms(nft) == expiration_timestamp_ms, EInvalidData); - assert!(domain::to_string(&nft::domain(nft)) == domain_name, EInvalidDomainData); + assert!(nft.expiration_timestamp_ms() == expiration_timestamp_ms, EInvalidData); + assert!(nft.domain().to_string() == domain_name, EInvalidDomainData); - nft::update_image_url(nft, ipfs_hash); + nft.update_image_url(ipfs_hash); // TODO emit an event // event::emit(ImageUpdatedEvent { @@ -71,13 +71,13 @@ module suins::update_image { fun image_data_from_bcs(msg_bytes: vector): (String, String, u64, String) { let mut bcs = bcs::new(msg_bytes); - let ipfs_hash = utf8(bcs::peel_vec_u8(&mut bcs)); - let domain_name = utf8(bcs::peel_vec_u8(&mut bcs)); - let expiration_timestamp_ms = bcs::peel_u64(&mut bcs); - let data = utf8(bcs::peel_vec_u8(&mut bcs)); + let ipfs_hash = utf8(bcs.peel_vec_u8()); + let domain_name = utf8(bcs.peel_vec_u8()); + let expiration_timestamp_ms = bcs.peel_u64(); + let data = utf8(bcs.peel_vec_u8()); - let remainder = bcs::into_remainder_bytes(bcs); - vector::destroy_empty(remainder); + let remainder = bcs.into_remainder_bytes(); + remainder.destroy_empty(); ( ipfs_hash, diff --git a/packages/suins/sources/admin.move b/packages/suins/sources/admin.move index e6960758..77158ddd 100644 --- a/packages/suins/sources/admin.move +++ b/packages/suins/sources/admin.move @@ -37,7 +37,7 @@ module suins::admin { let domain = domain::new(domain_name); config::assert_valid_user_registerable_domain(&domain); let registry = suins::app_registry_mut(Admin {}, suins); - registry::add_record(registry, domain, no_years, clock, ctx) + registry.add_record(domain, no_years, clock, ctx) } /// Reserve a list of domains. @@ -51,10 +51,10 @@ module suins::admin { ) { let sender = sender(ctx); let registry = suins::app_registry_mut(Admin {}, suins); - while (!vector::is_empty(&domains)) { - let domain = domain::new(vector::pop_back(&mut domains)); + while (!domains.is_empty()) { + let domain = domain::new(domains.pop_back()); config::assert_valid_user_registerable_domain(&domain); - let nft = registry::add_record(registry, domain, no_years, clock, ctx); + let nft = registry.add_record(domain, no_years, clock, ctx); sui::transfer::public_transfer(nft, sender); }; } diff --git a/packages/suins/sources/auction.move b/packages/suins/sources/auction.move index 8d97a320..ec198251 100644 --- a/packages/suins/sources/auction.move +++ b/packages/suins/sources/auction.move @@ -82,30 +82,30 @@ module suins::auction { clock: &Clock, ctx: &mut TxContext, ) { - suins::assert_app_is_authorized(suins); + suins.assert_app_is_authorized(); let domain = domain::new(domain_name); // make sure the domain is a .sui domain and not a subdomain config::assert_valid_user_registerable_domain(&domain); - assert!(!linked_table::contains(&self.auctions, domain), EAuctionStarted); + assert!(!self.auctions.contains(domain), EAuctionStarted); // The minimum price only applies to newly created auctions - let config = suins::get_config(suins); - let label = domain::sld(&domain); - let min_price = config::calculate_price(config, (string::length(label) as u8), DEFAULT_DURATION); - assert!(coin::value(&bid) >= min_price, EInvalidBidValue); + let config = suins.get_config(); + let label = domain.sld(); + let min_price = config.calculate_price((label.length() as u8), DEFAULT_DURATION); + assert!(bid.value() >= min_price, EInvalidBidValue); let registry = suins::app_registry_mut(App {}, suins); - let nft = registry::add_record(registry, domain, DEFAULT_DURATION, clock, ctx); - let starting_bid = coin::value(&bid); + let nft = registry.add_record(domain, DEFAULT_DURATION, clock, ctx); + let starting_bid = bid.value(); let auction = Auction { domain, - start_timestamp_ms: clock::timestamp_ms(clock), - end_timestamp_ms: clock::timestamp_ms(clock) + AUCTION_BIDDING_PERIOD_MS, - winner: tx_context::sender(ctx), + start_timestamp_ms: clock.timestamp_ms(), + end_timestamp_ms: clock.timestamp_ms() + AUCTION_BIDDING_PERIOD_MS, + winner: ctx.sender(), current_bid: bid, nft, }; @@ -118,7 +118,7 @@ module suins::auction { bidder: auction.winner, }); - linked_table::push_front(&mut self.auctions, domain, auction) + self.auctions.push_front(domain, auction) } /// #### Notice @@ -136,9 +136,9 @@ module suins::auction { ctx: &mut TxContext ) { let domain = domain::new(domain_name); - let bidder = tx_context::sender(ctx); + let bidder = ctx.sender(); - assert!(linked_table::contains(&self.auctions, domain), EAuctionNotStarted); + assert!(self.auctions.contains(domain), EAuctionNotStarted); let Auction { domain, @@ -147,16 +147,16 @@ module suins::auction { winner, current_bid, nft, - } = linked_table::remove(&mut self.auctions, domain); + } = self.auctions.remove(domain); // Ensure that the auction is not over - assert!(clock::timestamp_ms(clock) <= end_timestamp_ms, EAuctionEnded); + assert!(clock.timestamp_ms() <= end_timestamp_ms, EAuctionEnded); // Ensure the bidder isn't already the winner assert!(bidder != winner, EWinnerCannotPlaceBid); // get the current highest bid and ensure that the new bid is greater than the current winning bid - let current_winning_bid = coin::value(¤t_bid); - let bid_amount = coin::value(&bid); + let current_winning_bid = current_bid.value(); + let bid_amount = bid.value(); assert!(bid_amount > current_winning_bid, EBidAmountTooLow); // Return the previous winner their bid @@ -172,12 +172,12 @@ module suins::auction { // then extend the auction so that there is `AUCTION_MIN_QUIET_PERIOD_MS` left. // Auctions can't be finished until there is at least `AUCTION_MIN_QUIET_PERIOD_MS` // time where there are no bids. - if (end_timestamp_ms - clock::timestamp_ms(clock) < AUCTION_MIN_QUIET_PERIOD_MS) { - let new_end_timestamp_ms = clock::timestamp_ms(clock) + AUCTION_MIN_QUIET_PERIOD_MS; + if (end_timestamp_ms - clock.timestamp_ms() < AUCTION_MIN_QUIET_PERIOD_MS) { + let new_end_timestamp_ms = clock.timestamp_ms() + AUCTION_MIN_QUIET_PERIOD_MS; // Only extend the auction if the new auction end time is before // the NFT's expiration timestamp - if (new_end_timestamp_ms < nft::expiration_timestamp_ms(&nft)) { + if (new_end_timestamp_ms < nft.expiration_timestamp_ms()) { end_timestamp_ms = new_end_timestamp_ms; event::emit(AuctionExtendedEvent { @@ -196,7 +196,7 @@ module suins::auction { nft, }; - linked_table::push_front(&mut self.auctions, domain, auction); + self.auctions.push_front(domain, auction); } /// #### Notice @@ -219,13 +219,13 @@ module suins::auction { winner, current_bid, nft, - } = linked_table::remove(&mut self.auctions, domain); + } = self.auctions.remove(domain); // Ensure that the auction is over - assert!(clock::timestamp_ms(clock) > end_timestamp_ms, EAuctionNotEndedYet); + assert!(clock.timestamp_ms() > end_timestamp_ms, EAuctionNotEndedYet); // Ensure the sender is the winner - assert!(tx_context::sender(ctx) == winner, ENotWinner); + assert!(ctx.sender() == winner, ENotWinner); event::emit(AuctionFinalizedEvent { domain, @@ -237,7 +237,7 @@ module suins::auction { // Extract the NFT and their bid, returning the NFT to the user // and sending the proceeds of the auction to suins - balance::join(&mut self.balance, coin::into_balance(current_bid)); + self.balance.join(current_bid.into_balance()); nft } @@ -257,9 +257,9 @@ module suins::auction { ): (Option, Option, Option
, Option) { let domain = domain::new(domain_name); - if (linked_table::contains(&self.auctions, domain)) { - let auction = linked_table::borrow(&self.auctions, domain); - let highest_amount = coin::value(&auction.current_bid); + if (self.auctions.contains(domain)) { + let auction = self.auctions.borrow(domain); + let highest_amount = auction.current_bid.value(); return ( some(auction.start_timestamp_ms), some(auction.end_timestamp_ms), @@ -277,12 +277,12 @@ module suins::auction { ctx: &mut TxContext, ) { let domain = domain::new(domain_name); - let auction = linked_table::borrow_mut(&mut self.auctions, domain); + let auction = self.auctions.borrow_mut(domain); // Ensure that the auction is over - assert!(clock::timestamp_ms(clock) > auction.end_timestamp_ms, EAuctionNotEndedYet); + assert!(clock.timestamp_ms() > auction.end_timestamp_ms, EAuctionNotEndedYet); - let amount = coin::value(&mut auction.current_bid); - balance::join(&mut self.balance, coin::into_balance(coin::split(&mut auction.current_bid, amount, ctx))); + let amount = auction.current_bid.value(); + self.balance.join(auction.current_bid.split(amount, ctx).into_balance()); } // === Admin Functions === @@ -292,7 +292,7 @@ module suins::auction { self: &mut AuctionHouse, ctx: &mut TxContext, ): Coin { - let amount = balance::value(&self.balance); + let amount = self.balance.value(); assert!(amount > 0, ENoProfits); coin::take(&mut self.balance, amount, ctx) } @@ -335,10 +335,10 @@ module suins::auction { winner, current_bid, nft, - } = linked_table::remove(&mut self.auctions, domain); + } = self.auctions.remove(domain); // Ensure that the auction is over - assert!(clock::timestamp_ms(clock) > end_timestamp_ms, EAuctionNotEndedYet); + assert!(clock.timestamp_ms() > end_timestamp_ms, EAuctionNotEndedYet); event::emit(AuctionFinalizedEvent { domain, @@ -348,7 +348,7 @@ module suins::auction { winner, }); - balance::join(&mut self.balance, coin::into_balance(current_bid)); + self.balance.join(current_bid.into_balance()); transfer::public_transfer(nft, winner); } @@ -364,7 +364,7 @@ module suins::auction { mut operation_limit: u64, clock: &Clock, ) { - let mut next_domain = *linked_table::back(&self.auctions); + let mut next_domain = *self.auctions.back(); while (is_some(&next_domain)) { if (operation_limit == 0) { @@ -373,12 +373,12 @@ module suins::auction { operation_limit = operation_limit - 1; let domain = option::extract(&mut next_domain); - next_domain = *linked_table::prev(&self.auctions, domain); + next_domain = *self.auctions.prev(domain); - let auction = linked_table::borrow(&self.auctions, domain); + let auction = self.auctions.borrow(domain); // If the auction has ended, then try to finalize it - if (clock::timestamp_ms(clock) > auction.end_timestamp_ms) { + if (clock.timestamp_ms() > auction.end_timestamp_ms) { admin_finalize_auction_internal( admin, self, @@ -431,6 +431,6 @@ module suins::auction { #[test_only] public fun total_balance(self: &AuctionHouse): u64 { - balance::value(&self.balance) + self.balance.value() } } diff --git a/packages/suins/sources/config.move b/packages/suins/sources/config.move index 1e93be3d..9f7df30b 100644 --- a/packages/suins/sources/config.move +++ b/packages/suins/sources/config.move @@ -56,7 +56,7 @@ module suins::config { four_char_price: u64, five_plus_char_price: u64, ): Config { - assert!(vector::length(&public_key) == 33, EInvalidPublicKey); + assert!(public_key.length() == 33, EInvalidPublicKey); Config { public_key, @@ -70,7 +70,7 @@ module suins::config { /// Change the value of the `public_key` field. public fun set_public_key(self: &mut Config, value: vector) { - assert!(vector::length(&value) == 33, EInvalidPublicKey); + assert!(value.length() == 33, EInvalidPublicKey); self.public_key = value; } @@ -133,9 +133,9 @@ module suins::config { /// - only has 1 label, "name", other than the TLD /// - "name" is >= 3 characters long public fun assert_valid_user_registerable_domain(domain: &Domain) { - assert!(domain::number_of_levels(domain) == 2, EInvalidDomain); - assert!(domain::tld(domain) == &constants::sui_tld(), EInvalidTld); - let length = string::length(domain::sld(domain)); + assert!(domain.number_of_levels() == 2, EInvalidDomain); + assert!(domain.tld() == &constants::sui_tld(), EInvalidTld); + let length = domain.sld().length(); assert!(length >= (constants::min_domain_length() as u64), ELabelTooShort); assert!(length <= (constants::max_domain_length() as u64), ELabelTooLong); } diff --git a/packages/suins/sources/controller.move b/packages/suins/sources/controller.move index 12ba9073..c34c0d10 100644 --- a/packages/suins/sources/controller.move +++ b/packages/suins/sources/controller.move @@ -32,23 +32,23 @@ module suins::controller { clock: &Clock, ) { let registry = suins::app_registry_mut(Controller {}, suins); - registry::assert_nft_is_authorized(registry, nft, clock); + registry.assert_nft_is_authorized(nft, clock); - let domain = nft::domain(nft); - registry::set_target_address(registry, domain, new_target); + let domain = nft.domain(); + registry.set_target_address(domain, new_target); } /// User-facing function (upgradable) - set the reverse lookup address for the domain. entry fun set_reverse_lookup(suins: &mut SuiNS, domain_name: String, ctx: &TxContext) { let domain = domain::new(domain_name); let registry = suins::app_registry_mut(Controller {}, suins); - registry::set_reverse_lookup(registry, sender(ctx), domain); + registry.set_reverse_lookup(sender(ctx), domain); } /// User-facing function (upgradable) - unset the reverse lookup address for the domain. entry fun unset_reverse_lookup(suins: &mut SuiNS, ctx: &TxContext) { let registry = suins::app_registry_mut(Controller {}, suins); - registry::unset_reverse_lookup(registry, sender(ctx)); + registry.unset_reverse_lookup(sender(ctx)); } /// User-facing function (upgradable) - add a new key-value pair to the name record's data. @@ -57,19 +57,19 @@ module suins::controller { ) { let registry = suins::app_registry_mut(Controller {}, suins); - let mut data = *registry::get_data(registry, nft::domain(nft)); - let domain = nft::domain(nft); + let mut data = *registry.get_data(nft.domain()); + let domain = nft.domain(); - registry::assert_nft_is_authorized(registry, nft, clock); - let key_bytes = *string::bytes(&key); + registry.assert_nft_is_authorized(nft, clock); + let key_bytes = *key.bytes(); assert!(key_bytes == AVATAR || key_bytes == CONTENT_HASH, EUnsupportedKey); - if (vec_map::contains(&data, &key)) { - vec_map::remove(&mut data, &key); + if (data.contains(&key)) { + data.remove(&key); }; - vec_map::insert(&mut data, key, value); - registry::set_data(registry, domain, data); + data.insert(key, value); + registry.set_data(domain, data); } /// User-facing function (upgradable) - remove a key from the name record's data. @@ -77,16 +77,16 @@ module suins::controller { suins: &mut SuiNS, nft: &SuinsRegistration, key: String, clock: &Clock ) { let registry = suins::app_registry_mut(Controller {}, suins); - let mut data = *registry::get_data(registry, nft::domain(nft)); - let domain = nft::domain(nft); + let mut data = *registry.get_data(nft.domain()); + let domain = nft.domain(); - registry::assert_nft_is_authorized(registry, nft, clock); + registry.assert_nft_is_authorized(nft, clock); - if (vec_map::contains(&data, &key)) { - vec_map::remove(&mut data, &key); + if (data.contains(&key)) { + data.remove(&key); }; - registry::set_data(registry, domain, data); + registry.set_data(domain, data); } // === Testing === diff --git a/packages/suins/sources/domain.move b/packages/suins/sources/domain.move index e28172de..ac1b533f 100644 --- a/packages/suins/sources/domain.move +++ b/packages/suins/sources/domain.move @@ -30,11 +30,11 @@ module suins::domain { // Construct a `Domain` by parsing and validating the provided string public fun new(domain: String): Domain { - assert!(string::length(&domain) <= MAX_DOMAIN_LENGTH, EInvalidDomain); + assert!(domain.length() <= MAX_DOMAIN_LENGTH, EInvalidDomain); let mut labels = split_by_dot(domain); validate_labels(&labels); - vector::reverse(&mut labels); + labels.reverse(); Domain { labels } @@ -43,17 +43,17 @@ module suins::domain { /// Converts a domain into a fully-qualified string representation. public fun to_string(self: &Domain): String { let dot = utf8(b"."); - let len = vector::length(&self.labels); + let len = self.labels.length(); let mut i = 0; let mut out = string::utf8(vector::empty()); while (i < len) { - let part = vector::borrow(&self.labels, (len - i) - 1); - string::append(&mut out, *part); + let part = self.labels.borrow((len - i) - 1); + out.append(*part); i = i + 1; if (i != len) { - string::append(&mut out, dot); + out.append(dot); } }; @@ -69,7 +69,7 @@ module suins::domain { /// /// This means that the TLD will always be at level `0`. public fun label(self: &Domain, level: u64): &String { - vector::borrow(&self.labels, level) + self.labels.borrow(level) } /// Returns the TLD (Top-Level Domain) of a `Domain`. @@ -87,7 +87,7 @@ module suins::domain { } public fun number_of_levels(self: &Domain): u64 { - vector::length(&self.labels) + self.labels.length() } public fun is_subdomain(domain: &Domain): bool { @@ -99,7 +99,7 @@ module suins::domain { public fun parent(domain: &Domain): Domain { let mut labels = domain.labels; // we pop the last element and construct the parent from the remaining labels. - vector::pop_back(&mut labels); + labels.pop_back(); Domain { labels @@ -113,21 +113,21 @@ module suins::domain { } fun validate_labels(labels: &vector) { - assert!(!vector::is_empty(labels), EInvalidDomain); + assert!(!labels.is_empty(), EInvalidDomain); - let len = vector::length(labels); + let len = labels.length(); let mut index = 0; while (index < len) { - let label = vector::borrow(labels, index); + let label = labels.borrow(index); assert!(is_valid_label(label), EInvalidDomain); index = index + 1; } } fun is_valid_label(label: &String): bool { - let len = string::length(label); - let label_bytes = string::bytes(label); + let len = label.length(); + let label_bytes = label.bytes(); let mut index = 0; if (!(len >= MIN_LABEL_LENGTH && len <= MAX_LABEL_LENGTH)) { @@ -135,7 +135,7 @@ module suins::domain { }; while (index < len) { - let character = *vector::borrow(label_bytes, index); + let character = *label_bytes.borrow(index); let is_valid_character = (0x61 <= character && character <= 0x7A) // a-z || (0x30 <= character && character <= 0x39) // 0-9 @@ -155,19 +155,19 @@ module suins::domain { fun split_by_dot(mut s: String): vector { let dot = utf8(b"."); let mut parts: vector = vector[]; - while (!string::is_empty(&s)) { - let index_of_next_dot = string::index_of(&s, &dot); - let part = string::sub_string(&s, 0, index_of_next_dot); - vector::push_back(&mut parts, part); + while (!s.is_empty()) { + let index_of_next_dot = s.index_of(&dot); + let part = s.sub_string(0, index_of_next_dot); + parts.push_back(part); - let len = string::length(&s); + let len = s.length(); let start_of_next_part = if (index_of_next_dot == len) { len } else { index_of_next_dot + 1 }; - s = string::sub_string(&s, start_of_next_part, len); + s = s.sub_string(start_of_next_part, len); }; parts @@ -191,7 +191,7 @@ module suins::domain { let mut index = 0; while (index < len) { - let label = vector::borrow(&expected_labels, index); + let label = expected_labels.borrow(index); assert_eq(*label, *label(&domain, index)); index = index + 1; } @@ -200,9 +200,9 @@ module suins::domain { #[test_only] fun prep_expected_labels(mut labels: vector>): vector { let mut out = vector[]; - while (!vector::is_empty(&labels)) { - let label = vector::pop_back(&mut labels); - vector::push_back(&mut out, utf8(label)); + while (!labels.is_empty()) { + let label = labels.pop_back(); + out.push_back(utf8(label)); }; out } diff --git a/packages/suins/tests/auction_tests.move b/packages/suins/tests/auction_tests.move index 9a3d5ad6..63110674 100644 --- a/packages/suins/tests/auction_tests.move +++ b/packages/suins/tests/auction_tests.move @@ -29,7 +29,6 @@ module suins::auction_tests { const FIRST_DOMAIN_NAME: vector = b"tes-t2.sui"; const SECOND_DOMAIN_NAME: vector = b"tesq.sui"; const AUCTION_BIDDING_PERIOD_MS: u64 = 2 * 24 * 60 * 60 * 1000; - const AUCTION_MIN_QUIET_PERIOD_MS: u64 = 10 * 60 * 1000; // 10 minutes of quiet time public fun test_init(): Scenario { let mut scenario_val = test_scenario::begin(SUINS_ADDRESS); From f3114d2f344d1fe5f4cc64d15ef499549c93114d Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Mon, 1 Apr 2024 14:24:09 -0400 Subject: [PATCH 21/38] move part 2 --- packages/suins/sources/registry.move | 120 +++++++++--------- .../suins/sources/subdomain_registration.move | 6 +- packages/suins/sources/suins.move | 6 +- .../suins/sources/suins_registration.move | 2 +- 4 files changed, 67 insertions(+), 67 deletions(-) diff --git a/packages/suins/sources/registry.move b/packages/suins/sources/registry.move index 1f8e680a..adb66ec2 100644 --- a/packages/suins/sources/registry.move +++ b/packages/suins/sources/registry.move @@ -91,22 +91,22 @@ module suins::registry { clock: &Clock ) { // First we make sure that the SuinsRegistration object has expired. - assert!(nft::has_expired(&nft, clock), ERecordNotExpired); + assert!(nft.has_expired(clock), ERecordNotExpired); - let domain = nft::domain(&nft); + let domain = nft.domain(); // Then, if the registry still has a record for this domain and the NFT ID matches, we remove it. - if (table::contains(&self.registry, domain)) { + if (self.registry.contains(domain)) { - let record = table::borrow(&self.registry, domain); + let record = self.registry.borrow(domain); // We wanna remove the record only if the NFT ID matches. - if (name_record::nft_id(record) == object::id(&nft)) { - let record = table::remove(&mut self.registry, domain); - handle_invalidate_reverse_record(self, &domain, name_record::target_address(&record), none()); + if (record.nft_id() == object::id(&nft)) { + let record = self.registry.remove(domain); + handle_invalidate_reverse_record(self, &domain, record.target_address(), none()); } }; // burn the NFT. - nft::burn(nft); + nft.burn(); } /// Allow creation of subdomain wrappers only to authorized modules. @@ -126,7 +126,7 @@ module suins::registry { nft: SubDomainRegistration, clock: &Clock ) { - let nft = subdomain_registration::burn(nft, clock); + let nft = nft.burn(clock); burn_registration_object(self, nft, clock); } @@ -149,10 +149,10 @@ module suins::registry { target: address, _ctx: &mut TxContext ) { - assert!(domain::is_subdomain(&domain), EInvalidDepth); + assert!(domain.is_subdomain(), EInvalidDepth); // get the parent of the domain - let parent = domain::parent(&domain); + let parent = domain.parent(); let option_parent_name_record = lookup(self, parent); assert!(option::is_some(&option_parent_name_record), ERecordNotFound); @@ -162,13 +162,13 @@ module suins::registry { // Make sure that the parent isn't expired (because leaf record is invalid in that case). // Ignores grace period is it's only there so you don't accidently forget to renew your name. - assert!(!name_record::has_expired(parent_name_record, clock), ERecordExpired); + assert!(!parent_name_record.has_expired(clock), ERecordExpired); // Removes an existing record if it exists and is expired. remove_existing_record_if_exists_and_expired(self, domain, clock, false); // adds the `leaf` record to the registry. - table::add(&mut self.registry, domain, name_record::new_leaf(name_record::nft_id(parent_name_record), some(target))); + self.registry.add(domain, name_record::new_leaf(parent_name_record.nft_id(), some(target))); } /// Can be used to remove a leaf record. @@ -183,8 +183,8 @@ module suins::registry { // if it's a leaf record, there's no `SuinsRegistration` object. // We can just go ahead and remove the name_record, and invalidate the reverse record (if any). - let record = table::remove(&mut self.registry, domain); - let old_target_address = name_record::target_address(&record); + let record = self.registry.remove(domain); + let old_target_address = record.target_address(); handle_invalidate_reverse_record(self, &domain, old_target_address, none()); } @@ -194,15 +194,15 @@ module suins::registry { domain: Domain, new_target: Option
, ) { - let record = table::borrow_mut(&mut self.registry, domain); - let old_target = name_record::target_address(record); + let record = self.registry.borrow_mut(domain); + let old_target = record.target_address(); - name_record::set_target_address(record, new_target); + record.set_target_address(new_target); handle_invalidate_reverse_record(self, &domain, old_target, new_target); } public fun unset_reverse_lookup(self: &mut Registry, address: address) { - table::remove(&mut self.reverse_registry, address); + self.reverse_registry.remove(address); } /// Reverse lookup can only be set for the record that has the target address. @@ -211,16 +211,16 @@ module suins::registry { address: address, domain: Domain, ) { - let record = table::borrow(&self.registry, domain); - let target = name_record::target_address(record); + let record = self.registry.borrow(domain); + let target = record.target_address(); assert!(option::is_some(&target), ETargetNotSet); assert!(some(address) == target, ERecordMismatch); - if (table::contains(&self.reverse_registry, address)) { - *table::borrow_mut(&mut self.reverse_registry, address) = domain; + if (self.reverse_registry.contains(address)) { + *self.reverse_registry.borrow_mut(address) = domain; } else { - table::add(&mut self.reverse_registry, address, domain); + self.reverse_registry.add(address, domain); }; } @@ -235,9 +235,9 @@ module suins::registry { ) { let record = table::borrow_mut(&mut self.registry, domain); - assert!(object::id(nft) == name_record::nft_id(record), EIdMismatch); - name_record::set_expiration_timestamp_ms(record, expiration_timestamp_ms); - nft::set_expiration_timestamp_ms(nft, expiration_timestamp_ms); + assert!(object::id(nft) == record.nft_id(), EIdMismatch); + record.set_expiration_timestamp_ms(expiration_timestamp_ms); + nft.set_expiration_timestamp_ms(expiration_timestamp_ms); } /// Update the `data` of the given `NameRecord` using a `SuinsRegistration`. @@ -248,21 +248,21 @@ module suins::registry { domain: Domain, data: VecMap ) { - let record = table::borrow_mut(&mut self.registry, domain); - name_record::set_data(record, data); + let record = self.registry.borrow_mut(domain); + record.set_data(data); } // === Reads === /// Check whether the given `domain` is registered in the `Registry`. public fun has_record(self: &Registry, domain: Domain): bool { - table::contains(&self.registry, domain) + self.registry.contains(domain) } /// Returns the `NameRecord` associated with the given domain or None. public fun lookup(self: &Registry, domain: Domain): Option { - if (table::contains(&self.registry, domain)) { - let record = table::borrow(&self.registry, domain); + if (self.registry.contains(domain)) { + let record = self.registry.borrow(domain); some(*record) } else { none() @@ -272,7 +272,7 @@ module suins::registry { /// Returns the `domain_name` associated with the given address or None. public fun reverse_lookup(self: &Registry, address: address): Option { if (table::contains(&self.reverse_registry, address)) { - some(*table::borrow(&self.reverse_registry, address)) + some(*self.reverse_registry.borrow(address)) } else { none() } @@ -282,19 +282,19 @@ module suins::registry { /// 1. Matches the ID in the corresponding `Record` /// 2. Has not expired (does not take into account the grace period) public fun assert_nft_is_authorized(self: &Registry, nft: &SuinsRegistration, clock: &Clock) { - let domain = nft::domain(nft); - let record = table::borrow(&self.registry, domain); + let domain = nft.domain(); + let record = self.registry.borrow(domain); // The NFT does not - assert!(object::id(nft) == name_record::nft_id(record), EIdMismatch); - assert!(!name_record::has_expired(record, clock), ERecordExpired); - assert!(!nft::has_expired(nft, clock), ENftExpired); + assert!(object::id(nft) == record.nft_id(), EIdMismatch); + assert!(!record.has_expired(clock), ERecordExpired); + assert!(!nft.has_expired(clock), ENftExpired); } /// Returns the `data` associated with the given `Domain`. public fun get_data(self: &Registry, domain: Domain): &VecMap { - let record = table::borrow(&self.registry, domain); - name_record::data(record) + let record = self.registry.borrow(domain); + record.data() } // === Private Functions === @@ -309,7 +309,7 @@ module suins::registry { self: &Registry, domain: Domain ): bool { - if (!domain::is_subdomain(&domain)) { + if (!domain.is_subdomain()) { return false }; @@ -319,7 +319,7 @@ module suins::registry { return false }; - name_record::is_leaf_record(option::borrow(&option_name_record)) + option_name_record.borrow().is_leaf_record() } /// An internal helper to add a record @@ -336,8 +336,8 @@ module suins::registry { // If we've made it to this point then we know that we are able to // register an entry for this domain. let nft = nft::new(domain, no_years, clock, ctx); - let name_record = name_record::new(object::id(&nft), nft::expiration_timestamp_ms(&nft)); - table::add(&mut self.registry, domain, name_record); + let name_record = name_record::new(object::id(&nft), nft.expiration_timestamp_ms()); + self.registry.add(domain, name_record); nft } @@ -348,15 +348,15 @@ module suins::registry { with_grace_period: bool, ) { // if the domain is not part of the registry, we can override. - if (!table::contains(&self.registry, domain)) return; + if (!self.registry.contains(domain)) return; // Remove the record and assert that it has expired (past the grace period if applicable) - let record = table::remove(&mut self.registry, domain); + let record = self.registry.remove(domain); // Special case for leaf records, we can override them iff their parent has changed or has expired. - if (name_record::is_leaf_record(&record)) { + if (record.is_leaf_record()) { // find the parent of the leaf record. - let option_parent_name_record = lookup(self, domain::parent(&domain)); + let option_parent_name_record = lookup(self, domain.parent()); // if there's a parent (if not, we can just remove it), we need to check if the parent is valid. // -> If the parent is valid, we need to check if the parent is expired. @@ -366,17 +366,17 @@ module suins::registry { // If the parent is the same and hasn't expired, we can't override the leaf record like this. // We need to first remove + then call create (to protect accidental overrides). - if (name_record::nft_id(parent_name_record) == name_record::nft_id(&record)) { - assert!(name_record::has_expired(parent_name_record, clock), ERecordNotExpired); + if (parent_name_record.nft_id() == record.nft_id()) { + assert!(parent_name_record.has_expired(clock), ERecordNotExpired); }; } }else if (with_grace_period) { - assert!(name_record::has_expired_past_grace_period(&record, clock), ERecordNotExpired); + assert!(record.has_expired_past_grace_period(clock), ERecordNotExpired); } else { - assert!(name_record::has_expired(&record, clock), ERecordNotExpired); + assert!(record.has_expired(clock), ERecordNotExpired); }; - let old_target_address = name_record::target_address(&record); + let old_target_address = record.target_address(); handle_invalidate_reverse_record(self, &domain, old_target_address, none()); } @@ -398,9 +398,9 @@ module suins::registry { let reverse_registry = &mut self.reverse_registry; if (table::contains(reverse_registry, old_target_address)) { - let default_domain = table::borrow(reverse_registry, old_target_address); + let default_domain = reverse_registry.borrow(old_target_address); if (default_domain == domain) { - table::remove(reverse_registry, old_target_address); + reverse_registry.remove(old_target_address); } }; } @@ -427,7 +427,7 @@ module suins::registry { self: &mut Registry, domain: Domain, ): NameRecord { - table::remove(&mut self.registry, domain) + self.registry.remove(domain) } #[test_only] @@ -437,8 +437,8 @@ module suins::registry { reverse_registry, } = self; - table::destroy_empty(registry); - table::destroy_empty(reverse_registry); + registry.destroy_empty(); + reverse_registry.destroy_empty(); } #[test_only] @@ -448,7 +448,7 @@ module suins::registry { reverse_registry, } = self; - table::drop(registry); - table::drop(reverse_registry); + registry.drop(); + reverse_registry.drop(); } } diff --git a/packages/suins/sources/subdomain_registration.move b/packages/suins/sources/subdomain_registration.move index 5a28b601..56d91278 100644 --- a/packages/suins/sources/subdomain_registration.move +++ b/packages/suins/sources/subdomain_registration.move @@ -38,9 +38,9 @@ module suins::subdomain_registration { /// (as long as it's used for a subdomain). public(package) fun new(nft: SuinsRegistration, clock: &Clock, ctx: &mut TxContext): SubDomainRegistration { // Can't wrap a non-subdomain NFT. - assert!(domain::is_subdomain(&suins_registration::domain(&nft)), ENotSubdomain); + assert!(nft.domain().is_subdomain(), ENotSubdomain); // Can't wrap an expired NFT. - assert!(!suins_registration::has_expired(&nft, clock), EExpired); + assert!(!nft.has_expired(clock), EExpired); SubDomainRegistration { id: object::new(ctx), @@ -52,7 +52,7 @@ module suins::subdomain_registration { /// Fails if the subname is not expired. public(package) fun burn(name: SubDomainRegistration, clock: &Clock): SuinsRegistration { // tries to unwrap a non-expired subname. - assert!(suins_registration::has_expired(&name.nft, clock), ENameNotExpired); + assert!(name.nft.has_expired(clock), ENameNotExpired); let SubDomainRegistration { id, nft diff --git a/packages/suins/sources/suins.move b/packages/suins/sources/suins.move index 4b1e3993..feb40ddb 100644 --- a/packages/suins/sources/suins.move +++ b/packages/suins/sources/suins.move @@ -94,7 +94,7 @@ module suins::suins { /// transaction. This is useful for the admin to withdraw funds from the SuiNS /// and then send them somewhere specific or keep at the address. public fun withdraw(_: &AdminCap, self: &mut SuiNS, ctx: &mut TxContext): Coin { - let amount = balance::value(&self.balance); + let amount = self.balance.value(); assert!(amount > 0, ENoProfits); coin::take(&mut self.balance, amount, ctx) } @@ -134,7 +134,7 @@ module suins::suins { /// Adds balance to the SuiNS. public fun app_add_balance(_: App, self: &mut SuiNS, balance: Balance) { assert_app_is_authorized(self); - balance::join(&mut self.balance, balance); + self.balance.join(balance); } /// Get a mutable access to the `Registry` object. Can only be performed by authorized @@ -236,6 +236,6 @@ module suins::suins { #[test_only] public fun total_balance(self: &SuiNS): u64 { - balance::value(&self.balance) + self.balance.value() } } diff --git a/packages/suins/sources/suins_registration.move b/packages/suins/sources/suins_registration.move index a154753c..333421d9 100644 --- a/packages/suins/sources/suins_registration.move +++ b/packages/suins/sources/suins_registration.move @@ -47,7 +47,7 @@ module suins::suins_registration { ): SuinsRegistration { SuinsRegistration { id: object::new(ctx), - domain_name: domain::to_string(&domain), + domain_name: domain.to_string(), domain, expiration_timestamp_ms: timestamp_ms(clock) + ((no_years as u64) * constants::year_ms()), image_url: constants::default_image(), From f3486ace515ca0218f92f31b35f6c012d5b0dd80 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Mon, 1 Apr 2024 15:02:35 -0400 Subject: [PATCH 22/38] migration tests update --- packages/suins/tests/unit/admin_tests.move | 8 +- packages/suins/tests/unit/config_tests.move | 48 +++--- .../suins/tests/unit/name_record_tests.move | 44 +++--- .../tests/unit/registration_nft_tests.move | 28 ++-- packages/suins/tests/unit/registry_tests.move | 148 +++++++++--------- 5 files changed, 138 insertions(+), 138 deletions(-) diff --git a/packages/suins/tests/unit/admin_tests.move b/packages/suins/tests/unit/admin_tests.move index b5c5a4c5..a243c398 100644 --- a/packages/suins/tests/unit/admin_tests.move +++ b/packages/suins/tests/unit/admin_tests.move @@ -62,11 +62,11 @@ module suins::admin_tests { &mut ctx, ); - assert_eq(nft::domain(&nft), domain::new(utf8(b"test.sui"))); - assert_eq(nft::expiration_timestamp_ms(&nft), constants::year_ms()); + assert_eq(nft.domain(), domain::new(utf8(b"test.sui"))); + assert_eq(nft.expiration_timestamp_ms(), constants::year_ms()); - nft::burn_for_testing(nft); - clock::destroy_for_testing(clock); + nft.burn_for_testing(); + clock.destroy_for_testing(); suins::burn_admin_cap_for_testing(cap); suins::share_for_testing(suins); } diff --git a/packages/suins/tests/unit/config_tests.move b/packages/suins/tests/unit/config_tests.move index 193748d0..b8ae4fb8 100644 --- a/packages/suins/tests/unit/config_tests.move +++ b/packages/suins/tests/unit/config_tests.move @@ -23,22 +23,22 @@ module suins::config_tests { let mut config = default(); // check that the values are set correctly in the `new` function - assert!(config::public_key(&config) == &b"000000000000000000000000000000000", 0); - assert!(config::three_char_price(&config) == THREE, 0); - assert!(config::four_char_price(&config) == FOUR, 0); - assert!(config::five_plus_char_price(&config) == FIVE_PLUS, 0); + assert!(config.public_key() == &b"000000000000000000000000000000000", 0); + assert!(config.three_char_price() == THREE, 0); + assert!(config.four_char_price() == FOUR, 0); + assert!(config.five_plus_char_price() == FIVE_PLUS, 0); // update each of the values and make sure they are updated - config::set_public_key(&mut config, b"000000000000000000000000000000001"); - config::set_three_char_price(&mut config, 4_000_000_000); - config::set_four_char_price(&mut config, 3_000_000_000); - config::set_five_plus_char_price(&mut config, 1_000_000_000); + config.set_public_key(b"000000000000000000000000000000001"); + config.set_three_char_price(4_000_000_000); + config.set_four_char_price(3_000_000_000); + config.set_five_plus_char_price(1_000_000_000); // check that the updated values match the new ones - assert!(config::public_key(&config) == &b"000000000000000000000000000000001", 0); - assert!(config::three_char_price(&config) == 4_000_000_000, 0); - assert!(config::four_char_price(&config) == 3_000_000_000, 0); - assert!(config::five_plus_char_price(&config) == 1_000_000_000, 0); + assert!(config.public_key() == &b"000000000000000000000000000000001", 0); + assert!(config.three_char_price() == 4_000_000_000, 0); + assert!(config.four_char_price() == 3_000_000_000, 0); + assert!(config.five_plus_char_price() == 1_000_000_000, 0); } #[test] @@ -46,34 +46,34 @@ module suins::config_tests { let config = default(); // test each of the length ranges and 1 year duration - assert!(THREE == config::calculate_price(&config, 3, 1), 0); - assert!(FOUR == config::calculate_price(&config, 4, 1), 0); - assert!(FIVE_PLUS == config::calculate_price(&config, 5, 1), 0); - assert!(FIVE_PLUS == config::calculate_price(&config, 6, 1), 0); + assert!(THREE == config.calculate_price(3, 1), 0); + assert!(FOUR == config.calculate_price(4, 1), 0); + assert!(FIVE_PLUS == config.calculate_price(5, 1), 0); + assert!(FIVE_PLUS == config.calculate_price(6, 1), 0); // test each of the length ranges and 2 year duration - assert!(THREE * 2 == config::calculate_price(&config, 3, 2), 0); - assert!(FOUR * 2 == config::calculate_price(&config, 4, 2), 0); - assert!(FIVE_PLUS * 2 == config::calculate_price(&config, 5, 2), 0); - assert!(FIVE_PLUS * 2 == config::calculate_price(&config, 6, 2), 0); + assert!(THREE * 2 == config.calculate_price(3, 2), 0); + assert!(FOUR * 2 == config.calculate_price(4, 2), 0); + assert!(FIVE_PLUS * 2 == config.calculate_price(5, 2), 0); + assert!(FIVE_PLUS * 2 == config.calculate_price(6, 2), 0); } #[test] #[expected_failure(abort_code = suins::config::ENoYears)] fun calculate_price_years_fail() { - config::calculate_price(&default(), 3, 0); + default().calculate_price(3, 0); } #[test] #[expected_failure(abort_code = suins::config::ELabelTooShort)] fun calculate_price_length_min_fail() { - config::calculate_price(&default(), 2, 1); + default().calculate_price(2, 1); } #[test] #[expected_failure(abort_code = suins::config::ELabelTooLong)] fun calculate_price_length_max_fail() { - config::calculate_price(&default(), 255, 1); + default().calculate_price(255, 1); } #[test] @@ -89,7 +89,7 @@ module suins::config_tests { #[expected_failure(abort_code = suins::config::EInvalidPublicKey)] fun set_public_key_invalid_fail() { let mut config = default(); - config::set_public_key(&mut config, vector[]); + config.set_public_key(vector[]); } #[test] diff --git a/packages/suins/tests/unit/name_record_tests.move b/packages/suins/tests/unit/name_record_tests.move index 6f88bee7..11c0b285 100644 --- a/packages/suins/tests/unit/name_record_tests.move +++ b/packages/suins/tests/unit/name_record_tests.move @@ -29,25 +29,25 @@ module suins::name_record_tests { let mut record = record::new(nft_id, 0); // check default values - assert_eq(record::nft_id(&record), nft_id); - assert_eq(*record::data(&record), vec_map::empty()); - assert_eq(record::target_address(&record), none()); - assert_eq(record::expiration_timestamp_ms(&record), 0); + assert_eq(record.nft_id(), nft_id); + assert_eq(*record.data(), vec_map::empty()); + assert_eq(record.target_address(), none()); + assert_eq(record.expiration_timestamp_ms(), 0); let mut data = vec_map::empty(); - vec_map::insert(&mut data, utf8(b"user_name"), utf8(b"Brandon")); - vec_map::insert(&mut data, utf8(b"age"), utf8(b"forever young")); + data.insert(utf8(b"user_name"), utf8(b"Brandon")); + data.insert(utf8(b"age"), utf8(b"forever young")); // update values - record::set_data(&mut record, *&data); - record::set_target_address(&mut record, some(@suins)); - record::set_expiration_timestamp_ms(&mut record, 123456789); // 123456789 ms = 3.9 years + record.set_data(*&data); + record.set_target_address(some(@suins)); + record.set_expiration_timestamp_ms(123456789); // 123456789 ms = 3.9 years // check updated values - assert_eq(record::nft_id(&record), nft_id); - assert_eq(*record::data(&record), data); - assert_eq(record::target_address(&record), some(@suins)); - assert_eq(record::expiration_timestamp_ms(&record), 123456789); + assert_eq(record.nft_id(), nft_id); + assert_eq(*record.data(), data); + assert_eq(record.target_address(), some(@suins)); + assert_eq(record.expiration_timestamp_ms(), 123456789); } #[test] @@ -58,21 +58,21 @@ module suins::name_record_tests { let mut clock = clock::create_for_testing(&mut ctx); // clock is 0, record expires in 1 second with a 30 days (grace period) - assert_eq(record::has_expired(&record, &clock), false); - assert_eq(record::has_expired_past_grace_period(&record, &clock), false); + assert_eq(record.has_expired(&clock), false); + assert_eq(record.has_expired_past_grace_period(&clock), false); // increment time by 30 days to check if the grace period is working; // in just 1 second from that the record will expire - clock::increment_for_testing(&mut clock, constants::grace_period_ms()); - assert_eq(record::has_expired(&record, &clock), true); - assert_eq(record::has_expired_past_grace_period(&record, &clock), false); + clock.increment_for_testing(constants::grace_period_ms()); + assert_eq(record.has_expired(&clock), true); + assert_eq(record.has_expired_past_grace_period(&clock), false); // increment time by 1 second to check if record has expired - clock::increment_for_testing(&mut clock, constants::grace_period_ms() + 1000); - assert_eq(record::has_expired(&record, &clock), true); - assert_eq(record::has_expired_past_grace_period(&record, &clock), true); + clock.increment_for_testing(constants::grace_period_ms() + 1000); + assert_eq(record.has_expired(&clock), true); + assert_eq(record.has_expired_past_grace_period(&clock), true); - clock::destroy_for_testing(clock); + clock.destroy_for_testing(); } fun fresh_id(ctx: &mut TxContext): ID { diff --git a/packages/suins/tests/unit/registration_nft_tests.move b/packages/suins/tests/unit/registration_nft_tests.move index 8f98730a..6add3da1 100644 --- a/packages/suins/tests/unit/registration_nft_tests.move +++ b/packages/suins/tests/unit/registration_nft_tests.move @@ -25,27 +25,27 @@ module suins::registation_nft_tests { let nft = new(utf8(b"test.sui"), 1, &clock, &mut ctx); // expiration date for 1 year should be 365 days from now - assert_eq(nft::expiration_timestamp_ms(&nft), 365 * 24 * 60 * 60 * 1000); - assert_eq(nft::image_url(&nft), constants::default_image()); - assert_eq(nft::domain(&nft), domain::new(utf8(b"test.sui"))); + assert_eq(nft.expiration_timestamp_ms(), 365 * 24 * 60 * 60 * 1000); + assert_eq(nft.image_url(), constants::default_image()); + assert_eq(nft.domain(), domain::new(utf8(b"test.sui"))); // bump the clock value to 1 year from now // and create a new NFT with expiration in 2 years + 1 ms - clock::increment_for_testing(&mut clock, constants::year_ms() + 1); + clock.increment_for_testing(constants::year_ms() + 1); // test if the first NFT would have expired by then (but no grace period) - assert_eq(nft::has_expired(&nft, &clock), true); - assert_eq(nft::has_expired_past_grace_period(&nft, &clock), false); + assert_eq(nft.has_expired(&clock), true); + assert_eq(nft.has_expired_past_grace_period(&clock), false); burn(nft); // create a new NFT with expiration in 2 years let nft = new(utf8(b"test.sui"), 2, &clock, &mut ctx); // expiration timestamp for 2 years (1 off) should be 3 * 365 days (and 1 ms) from now - assert_eq(nft::expiration_timestamp_ms(&nft), 3 * constants::year_ms() + 1); + assert_eq(nft.expiration_timestamp_ms(), 3 * constants::year_ms() + 1); burn(nft); - clock::destroy_for_testing(clock); + clock.destroy_for_testing(); } #[test] @@ -54,13 +54,13 @@ module suins::registation_nft_tests { let clock = clock::create_for_testing(&mut ctx); let mut nft = new(utf8(b"test.sui"), 5, &clock, &mut ctx); - nft::set_expiration_timestamp_ms_for_testing(&mut nft, 0); - assert_eq(nft::expiration_timestamp_ms(&nft), 0); + nft.set_expiration_timestamp_ms_for_testing(0); + assert_eq(nft.expiration_timestamp_ms(), 0); - nft::update_image_url_for_testing(&mut nft, utf8(b"test_image_url")); - assert_eq(nft::image_url(&nft), utf8(b"test_image_url")); + nft.update_image_url_for_testing(utf8(b"test_image_url")); + assert_eq(nft.image_url(), utf8(b"test_image_url")); - clock::destroy_for_testing(clock); + clock.destroy_for_testing(); burn(nft); } @@ -81,6 +81,6 @@ module suins::registation_nft_tests { } fun burn(nft: SuinsRegistration) { - nft::burn_for_testing(nft) + nft.burn_for_testing() } } diff --git a/packages/suins/tests/unit/registry_tests.move b/packages/suins/tests/unit/registry_tests.move index 46e319e7..d4add17f 100644 --- a/packages/suins/tests/unit/registry_tests.move +++ b/packages/suins/tests/unit/registry_tests.move @@ -25,15 +25,15 @@ module suins::registry_tests { let (mut registry, clock, domain) = setup(&mut ctx); // create a record for the test domain with expiration set to 1 year - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // make sure that the nft matches the domain - assert_eq(nft::domain(&nft), domain); - assert_eq(registry::has_record(®istry, nft::domain(&nft)), true); + assert_eq(nft.domain(), domain); + assert_eq(registry.has_record(nft.domain()), true); // take the record and compare it against the nft - let record = registry::remove_record_for_testing(&mut registry, domain); - assert_eq(record::expiration_timestamp_ms(&record), nft::expiration_timestamp_ms(&nft)); + let record = registry.remove_record_for_testing(domain); + assert_eq(record.expiration_timestamp_ms(), nft.expiration_timestamp_ms()); burn_nfts(vector[ nft ]); @@ -52,24 +52,24 @@ module suins::registry_tests { let subdomain_one = domain::new(utf8(b"test.hahaha.sui")); // create a record for the test domain with expiration set to 1 year - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // register a leaf record and set the target to @0x0 - registry::add_leaf_record(&mut registry, subdomain_one, &clock, @0x0, &mut ctx); + registry.add_leaf_record(subdomain_one, &clock, @0x0, &mut ctx); // set the reverse_Registry of @0x0 to be that leaf subdomain - registry::set_reverse_lookup(&mut registry, @0x0, subdomain_one); + registry.set_reverse_lookup(@0x0, subdomain_one); - let name_record = option::extract(&mut registry::lookup(®istry, subdomain_one)); + let name_record = option::extract(&mut registry.lookup(subdomain_one)); // validate that the parent nft_id is the same as the leaf's one. - assert_eq(object::id(&nft), record::nft_id(&name_record)); + assert_eq(object::id(&nft), name_record.nft_id()); // Reverse lookup should work as expected, since it's set. - let name = option::extract(&mut registry::reverse_lookup(®istry, @0x0)); + let name = option::extract(&mut registry.reverse_lookup(@0x0)); assert!(name == subdomain_one, 0); // remove leaf_record to test removal too - registry::remove_leaf_record(&mut registry, subdomain_one); + registry.remove_leaf_record(subdomain_one); // validate that now @0x0 doesn't have a reverse lookup anymore. let res = registry::reverse_lookup(®istry, @0x0); @@ -86,21 +86,21 @@ module suins::registry_tests { let mut ctx = tx_context::dummy(); let (mut registry, mut clock, _domain) = setup(&mut ctx); - let nft = registry::add_record(&mut registry, domain::new(utf8(b"test.sui")), 1, &clock, &mut ctx); + let nft = registry.add_record(domain::new(utf8(b"test.sui")), 1, &clock, &mut ctx); // add 2 leaf records as nft - registry::add_leaf_record(&mut registry, domain::new(utf8(b"test.test.sui")), &clock, @0x0, &mut ctx); - registry::add_leaf_record(&mut registry, domain::new(utf8(b"test2.test.sui")), &clock, @0x0, &mut ctx); + registry.add_leaf_record(domain::new(utf8(b"test.test.sui")), &clock, @0x0, &mut ctx); + registry.add_leaf_record(domain::new(utf8(b"test2.test.sui")), &clock, @0x0, &mut ctx); // increment the clock to 1 years + grace period clock::increment_for_testing(&mut clock, constants::year_ms() + constants::grace_period_ms() + 1); // become a new owner, `new_oner_nft` - let new_owner_nft = registry::add_record(&mut registry, domain::new(utf8(b"test.sui")), 1, &clock, &mut ctx); + let new_owner_nft = registry.add_record(domain::new(utf8(b"test.sui")), 1, &clock, &mut ctx); // override both leaf records, one with a node subdomain, the other iwth a leaf subdomain - let normal_subdomain_override = registry::add_record_ignoring_grace_period(&mut registry, domain::new(utf8(b"test.test.sui")), 1, &clock, &mut ctx); - registry::add_leaf_record(&mut registry, domain::new(utf8(b"test2.test.sui")), &clock, @0x1, &mut ctx); + let normal_subdomain_override = registry.add_record_ignoring_grace_period(domain::new(utf8(b"test.test.sui")), 1, &clock, &mut ctx); + registry.add_leaf_record(domain::new(utf8(b"test2.test.sui")), &clock, @0x1, &mut ctx); burn_nfts(vector[ nft, new_owner_nft, normal_subdomain_override ]); wrapup_non_empty(registry, clock); @@ -115,14 +115,14 @@ module suins::registry_tests { let (mut registry, mut clock, domain) = setup(&mut ctx); // create a record for the test domain with expiration set to 1 year - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // increment the clock to 1 years + grace period clock::increment_for_testing(&mut clock, constants::year_ms() + constants::grace_period_ms() + 1); // override the record - let nft_2 = registry::add_record(&mut registry, domain, 2, &clock, &mut ctx); - let record = registry::remove_record_for_testing(&mut registry, domain); + let nft_2 = registry.add_record(domain, 2, &clock, &mut ctx); + let record = registry.remove_record_for_testing(domain); // make sure the old NFT is no longer matches to the domain assert!(object::id(&nft) != record::nft_id(&record), 0); @@ -143,14 +143,14 @@ module suins::registry_tests { let (mut registry, mut clock, domain) = setup(&mut ctx); // create a record for the test domain with expiration set to 1 year - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // increment the clock to 1 years + grace period clock::increment_for_testing(&mut clock, constants::year_ms() + 1); // override the record - let nft_2 = registry::add_record_ignoring_grace_period(&mut registry, domain, 2, &clock, &mut ctx); - let record = registry::remove_record_for_testing(&mut registry, domain); + let nft_2 = registry.add_record_ignoring_grace_period(domain, 2, &clock, &mut ctx); + let record = registry.remove_record_for_testing(domain); // make sure the old NFT is no longer matches to the domain assert!(object::id(&nft) != record::nft_id(&record), 0); @@ -171,10 +171,10 @@ module suins::registry_tests { let (mut registry, clock, domain) = setup(&mut ctx); // create a record for the test domain with expiration set to 1 year - let _nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let _nft = registry.add_record(domain, 1, &clock, &mut ctx); // try to override the record and fail - not expired - let _nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let _nft = registry.add_record(domain, 1, &clock, &mut ctx); abort 1337 } @@ -186,11 +186,11 @@ module suins::registry_tests { let (mut registry, mut clock, domain) = setup(&mut ctx); // create a record for the test domain with expiration set to 1 year - let _nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let _nft = registry.add_record(domain, 1, &clock, &mut ctx); // increment the clock to 1 years + grace period clock::increment_for_testing(&mut clock, constants::year_ms() + 1); // try to override the record and fail - not expired - let _nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let _nft = registry.add_record(domain, 1, &clock, &mut ctx); abort 1337 } @@ -205,22 +205,22 @@ module suins::registry_tests { let (mut registry, mut clock, domain) = setup(&mut ctx); // create a record for the test domain with expiration set to 1 year - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // increment the clock to 1 years + grace period clock::increment_for_testing(&mut clock, constants::year_ms() + constants::grace_period_ms() + 1); // we re-register the same domain now that the other has expired. - let new_nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let new_nft = registry.add_record(domain, 1, &clock, &mut ctx); // we burn the first one as it is an expired name now. - registry::burn_registration_object(&mut registry, nft, &clock); + registry.burn_registration_object(nft, &clock); // we still have a registry entry though, it's not removed as the owner is different. - assert!(option::is_some(®istry::lookup(®istry, domain)), 1); + assert!(option::is_some(®istry.lookup(domain)), 1); // remove the record so we can wrap this up. - registry::remove_record_for_testing(&mut registry, domain); + registry.remove_record_for_testing(domain); wrapup(registry, clock); burn_nfts(vector[new_nft]); @@ -234,16 +234,16 @@ module suins::registry_tests { let (mut registry, mut clock, domain) = setup(&mut ctx); // create a record for the test domain with expiration set to 1 year - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // increment the clock to 1 years + grace period clock::increment_for_testing(&mut clock, constants::year_ms() + constants::grace_period_ms() + 1); // we burn the first one as it is an expired name now. - registry::burn_registration_object(&mut registry, nft, &clock); + registry.burn_registration_object(nft, &clock); // we still have a registry entry though, it's not removed as the owner is different. - assert!(option::is_none(®istry::lookup(®istry, domain)), 1); + assert!(option::is_none(®istry.lookup(domain)), 1); wrapup(registry, clock); } @@ -259,12 +259,12 @@ module suins::registry_tests { let (mut registry, clock, domain) = setup(&mut ctx); // create a record for the test domain with expiration set to 1 year - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); - registry::set_target_address(&mut registry, domain, some(@0x2)); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); + registry.set_target_address(domain, some(@0x2)); // try to find a record and then get a record - let mut search = registry::lookup(®istry, domain); - let record = registry::remove_record_for_testing(&mut registry, domain); + let mut search = registry.lookup(domain); + let record = registry.remove_record_for_testing(domain); // make sure the search is a success assert!(option::is_some(&search), 0); @@ -284,11 +284,11 @@ module suins::registry_tests { fun set_reverse_lookup() { let mut ctx = tx_context::dummy(); let (mut registry, clock, domain) = setup(&mut ctx); - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // set the `domain` points to @0x0; set the reverse lookup too - registry::set_target_address(&mut registry, domain, some(@0xB0B)); - registry::set_reverse_lookup(&mut registry, @0xB0B, domain); + registry.set_target_address(domain, some(@0xB0B)); + registry.set_reverse_lookup(@0xB0B, domain); // search for the reverse_lookup record let mut search = registry::reverse_lookup(®istry, @0xB0B); @@ -297,8 +297,8 @@ module suins::registry_tests { assert!(option::extract(&mut search) == domain, 0); // wrapup - registry::unset_reverse_lookup(&mut registry, @0xB0B); - let _ = registry::remove_record_for_testing(&mut registry, domain); + registry.unset_reverse_lookup(@0xB0B); + let _ = registry.remove_record_for_testing(domain); wrapup(registry, clock); burn_nfts(vector[ nft ]); @@ -309,13 +309,13 @@ module suins::registry_tests { let mut ctx = tx_context::dummy(); let (mut registry, mut clock, _domain) = setup(&mut ctx); - let nft = registry::add_record(&mut registry, domain::new(utf8(b"node.test.sui")), 1, &clock, &mut ctx); + let nft = registry.add_record(domain::new(utf8(b"node.test.sui")), 1, &clock, &mut ctx); - let subdomain = registry::wrap_subdomain(&mut registry, nft, &clock, &mut ctx); + let subdomain = registry.wrap_subdomain(nft, &clock, &mut ctx); clock::increment_for_testing(&mut clock, constants::year_ms() + 1); - registry::burn_subdomain_object(&mut registry, subdomain, &clock); + registry.burn_subdomain_object(subdomain, &clock); wrapup(registry, clock); } @@ -324,14 +324,14 @@ module suins::registry_tests { fun burn_expired_suins_registration() { let mut ctx = tx_context::dummy(); let (mut registry, mut clock, domain) = setup(&mut ctx); - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // increment the clock to 1 years + grace period clock::increment_for_testing(&mut clock, constants::year_ms() + 1); // burn the registration object - registry::burn_registration_object(&mut registry, nft, &clock); + registry.burn_registration_object(nft, &clock); - let name = registry::lookup(®istry, domain); + let name = registry.lookup(domain); assert!(option::is_none(&name), 0); wrapup(registry, clock); @@ -341,19 +341,19 @@ module suins::registry_tests { fun burn_expired_registration_without_overriding() { let mut ctx = tx_context::dummy(); let (mut registry, mut clock, domain) = setup(&mut ctx); - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // increment the clock to 1 years + grace period clock::increment_for_testing(&mut clock, constants::year_ms() + constants::grace_period_ms() + 1); // re-register - let new_nft_post_expiration = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let new_nft_post_expiration = registry.add_record(domain, 1, &clock, &mut ctx); // burn the expired object - registry::burn_registration_object(&mut registry, nft, &clock); + registry.burn_registration_object(nft, &clock); // Validate that the record still exists (no invalidation happened), // since the name was bought again after this. - let name = registry::lookup(®istry, domain); + let name = registry.lookup(domain); assert!(option::is_some(&name), 0); wrapup_non_empty(registry, clock); @@ -366,10 +366,10 @@ module suins::registry_tests { fun set_reverse_lookup_fail_target_not_set() { let mut ctx = tx_context::dummy(); let (mut registry, clock, domain) = setup(&mut ctx); - let _nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let _nft = registry.add_record(domain, 1, &clock, &mut ctx); // set the `domain` points to @0x0 - registry::set_reverse_lookup(&mut registry, @0x0, domain); + registry.set_reverse_lookup(@0x0, domain); abort 1337 } @@ -381,11 +381,11 @@ module suins::registry_tests { fun set_reverse_lookup_fail_record_mismatch() { let mut ctx = tx_context::dummy(); let (mut registry, clock, domain) = setup(&mut ctx); - let _nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let _nft = registry.add_record(domain, 1, &clock, &mut ctx); // set the `domain` points to @0x0 - registry::set_target_address(&mut registry, domain, some(@0xB0B)); - registry::set_reverse_lookup(&mut registry, @0xA11CE, domain); + registry.set_target_address(domain, some(@0xB0B)); + registry.set_reverse_lookup(@0xA11CE, domain); abort 1337 } @@ -396,7 +396,7 @@ module suins::registry_tests { let mut ctx = tx_context::dummy(); let (mut registry, clock, _domain) = setup(&mut ctx); - registry::add_leaf_record(&mut registry, domain::new(utf8(b"test.sui")), &clock,@0x0, &mut ctx); + registry.add_leaf_record(domain::new(utf8(b"test.sui")), &clock,@0x0, &mut ctx); abort 1337 } @@ -407,7 +407,7 @@ module suins::registry_tests { let mut ctx = tx_context::dummy(); let (mut registry, clock, _domain) = setup(&mut ctx); - registry::add_leaf_record(&mut registry, domain::new(utf8(b"test.test.sui")), &clock,@0x0, &mut ctx); + registry.add_leaf_record(domain::new(utf8(b"test.test.sui")), &clock,@0x0, &mut ctx); abort 1337 } @@ -418,9 +418,9 @@ module suins::registry_tests { let mut ctx = tx_context::dummy(); let (mut registry, clock, _domain) = setup(&mut ctx); - let _nft = registry::add_record(&mut registry, domain::new(utf8(b"test.test.sui")), 1, &clock, &mut ctx); + let _nft = registry.add_record(domain::new(utf8(b"test.test.sui")), 1, &clock, &mut ctx); - registry::remove_leaf_record(&mut registry, domain::new(utf8(b"test.test.sui"))); + registry.remove_leaf_record(domain::new(utf8(b"test.test.sui"))); abort 1337 } @@ -431,10 +431,10 @@ module suins::registry_tests { let mut ctx = tx_context::dummy(); let (mut registry, clock, _domain) = setup(&mut ctx); - let _nft = registry::add_record(&mut registry, domain::new(utf8(b"test.sui")), 1, &clock, &mut ctx); - let _existing = registry::add_record(&mut registry, domain::new(utf8(b"test.test.sui")), 1, &clock, &mut ctx); + let _nft = registry.add_record(domain::new(utf8(b"test.sui")), 1, &clock, &mut ctx); + let _existing = registry.add_record(domain::new(utf8(b"test.test.sui")), 1, &clock, &mut ctx); - registry::add_leaf_record(&mut registry, domain::new(utf8(b"test.test.sui")), &clock,@0x0, &mut ctx); + registry.add_leaf_record(domain::new(utf8(b"test.test.sui")), &clock,@0x0, &mut ctx); abort 1337 } @@ -445,11 +445,11 @@ module suins::registry_tests { let mut ctx = tx_context::dummy(); let (mut registry, clock, _domain) = setup(&mut ctx); - let _nft = registry::add_record(&mut registry, domain::new(utf8(b"test.sui")), 1, &clock, &mut ctx); + let _nft = registry.add_record(domain::new(utf8(b"test.sui")), 1, &clock, &mut ctx); - registry::add_leaf_record(&mut registry, domain::new(utf8(b"test.test.sui")), &clock,@0x0, &mut ctx); + registry.add_leaf_record(domain::new(utf8(b"test.test.sui")), &clock,@0x0, &mut ctx); - let _existing = registry::add_record_ignoring_grace_period(&mut registry, domain::new(utf8(b"test.test.sui")), 1, &clock, &mut ctx); + let _existing = registry.add_record_ignoring_grace_period(domain::new(utf8(b"test.test.sui")), 1, &clock, &mut ctx); abort 1337 @@ -459,10 +459,10 @@ module suins::registry_tests { fun burn_non_expired_domain_failure() { let mut ctx = tx_context::dummy(); let (mut registry, clock, domain) = setup(&mut ctx); - let nft = registry::add_record(&mut registry, domain, 1, &clock, &mut ctx); + let nft = registry.add_record(domain, 1, &clock, &mut ctx); // burn the expired object - registry::burn_registration_object(&mut registry, nft, &clock); + registry.burn_registration_object(nft, &clock); abort 1337 } @@ -482,12 +482,12 @@ module suins::registry_tests { fun wrapup(registry: Registry, clock: Clock) { registry::destroy_empty_for_testing(registry); - clock::destroy_for_testing(clock); + clock.destroy_for_testing(); } fun wrapup_non_empty(registry: Registry, clock: Clock) { registry::destroy_for_testing(registry); - clock::destroy_for_testing(clock); + clock.destroy_for_testing(); } #[test_only] From 96d6d609b97b9d87bff3ef21a463dfa19cdc3953 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Mon, 1 Apr 2024 19:33:42 -0400 Subject: [PATCH 23/38] remaining tests --- packages/suins/tests/auction_tests.move | 200 +++++++++--------- packages/suins/tests/controller_tests.move | 142 ++++++------- packages/suins/tests/register_tests.move | 126 +++++------ packages/suins/tests/renew_tests.move | 66 +++--- packages/suins/tests/unit/sub_name_tests.move | 14 +- packages/suins/tests/unit/suins_tests.move | 14 +- 6 files changed, 281 insertions(+), 281 deletions(-) diff --git a/packages/suins/tests/auction_tests.move b/packages/suins/tests/auction_tests.move index 63110674..6b55339d 100644 --- a/packages/suins/tests/auction_tests.move +++ b/packages/suins/tests/auction_tests.move @@ -35,16 +35,16 @@ module suins::auction_tests { let scenario = &mut scenario_val; { let mut suins = suins::init_for_testing(ctx(scenario)); - suins::authorize_app_for_testing(&mut suins); - suins::share_for_testing(suins); + suins.authorize_app_for_testing(); + suins.share_for_testing(); auction::init_for_testing(ctx(scenario)); let clock = clock::create_for_testing(ctx(scenario)); - clock::share_for_testing(clock); + clock.share_for_testing(); }; { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario)); @@ -60,11 +60,11 @@ module suins::auction_tests { domain_name: String, amount: u64 ) { - test_scenario::next_tx(scenario, sender); - let mut auction_house = test_scenario::take_shared(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(sender); + let mut auction_house = scenario.take_shared(); + let mut suins = scenario.take_shared(); let payment = coin::mint_for_testing(amount, ctx(scenario)); - let clock = test_scenario::take_shared(scenario); + let clock = scenario.take_shared(); start_auction_and_place_bid( &mut auction_house, @@ -81,12 +81,12 @@ module suins::auction_tests { } fun place_bid_util(scenario: &mut Scenario, sender: address, domain_name: String, value: u64, clock_tick: u64) { - test_scenario::next_tx(scenario, sender); - let mut auction_house = test_scenario::take_shared(scenario); + scenario.next_tx(sender); + let mut auction_house = scenario.take_shared(); let payment = coin::mint_for_testing(value, ctx(scenario)); - let mut clock = test_scenario::take_shared(scenario); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); place_bid(&mut auction_house, domain_name, payment, &clock, ctx(scenario)); test_scenario::return_shared(clock); @@ -99,11 +99,11 @@ module suins::auction_tests { domain_name: String, clock_tick: u64 ): SuinsRegistration { - test_scenario::next_tx(scenario, sender); - let mut auction_house = test_scenario::take_shared(scenario); - let mut clock = test_scenario::take_shared(scenario); + scenario.next_tx(sender); + let mut auction_house = scenario.take_shared(); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); let nft = claim(&mut auction_house, domain_name, &clock, ctx(scenario)); test_scenario::return_shared(clock); @@ -112,17 +112,17 @@ module suins::auction_tests { } fun withdraw_util(scenario: &mut Scenario, sender: address): Coin { - test_scenario::next_tx(scenario, sender); + scenario.next_tx(sender); let returned_payment = test_scenario::take_from_sender>(scenario); returned_payment } fun admin_collect_fund_util(scenario: &mut Scenario, domain_name: String, clock_tick: u64) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let mut auction_house = test_scenario::take_shared(scenario); - let mut clock = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let mut auction_house = scenario.take_shared(); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); collect_winning_auction_fund(&mut auction_house, domain_name, &clock, ctx(scenario)); test_scenario::return_shared(clock); @@ -134,12 +134,12 @@ module suins::auction_tests { domain: String, clock_tick: u64 ) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut auction_house = test_scenario::take_shared(scenario); - let mut clock = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut auction_house = scenario.take_shared(); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); admin_finalize_auction(&admin_cap, &mut auction_house, domain, &clock); test_scenario::return_shared(clock); @@ -148,12 +148,12 @@ module suins::auction_tests { } fun admin_try_finalize_auctions_util(scenario: &mut Scenario, operation_limit: u64, clock_tick: u64) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut auction_house = test_scenario::take_shared(scenario); - let mut clock = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut auction_house = scenario.take_shared(); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); admin_try_finalize_auctions(&admin_cap, &mut auction_house, operation_limit, &clock); test_scenario::return_shared(clock); @@ -162,9 +162,9 @@ module suins::auction_tests { } fun admin_withdraw_funds_util(scenario: &mut Scenario): Coin { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut auction_house = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut auction_house = scenario.take_shared(); let funds = admin_withdraw_funds(&admin_cap, &mut auction_house, ctx(scenario)); @@ -174,9 +174,9 @@ module suins::auction_tests { } fun deauthorize_app_util(scenario: &mut Scenario) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); suins::deauthorize_app(&admin_cap, &mut suins); @@ -185,8 +185,8 @@ module suins::auction_tests { } fun assert_balance(scenario: &mut Scenario, amount: u64) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let auction_house = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let auction_house = scenario.take_shared(); assert!(total_balance(&auction_house) == amount, 0); test_scenario::return_shared(auction_house); } @@ -199,9 +199,9 @@ module suins::auction_tests { expected_winner: address, expected_highest_amount: u64 ) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let auction_house = test_scenario::take_shared(scenario); - let (mut start_ms, mut end_ms, mut winner, mut highest_amount) = auction::get_auction_metadata(&auction_house, domain_name); + scenario.next_tx(SUINS_ADDRESS); + let auction_house = scenario.take_shared(); + let (mut start_ms, mut end_ms, mut winner, mut highest_amount) = auction_house.get_auction_metadata(domain_name); assert!(option::extract(&mut start_ms) == expected_start_ms, 0); assert!(option::extract(&mut end_ms) == expected_end_ms, 0); assert!(option::extract(&mut winner) == expected_winner, 0); @@ -235,9 +235,9 @@ module suins::auction_tests { ); let nft = claim_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), AUCTION_BIDDING_PERIOD_MS + 1); - assert!(suins_registration::domain(&nft) == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == constants::year_ms(), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == constants::year_ms(), 0); + nft.burn_for_testing(); let payment = withdraw_util(scenario, FIRST_ADDRESS); assert!(coin::value(&payment) == 1200 * mist_per_sui(), 0); @@ -255,7 +255,7 @@ module suins::auction_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; normal_auction_flow(scenario); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = sui::dynamic_field::EFieldDoesNotExist)] @@ -271,10 +271,10 @@ module suins::auction_tests { place_bid_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), 1210 * mist_per_sui(), 0); let nft = claim_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), AUCTION_BIDDING_PERIOD_MS + 1); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); let nft = claim_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), AUCTION_BIDDING_PERIOD_MS + 1); - suins_registration::burn_for_testing(nft); - test_scenario::end(scenario_val); + nft.burn_for_testing(); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::EWinnerCannotPlaceBid)] @@ -290,7 +290,7 @@ module suins::auction_tests { place_bid_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), 1210 * mist_per_sui(), 0); place_bid_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), 1210 * mist_per_sui(), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::EBidAmountTooLow)] @@ -305,7 +305,7 @@ module suins::auction_tests { ); place_bid_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), 1200 * mist_per_sui(), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::ENotWinner)] @@ -321,8 +321,8 @@ module suins::auction_tests { place_bid_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), 1210 * mist_per_sui(), 0); let nft = claim_util(scenario, FIRST_ADDRESS, utf8(FIRST_DOMAIN_NAME), AUCTION_BIDDING_PERIOD_MS + 1); - suins_registration::burn_for_testing(nft); - test_scenario::end(scenario_val); + nft.burn_for_testing(); + scenario_val.end(); } #[test] @@ -342,9 +342,9 @@ module suins::auction_tests { assert_balance(scenario, 1220 * mist_per_sui()); let nft = test_scenario::take_from_address(scenario, THIRD_ADDRESS); - assert!(suins_registration::domain(&nft) == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == constants::year_ms(), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == constants::year_ms(), 0); + nft.burn_for_testing(); let payment = test_scenario::take_from_address>(scenario, SECOND_ADDRESS); assert!(coin::value(&payment) == 1210 * mist_per_sui(), 0); @@ -355,7 +355,7 @@ module suins::auction_tests { coin::burn_for_testing(payment); assert_balance(scenario, 1220 * mist_per_sui()); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -379,16 +379,16 @@ module suins::auction_tests { assert_balance(scenario, 2410 * mist_per_sui()); let nft = test_scenario::take_from_address(scenario, SECOND_ADDRESS); - assert!(suins_registration::domain(&nft) == domain::new(utf8(SECOND_DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == constants::year_ms(), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(SECOND_DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == constants::year_ms(), 0); + nft.burn_for_testing(); let nft = test_scenario::take_from_address(scenario, FIRST_ADDRESS); - assert!(suins_registration::domain(&nft) == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == constants::year_ms(), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == constants::year_ms(), 0); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::EAuctionNotEndedYet)] @@ -403,7 +403,7 @@ module suins::auction_tests { ); admin_try_finalize_auction_util(scenario, utf8(FIRST_DOMAIN_NAME), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -419,7 +419,7 @@ module suins::auction_tests { admin_try_finalize_auctions_util(scenario, 3, 0); assert_balance(scenario, 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::EAuctionEnded)] @@ -439,7 +439,7 @@ module suins::auction_tests { 1210 * mist_per_sui(), AUCTION_BIDDING_PERIOD_MS + 1 ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::ENoProfits)] @@ -448,7 +448,7 @@ module suins::auction_tests { let scenario = &mut scenario_val; let funds = admin_withdraw_funds_util(scenario); coin::burn_for_testing(funds); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = config::EInvalidTld)] @@ -461,7 +461,7 @@ module suins::auction_tests { utf8(b"test.move"), 1200 * mist_per_sui() ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = config::ELabelTooShort)] @@ -474,7 +474,7 @@ module suins::auction_tests { utf8(b"tt.sui"), 1200 * mist_per_sui() ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -487,7 +487,7 @@ module suins::auction_tests { utf8(b"g2bst97onsyl8gwo5brfglcb-obh8i7p01lz5ccscd6zxx4qn7wnv8b1in5sectj8s.sui"), 1200 * mist_per_sui() ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -500,7 +500,7 @@ module suins::auction_tests { utf8(b"-test.sui"), 1200 * mist_per_sui() ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -513,7 +513,7 @@ module suins::auction_tests { utf8(b"test-.sui"), 1200 * mist_per_sui() ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -526,7 +526,7 @@ module suins::auction_tests { utf8(b"ttABC.sui"), 1200 * mist_per_sui() ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::EAuctionNotStarted)] @@ -534,7 +534,7 @@ module suins::auction_tests { let mut scenario_val = test_init(); let scenario = &mut scenario_val; place_bid_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), 1210 * mist_per_sui(), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::EInvalidBidValue)] @@ -547,7 +547,7 @@ module suins::auction_tests { utf8(b"test.sui"), 10 * mist_per_sui() ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -572,9 +572,9 @@ module suins::auction_tests { assert_balance(scenario, 1210 * mist_per_sui()); let nft = claim_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), AUCTION_BIDDING_PERIOD_MS + 1); - assert!(suins_registration::domain(&nft) == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == constants::year_ms(), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == constants::year_ms(), 0); + nft.burn_for_testing(); let payment = withdraw_util(scenario, FIRST_ADDRESS); assert!(coin::value(&payment) == 1200 * mist_per_sui(), 0); @@ -586,7 +586,7 @@ module suins::auction_tests { assert_balance(scenario, 0); coin::burn_for_testing(funds); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = auction::EAuctionNotEndedYet)] @@ -600,7 +600,7 @@ module suins::auction_tests { 1200 * mist_per_sui() ); admin_collect_fund_util(scenario, utf8(FIRST_DOMAIN_NAME), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -614,7 +614,7 @@ module suins::auction_tests { utf8(FIRST_DOMAIN_NAME), 1200 * mist_per_sui() ); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -639,9 +639,9 @@ module suins::auction_tests { ); let nft = claim_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), AUCTION_BIDDING_PERIOD_MS + 1); - assert!(suins_registration::domain(&nft) == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == constants::year_ms(), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == constants::year_ms(), 0); + nft.burn_for_testing(); let payment = withdraw_util(scenario, FIRST_ADDRESS); assert!(coin::value(&payment) == 1200 * mist_per_sui(), 0); @@ -653,7 +653,7 @@ module suins::auction_tests { assert_balance(scenario, 0); coin::burn_for_testing(funds); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -674,9 +674,9 @@ module suins::auction_tests { assert_balance(scenario, 1220 * mist_per_sui()); let nft = test_scenario::take_from_address(scenario, THIRD_ADDRESS); - assert!(suins_registration::domain(&nft) == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == constants::year_ms(), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == constants::year_ms(), 0); + nft.burn_for_testing(); let payment = test_scenario::take_from_address>(scenario, SECOND_ADDRESS); assert!(coin::value(&payment) == 1210 * mist_per_sui(), 0); @@ -687,7 +687,7 @@ module suins::auction_tests { coin::burn_for_testing(payment); assert_balance(scenario, 1220 * mist_per_sui()); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -713,20 +713,20 @@ module suins::auction_tests { assert_balance(scenario, 1210 * mist_per_sui()); let nft = claim_util(scenario, SECOND_ADDRESS, utf8(FIRST_DOMAIN_NAME), AUCTION_BIDDING_PERIOD_MS + 1); - assert!(suins_registration::domain(&nft) == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == constants::year_ms(), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(FIRST_DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == constants::year_ms(), 0); + nft.burn_for_testing(); let payment = withdraw_util(scenario, FIRST_ADDRESS); - assert!(coin::value(&payment) == 1200 * mist_per_sui(), 0); - coin::burn_for_testing(payment); + assert!(payment.value() == 1200 * mist_per_sui(), 0); + payment.burn_for_testing(); assert_balance(scenario, 1210 * mist_per_sui()); let funds = admin_withdraw_funds_util(scenario); - assert!(coin::value(&funds) == 1210 * mist_per_sui(), 0); + assert!(funds.value() == 1210 * mist_per_sui(), 0); assert_balance(scenario, 0); - coin::burn_for_testing(funds); + funds.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } } diff --git a/packages/suins/tests/controller_tests.move b/packages/suins/tests/controller_tests.move index 11260b23..3f5b1d0a 100644 --- a/packages/suins/tests/controller_tests.move +++ b/packages/suins/tests/controller_tests.move @@ -36,16 +36,16 @@ module suins::controller_tests { let scenario = &mut scenario_val; { let mut suins = suins::init_for_testing(ctx(scenario)); - suins::authorize_app_for_testing(&mut suins); + suins.authorize_app_for_testing(); suins::authorize_app_for_testing(&mut suins); suins::share_for_testing(suins); let clock = clock::create_for_testing(ctx(scenario)); - clock::share_for_testing(clock); + clock.share_for_testing(); }; { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario)); @@ -61,12 +61,12 @@ module suins::controller_tests { } public fun set_target_address_util(scenario: &mut Scenario, sender: address, target: Option
, clock_tick: u64) { - test_scenario::next_tx(scenario, sender); - let mut suins = test_scenario::take_shared(scenario); - let nft = test_scenario::take_from_sender(scenario); - let mut clock = test_scenario::take_shared(scenario); + scenario.next_tx(sender); + let mut suins = scenario.take_shared(); + let nft = scenario.take_from_sender(); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); set_target_address_for_testing(&mut suins, &nft, target, &clock); test_scenario::return_shared(clock); @@ -75,8 +75,8 @@ module suins::controller_tests { } public fun set_reverse_lookup_util(scenario: &mut Scenario, sender: address, domain_name: String) { - test_scenario::next_tx(scenario, sender); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(sender); + let mut suins = scenario.take_shared(); set_reverse_lookup_for_testing(&mut suins, domain_name, ctx(scenario)); @@ -84,8 +84,8 @@ module suins::controller_tests { } public fun unset_reverse_lookup_util(scenario: &mut Scenario, sender: address) { - test_scenario::next_tx(scenario, sender); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(sender); + let mut suins = scenario.take_shared(); unset_reverse_lookup_for_testing(&mut suins, ctx(scenario)); @@ -93,12 +93,12 @@ module suins::controller_tests { } public fun set_user_data_util(scenario: &mut Scenario, sender: address, key: String, value: String, clock_tick: u64) { - test_scenario::next_tx(scenario, sender); - let mut suins = test_scenario::take_shared(scenario); - let nft = test_scenario::take_from_sender(scenario); - let mut clock = test_scenario::take_shared(scenario); + scenario.next_tx(sender); + let mut suins = scenario.take_shared(); + let nft = scenario.take_from_sender(); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); set_user_data_for_testing(&mut suins, &nft, key, value, &clock); test_scenario::return_shared(clock); @@ -107,12 +107,12 @@ module suins::controller_tests { } public fun unset_user_data_util(scenario: &mut Scenario, sender: address, key: String, clock_tick: u64) { - test_scenario::next_tx(scenario, sender); - let mut suins = test_scenario::take_shared(scenario); - let nft = test_scenario::take_from_sender(scenario); - let mut clock = test_scenario::take_shared(scenario); + scenario.next_tx(sender); + let mut suins = scenario.take_shared(); + let nft = scenario.take_from_sender(); + let mut clock = scenario.take_shared(); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); unset_user_data_for_testing(&mut suins, &nft, key, &clock); test_scenario::return_shared(clock); @@ -121,33 +121,33 @@ module suins::controller_tests { } fun lookup_util(scenario: &mut Scenario, domain_name: String, expected_target_addr: Option
) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let suins = scenario.take_shared(); - let registry = suins::registry(&suins); + let registry = suins.registry(); let record = extract(&mut lookup(registry, domain::new(domain_name))); - assert_eq(name_record::target_address(&record), expected_target_addr); + assert_eq(record.target_address(), expected_target_addr); test_scenario::return_shared(suins); } fun get_user_data(scenario: &mut Scenario, domain_name: String): VecMap { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let suins = scenario.take_shared(); - let registry = suins::registry(&suins); + let registry = suins.registry(); let record = extract(&mut lookup(registry, domain::new(domain_name))); - let data = *name_record::data(&record); + let data = *record.data(); test_scenario::return_shared(suins); data } fun reverse_lookup_util(scenario: &mut Scenario, addr: address, expected_domain_name: Option) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let suins = scenario.take_shared(); - let registry = suins::registry(&suins); + let registry = suins.registry(); let domain_name = reverse_lookup(registry, addr); assert_eq(domain_name, expected_domain_name); @@ -155,9 +155,9 @@ module suins::controller_tests { } fun deauthorize_app_util(scenario: &mut Scenario) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); suins::deauthorize_app(&admin_cap, &mut suins); @@ -178,7 +178,7 @@ module suins::controller_tests { set_target_address_util(scenario, FIRST_ADDRESS, none(), 0); lookup_util(scenario, utf8(DOMAIN_NAME), none()); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ERecordExpired)] @@ -189,7 +189,7 @@ module suins::controller_tests { set_target_address_util(scenario, FIRST_ADDRESS, some(SECOND_ADDRESS), 2 * year_ms()); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::EIdMismatch)] @@ -201,7 +201,7 @@ module suins::controller_tests { set_target_address_util(scenario, FIRST_ADDRESS, some(SECOND_ADDRESS), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -214,7 +214,7 @@ module suins::controller_tests { set_target_address_util(scenario, SECOND_ADDRESS, some(SECOND_ADDRESS), 0); lookup_util(scenario, utf8(DOMAIN_NAME), some(SECOND_ADDRESS)); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -226,7 +226,7 @@ module suins::controller_tests { deauthorize_app_util(scenario); set_target_address_util(scenario, FIRST_ADDRESS, some(SECOND_ADDRESS), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -247,7 +247,7 @@ module suins::controller_tests { reverse_lookup_util(scenario, FIRST_ADDRESS, some(domain::new(utf8(DOMAIN_NAME)))); reverse_lookup_util(scenario, SECOND_ADDRESS, none()); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ETargetNotSet)] @@ -259,7 +259,7 @@ module suins::controller_tests { reverse_lookup_util(scenario, SECOND_ADDRESS, none()); set_reverse_lookup_util(scenario, SECOND_ADDRESS, utf8(DOMAIN_NAME)); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ERecordMismatch)] @@ -272,7 +272,7 @@ module suins::controller_tests { reverse_lookup_util(scenario, SECOND_ADDRESS, none()); set_reverse_lookup_util(scenario, SECOND_ADDRESS, utf8(DOMAIN_NAME)); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -285,7 +285,7 @@ module suins::controller_tests { deauthorize_app_util(scenario); set_reverse_lookup_util(scenario, SECOND_ADDRESS, utf8(DOMAIN_NAME)); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -300,7 +300,7 @@ module suins::controller_tests { unset_reverse_lookup_util(scenario, SECOND_ADDRESS); reverse_lookup_util(scenario, SECOND_ADDRESS, none()); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -314,7 +314,7 @@ module suins::controller_tests { deauthorize_app_util(scenario); unset_reverse_lookup_util(scenario, SECOND_ADDRESS); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = dynamic_field::EFieldDoesNotExist)] @@ -325,7 +325,7 @@ module suins::controller_tests { unset_reverse_lookup_util(scenario, SECOND_ADDRESS); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -335,19 +335,19 @@ module suins::controller_tests { setup(scenario, FIRST_ADDRESS, 0); let data = &get_user_data(scenario, utf8(DOMAIN_NAME)); - assert_eq(vec_map::size(data), 0); + assert_eq(data.size(), 0); set_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), utf8(b"value_avatar"), 0); let data = &get_user_data(scenario, utf8(DOMAIN_NAME)); - assert_eq(vec_map::size(data), 1); - assert_eq(*vec_map::get(data, &utf8(AVATAR)), utf8(b"value_avatar")); + assert_eq(data.size(), 1); + assert_eq(*data.get(&utf8(AVATAR)), utf8(b"value_avatar")); set_user_data_util(scenario, FIRST_ADDRESS, utf8(CONTENT_HASH), utf8(b"value_content_hash"), 0); let data = &get_user_data(scenario, utf8(DOMAIN_NAME)); - assert_eq(vec_map::size(data), 2); - assert_eq(*vec_map::get(data, &utf8(AVATAR)), utf8(b"value_avatar")); - assert_eq(*vec_map::get(data, &utf8(CONTENT_HASH)), utf8(b"value_content_hash")); + assert_eq(data.size(), 2); + assert_eq(*data.get(&utf8(AVATAR)), utf8(b"value_avatar")); + assert_eq(*data.get(&utf8(CONTENT_HASH)), utf8(b"value_content_hash")); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = controller::EUnsupportedKey)] @@ -358,7 +358,7 @@ module suins::controller_tests { set_user_data_util(scenario, FIRST_ADDRESS, utf8(b"key"), utf8(b"value"), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ERecordExpired)] @@ -369,7 +369,7 @@ module suins::controller_tests { set_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), utf8(b"value"), 2 * year_ms()); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::EIdMismatch)] @@ -381,7 +381,7 @@ module suins::controller_tests { set_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), utf8(b"value"), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -393,10 +393,10 @@ module suins::controller_tests { set_user_data_util(scenario, SECOND_ADDRESS, utf8(AVATAR), utf8(b"value"), 0); let data = &get_user_data(scenario, utf8(DOMAIN_NAME)); - assert_eq(vec_map::size(data), 1); - assert_eq(*vec_map::get(data, &utf8(AVATAR)), utf8(b"value")); + assert_eq(data.size(), 1); + assert_eq(*data.get(&utf8(AVATAR)), utf8(b"value")); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -408,7 +408,7 @@ module suins::controller_tests { deauthorize_app_util(scenario); set_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), utf8(b"value_avatar"), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -420,16 +420,16 @@ module suins::controller_tests { set_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), utf8(b"value_avatar"), 0); unset_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), 0); let data = &get_user_data(scenario, utf8(DOMAIN_NAME)); - assert_eq(vec_map::size(data), 0); + assert_eq(data.size(), 0); set_user_data_util(scenario, FIRST_ADDRESS, utf8(CONTENT_HASH), utf8(b"value_content_hash"), 0); set_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), utf8(b"value_avatar"), 0); unset_user_data_util(scenario, FIRST_ADDRESS, utf8(CONTENT_HASH), 0); let data = &get_user_data(scenario, utf8(DOMAIN_NAME)); - assert_eq(vec_map::size(data), 1); - assert_eq(*vec_map::get(data, &utf8(AVATAR)), utf8(b"value_avatar")); + assert_eq(data.size(), 1); + assert_eq(*data.get(&utf8(AVATAR)), utf8(b"value_avatar")); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -440,7 +440,7 @@ module suins::controller_tests { unset_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ERecordExpired)] @@ -451,7 +451,7 @@ module suins::controller_tests { unset_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), 2 * year_ms()); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -463,6 +463,6 @@ module suins::controller_tests { deauthorize_app_util(scenario); unset_user_data_util(scenario, FIRST_ADDRESS, utf8(AVATAR), 0); - test_scenario::end(scenario_val); + scenario_val.end(); } } diff --git a/packages/suins/tests/register_tests.move b/packages/suins/tests/register_tests.move index 1ac3520f..dcb82fa5 100644 --- a/packages/suins/tests/register_tests.move +++ b/packages/suins/tests/register_tests.move @@ -31,16 +31,16 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; { let mut suins = suins::init_for_testing(ctx(scenario)); - suins::authorize_app_for_testing(&mut suins); - suins::authorize_app_for_testing(&mut suins); + suins.authorize_app_for_testing(); + suins.authorize_app_for_testing(); suins::share_for_testing(suins); let clock = clock::create_for_testing(ctx(scenario)); - clock::share_for_testing(clock); + clock.share_for_testing(); }; { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario)); @@ -57,12 +57,12 @@ module suins::register_sample_tests { amount: u64, clock_tick: u64 ): SuinsRegistration { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let mut suins = scenario.take_shared(); let payment = coin::mint_for_testing(amount, ctx(scenario)); let mut clock = test_scenario::take_shared(scenario); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); let nft = register(&mut suins, domain_name, no_years, payment, &clock, ctx(scenario)); test_scenario::return_shared(clock); @@ -72,9 +72,9 @@ module suins::register_sample_tests { } fun deauthorize_app_util(scenario: &mut Scenario) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); suins::deauthorize_app(&admin_cap, &mut suins); @@ -83,8 +83,8 @@ module suins::register_sample_tests { } public fun assert_balance(scenario: &mut Scenario, amount: u64) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let auction_house = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let auction_house = scenario.take_shared(); assert!(total_balance(&auction_house) == amount, 0); test_scenario::return_shared(auction_house); } @@ -96,23 +96,23 @@ module suins::register_sample_tests { let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == year_ms() + 10, 0); + nft.burn_for_testing(); let nft = register_util(scenario, utf8(b"abcd.sui"), 2, 400 * mist_per_sui(), 20); assert_balance(scenario, 1600 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abcd.sui")), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 30, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(b"abcd.sui")), 0); + assert!(nft.expiration_timestamp_ms() == 2 * year_ms() + 30, 0); + nft.burn_for_testing(); let nft = register_util(scenario, utf8(b"abce-f12.sui"), 3, 150 * mist_per_sui(), 30); assert_balance(scenario, 1750 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(b"abce-f12.sui")), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 3 * year_ms() + 60, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(b"abce-f12.sui")), 0); + assert!(nft.expiration_timestamp_ms() == 3 * year_ms() + 60, 0); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = config::EInvalidTld)] @@ -121,9 +121,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"abc.move"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = register::EIncorrectAmount)] @@ -132,9 +132,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1210 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = register::EIncorrectAmount)] @@ -143,9 +143,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 90 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = register::EInvalidYearsArgument)] @@ -154,9 +154,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(DOMAIN_NAME), 6, 6 * 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = register::EInvalidYearsArgument)] @@ -165,9 +165,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(DOMAIN_NAME), 0, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -177,9 +177,9 @@ module suins::register_sample_tests { let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == year_ms() + 10, 0); + nft.burn_for_testing(); let nft = register_util( scenario, @@ -189,14 +189,14 @@ module suins::register_sample_tests { year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 2400 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(nft.domain() == domain::new(utf8(DOMAIN_NAME)), 0); assert!( - suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + grace_period_ms() + 30, + nft.expiration_timestamp_ms() == 2 * year_ms() + grace_period_ms() + 30, 0 ); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ERecordNotExpired)] @@ -206,14 +206,14 @@ module suins::register_sample_tests { let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); assert_balance(scenario, 1200 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(DOMAIN_NAME)), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(DOMAIN_NAME)), 0); + assert!(nft.expiration_timestamp_ms() == year_ms() + 10, 0); + nft.burn_for_testing(); let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 20); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -222,9 +222,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"-ab.sui"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -233,9 +233,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"ab-.sui"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = domain::EInvalidDomain)] @@ -244,9 +244,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"Abc.com"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = config::ELabelTooShort)] @@ -255,9 +255,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"ab.sui"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = config::EInvalidDomain)] @@ -266,9 +266,9 @@ module suins::register_sample_tests { let scenario = &mut scenario_val; let nft = register_util(scenario, utf8(b"abc.xyz.sui"), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = registry::ERecordNotExpired)] @@ -279,9 +279,9 @@ module suins::register_sample_tests { auction_tests::normal_auction_flow(scenario); let nft = register_util(scenario, utf8(AUCTIONED_DOMAIN_NAME), 1, 50 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test] @@ -299,10 +299,10 @@ module suins::register_sample_tests { year_ms() + grace_period_ms() + 20, ); assert_balance(scenario, 50 * mist_per_sui()); - assert!(suins_registration::domain(&nft) == domain::new(utf8(AUCTIONED_DOMAIN_NAME)), 0); - suins_registration::burn_for_testing(nft); + assert!(nft.domain() == domain::new(utf8(AUCTIONED_DOMAIN_NAME)), 0); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -312,8 +312,8 @@ module suins::register_sample_tests { deauthorize_app_util(scenario); let nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } } diff --git a/packages/suins/tests/renew_tests.move b/packages/suins/tests/renew_tests.move index 3bbec113..4b97f0a7 100644 --- a/packages/suins/tests/renew_tests.move +++ b/packages/suins/tests/renew_tests.move @@ -26,16 +26,16 @@ module suins::renew_tests { let scenario = &mut scenario_val; { let mut suins = suins::init_for_testing(ctx(scenario)); - suins::authorize_app_for_testing(&mut suins); - suins::authorize_app_for_testing(&mut suins); - suins::share_for_testing(suins); + suins.authorize_app_for_testing(); + suins.authorize_app_for_testing(); + suins.share_for_testing(); let clock = clock::create_for_testing(ctx(scenario)); clock::share_for_testing(clock); }; { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); registry::init_for_testing(&admin_cap, &mut suins, ctx(scenario)); @@ -46,12 +46,12 @@ module suins::renew_tests { } fun renew_util(scenario: &mut Scenario, nft: &mut SuinsRegistration, no_years: u8, amount: u64, clock_tick: u64) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let mut suins = scenario.take_shared(); let payment = coin::mint_for_testing(amount, ctx(scenario)); let mut clock = test_scenario::take_shared(scenario); - clock::increment_for_testing(&mut clock, clock_tick); + clock.increment_for_testing(clock_tick); renew(&mut suins, nft, no_years, payment, &clock); test_scenario::return_shared(clock); @@ -59,9 +59,9 @@ module suins::renew_tests { } fun deauthorize_app_util(scenario: &mut Scenario) { - test_scenario::next_tx(scenario, SUINS_ADDRESS); - let admin_cap = test_scenario::take_from_sender(scenario); - let mut suins = test_scenario::take_shared(scenario); + scenario.next_tx(SUINS_ADDRESS); + let admin_cap = scenario.take_from_sender(); + let mut suins = scenario.take_shared(); suins::deauthorize_app(&admin_cap, &mut suins); @@ -75,29 +75,29 @@ module suins::renew_tests { let scenario = &mut scenario_val; let mut nft = register_util(scenario, utf8(b"abcd.sui"), 1, 200 * mist_per_sui(), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms(), 0); + assert!(nft.expiration_timestamp_ms() == year_ms(), 0); renew_util(scenario, &mut nft, 1, 200 * mist_per_sui(), 0); assert_balance(scenario, 400 * mist_per_sui()); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); let mut nft = register_util(scenario, utf8(b"abcde.sui"), 1, 50 * mist_per_sui(), 0); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms(), 0); + assert!(nft.expiration_timestamp_ms() == year_ms(), 0); renew_util(scenario, &mut nft, 1, 50 * mist_per_sui(), 0); assert_balance(scenario, 500 * mist_per_sui()); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); let mut nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); - assert!(suins_registration::expiration_timestamp_ms(&nft) == year_ms() + 10, 0); + assert!(nft.expiration_timestamp_ms() == year_ms() + 10, 0); renew_util(scenario, &mut nft, 1, 1200 * mist_per_sui(), 0); assert_balance(scenario, 2900 * mist_per_sui()); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 2 * year_ms() + 10, 0); + assert!(nft.expiration_timestamp_ms() == 2 * year_ms() + 10, 0); renew_util(scenario, &mut nft, 2, 2400 * mist_per_sui(), 0); assert_balance(scenario, 5300 * mist_per_sui()); - assert!(suins_registration::expiration_timestamp_ms(&nft) == 4 * year_ms() + 10, 0); - suins_registration::burn_for_testing(nft); + assert!(nft.expiration_timestamp_ms() == 4 * year_ms() + 10, 0); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = renew::EIncorrectAmount)] @@ -107,9 +107,9 @@ module suins::renew_tests { let mut nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); renew_util(scenario, &mut nft, 1, 1210 * mist_per_sui(), 0); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = renew::EIncorrectAmount)] @@ -119,9 +119,9 @@ module suins::renew_tests { let mut nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); renew_util(scenario, &mut nft, 1, 10 * mist_per_sui(), 0); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = renew::EGracePeriodPassed)] @@ -131,9 +131,9 @@ module suins::renew_tests { let mut nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 10); renew_util(scenario, &mut nft, 1, 1200 * mist_per_sui(), 2 * year_ms() + 20); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = renew::EInvalidYearsArgument)] @@ -143,9 +143,9 @@ module suins::renew_tests { let mut nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 0); renew_util(scenario, &mut nft, 6, 7200 * mist_per_sui(), 0); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = renew::EInvalidNewExpiredAt)] @@ -156,9 +156,9 @@ module suins::renew_tests { let mut nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 0); renew_util(scenario, &mut nft, 2, 2400 * mist_per_sui(), 0); renew_util(scenario, &mut nft, 4, 4800 * mist_per_sui(), 0); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] @@ -169,8 +169,8 @@ module suins::renew_tests { let mut nft = register_util(scenario, utf8(DOMAIN_NAME), 1, 1200 * mist_per_sui(), 0); deauthorize_app_util(scenario); renew_util(scenario, &mut nft, 2, 2400 * mist_per_sui(), 0); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - test_scenario::end(scenario_val); + scenario_val.end(); } } diff --git a/packages/suins/tests/unit/sub_name_tests.move b/packages/suins/tests/unit/sub_name_tests.move index b3ba253b..ea14a439 100644 --- a/packages/suins/tests/unit/sub_name_tests.move +++ b/packages/suins/tests/unit/sub_name_tests.move @@ -24,16 +24,16 @@ module suins::sub_name_tests { // create subdomain from name let mut sub_nft = subdomain::new(nft, &clock, &mut ctx); - assert!(suins_registration::domain(subdomain::nft(&sub_nft)) == domain, 1); + assert!(sub_nft.nft().domain() == domain, 1); // destroy subdomain (added mut borrow for coverage) - clock::set_for_testing(&mut clock, suins_registration::expiration_timestamp_ms(subdomain::nft_mut(&mut sub_nft)) + 1); + clock.set_for_testing(sub_nft.nft_mut().expiration_timestamp_ms() + 1); - nft = subdomain::burn(sub_nft, &clock); + nft = sub_nft.burn(&clock); - suins_registration::burn_for_testing(nft); + nft.burn_for_testing(); - clock::destroy_for_testing(clock); + clock.destroy_for_testing(); } #[test, expected_failure(abort_code=suins::subdomain_registration::ENotSubdomain)] @@ -55,7 +55,7 @@ module suins::sub_name_tests { let mut clock = clock::create_for_testing(&mut ctx); let nft = suins_registration::new_for_testing(domain::new(utf8(b"sub.example.sui")), 1, &clock, &mut ctx); - clock::set_for_testing(&mut clock, suins_registration::expiration_timestamp_ms(&nft) + 1); + clock.set_for_testing(nft.expiration_timestamp_ms() + 1); // create subdomain from name let _sub_nft = subdomain::new(nft, &clock, &mut ctx); @@ -74,7 +74,7 @@ module suins::sub_name_tests { let sub_nft = subdomain::new(nft, &clock, &mut ctx); // try to destroy - let _nft = subdomain::burn(sub_nft, &clock); + let _nft = sub_nft.burn(&clock); abort 1337 } diff --git a/packages/suins/tests/unit/suins_tests.move b/packages/suins/tests/unit/suins_tests.move index 488af7bc..c3140a45 100644 --- a/packages/suins/tests/unit/suins_tests.move +++ b/packages/suins/tests/unit/suins_tests.move @@ -22,7 +22,7 @@ module suins::suins_tests { let (mut suins, cap) = suins::new_for_testing(&mut ctx); suins::add_config(&cap, &mut suins, TestConfig { a: 1 }); - let _cfg = suins::get_config(&suins); + let _cfg = suins.get_config(); let cfg = suins::remove_config(&cap, &mut suins); assert_eq(cfg.a, 1); @@ -40,7 +40,7 @@ module suins::suins_tests { let (mut suins, cap) = suins::new_for_testing(&mut ctx); suins::add_registry(&cap, &mut suins, TestRegistry { counter: 1 }); - let reg = suins::registry(&suins); + let reg = suins.registry(); assert_eq(reg.counter, 1); wrapup(suins, cap); @@ -78,8 +78,8 @@ module suins::suins_tests { // authorize and check right away suins::authorize_app(&cap, &mut suins); - assert!(suins::is_app_authorized(&suins), 0); - suins::assert_app_is_authorized(&suins); + assert!(suins.is_app_authorized(), 0); + suins.assert_app_is_authorized(); // add balance and read registry suins::app_add_balance(TestApp {}, &mut suins, balance::zero()); @@ -87,11 +87,11 @@ module suins::suins_tests { registry.counter = 2; // now read the registry again - assert_eq(suins::registry(&suins).counter, 2); + assert_eq(suins.registry().counter, 2); // deauthorize application suins::deauthorize_app(&cap, &mut suins); - assert!(!suins::is_app_authorized(&suins), 0); + assert!(!suins.is_app_authorized(), 0); wrapup(suins, cap); } @@ -128,7 +128,7 @@ module suins::suins_tests { // for a softer and simpler wrapup we can just share the object fun wrapup(suins: SuiNS, cap: AdminCap) { - suins::share_for_testing(suins); + suins.share_for_testing(); suins::burn_admin_cap_for_testing(cap); } } From b0a2def534dba7890d68e37b892e39349a900f7b Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Mon, 1 Apr 2024 20:07:10 -0400 Subject: [PATCH 24/38] dependency updates --- packages/suins/sources/actions/update_image.move | 12 +++++------- packages/suins/sources/admin.move | 3 +-- packages/suins/sources/auction.move | 8 ++++---- packages/suins/sources/config.move | 4 +--- packages/suins/sources/controller.move | 6 ++---- packages/suins/sources/registry.move | 2 +- packages/suins/sources/subdomain_registration.move | 3 +-- packages/suins/sources/suins_registration.move | 2 +- packages/suins/tests/auction_tests.move | 2 +- packages/suins/tests/controller_tests.move | 4 +--- packages/suins/tests/register_tests.move | 1 - packages/suins/tests/renew_tests.move | 2 +- packages/suins/tests/unit/admin_tests.move | 4 ---- 13 files changed, 19 insertions(+), 34 deletions(-) diff --git a/packages/suins/sources/actions/update_image.move b/packages/suins/sources/actions/update_image.move index 941cc953..a766037e 100644 --- a/packages/suins/sources/actions/update_image.move +++ b/packages/suins/sources/actions/update_image.move @@ -2,17 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 module suins::update_image { - use std::vector; use std::string::{utf8, String}; use sui::clock::Clock; use sui::bcs; use sui::ecdsa_k1; - use suins::domain; - use suins::registry::{Self, Registry}; - use suins::suins::{Self, SuiNS}; - use suins::config::{Self, Config}; - use suins::suins_registration::{Self as nft, SuinsRegistration}; + use suins::registry::Registry; + use suins::suins::SuiNS; + use suins::config::Config; + use suins::suins_registration::SuinsRegistration; /// Message data cannot be parsed. const EInvalidData: u64 = 0; @@ -26,7 +24,7 @@ module suins::update_image { /// Updates the image attached to a `SuinsRegistration`. entry fun update_image_url( - suins: &mut SuiNS, + suins: &SuiNS, nft: &mut SuinsRegistration, raw_msg: vector, signature: vector, diff --git a/packages/suins/sources/admin.move b/packages/suins/sources/admin.move index 77158ddd..a8bdff19 100644 --- a/packages/suins/sources/admin.move +++ b/packages/suins/sources/admin.move @@ -4,7 +4,6 @@ /// Admin features of the SuiNS application. Meant to be called directly /// by the suins admin. module suins::admin { - use std::vector; use std::string::String; use sui::clock::Clock; use sui::tx_context::{sender, TxContext}; @@ -13,7 +12,7 @@ module suins::admin { use suins::config; use suins::suins::{Self, AdminCap, SuiNS}; use suins::suins_registration::SuinsRegistration; - use suins::registry::{Self, Registry}; + use suins::registry::Registry; /// The authorization witness. public struct Admin has drop {} diff --git a/packages/suins/sources/auction.move b/packages/suins/sources/auction.move index ec198251..1ca70c23 100644 --- a/packages/suins/sources/auction.move +++ b/packages/suins/sources/auction.move @@ -5,13 +5,13 @@ /// More information in: ../../../docs module suins::auction { use std::option::{Self, Option, none, some, is_some}; - use std::string::{Self, String}; + use std::string::String; use sui::tx_context::{Self, TxContext}; use sui::balance::{Self, Balance}; use sui::transfer; use sui::coin::{Self, Coin}; - use sui::clock::{Self, Clock}; + use sui::clock::Clock; use sui::event; use sui::object::{Self, UID}; use sui::sui::SUI; @@ -19,8 +19,8 @@ module suins::auction { use suins::config::{Self, Config}; use suins::suins::{Self, AdminCap, SuiNS}; - use suins::suins_registration::{Self as nft, SuinsRegistration}; - use suins::registry::{Self, Registry}; + use suins::suins_registration::SuinsRegistration; + use suins::registry::Registry; use suins::domain::{Self, Domain}; /// One year is the default duration for a domain. diff --git a/packages/suins/sources/config.move b/packages/suins/sources/config.move index 9f7df30b..e45b6946 100644 --- a/packages/suins/sources/config.move +++ b/packages/suins/sources/config.move @@ -17,10 +17,8 @@ /// and set again within the same Programmable Transaction Block (can only be /// performed by Admin) module suins::config { - use std::vector; - use std::string; use suins::constants; - use suins::domain::{Self, Domain}; + use suins::domain::Domain; /// A label is too short to be registered. const ELabelTooShort: u64 = 0; diff --git a/packages/suins/sources/controller.move b/packages/suins/sources/controller.move index c34c0d10..59592343 100644 --- a/packages/suins/sources/controller.move +++ b/packages/suins/sources/controller.move @@ -6,13 +6,11 @@ module suins::controller { use std::string::String; use sui::tx_context::{sender, TxContext}; use sui::clock::Clock; - use sui::vec_map; use suins::domain; - use suins::registry::{Self, Registry}; + use suins::registry::Registry; use suins::suins::{Self, SuiNS}; - use suins::suins_registration::{Self as nft, SuinsRegistration}; - use std::string; + use suins::suins_registration::SuinsRegistration; const AVATAR: vector = b"avatar"; const CONTENT_HASH: vector = b"content_hash"; diff --git a/packages/suins/sources/registry.move b/packages/suins/sources/registry.move index adb66ec2..1919b88f 100644 --- a/packages/suins/sources/registry.move +++ b/packages/suins/sources/registry.move @@ -13,7 +13,7 @@ module suins::registry { use suins::suins_registration::{Self as nft, SuinsRegistration}; use suins::name_record::{Self, NameRecord}; - use suins::domain::{Self, Domain}; + use suins::domain::Domain; use suins::suins::AdminCap; use suins::subdomain_registration::{Self, SubDomainRegistration}; diff --git a/packages/suins/sources/subdomain_registration.move b/packages/suins/sources/subdomain_registration.move index 56d91278..04a7aa48 100644 --- a/packages/suins/sources/subdomain_registration.move +++ b/packages/suins/sources/subdomain_registration.move @@ -13,8 +13,7 @@ module suins::subdomain_registration { use sui::tx_context::TxContext; use sui::clock::Clock; - use suins::suins_registration::{Self, SuinsRegistration}; - use suins::domain; + use suins::suins_registration::SuinsRegistration; /* friend suins::registry; */ /* #[test_only] */ /* friend suins::sub_name_tests; */ diff --git a/packages/suins/sources/suins_registration.move b/packages/suins/sources/suins_registration.move index 333421d9..2f927ceb 100644 --- a/packages/suins/sources/suins_registration.move +++ b/packages/suins/sources/suins_registration.move @@ -17,7 +17,7 @@ module suins::suins_registration { use sui::clock::{timestamp_ms, Clock}; use suins::constants; - use suins::domain::{Self, Domain}; + use suins::domain::Domain; /* friend suins::registry; */ /* friend suins::update_image; */ diff --git a/packages/suins/tests/auction_tests.move b/packages/suins/tests/auction_tests.move index 6b55339d..248d5f26 100644 --- a/packages/suins/tests/auction_tests.move +++ b/packages/suins/tests/auction_tests.move @@ -15,7 +15,7 @@ module suins::auction_tests { Self, App as AuctionApp, place_bid, claim, AuctionHouse, start_auction_and_place_bid, total_balance, admin_finalize_auction, admin_try_finalize_auctions, admin_withdraw_funds, collect_winning_auction_fund }; - use suins::suins_registration::{Self, SuinsRegistration}; + use suins::suins_registration::SuinsRegistration; use suins::config; use suins::domain; use suins::constants::{Self, mist_per_sui}; diff --git a/packages/suins/tests/controller_tests.move b/packages/suins/tests/controller_tests.move index 3f5b1d0a..fbd17797 100644 --- a/packages/suins/tests/controller_tests.move +++ b/packages/suins/tests/controller_tests.move @@ -11,7 +11,7 @@ module suins::controller_tests { use sui::transfer; use sui::test_utils::assert_eq; use sui::dynamic_field; - use sui::vec_map::{Self, VecMap}; + use sui::vec_map::VecMap; use suins::register_sample::Register; use suins::constants::{mist_per_sui, year_ms}; @@ -20,13 +20,11 @@ module suins::controller_tests { use suins::register_sample_tests::register_util; use suins::controller::{Self, Controller, set_target_address_for_testing, set_reverse_lookup_for_testing, unset_reverse_lookup_for_testing, set_user_data_for_testing, unset_user_data_for_testing}; use suins::registry::{Self, Registry, lookup, reverse_lookup}; - use suins::name_record; use suins::domain::{Self, Domain}; const SUINS_ADDRESS: address = @0xA001; const FIRST_ADDRESS: address = @0xB001; const SECOND_ADDRESS: address = @0xB002; - const AUCTIONED_DOMAIN_NAME: vector = b"tes-t2.sui"; const DOMAIN_NAME: vector = b"abc.sui"; const AVATAR: vector = b"avatar"; const CONTENT_HASH: vector = b"content_hash"; diff --git a/packages/suins/tests/register_tests.move b/packages/suins/tests/register_tests.move index dcb82fa5..a9917de2 100644 --- a/packages/suins/tests/register_tests.move +++ b/packages/suins/tests/register_tests.move @@ -15,7 +15,6 @@ module suins::register_sample_tests { use suins::constants::{mist_per_sui, grace_period_ms, year_ms}; use suins::suins::{Self, SuiNS, total_balance, AdminCap}; use suins::suins_registration::SuinsRegistration; - use suins::suins_registration; use suins::domain; use suins::registry; use suins::config; diff --git a/packages/suins/tests/renew_tests.move b/packages/suins/tests/renew_tests.move index 4b97f0a7..48cee034 100644 --- a/packages/suins/tests/renew_tests.move +++ b/packages/suins/tests/renew_tests.move @@ -15,7 +15,7 @@ module suins::renew_tests { use suins::register_sample_tests::{register_util, assert_balance}; use suins::constants::{mist_per_sui, year_ms}; use suins::suins::{Self, SuiNS, AdminCap}; - use suins::suins_registration::{Self, SuinsRegistration}; + use suins::suins_registration::SuinsRegistration; use suins::registry; const SUINS_ADDRESS: address = @0xA001; diff --git a/packages/suins/tests/unit/admin_tests.move b/packages/suins/tests/unit/admin_tests.move index a243c398..47f32bb2 100644 --- a/packages/suins/tests/unit/admin_tests.move +++ b/packages/suins/tests/unit/admin_tests.move @@ -15,15 +15,11 @@ module suins::admin_tests { use sui::test_utils::assert_eq; use suins::admin::{Self, Admin}; - use suins::suins_registration as nft; use suins::constants; use suins::domain; use suins::suins; use suins::registry; - /// The admin account. - const ADMIN: address = @suins; - #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] fun try_unathorized_fail() { let mut ctx = tx_context::dummy(); From 273842ee01c54e96eb249d7e30b664b4c919a006 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Wed, 10 Apr 2024 16:11:00 -0400 Subject: [PATCH 25/38] update coupons --- packages/coupons/sources/coupons.move | 5 +---- packages/coupons/sources/range.move | 4 ++-- packages/coupons/sources/rules.move | 3 --- packages/coupons/tests/coupons_tests.move | 1 - packages/coupons/tests/setup.move | 3 --- 5 files changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index da3e8cab..1d4fbc42 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -12,9 +12,6 @@ module coupons::coupons { use std::string::String; use sui::table::{Self, Table}; - use sui::tx_context::{TxContext, sender}; - use sui::object::{Self, UID}; - use sui::transfer; use sui::dynamic_field::{Self as df}; use sui::clock::Clock; use sui::sui::SUI; @@ -120,7 +117,7 @@ module coupons::coupons { // 2. Decrease available claims. Will ABORT if the coupon doesn't have enough available claims. rules::decrease_available_claims(&mut coupon.rules); // 3. Validate the coupon is valid for the specified user. - rules::assert_coupon_valid_for_address(&coupon.rules, sender(ctx)); + rules::assert_coupon_valid_for_address(&coupon.rules, ctx.sender()); // 4. Validate the coupon hasn't expired (Based on clock) rules::assert_coupon_is_not_expired(&coupon.rules, clock); // 5. Validate years are valid for the coupon. diff --git a/packages/coupons/sources/range.move b/packages/coupons/sources/range.move index 508f5a75..a78b6c33 100644 --- a/packages/coupons/sources/range.move +++ b/packages/coupons/sources/range.move @@ -29,12 +29,12 @@ module coupons::range { /// Get floor limit for the range. public fun from(range: &Range): u8 { - *range.vec.borrow(0) + range.vec[0] } /// Get upper limit for the range. public fun to(range: &Range): u8 { - *range.vec.borrow(1) + range.vec[1] } } diff --git a/packages/coupons/sources/rules.move b/packages/coupons/sources/rules.move index b243e481..7e21b15f 100644 --- a/packages/coupons/sources/rules.move +++ b/packages/coupons/sources/rules.move @@ -4,9 +4,6 @@ // A module with a couple of helpers for validation of coupons // validation of names etc. module coupons::rules { - - use std::option::{Self, Option}; - use sui::clock::Clock; use coupons::{constants, range::Range}; diff --git a/packages/coupons/tests/coupons_tests.move b/packages/coupons/tests/coupons_tests.move index 13622ea2..8a727ad5 100644 --- a/packages/coupons/tests/coupons_tests.move +++ b/packages/coupons/tests/coupons_tests.move @@ -3,7 +3,6 @@ #[test_only] module coupons::coupon_tests { - use std::option; use std::string::{utf8}; use sui::test_scenario::{Self, Scenario, ctx, return_shared, end}; diff --git a/packages/coupons/tests/setup.move b/packages/coupons/tests/setup.move index 8c1f3d77..ad80c62f 100644 --- a/packages/coupons/tests/setup.move +++ b/packages/coupons/tests/setup.move @@ -3,15 +3,12 @@ #[test_only] module coupons::setup { - use std::option; use std::string::{utf8, String}; use sui::clock::{Self, Clock}; use sui::test_scenario::{Self, Scenario, ctx}; - use sui::tx_context::{TxContext}; use sui::sui::SUI; use sui::coin::{Self}; - use sui::transfer; use coupons::coupons::{Self, CouponsApp,Data, CouponHouse}; use coupons::rules::{Self}; From 052eb9fa3c52a64d6d30f8802dac89bde14a4bb5 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Wed, 10 Apr 2024 16:19:07 -0400 Subject: [PATCH 26/38] more syntax conversion --- packages/coupons/sources/coupons.move | 4 ++-- packages/denylist/sources/denylist.move | 5 ++--- packages/denylist/tests/denylist_tests.move | 1 - packages/discounts/sources/discounts.move | 2 -- packages/discounts/sources/free_claims.move | 11 ++++------- packages/discounts/sources/house.move | 3 --- packages/discounts/tests/discount_tests.move | 2 -- packages/discounts/tests/free_claims_test.move | 2 -- 8 files changed, 8 insertions(+), 22 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index 1d4fbc42..4e642f10 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -108,7 +108,7 @@ module coupons::coupons { let domain_length = (label.length() as u8); // Borrow coupon from the table. - let coupon = self.data.coupons.borrow_mut(coupon_code); + let coupon = &mut self.data.coupons[coupon_code]; // We need to do a total of 5 checks, based on `CouponRules` // Our checks work with `AND`, all of the conditions must pass for a coupon to be used. @@ -149,7 +149,7 @@ module coupons::coupons { // Validate that specified coupon is valid. assert!(self.data.coupons.contains(coupon_code), ECouponNotExists); // Borrow coupon from the table. - let coupon = self.data.coupons.borrow_mut(coupon_code); + let coupon = &mut self.data.coupons[coupon_code]; internal_calculate_sale_price(price, coupon) } diff --git a/packages/denylist/sources/denylist.move b/packages/denylist/sources/denylist.move index 13ddfc26..530bc311 100644 --- a/packages/denylist/sources/denylist.move +++ b/packages/denylist/sources/denylist.move @@ -4,7 +4,6 @@ module denylist::denylist { use std::string::String; - use sui::tx_context::{TxContext}; use sui::table::{Self, Table}; use suins::suins::{Self, AdminCap, SuiNS}; @@ -80,7 +79,7 @@ module denylist::denylist { while (i > 0) { i = i - 1; - let word = *words.borrow(i); + let word = words[i]; table.add(word, true); }; } @@ -93,7 +92,7 @@ module denylist::denylist { while (i > 0) { i = i - 1; - let word = *words.borrow(i); + let word = words[i]; table.remove(word); }; } diff --git a/packages/denylist/tests/denylist_tests.move b/packages/denylist/tests/denylist_tests.move index 7dc7c63d..0cf2a745 100644 --- a/packages/denylist/tests/denylist_tests.move +++ b/packages/denylist/tests/denylist_tests.move @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 module denylist::denylist_tests { - use std::vector; use std::string::{utf8, String}; use sui::test_scenario::{Self as ts, Scenario}; diff --git a/packages/discounts/sources/discounts.move b/packages/discounts/sources/discounts.move index 65fb7f9b..c7da6a20 100644 --- a/packages/discounts/sources/discounts.move +++ b/packages/discounts/sources/discounts.move @@ -8,11 +8,9 @@ /// Can be called only when promotions are active for a specific type T. /// Activation / deactivation happens through PTBs. module discounts::discounts { - use std::option::{Option}; use std::string::String; use std::type_name::{Self as `type`}; - use sui::tx_context::{TxContext}; use sui::dynamic_field::{Self as df}; use sui::clock::{Clock}; use sui::coin::Coin; diff --git a/packages/discounts/sources/free_claims.move b/packages/discounts/sources/free_claims.move index b3bef7c6..ea673206 100644 --- a/packages/discounts/sources/free_claims.move +++ b/packages/discounts/sources/free_claims.move @@ -12,9 +12,6 @@ module discounts::free_claims { use std::string::{String}; use std::type_name::{Self as `type`}; - use sui::object::{Self, ID}; - use sui::tx_context::{TxContext}; - use sui::dynamic_field::{Self as df}; use sui::clock::{Clock}; use sui::linked_table::{Self, LinkedTable}; @@ -169,8 +166,8 @@ module discounts::free_claims { /// Validate that the domain length is valid for the passed configuration. fun assert_domain_length_eligible(domain: &Domain, config: &FreeClaimsConfig) { let domain_length = (domain.sld().length() as u8); - let from = *config.domain_length_range.borrow(0); - let to = *config.domain_length_range.borrow(1); + let from = config.domain_length_range[0]; + let to = config.domain_length_range[1]; assert!(domain_length >= from && domain_length <= to, EInvalidCharacterRange); } @@ -180,8 +177,8 @@ module discounts::free_claims { fun assert_valid_length_setup(domain_length_range: &vector) { assert!(domain_length_range.length() == 2, EInvalidCharacterRange); - let from = *domain_length_range.borrow(0); - let to = *domain_length_range.borrow(1); + let from = domain_length_range[0]; + let to = domain_length_range[1]; assert!(to >= from, EInvalidCharacterRange); } diff --git a/packages/discounts/sources/house.move b/packages/discounts/sources/house.move index 372261e8..3ba177d8 100644 --- a/packages/discounts/sources/house.move +++ b/packages/discounts/sources/house.move @@ -5,9 +5,6 @@ /// and exports some package utilities for the 2 systems to use. module discounts::house { - use sui::object::{Self, UID}; - use sui::tx_context::{TxContext}; - use sui::transfer; use sui::clock::{Clock}; use suins::domain::Domain; diff --git a/packages/discounts/tests/discount_tests.move b/packages/discounts/tests/discount_tests.move index 3ca1067b..ca085a80 100644 --- a/packages/discounts/tests/discount_tests.move +++ b/packages/discounts/tests/discount_tests.move @@ -3,14 +3,12 @@ #[test_only] module discounts::discount_tests { - use std::option; use std::string::{utf8, String}; use sui::test_scenario::{Self as ts, Scenario, ctx}; use sui::clock::{Self, Clock}; use sui::coin::{Self, Coin}; use sui::sui::SUI; - use sui::transfer; use suins::suins::{Self, SuiNS, AdminCap}; use suins::registry; diff --git a/packages/discounts/tests/free_claims_test.move b/packages/discounts/tests/free_claims_test.move index 9dc500cd..966abc6b 100644 --- a/packages/discounts/tests/free_claims_test.move +++ b/packages/discounts/tests/free_claims_test.move @@ -6,10 +6,8 @@ module discounts::free_claims_tests { use std::string::{utf8, String}; - use sui::object::{Self, UID}; use sui::test_scenario::{Self as ts, Scenario, ctx}; use sui::clock::{Self, Clock}; - use sui::transfer; use suins::suins::{Self, SuiNS, AdminCap}; use suins::registry; From 31f2779080e4c897e1809fec96ae079e7178101b Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 09:26:58 -0400 Subject: [PATCH 27/38] borrow syntax additional --- packages/managed_names/sources/managed.move | 7 ++----- packages/managed_names/tests/managed_tests.move | 3 --- packages/suins/sources/auction.move | 2 +- packages/suins/sources/registry.move | 6 +++--- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/managed_names/sources/managed.move b/packages/managed_names/sources/managed.move index edc49607..1a0a64e4 100644 --- a/packages/managed_names/sources/managed.move +++ b/packages/managed_names/sources/managed.move @@ -17,13 +17,10 @@ /// module managed_names::managed { use std::string::{String}; - use std::option::{Self, Option}; - use sui::object::{Self, ID}; use sui::table::{Self, Table}; - use sui::tx_context::{TxContext, sender}; + use sui::tx_context::sender; use sui::clock::Clock; - use sui::transfer; use suins::domain::{Self, Domain}; use suins::suins_registration::SuinsRegistration; @@ -206,7 +203,7 @@ module managed_names::managed { fun internal_get_managed_name(managed_names: &mut ManagedNames, domain: Domain): &mut ManagedName { assert!(managed_names.names.contains(domain), ENameNotExists); - managed_names.names.borrow_mut(domain) + &mut managed_names.names[domain] } diff --git a/packages/managed_names/tests/managed_tests.move b/packages/managed_names/tests/managed_tests.move index b5b8c5c5..1025b2f0 100644 --- a/packages/managed_names/tests/managed_tests.move +++ b/packages/managed_names/tests/managed_tests.move @@ -2,13 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 module managed_names::managed_tests { - use std::option; use std::string::{String, utf8}; use sui::test_scenario::{Self as ts, Scenario, ctx}; use sui::clock::{Self, Clock}; - use sui::transfer; - use sui::object; use suins::suins_registration::{Self, new_for_testing, SuinsRegistration}; use suins::suins::{Self, SuiNS}; diff --git a/packages/suins/sources/auction.move b/packages/suins/sources/auction.move index 1ca70c23..55f7ca0b 100644 --- a/packages/suins/sources/auction.move +++ b/packages/suins/sources/auction.move @@ -277,7 +277,7 @@ module suins::auction { ctx: &mut TxContext, ) { let domain = domain::new(domain_name); - let auction = self.auctions.borrow_mut(domain); + let auction = &mut self.auctions[domain]; // Ensure that the auction is over assert!(clock.timestamp_ms() > auction.end_timestamp_ms, EAuctionNotEndedYet); diff --git a/packages/suins/sources/registry.move b/packages/suins/sources/registry.move index 1919b88f..d326b72d 100644 --- a/packages/suins/sources/registry.move +++ b/packages/suins/sources/registry.move @@ -194,7 +194,7 @@ module suins::registry { domain: Domain, new_target: Option
, ) { - let record = self.registry.borrow_mut(domain); + let record = &mut self.registry[domain]; let old_target = record.target_address(); record.set_target_address(new_target); @@ -233,7 +233,7 @@ module suins::registry { domain: Domain, expiration_timestamp_ms: u64, ) { - let record = table::borrow_mut(&mut self.registry, domain); + let record = &mut self.registry[domain]; assert!(object::id(nft) == record.nft_id(), EIdMismatch); record.set_expiration_timestamp_ms(expiration_timestamp_ms); @@ -248,7 +248,7 @@ module suins::registry { domain: Domain, data: VecMap ) { - let record = self.registry.borrow_mut(domain); + let record = &mut self.registry[domain]; record.set_data(data); } From ec2fbad8ebc1973badc6b51d2006768fbcd57077 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 09:56:14 -0400 Subject: [PATCH 28/38] final borrow changes --- packages/subdomains/sources/config.move | 2 +- packages/suins/sources/auction.move | 4 ++-- packages/suins/sources/domain.move | 10 +++++----- packages/suins/sources/registry.move | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/subdomains/sources/config.move b/packages/subdomains/sources/config.move index 0f201522..b04153d7 100644 --- a/packages/subdomains/sources/config.move +++ b/packages/subdomains/sources/config.move @@ -80,7 +80,7 @@ module subdomains::config { public fun is_valid_tld(domain: &Domain, config: &SubDomainConfig): bool { let mut i=0; while (i < config.allowed_tlds.length()) { - if (domain.tld() == config.allowed_tlds.borrow(i)) { + if (domain.tld() == &config.allowed_tlds[i]) { return true }; i = i + 1; diff --git a/packages/suins/sources/auction.move b/packages/suins/sources/auction.move index 55f7ca0b..88964652 100644 --- a/packages/suins/sources/auction.move +++ b/packages/suins/sources/auction.move @@ -258,7 +258,7 @@ module suins::auction { let domain = domain::new(domain_name); if (self.auctions.contains(domain)) { - let auction = self.auctions.borrow(domain); + let auction = &self.auctions[domain]; let highest_amount = auction.current_bid.value(); return ( some(auction.start_timestamp_ms), @@ -375,7 +375,7 @@ module suins::auction { let domain = option::extract(&mut next_domain); next_domain = *self.auctions.prev(domain); - let auction = self.auctions.borrow(domain); + let auction = &self.auctions[domain]; // If the auction has ended, then try to finalize it if (clock.timestamp_ms() > auction.end_timestamp_ms) { diff --git a/packages/suins/sources/domain.move b/packages/suins/sources/domain.move index ac1b533f..eb09d4d4 100644 --- a/packages/suins/sources/domain.move +++ b/packages/suins/sources/domain.move @@ -48,7 +48,7 @@ module suins::domain { let mut out = string::utf8(vector::empty()); while (i < len) { - let part = self.labels.borrow((len - i) - 1); + let part = &self.labels[(len - i) - 1]; out.append(*part); i = i + 1; @@ -69,7 +69,7 @@ module suins::domain { /// /// This means that the TLD will always be at level `0`. public fun label(self: &Domain, level: u64): &String { - self.labels.borrow(level) + &self.labels[level] } /// Returns the TLD (Top-Level Domain) of a `Domain`. @@ -119,7 +119,7 @@ module suins::domain { let mut index = 0; while (index < len) { - let label = labels.borrow(index); + let label = &labels[index]; assert!(is_valid_label(label), EInvalidDomain); index = index + 1; } @@ -135,7 +135,7 @@ module suins::domain { }; while (index < len) { - let character = *label_bytes.borrow(index); + let character = label_bytes[index]; let is_valid_character = (0x61 <= character && character <= 0x7A) // a-z || (0x30 <= character && character <= 0x39) // 0-9 @@ -191,7 +191,7 @@ module suins::domain { let mut index = 0; while (index < len) { - let label = expected_labels.borrow(index); + let label = &expected_labels[index]; assert_eq(*label, *label(&domain, index)); index = index + 1; } diff --git a/packages/suins/sources/registry.move b/packages/suins/sources/registry.move index d326b72d..7464b49d 100644 --- a/packages/suins/sources/registry.move +++ b/packages/suins/sources/registry.move @@ -97,7 +97,7 @@ module suins::registry { // Then, if the registry still has a record for this domain and the NFT ID matches, we remove it. if (self.registry.contains(domain)) { - let record = self.registry.borrow(domain); + let record = &self.registry[domain]; // We wanna remove the record only if the NFT ID matches. if (record.nft_id() == object::id(&nft)) { @@ -211,7 +211,7 @@ module suins::registry { address: address, domain: Domain, ) { - let record = self.registry.borrow(domain); + let record = &self.registry[domain]; let target = record.target_address(); assert!(option::is_some(&target), ETargetNotSet); @@ -262,7 +262,7 @@ module suins::registry { /// Returns the `NameRecord` associated with the given domain or None. public fun lookup(self: &Registry, domain: Domain): Option { if (self.registry.contains(domain)) { - let record = self.registry.borrow(domain); + let record = &self.registry[domain]; some(*record) } else { none() @@ -272,7 +272,7 @@ module suins::registry { /// Returns the `domain_name` associated with the given address or None. public fun reverse_lookup(self: &Registry, address: address): Option { if (table::contains(&self.reverse_registry, address)) { - some(*self.reverse_registry.borrow(address)) + some(self.reverse_registry[address]) } else { none() } @@ -283,7 +283,7 @@ module suins::registry { /// 2. Has not expired (does not take into account the grace period) public fun assert_nft_is_authorized(self: &Registry, nft: &SuinsRegistration, clock: &Clock) { let domain = nft.domain(); - let record = self.registry.borrow(domain); + let record = &self.registry[domain]; // The NFT does not assert!(object::id(nft) == record.nft_id(), EIdMismatch); @@ -293,7 +293,7 @@ module suins::registry { /// Returns the `data` associated with the given `Domain`. public fun get_data(self: &Registry, domain: Domain): &VecMap { - let record = self.registry.borrow(domain); + let record = &self.registry[domain]; record.data() } @@ -398,7 +398,7 @@ module suins::registry { let reverse_registry = &mut self.reverse_registry; if (table::contains(reverse_registry, old_target_address)) { - let default_domain = reverse_registry.borrow(old_target_address); + let default_domain = &reverse_registry[old_target_address]; if (default_domain == domain) { reverse_registry.remove(old_target_address); } From 390eb23bdf2de692b087446e8db84861fbb04f86 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 10:05:31 -0400 Subject: [PATCH 29/38] cleanup use --- packages/suins/sources/admin.move | 2 +- packages/suins/sources/auction.move | 5 +---- packages/suins/sources/controller.move | 3 +-- packages/suins/sources/domain.move | 1 - packages/suins/sources/name_record.move | 2 -- packages/suins/sources/registry.move | 4 +--- packages/suins/sources/subdomain_registration.move | 3 --- packages/suins/sources/suins.move | 3 --- packages/suins/sources/suins_registration.move | 2 -- packages/suins/tests/auction_tests.move | 1 - packages/suins/tests/controller_tests.move | 3 +-- packages/suins/tests/unit/admin_tests.move | 1 - packages/suins/tests/unit/name_record_tests.move | 2 -- packages/suins/tests/unit/registration_nft_tests.move | 1 - packages/suins/tests/unit/registry_tests.move | 5 +---- packages/suins/tests/unit/sub_name_tests.move | 1 - packages/suins/tests/unit/suins_tests.move | 1 - packages/suins/tests/v2/register.move | 1 - packages/suins/tests/v2/renew.move | 2 -- 19 files changed, 6 insertions(+), 37 deletions(-) diff --git a/packages/suins/sources/admin.move b/packages/suins/sources/admin.move index a8bdff19..e8a960c3 100644 --- a/packages/suins/sources/admin.move +++ b/packages/suins/sources/admin.move @@ -6,7 +6,7 @@ module suins::admin { use std::string::String; use sui::clock::Clock; - use sui::tx_context::{sender, TxContext}; + use sui::tx_context::{sender}; use suins::domain; use suins::config; diff --git a/packages/suins/sources/auction.move b/packages/suins/sources/auction.move index 88964652..005ce574 100644 --- a/packages/suins/sources/auction.move +++ b/packages/suins/sources/auction.move @@ -4,16 +4,13 @@ /// Implementation of auction module. /// More information in: ../../../docs module suins::auction { - use std::option::{Self, Option, none, some, is_some}; + use std::option::{none, some, is_some}; use std::string::String; - use sui::tx_context::{Self, TxContext}; use sui::balance::{Self, Balance}; - use sui::transfer; use sui::coin::{Self, Coin}; use sui::clock::Clock; use sui::event; - use sui::object::{Self, UID}; use sui::sui::SUI; use sui::linked_table::{Self, LinkedTable}; diff --git a/packages/suins/sources/controller.move b/packages/suins/sources/controller.move index 59592343..69c8e501 100644 --- a/packages/suins/sources/controller.move +++ b/packages/suins/sources/controller.move @@ -2,9 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 module suins::controller { - use std::option::Option; use std::string::String; - use sui::tx_context::{sender, TxContext}; + use sui::tx_context::{sender,}; use sui::clock::Clock; use suins::domain; diff --git a/packages/suins/sources/domain.move b/packages/suins/sources/domain.move index eb09d4d4..9b9d30d4 100644 --- a/packages/suins/sources/domain.move +++ b/packages/suins/sources/domain.move @@ -8,7 +8,6 @@ /// https://en.wikipedia.org/wiki/Domain_name#Domain_name_syntax module suins::domain { use std::string::{Self, String, utf8}; - use std::vector; const EInvalidDomain: u64 = 0; diff --git a/packages/suins/sources/name_record.move b/packages/suins/sources/name_record.move index 91f2383e..357b29a8 100644 --- a/packages/suins/sources/name_record.move +++ b/packages/suins/sources/name_record.move @@ -6,12 +6,10 @@ /// stored and managed. SuiNS has no direct and permanent dependency on this /// module. module suins::name_record { - use std::option::{Self, Option}; use std::string::String; use sui::clock::{timestamp_ms, Clock}; use sui::vec_map::{Self, VecMap}; - use sui::object::ID; use suins::constants; diff --git a/packages/suins/sources/registry.move b/packages/suins/sources/registry.move index 7464b49d..611b7fa4 100644 --- a/packages/suins/sources/registry.move +++ b/packages/suins/sources/registry.move @@ -2,11 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 module suins::registry { - use std::option::{Self, none, some, Option}; + use std::option::{none, some}; use std::string::String; - use sui::tx_context::TxContext; - use sui::object; use sui::table::{Self, Table}; use sui::clock::Clock; use sui::vec_map::VecMap; diff --git a/packages/suins/sources/subdomain_registration.move b/packages/suins/sources/subdomain_registration.move index 04a7aa48..9c8c25b8 100644 --- a/packages/suins/sources/subdomain_registration.move +++ b/packages/suins/sources/subdomain_registration.move @@ -8,9 +8,6 @@ /// /// We maintain all core functionality unchanged for registry, expiration etc. module suins::subdomain_registration { - use sui::object::{Self, UID}; - - use sui::tx_context::TxContext; use sui::clock::Clock; use suins::suins_registration::SuinsRegistration; diff --git a/packages/suins/sources/suins.move b/packages/suins/sources/suins.move index feb40ddb..298f8532 100644 --- a/packages/suins/sources/suins.move +++ b/packages/suins/sources/suins.move @@ -21,12 +21,9 @@ /// - Any of the old modules can be deauthorized hence disabling its access to /// the registry and the balance. module suins::suins { - use sui::tx_context::{Self, TxContext}; use sui::balance::{Self, Balance}; use sui::coin::{Self, Coin}; use sui::dynamic_field as df; - use sui::object::{Self, UID}; - use sui::transfer; use sui::sui::SUI; /// Trying to withdraw from an empty balance. diff --git a/packages/suins/sources/suins_registration.move b/packages/suins/sources/suins_registration.move index 2f927ceb..9e5605f4 100644 --- a/packages/suins/sources/suins_registration.move +++ b/packages/suins/sources/suins_registration.move @@ -12,8 +12,6 @@ /// module suins::suins_registration { use std::string::{String}; - use sui::object::{Self, UID}; - use sui::tx_context::TxContext; use sui::clock::{timestamp_ms, Clock}; use suins::constants; diff --git a/packages/suins/tests/auction_tests.move b/packages/suins/tests/auction_tests.move index 248d5f26..d837df2b 100644 --- a/packages/suins/tests/auction_tests.move +++ b/packages/suins/tests/auction_tests.move @@ -3,7 +3,6 @@ #[test_only] module suins::auction_tests { - use std::option; use std::string::{String, utf8}; use sui::test_scenario::{Self, Scenario, ctx}; diff --git a/packages/suins/tests/controller_tests.move b/packages/suins/tests/controller_tests.move index fbd17797..28e3ae14 100644 --- a/packages/suins/tests/controller_tests.move +++ b/packages/suins/tests/controller_tests.move @@ -4,11 +4,10 @@ #[test_only] module suins::controller_tests { use std::string::{utf8, String}; - use std::option::{Option, extract, some, none}; + use std::option::{extract, some, none}; use sui::test_scenario::{Self, Scenario, ctx}; use sui::clock::{Self, Clock}; - use sui::transfer; use sui::test_utils::assert_eq; use sui::dynamic_field; use sui::vec_map::VecMap; diff --git a/packages/suins/tests/unit/admin_tests.move b/packages/suins/tests/unit/admin_tests.move index 47f32bb2..02c2d46e 100644 --- a/packages/suins/tests/unit/admin_tests.move +++ b/packages/suins/tests/unit/admin_tests.move @@ -10,7 +10,6 @@ /// module suins::admin_tests { use std::string::utf8; - use sui::tx_context; use sui::clock; use sui::test_utils::assert_eq; diff --git a/packages/suins/tests/unit/name_record_tests.move b/packages/suins/tests/unit/name_record_tests.move index 11c0b285..02b50289 100644 --- a/packages/suins/tests/unit/name_record_tests.move +++ b/packages/suins/tests/unit/name_record_tests.move @@ -11,8 +11,6 @@ module suins::name_record_tests { use std::string::utf8; use std::option::{none, some}; - use sui::object::{Self, ID}; - use sui::tx_context::{Self, TxContext}; use sui::test_utils::assert_eq; use sui::vec_map; use sui::clock; diff --git a/packages/suins/tests/unit/registration_nft_tests.move b/packages/suins/tests/unit/registration_nft_tests.move index 6add3da1..d4cdb3d0 100644 --- a/packages/suins/tests/unit/registration_nft_tests.move +++ b/packages/suins/tests/unit/registration_nft_tests.move @@ -10,7 +10,6 @@ /// module suins::registation_nft_tests { use std::string::{utf8, String}; - use sui::tx_context::{Self, TxContext}; use sui::clock::{Self, Clock}; use sui::test_utils::assert_eq; diff --git a/packages/suins/tests/unit/registry_tests.move b/packages/suins/tests/unit/registry_tests.move index d4add17f..53586969 100644 --- a/packages/suins/tests/unit/registry_tests.move +++ b/packages/suins/tests/unit/registry_tests.move @@ -4,10 +4,7 @@ #[test_only] module suins::registry_tests { use std::string::utf8; - use std::option::{Self, some}; - use std::vector; - use sui::object; - use sui::tx_context::{Self, TxContext}; + use std::option::{some}; use sui::clock::{Self, Clock}; use sui::test_utils::assert_eq; diff --git a/packages/suins/tests/unit/sub_name_tests.move b/packages/suins/tests/unit/sub_name_tests.move index ea14a439..667fdd99 100644 --- a/packages/suins/tests/unit/sub_name_tests.move +++ b/packages/suins/tests/unit/sub_name_tests.move @@ -5,7 +5,6 @@ module suins::sub_name_tests { use std::string::utf8; - use sui::tx_context; use sui::clock; use suins::suins_registration; diff --git a/packages/suins/tests/unit/suins_tests.move b/packages/suins/tests/unit/suins_tests.move index c3140a45..e3149851 100644 --- a/packages/suins/tests/unit/suins_tests.move +++ b/packages/suins/tests/unit/suins_tests.move @@ -7,7 +7,6 @@ module suins::suins_tests { use sui::coin; use sui::balance; use sui::sui::SUI; - use sui::tx_context; use sui::test_utils::assert_eq; use suins::suins::{Self, AdminCap, SuiNS}; diff --git a/packages/suins/tests/v2/register.move b/packages/suins/tests/v2/register.move index f53a19e6..59735748 100644 --- a/packages/suins/tests/v2/register.move +++ b/packages/suins/tests/v2/register.move @@ -5,7 +5,6 @@ module suins::register_sample { use std::string::{Self, String}; use sui::coin::{Self, Coin}; - use sui::tx_context::TxContext; use sui::clock::Clock; use sui::sui::SUI; diff --git a/packages/suins/tests/v2/renew.move b/packages/suins/tests/v2/renew.move index 5c5d76af..74dccd7d 100644 --- a/packages/suins/tests/v2/renew.move +++ b/packages/suins/tests/v2/renew.move @@ -3,12 +3,10 @@ #[test_only] module suins::renew { - use std::option; use std::string; use sui::coin::{Self, Coin}; use sui::clock::{timestamp_ms, Clock}; use sui::sui::SUI; - use sui::object; use suins::domain; use suins::constants; From e65e360bfac4262bb47d40a0613bde4d08f801fc Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 10:10:51 -0400 Subject: [PATCH 30/38] more cleanup --- packages/registration/sources/register.move | 1 - packages/renewal/sources/renew.move | 3 --- packages/renewal/tests/renew_tests.move | 1 - packages/subdomains/sources/subdomains.move | 3 --- packages/temp_subdomain_proxy/sources/subdomain_proxy.move | 1 - 5 files changed, 9 deletions(-) diff --git a/packages/registration/sources/register.move b/packages/registration/sources/register.move index b9022cae..36d3c8ec 100644 --- a/packages/registration/sources/register.move +++ b/packages/registration/sources/register.move @@ -4,7 +4,6 @@ module registration::register { use std::string::String; use sui::coin::Coin; - use sui::tx_context::TxContext; use sui::clock::Clock; use sui::sui::SUI; diff --git a/packages/renewal/sources/renew.move b/packages/renewal/sources/renew.move index 470117b1..e77c0e39 100644 --- a/packages/renewal/sources/renew.move +++ b/packages/renewal/sources/renew.move @@ -6,13 +6,10 @@ /// /// The renewal is capped at 5 years. module renewal::renew { - use std::option; - use sui::coin::{Self, Coin}; use sui::clock::Clock; use sui::sui::SUI; - use sui::object; use suins::constants; use suins::domain::Domain; diff --git a/packages/renewal/tests/renew_tests.move b/packages/renewal/tests/renew_tests.move index 5961c7c2..56c9b1f0 100644 --- a/packages/renewal/tests/renew_tests.move +++ b/packages/renewal/tests/renew_tests.move @@ -8,7 +8,6 @@ module renewal::renew_tests { use sui::coin; use sui::sui::SUI; use sui::clock::{Self, Clock}; - use sui::tx_context::{Self, TxContext}; use suins::constants::{mist_per_sui, year_ms, grace_period_ms}; use suins::suins::{Self, SuiNS}; diff --git a/packages/subdomains/sources/subdomains.move b/packages/subdomains/sources/subdomains.move index 7d9bb252..e4abc03b 100644 --- a/packages/subdomains/sources/subdomains.move +++ b/packages/subdomains/sources/subdomains.move @@ -25,11 +25,8 @@ /// OPEN TODOS: /// module subdomains::subdomains { - use std::option; use std::string::{String, utf8}; - use sui::object::{Self, ID}; - use sui::tx_context::{TxContext}; use sui::clock::Clock; use sui::dynamic_field as df; use sui::vec_map::VecMap; diff --git a/packages/temp_subdomain_proxy/sources/subdomain_proxy.move b/packages/temp_subdomain_proxy/sources/subdomain_proxy.move index 1310ef7d..88e479ff 100644 --- a/packages/temp_subdomain_proxy/sources/subdomain_proxy.move +++ b/packages/temp_subdomain_proxy/sources/subdomain_proxy.move @@ -11,7 +11,6 @@ module temp_subdomain_proxy::subdomain_proxy { use std::string::String; - use sui::tx_context::TxContext; use sui::clock::Clock; use suins::suins::SuiNS; From 6fc749005c91fddf35e4091683d8ef69d79e32e0 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 11:40:37 -0400 Subject: [PATCH 31/38] minor --- packages/utils/sources/direct_setup.move | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/utils/sources/direct_setup.move b/packages/utils/sources/direct_setup.move index a8027de9..9ee86e30 100644 --- a/packages/utils/sources/direct_setup.move +++ b/packages/utils/sources/direct_setup.move @@ -4,10 +4,9 @@ /// A simple package to allows us set a target address & default name in a single PTB in frontend. /// Unblocks better UX in the registration flow | easier adoption for non-technical users. module utils::direct_setup { - use std::option; use std::string::{String}; - use sui::tx_context::{TxContext, sender}; + use sui::tx_context::{sender}; use sui::clock::Clock; use suins::domain; From 348401c05024f19900b4c664ce947bf277e39151 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 14:08:01 -0400 Subject: [PATCH 32/38] nesting added --- packages/coupons/sources/coupons.move | 11 ++---- packages/coupons/tests/coupons_tests.move | 6 +--- packages/coupons/tests/setup.move | 10 ++---- packages/discounts/sources/discounts.move | 12 ++----- packages/discounts/sources/free_claims.move | 12 ++----- packages/discounts/sources/house.move | 6 +--- packages/discounts/tests/discount_tests.move | 11 ++---- .../discounts/tests/free_claims_test.move | 6 ++-- packages/managed_names/sources/managed.move | 8 ++--- .../managed_names/tests/managed_tests.move | 7 ++-- packages/registration/sources/register.move | 12 ++----- .../registration/tests/register_tests.move | 15 ++------ packages/renewal/sources/renew.move | 12 ++----- packages/renewal/tests/renew_tests.move | 13 ++----- packages/subdomains/sources/config.move | 3 +- packages/subdomains/sources/subdomains.move | 13 ++----- .../subdomains/tests/subdomain_tests.move | 13 ++----- .../suins/sources/actions/update_image.move | 9 ++--- packages/suins/sources/admin.move | 9 ++--- packages/suins/sources/auction.move | 20 +++-------- packages/suins/sources/config.move | 3 +- packages/suins/sources/controller.move | 8 ++--- packages/suins/sources/name_record.move | 3 +- packages/suins/sources/registry.move | 17 +++------- packages/suins/sources/suins.move | 5 +-- .../suins/sources/suins_registration.move | 3 +- packages/suins/tests/auction_tests.move | 20 ++++++----- packages/suins/tests/controller_tests.move | 34 +++++++++---------- packages/suins/tests/register_tests.move | 27 +++++++-------- packages/suins/tests/renew_tests.move | 28 ++++++++------- packages/suins/tests/unit/admin_tests.move | 9 ++--- .../suins/tests/unit/name_record_tests.move | 10 ++---- .../tests/unit/registration_nft_tests.move | 7 ++-- packages/suins/tests/unit/registry_tests.move | 14 +++----- packages/suins/tests/unit/sub_name_tests.move | 4 +-- packages/suins/tests/unit/suins_tests.move | 5 +-- packages/suins/tests/v2/register.move | 12 ++----- packages/suins/tests/v2/renew.move | 12 ++----- .../sources/subdomain_proxy.move | 3 +- packages/utils/sources/direct_setup.move | 8 ++--- 40 files changed, 137 insertions(+), 303 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index 4e642f10..ae5045ac 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -11,14 +11,9 @@ module coupons::coupons { use std::string::String; - use sui::table::{Self, Table}; - use sui::dynamic_field::{Self as df}; - use sui::clock::Clock; - use sui::sui::SUI; - use sui::coin::{Self, Coin}; - - use coupons::rules::{Self, CouponRules}; - use coupons::constants; + use sui::{table::{Self, Table}, dynamic_field::{Self as df}, clock::Clock, sui::SUI, coin::{Self, Coin}}; + + use coupons::{rules::{Self, CouponRules}, constants}; use suins::{domain, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, config::Self, registry::{Self, Registry}}; /// Coupon already exists diff --git a/packages/coupons/tests/coupons_tests.move b/packages/coupons/tests/coupons_tests.move index 8a727ad5..e06e9e34 100644 --- a/packages/coupons/tests/coupons_tests.move +++ b/packages/coupons/tests/coupons_tests.move @@ -8,11 +8,7 @@ module coupons::coupon_tests { use sui::test_scenario::{Self, Scenario, ctx, return_shared, end}; // test dependencies. - use coupons::setup::{Self, TestApp, user, user_two, mist_per_sui, test_app, admin_add_coupon, register_with_coupon, test_init}; - use coupons::coupons::{Self, CouponHouse}; - use coupons::constants::{Self}; - use coupons::rules; - use coupons::range; + use coupons::{setup::{Self, TestApp, user, user_two, mist_per_sui, test_app, admin_add_coupon, register_with_coupon, test_init}, coupons::{Self, CouponHouse}, constants::{Self}, rules, range}; // populate a lot of coupons with different cases. // This populates the coupon as an authorized app diff --git a/packages/coupons/tests/setup.move b/packages/coupons/tests/setup.move index ad80c62f..0c62c9e7 100644 --- a/packages/coupons/tests/setup.move +++ b/packages/coupons/tests/setup.move @@ -5,15 +5,9 @@ module coupons::setup { use std::string::{utf8, String}; - use sui::clock::{Self, Clock}; - use sui::test_scenario::{Self, Scenario, ctx}; - use sui::sui::SUI; - use sui::coin::{Self}; + use sui::{clock::{Self, Clock}, test_scenario::{Self, Scenario, ctx}, sui::SUI, coin::{Self}}; - use coupons::coupons::{Self, CouponsApp,Data, CouponHouse}; - use coupons::rules::{Self}; - use coupons::constants; - use coupons::range; + use coupons::{coupons::{Self, CouponsApp,Data, CouponHouse}, rules::{Self}, constants, range}; public struct TestApp has drop {} diff --git a/packages/discounts/sources/discounts.move b/packages/discounts/sources/discounts.move index c7da6a20..99d6ad1c 100644 --- a/packages/discounts/sources/discounts.move +++ b/packages/discounts/sources/discounts.move @@ -8,17 +8,11 @@ /// Can be called only when promotions are active for a specific type T. /// Activation / deactivation happens through PTBs. module discounts::discounts { - use std::string::String; - use std::type_name::{Self as `type`}; + use std::{string::String, type_name::{Self as `type`}}; - use sui::dynamic_field::{Self as df}; - use sui::clock::{Clock}; - use sui::coin::Coin; - use sui::sui::SUI; + use sui::{dynamic_field::{Self as df}, clock::{Clock}, coin::Coin, sui::SUI}; - use suins::domain::{Self}; - use suins::suins::{Self, AdminCap, SuiNS}; - use suins::suins_registration::SuinsRegistration; + use suins::{domain::{Self}, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration}; // The base shared object. use discounts::house::{Self, DiscountHouse}; diff --git a/packages/discounts/sources/free_claims.move b/packages/discounts/sources/free_claims.move index ea673206..154889a6 100644 --- a/packages/discounts/sources/free_claims.move +++ b/packages/discounts/sources/free_claims.move @@ -9,16 +9,10 @@ /// Activation / deactivation happens through PTBs. module discounts::free_claims { - use std::string::{String}; - use std::type_name::{Self as `type`}; + use std::{string::{String}, type_name::{Self as `type`}}; + use sui::{dynamic_field::{Self as df}, clock::{Clock}, linked_table::{Self, LinkedTable}}; - use sui::dynamic_field::{Self as df}; - use sui::clock::{Clock}; - use sui::linked_table::{Self, LinkedTable}; - - use suins::domain::{Self, Domain}; - use suins::suins::{AdminCap, SuiNS}; - use suins::suins_registration::SuinsRegistration; + use suins::{domain::{Self, Domain}, suins::{AdminCap, SuiNS}, suins_registration::SuinsRegistration}; use discounts::house::{Self, DiscountHouse}; diff --git a/packages/discounts/sources/house.move b/packages/discounts/sources/house.move index 3ba177d8..4bff0a23 100644 --- a/packages/discounts/sources/house.move +++ b/packages/discounts/sources/house.move @@ -7,11 +7,7 @@ module discounts::house { use sui::clock::{Clock}; - use suins::domain::Domain; - use suins::registry::Registry; - use suins::suins::{Self, AdminCap, SuiNS}; - use suins::config; - use suins::suins_registration::SuinsRegistration; + use suins::{domain::Domain, registry::Registry, suins::{Self, AdminCap, SuiNS}, config, suins_registration::SuinsRegistration}; // The `free_claims` module can use the shared object to attach configuration & claim names. /* friend discounts::free_claims; */ diff --git a/packages/discounts/tests/discount_tests.move b/packages/discounts/tests/discount_tests.move index ca085a80..5a42c274 100644 --- a/packages/discounts/tests/discount_tests.move +++ b/packages/discounts/tests/discount_tests.move @@ -5,16 +5,11 @@ module discounts::discount_tests { use std::string::{utf8, String}; - use sui::test_scenario::{Self as ts, Scenario, ctx}; - use sui::clock::{Self, Clock}; - use sui::coin::{Self, Coin}; - use sui::sui::SUI; + use sui::{test_scenario::{Self as ts, Scenario, ctx}, clock::{Self, Clock}, coin::{Self, Coin}, sui::SUI}; - use suins::suins::{Self, SuiNS, AdminCap}; - use suins::registry; + use suins::{suins::{Self, SuiNS, AdminCap}, registry}; - use discounts::house::{Self, DiscountHouse, DiscountHouseApp}; - use discounts::discounts; + use discounts::{house::{Self, DiscountHouse, DiscountHouseApp}, discounts}; use day_one::day_one::{Self, DayOne}; diff --git a/packages/discounts/tests/free_claims_test.move b/packages/discounts/tests/free_claims_test.move index 966abc6b..292ccb01 100644 --- a/packages/discounts/tests/free_claims_test.move +++ b/packages/discounts/tests/free_claims_test.move @@ -6,11 +6,9 @@ module discounts::free_claims_tests { use std::string::{utf8, String}; - use sui::test_scenario::{Self as ts, Scenario, ctx}; - use sui::clock::{Self, Clock}; + use sui::{test_scenario::{Self as ts, Scenario, ctx}, clock::{Self, Clock}}; - use suins::suins::{Self, SuiNS, AdminCap}; - use suins::registry; + use suins::{suins::{Self, SuiNS, AdminCap}, registry}; use discounts::house::{Self, DiscountHouse, DiscountHouseApp}; use discounts::free_claims; diff --git a/packages/managed_names/sources/managed.move b/packages/managed_names/sources/managed.move index 1a0a64e4..520d09a1 100644 --- a/packages/managed_names/sources/managed.move +++ b/packages/managed_names/sources/managed.move @@ -18,13 +18,9 @@ module managed_names::managed { use std::string::{String}; - use sui::table::{Self, Table}; - use sui::tx_context::sender; - use sui::clock::Clock; + use sui::{table::{Self, Table}, tx_context::sender, clock::Clock}; - use suins::domain::{Self, Domain}; - use suins::suins_registration::SuinsRegistration; - use suins::suins::{Self, SuiNS, AdminCap}; + use suins::{domain::{Self, Domain}, suins_registration::SuinsRegistration, suins::{Self, SuiNS, AdminCap}}; /// Tries to add an NFT that has expired. const EExpiredNFT: u64 = 1; diff --git a/packages/managed_names/tests/managed_tests.move b/packages/managed_names/tests/managed_tests.move index 1025b2f0..ca8487d4 100644 --- a/packages/managed_names/tests/managed_tests.move +++ b/packages/managed_names/tests/managed_tests.move @@ -4,12 +4,9 @@ module managed_names::managed_tests { use std::string::{String, utf8}; - use sui::test_scenario::{Self as ts, Scenario, ctx}; - use sui::clock::{Self, Clock}; + use sui::{test_scenario::{Self as ts, Scenario, ctx}, clock::{Self, Clock}}; - use suins::suins_registration::{Self, new_for_testing, SuinsRegistration}; - use suins::suins::{Self, SuiNS}; - use suins::domain; + use suins::{suins_registration::{Self, new_for_testing, SuinsRegistration}, suins::{Self, SuiNS}, domain}; use managed_names::managed::{Self, ManagedNamesApp, ReturnPromise}; diff --git a/packages/registration/sources/register.move b/packages/registration/sources/register.move index 36d3c8ec..ba4b1ba9 100644 --- a/packages/registration/sources/register.move +++ b/packages/registration/sources/register.move @@ -3,15 +3,9 @@ module registration::register { use std::string::String; - use sui::coin::Coin; - use sui::clock::Clock; - use sui::sui::SUI; - - use suins::domain; - use suins::registry::Registry; - use suins::suins::{Self, SuiNS}; - use suins::config::{Self, Config}; - use suins::suins_registration::SuinsRegistration; + use sui::{coin::Coin, clock::Clock, sui::SUI}; + + use suins::{domain, registry::Registry, suins::{Self, SuiNS}, config::{Self, Config}, suins_registration::SuinsRegistration}; /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; diff --git a/packages/registration/tests/register_tests.move b/packages/registration/tests/register_tests.move index d00fd832..5b0a2044 100644 --- a/packages/registration/tests/register_tests.move +++ b/packages/registration/tests/register_tests.move @@ -6,21 +6,10 @@ module registration::register_tests { use std::string::{utf8, String}; - use sui::test_scenario::{Self, Scenario, ctx}; - use sui::clock::{Self, Clock}; - use sui::coin; - use sui::sui::SUI; + use sui::{test_scenario::{Self, Scenario, ctx}, clock::{Self, Clock}, coin, sui::SUI}; use registration::register::{Self, Register, register}; - use suins::constants::{mist_per_sui, grace_period_ms, year_ms}; - use suins::suins::{Self, SuiNS, total_balance, AdminCap}; - use suins::suins_registration::SuinsRegistration; - use suins::suins_registration; - use suins::domain; - use suins::registry; - use suins::config; - use suins::auction_tests; - use suins::auction::{Self, App as AuctionApp}; + use suins::{constants::{mist_per_sui, grace_period_ms, year_ms}, suins::{Self, SuiNS, total_balance, AdminCap}, suins_registration::SuinsRegistration, suins_registration, domain, registry, config, auction_tests, auction::{Self, App as AuctionApp}}; const SUINS_ADDRESS: address = @0xA001; const AUCTIONED_DOMAIN_NAME: vector = b"tes-t2.sui"; diff --git a/packages/renewal/sources/renew.move b/packages/renewal/sources/renew.move index e77c0e39..0c0fa599 100644 --- a/packages/renewal/sources/renew.move +++ b/packages/renewal/sources/renew.move @@ -6,17 +6,9 @@ /// /// The renewal is capped at 5 years. module renewal::renew { - use sui::coin::{Self, Coin}; + use sui::{coin::{Self, Coin}, clock::Clock, sui::SUI}; - use sui::clock::Clock; - use sui::sui::SUI; - - use suins::constants; - use suins::domain::Domain; - use suins::registry::Registry; - use suins::suins::{Self, SuiNS, AdminCap}; - use suins::config::{Self, Config}; - use suins::suins_registration::SuinsRegistration; + use suins::{constants, domain::Domain, registry::Registry, suins::{Self, SuiNS, AdminCap}, config::{Self, Config}, suins_registration::SuinsRegistration}; /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; diff --git a/packages/renewal/tests/renew_tests.move b/packages/renewal/tests/renew_tests.move index 56c9b1f0..4cb7534f 100644 --- a/packages/renewal/tests/renew_tests.move +++ b/packages/renewal/tests/renew_tests.move @@ -5,16 +5,9 @@ module renewal::renew_tests { use std::string::utf8; - use sui::coin; - use sui::sui::SUI; - use sui::clock::{Self, Clock}; - - use suins::constants::{mist_per_sui, year_ms, grace_period_ms}; - use suins::suins::{Self, SuiNS}; - use suins::suins_registration::{Self as nft, SuinsRegistration}; - use suins::registry; - use suins::domain; - use suins::config; + use sui::{coin, sui::SUI, clock::{Self, Clock}}; + + use suins::{constants::{mist_per_sui, year_ms, grace_period_ms}, suins::{Self, SuiNS}, suins_registration::{Self as nft, SuinsRegistration}, registry, domain, config}; use renewal::renew::{Self as renewal, Renew}; diff --git a/packages/subdomains/sources/config.move b/packages/subdomains/sources/config.move index b04153d7..ba1fb792 100644 --- a/packages/subdomains/sources/config.move +++ b/packages/subdomains/sources/config.move @@ -4,8 +4,7 @@ module subdomains::config { use std::string::String; - use suins::domain::{Domain, is_parent_of}; - use suins::constants::sui_tld; + use suins::{domain::{Domain, is_parent_of}, constants::sui_tld}; /// the minimum size a subdomain label can have. const MIN_LABEL_SIZE: u8 = 3; diff --git a/packages/subdomains/sources/subdomains.move b/packages/subdomains/sources/subdomains.move index e4abc03b..b3182196 100644 --- a/packages/subdomains/sources/subdomains.move +++ b/packages/subdomains/sources/subdomains.move @@ -27,16 +27,9 @@ module subdomains::subdomains { use std::string::{String, utf8}; - use sui::clock::Clock; - use sui::dynamic_field as df; - use sui::vec_map::VecMap; - - use suins::domain::{Self, Domain, is_subdomain}; - use suins::registry::Registry; - use suins::suins::{Self, SuiNS, AdminCap}; - use suins::suins_registration::SuinsRegistration; - use suins::subdomain_registration::SubDomainRegistration; - use suins::constants::{subdomain_allow_extension_key, subdomain_allow_creation_key}; + use sui::{clock::Clock, dynamic_field as df, vec_map::VecMap}; + + use suins::{domain::{Self, Domain, is_subdomain}, registry::Registry, suins::{Self, SuiNS, AdminCap}, suins_registration::SuinsRegistration, subdomain_registration::SubDomainRegistration, constants::{subdomain_allow_extension_key, subdomain_allow_creation_key}}; use subdomains::config::{Self, SubDomainConfig}; diff --git a/packages/subdomains/tests/subdomain_tests.move b/packages/subdomains/tests/subdomain_tests.move index 08685260..26a5895f 100644 --- a/packages/subdomains/tests/subdomain_tests.move +++ b/packages/subdomains/tests/subdomain_tests.move @@ -5,16 +5,9 @@ module subdomains::subdomain_tests { use std::string::{String, utf8}; - use sui::test_scenario::{Self as ts, Scenario, ctx}; - use sui::clock::{Self, Clock}; - - use suins::domain; - use suins::constants::{grace_period_ms, year_ms}; - use suins::suins::{Self, SuiNS, AdminCap}; - use suins::registry::{Self, Registry}; - use suins::suins_registration::{Self, SuinsRegistration}; - use suins::subdomain_registration::{Self, SubDomainRegistration}; - use suins::registry_tests::{burn_nfts}; + use sui::{test_scenario::{Self as ts, Scenario, ctx}, clock::{Self, Clock}}; + + use suins::{domain, constants::{grace_period_ms, year_ms}, suins::{Self, SuiNS, AdminCap}, registry::{Self, Registry}, suins_registration::{Self, SuinsRegistration}, subdomain_registration::{Self, SubDomainRegistration}, registry_tests::{burn_nfts}}; use denylist::denylist; diff --git a/packages/suins/sources/actions/update_image.move b/packages/suins/sources/actions/update_image.move index a766037e..84e550f2 100644 --- a/packages/suins/sources/actions/update_image.move +++ b/packages/suins/sources/actions/update_image.move @@ -3,14 +3,9 @@ module suins::update_image { use std::string::{utf8, String}; - use sui::clock::Clock; - use sui::bcs; - use sui::ecdsa_k1; + use sui::{clock::Clock, bcs, ecdsa_k1}; - use suins::registry::Registry; - use suins::suins::SuiNS; - use suins::config::Config; - use suins::suins_registration::SuinsRegistration; + use suins::{registry::Registry, suins::SuiNS, config::Config, suins_registration::SuinsRegistration}; /// Message data cannot be parsed. const EInvalidData: u64 = 0; diff --git a/packages/suins/sources/admin.move b/packages/suins/sources/admin.move index e8a960c3..62fbd7e1 100644 --- a/packages/suins/sources/admin.move +++ b/packages/suins/sources/admin.move @@ -5,14 +5,9 @@ /// by the suins admin. module suins::admin { use std::string::String; - use sui::clock::Clock; - use sui::tx_context::{sender}; + use sui::{clock::Clock, tx_context::{sender}}; - use suins::domain; - use suins::config; - use suins::suins::{Self, AdminCap, SuiNS}; - use suins::suins_registration::SuinsRegistration; - use suins::registry::Registry; + use suins::{domain, config, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, registry::Registry}; /// The authorization witness. public struct Admin has drop {} diff --git a/packages/suins/sources/auction.move b/packages/suins/sources/auction.move index 005ce574..d78a333c 100644 --- a/packages/suins/sources/auction.move +++ b/packages/suins/sources/auction.move @@ -4,21 +4,11 @@ /// Implementation of auction module. /// More information in: ../../../docs module suins::auction { - use std::option::{none, some, is_some}; - use std::string::String; - - use sui::balance::{Self, Balance}; - use sui::coin::{Self, Coin}; - use sui::clock::Clock; - use sui::event; - use sui::sui::SUI; - use sui::linked_table::{Self, LinkedTable}; - - use suins::config::{Self, Config}; - use suins::suins::{Self, AdminCap, SuiNS}; - use suins::suins_registration::SuinsRegistration; - use suins::registry::Registry; - use suins::domain::{Self, Domain}; + use std::{option::{none, some, is_some}, string::String}; + + use sui::{balance::{Self, Balance}, coin::{Self, Coin}, clock::Clock, event, sui::SUI, linked_table::{Self, LinkedTable}}; + + use suins::{config::{Self, Config}, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, registry::Registry, domain::{Self, Domain}}; /// One year is the default duration for a domain. const DEFAULT_DURATION: u8 = 1; diff --git a/packages/suins/sources/config.move b/packages/suins/sources/config.move index e45b6946..350f499b 100644 --- a/packages/suins/sources/config.move +++ b/packages/suins/sources/config.move @@ -17,8 +17,7 @@ /// and set again within the same Programmable Transaction Block (can only be /// performed by Admin) module suins::config { - use suins::constants; - use suins::domain::Domain; + use suins::{constants, domain::Domain}; /// A label is too short to be registered. const ELabelTooShort: u64 = 0; diff --git a/packages/suins/sources/controller.move b/packages/suins/sources/controller.move index 69c8e501..c41181e4 100644 --- a/packages/suins/sources/controller.move +++ b/packages/suins/sources/controller.move @@ -3,13 +3,9 @@ module suins::controller { use std::string::String; - use sui::tx_context::{sender,}; - use sui::clock::Clock; + use sui::{tx_context::{sender}, clock::Clock}; - use suins::domain; - use suins::registry::Registry; - use suins::suins::{Self, SuiNS}; - use suins::suins_registration::SuinsRegistration; + use suins::{domain, registry::Registry, suins::{Self, SuiNS}, suins_registration::SuinsRegistration}; const AVATAR: vector = b"avatar"; const CONTENT_HASH: vector = b"content_hash"; diff --git a/packages/suins/sources/name_record.move b/packages/suins/sources/name_record.move index 357b29a8..cd6a57a8 100644 --- a/packages/suins/sources/name_record.move +++ b/packages/suins/sources/name_record.move @@ -8,8 +8,7 @@ module suins::name_record { use std::string::String; - use sui::clock::{timestamp_ms, Clock}; - use sui::vec_map::{Self, VecMap}; + use sui::{clock::{timestamp_ms, Clock}, vec_map::{Self, VecMap}}; use suins::constants; diff --git a/packages/suins/sources/registry.move b/packages/suins/sources/registry.move index 611b7fa4..62e05f80 100644 --- a/packages/suins/sources/registry.move +++ b/packages/suins/sources/registry.move @@ -2,18 +2,11 @@ // SPDX-License-Identifier: Apache-2.0 module suins::registry { - use std::option::{none, some}; - use std::string::String; - - use sui::table::{Self, Table}; - use sui::clock::Clock; - use sui::vec_map::VecMap; - - use suins::suins_registration::{Self as nft, SuinsRegistration}; - use suins::name_record::{Self, NameRecord}; - use suins::domain::Domain; - use suins::suins::AdminCap; - use suins::subdomain_registration::{Self, SubDomainRegistration}; + use std::{option::{none, some}, string::String}; + + use sui::{table::{Self, Table}, clock::Clock, vec_map::VecMap}; + + use suins::{suins_registration::{Self as nft, SuinsRegistration}, name_record::{Self, NameRecord}, domain::Domain, suins::AdminCap, subdomain_registration::{Self, SubDomainRegistration}}; /// The `SuinsRegistration` has expired. const ENftExpired: u64 = 0; diff --git a/packages/suins/sources/suins.move b/packages/suins/sources/suins.move index 298f8532..7d29393e 100644 --- a/packages/suins/sources/suins.move +++ b/packages/suins/sources/suins.move @@ -21,10 +21,7 @@ /// - Any of the old modules can be deauthorized hence disabling its access to /// the registry and the balance. module suins::suins { - use sui::balance::{Self, Balance}; - use sui::coin::{Self, Coin}; - use sui::dynamic_field as df; - use sui::sui::SUI; + use sui::{balance::{Self, Balance}, coin::{Self, Coin}, dynamic_field as df, sui::SUI}; /// Trying to withdraw from an empty balance. const ENoProfits: u64 = 0; diff --git a/packages/suins/sources/suins_registration.move b/packages/suins/sources/suins_registration.move index 9e5605f4..0a0b89b5 100644 --- a/packages/suins/sources/suins_registration.move +++ b/packages/suins/sources/suins_registration.move @@ -14,8 +14,7 @@ module suins::suins_registration { use std::string::{String}; use sui::clock::{timestamp_ms, Clock}; - use suins::constants; - use suins::domain::Domain; + use suins::{constants, domain::Domain}; /* friend suins::registry; */ /* friend suins::update_image; */ diff --git a/packages/suins/tests/auction_tests.move b/packages/suins/tests/auction_tests.move index d837df2b..21bf58f1 100644 --- a/packages/suins/tests/auction_tests.move +++ b/packages/suins/tests/auction_tests.move @@ -10,16 +10,18 @@ module suins::auction_tests { use sui::clock::{Self, Clock}; use sui::coin::{Self, Coin}; - use suins::auction::{ - Self, App as AuctionApp, place_bid, claim, AuctionHouse, start_auction_and_place_bid, total_balance, - admin_finalize_auction, admin_try_finalize_auctions, admin_withdraw_funds, collect_winning_auction_fund + use suins::{ + auction::{ + Self, App as AuctionApp, place_bid, claim, AuctionHouse, start_auction_and_place_bid, total_balance, + admin_finalize_auction, admin_try_finalize_auctions, admin_withdraw_funds, collect_winning_auction_fund + }, + suins_registration::SuinsRegistration, + config, + domain, + constants::{Self, mist_per_sui}, + suins::{Self, SuiNS, AdminCap}, + registry }; - use suins::suins_registration::SuinsRegistration; - use suins::config; - use suins::domain; - use suins::constants::{Self, mist_per_sui}; - use suins::suins::{Self, SuiNS, AdminCap}; - use suins::registry; const SUINS_ADDRESS: address = @0xA001; const FIRST_ADDRESS: address = @0xB001; diff --git a/packages/suins/tests/controller_tests.move b/packages/suins/tests/controller_tests.move index 28e3ae14..1a145267 100644 --- a/packages/suins/tests/controller_tests.move +++ b/packages/suins/tests/controller_tests.move @@ -3,23 +3,23 @@ #[test_only] module suins::controller_tests { - use std::string::{utf8, String}; - use std::option::{extract, some, none}; - - use sui::test_scenario::{Self, Scenario, ctx}; - use sui::clock::{Self, Clock}; - use sui::test_utils::assert_eq; - use sui::dynamic_field; - use sui::vec_map::VecMap; - - use suins::register_sample::Register; - use suins::constants::{mist_per_sui, year_ms}; - use suins::suins::{Self, SuiNS, AdminCap}; - use suins::suins_registration::SuinsRegistration; - use suins::register_sample_tests::register_util; - use suins::controller::{Self, Controller, set_target_address_for_testing, set_reverse_lookup_for_testing, unset_reverse_lookup_for_testing, set_user_data_for_testing, unset_user_data_for_testing}; - use suins::registry::{Self, Registry, lookup, reverse_lookup}; - use suins::domain::{Self, Domain}; + use std::{string::{utf8, String}, option::{extract, some, none}}; + + use sui::{test_scenario::{Self, Scenario, ctx}, clock::{Self, Clock}, test_utils::assert_eq, dynamic_field, vec_map::VecMap}; + + use suins::{ + register_sample::Register, + constants::{mist_per_sui, year_ms}, + suins::{Self, SuiNS, AdminCap}, + suins_registration::SuinsRegistration, + register_sample_tests::register_util, + controller::{ + Self, Controller, set_target_address_for_testing, set_reverse_lookup_for_testing, + unset_reverse_lookup_for_testing, set_user_data_for_testing, unset_user_data_for_testing + }, + registry::{Self, Registry, lookup, reverse_lookup}, + domain::{Self, Domain} + }; const SUINS_ADDRESS: address = @0xA001; const FIRST_ADDRESS: address = @0xB001; diff --git a/packages/suins/tests/register_tests.move b/packages/suins/tests/register_tests.move index a9917de2..de950606 100644 --- a/packages/suins/tests/register_tests.move +++ b/packages/suins/tests/register_tests.move @@ -6,20 +6,19 @@ module suins::register_sample_tests { use std::string::{utf8, String}; - use sui::test_scenario::{Self, Scenario, ctx}; - use sui::clock::{Self, Clock}; - use sui::coin; - use sui::sui::SUI; - - use suins::register_sample::{Self as register, Register, register}; - use suins::constants::{mist_per_sui, grace_period_ms, year_ms}; - use suins::suins::{Self, SuiNS, total_balance, AdminCap}; - use suins::suins_registration::SuinsRegistration; - use suins::domain; - use suins::registry; - use suins::config; - use suins::auction_tests; - use suins::auction::{Self, App as AuctionApp}; + use sui::{test_scenario::{Self, Scenario, ctx}, clock::{Self, Clock}, coin, sui::SUI}; + + use suins::{ + register_sample::{Self as register, Register, register}, + constants::{mist_per_sui, grace_period_ms, year_ms}, + suins::{Self, SuiNS, total_balance, AdminCap}, + suins_registration::SuinsRegistration, + domain, + registry, + config, + auction_tests, + auction::{Self, App as AuctionApp}, + }; const SUINS_ADDRESS: address = @0xA001; const AUCTIONED_DOMAIN_NAME: vector = b"tes-t2.sui"; diff --git a/packages/suins/tests/renew_tests.move b/packages/suins/tests/renew_tests.move index 48cee034..71d52775 100644 --- a/packages/suins/tests/renew_tests.move +++ b/packages/suins/tests/renew_tests.move @@ -5,18 +5,22 @@ module suins::renew_tests { use std::string::utf8; - use sui::test_scenario::{Self, Scenario, ctx}; - use sui::coin; - use sui::sui::SUI; - use sui::clock::{Self, Clock}; - - use suins::renew::{Self, Renew, renew}; - use suins::register_sample::Register; - use suins::register_sample_tests::{register_util, assert_balance}; - use suins::constants::{mist_per_sui, year_ms}; - use suins::suins::{Self, SuiNS, AdminCap}; - use suins::suins_registration::SuinsRegistration; - use suins::registry; + use sui::{ + test_scenario::{Self, Scenario, ctx}, + coin, + sui::SUI, + clock::{Self, Clock} + }; + + use suins::{ + renew::{Self, Renew, renew}, + register_sample::Register, + register_sample_tests::{register_util, assert_balance}, + constants::{mist_per_sui, year_ms}, + suins::{Self, SuiNS, AdminCap}, + suins_registration::SuinsRegistration, + registry, + }; const SUINS_ADDRESS: address = @0xA001; const DOMAIN_NAME: vector = b"abc.sui"; diff --git a/packages/suins/tests/unit/admin_tests.move b/packages/suins/tests/unit/admin_tests.move index 02c2d46e..73feb054 100644 --- a/packages/suins/tests/unit/admin_tests.move +++ b/packages/suins/tests/unit/admin_tests.move @@ -10,14 +10,9 @@ /// module suins::admin_tests { use std::string::utf8; - use sui::clock; - use sui::test_utils::assert_eq; + use sui::{clock, test_utils::assert_eq}; - use suins::admin::{Self, Admin}; - use suins::constants; - use suins::domain; - use suins::suins; - use suins::registry; + use suins::{admin::{Self, Admin}, constants, domain, suins, registry}; #[test, expected_failure(abort_code = ::suins::suins::EAppNotAuthorized)] fun try_unathorized_fail() { diff --git a/packages/suins/tests/unit/name_record_tests.move b/packages/suins/tests/unit/name_record_tests.move index 02b50289..e46d91cb 100644 --- a/packages/suins/tests/unit/name_record_tests.move +++ b/packages/suins/tests/unit/name_record_tests.move @@ -9,14 +9,10 @@ /// and the expiration timestamp are working correctly; /// module suins::name_record_tests { - use std::string::utf8; - use std::option::{none, some}; - use sui::test_utils::assert_eq; - use sui::vec_map; - use sui::clock; + use std::{string::utf8, option::{none, some}}; + use sui::{test_utils::assert_eq, vec_map, clock}; - use suins::name_record as record; - use suins::constants; + use suins::{name_record as record, constants}; #[test] /// Make sure that the fields are empty by default. That they are updated diff --git a/packages/suins/tests/unit/registration_nft_tests.move b/packages/suins/tests/unit/registration_nft_tests.move index d4cdb3d0..6cd29789 100644 --- a/packages/suins/tests/unit/registration_nft_tests.move +++ b/packages/suins/tests/unit/registration_nft_tests.move @@ -10,12 +10,9 @@ /// module suins::registation_nft_tests { use std::string::{utf8, String}; - use sui::clock::{Self, Clock}; - use sui::test_utils::assert_eq; + use sui::{clock::{Self, Clock}, test_utils::assert_eq}; - use suins::suins_registration::{Self as nft, SuinsRegistration}; - use suins::constants; - use suins::domain; + use suins::{suins_registration::{Self as nft, SuinsRegistration}, constants, domain}; #[test] fun test_new() { diff --git a/packages/suins/tests/unit/registry_tests.move b/packages/suins/tests/unit/registry_tests.move index 53586969..34b12213 100644 --- a/packages/suins/tests/unit/registry_tests.move +++ b/packages/suins/tests/unit/registry_tests.move @@ -3,16 +3,10 @@ #[test_only] module suins::registry_tests { - use std::string::utf8; - use std::option::{some}; - use sui::clock::{Self, Clock}; - use sui::test_utils::assert_eq; - - use suins::suins_registration::{Self as nft, SuinsRegistration}; - use suins::name_record as record; - use suins::registry::{Self, Registry}; - use suins::domain::{Self, Domain}; - use suins::constants; + use std::{string::utf8, option::{some}}; + use sui::{clock::{Self, Clock}, test_utils::assert_eq}; + + use suins::{suins_registration::{Self as nft, SuinsRegistration}, name_record as record, registry::{Self, Registry}, domain::{Self, Domain}, constants}; // === Registry + Record Addition === diff --git a/packages/suins/tests/unit/sub_name_tests.move b/packages/suins/tests/unit/sub_name_tests.move index 667fdd99..30533acd 100644 --- a/packages/suins/tests/unit/sub_name_tests.move +++ b/packages/suins/tests/unit/sub_name_tests.move @@ -7,9 +7,7 @@ module suins::sub_name_tests { use sui::clock; - use suins::suins_registration; - use suins::subdomain_registration as subdomain; - use suins::domain; + use suins::{suins_registration, subdomain_registration as subdomain, domain}; #[test] fun test_wrap_and_destroy(){ diff --git a/packages/suins/tests/unit/suins_tests.move b/packages/suins/tests/unit/suins_tests.move index e3149851..86173771 100644 --- a/packages/suins/tests/unit/suins_tests.move +++ b/packages/suins/tests/unit/suins_tests.move @@ -4,10 +4,7 @@ #[test_only] /// module suins::suins_tests { - use sui::coin; - use sui::balance; - use sui::sui::SUI; - use sui::test_utils::assert_eq; + use sui::{coin, balance, sui::SUI, test_utils::assert_eq}; use suins::suins::{Self, AdminCap, SuiNS}; // === Config management === diff --git a/packages/suins/tests/v2/register.move b/packages/suins/tests/v2/register.move index 59735748..2886e0ee 100644 --- a/packages/suins/tests/v2/register.move +++ b/packages/suins/tests/v2/register.move @@ -4,15 +4,9 @@ #[test_only] module suins::register_sample { use std::string::{Self, String}; - use sui::coin::{Self, Coin}; - use sui::clock::Clock; - use sui::sui::SUI; - - use suins::domain; - use suins::registry::{Self, Registry}; - use suins::suins::{Self, SuiNS}; - use suins::config::{Self, Config}; - use suins::suins_registration::SuinsRegistration; + use sui::{coin::{Self, Coin}, clock::Clock, sui::SUI}; + + use suins::{domain, registry::{Self, Registry}, suins::{Self, SuiNS}, config::{Self, Config}, suins_registration::SuinsRegistration}; /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; diff --git a/packages/suins/tests/v2/renew.move b/packages/suins/tests/v2/renew.move index 74dccd7d..6373b5c7 100644 --- a/packages/suins/tests/v2/renew.move +++ b/packages/suins/tests/v2/renew.move @@ -4,17 +4,9 @@ #[test_only] module suins::renew { use std::string; - use sui::coin::{Self, Coin}; - use sui::clock::{timestamp_ms, Clock}; - use sui::sui::SUI; + use sui::{coin::{Self, Coin}, clock::{timestamp_ms, Clock}, sui::SUI}; - use suins::domain; - use suins::constants; - use suins::name_record; - use suins::registry::{Self, Registry}; - use suins::suins::{Self, SuiNS}; - use suins::config::{Self, Config}; - use suins::suins_registration::{Self as nft, SuinsRegistration}; + use suins::{domain, constants, name_record, registry::{Self, Registry}, suins::{Self, SuiNS}, config::{Self, Config}, suins_registration::{Self as nft, SuinsRegistration}}; /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; diff --git a/packages/temp_subdomain_proxy/sources/subdomain_proxy.move b/packages/temp_subdomain_proxy/sources/subdomain_proxy.move index 88e479ff..e00db9cd 100644 --- a/packages/temp_subdomain_proxy/sources/subdomain_proxy.move +++ b/packages/temp_subdomain_proxy/sources/subdomain_proxy.move @@ -13,8 +13,7 @@ module temp_subdomain_proxy::subdomain_proxy { use sui::clock::Clock; - use suins::suins::SuiNS; - use suins::subdomain_registration::SubDomainRegistration; + use suins::{suins::SuiNS, subdomain_registration::SubDomainRegistration}; use subdomains::subdomains; use utils::direct_setup; diff --git a/packages/utils/sources/direct_setup.move b/packages/utils/sources/direct_setup.move index 9ee86e30..7decf7d8 100644 --- a/packages/utils/sources/direct_setup.move +++ b/packages/utils/sources/direct_setup.move @@ -6,13 +6,9 @@ module utils::direct_setup { use std::string::{String}; - use sui::tx_context::{sender}; - use sui::clock::Clock; + use sui::{tx_context::{sender}, clock::Clock}; - use suins::domain; - use suins::registry::Registry; - use suins::suins::{Self, SuiNS}; - use suins::suins_registration::SuinsRegistration; + use suins::{domain, registry::Registry, suins::{Self, SuiNS}, suins_registration::SuinsRegistration}; /// Authorization token for the controller. public struct DirectSetup has drop {} From cd9fba018d85cd4a85b3193cf8ac10976d6fe420 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 14:16:32 -0400 Subject: [PATCH 33/38] formatting --- .../coupons/tests/authorization_tests.move | 13 ++++++++++++- packages/coupons/tests/coupons_tests.move | 8 +++++++- packages/discounts/sources/house.move | 8 +++++++- .../registration/tests/register_tests.move | 12 +++++++++++- packages/renewal/sources/renew.move | 9 ++++++++- packages/renewal/tests/renew_tests.move | 9 ++++++++- packages/subdomains/sources/subdomains.move | 9 ++++++++- .../subdomains/tests/subdomain_tests.move | 10 +++++++++- packages/suins/sources/auction.move | 19 ++++++++++++++++--- packages/suins/sources/registry.move | 8 +++++++- packages/suins/tests/auction_tests.move | 13 +++++++++++-- packages/suins/tests/unit/registry_tests.move | 7 ++++++- packages/suins/tests/v2/renew.move | 10 +++++++++- 13 files changed, 119 insertions(+), 16 deletions(-) diff --git a/packages/coupons/tests/authorization_tests.move b/packages/coupons/tests/authorization_tests.move index 2057274d..0fd7611f 100644 --- a/packages/coupons/tests/authorization_tests.move +++ b/packages/coupons/tests/authorization_tests.move @@ -7,7 +7,18 @@ module coupons::app_authorization_tests { use sui::test_scenario::{return_shared, return_to_sender, end}; - use coupons::{coupons::{app_data_mut, deauthorize_app}, setup::{Self, UnauthorizedTestApp, TestApp, admin, user, test_init, unauthorized_test_app}}; + use coupons::{ + coupons::{app_data_mut, deauthorize_app}, + setup::{ + Self, + UnauthorizedTestApp, + TestApp, + admin, + user, + test_init, + unauthorized_test_app + } + }; #[test] fun admin_get_app_success() { diff --git a/packages/coupons/tests/coupons_tests.move b/packages/coupons/tests/coupons_tests.move index e06e9e34..1c580ef2 100644 --- a/packages/coupons/tests/coupons_tests.move +++ b/packages/coupons/tests/coupons_tests.move @@ -8,7 +8,13 @@ module coupons::coupon_tests { use sui::test_scenario::{Self, Scenario, ctx, return_shared, end}; // test dependencies. - use coupons::{setup::{Self, TestApp, user, user_two, mist_per_sui, test_app, admin_add_coupon, register_with_coupon, test_init}, coupons::{Self, CouponHouse}, constants::{Self}, rules, range}; + use coupons::{ + setup::{Self, TestApp, user, user_two, mist_per_sui, test_app, admin_add_coupon, register_with_coupon, test_init}, + coupons::{Self, CouponHouse}, + constants::{Self}, + rules, + range + }; // populate a lot of coupons with different cases. // This populates the coupon as an authorized app diff --git a/packages/discounts/sources/house.move b/packages/discounts/sources/house.move index 4bff0a23..1af58811 100644 --- a/packages/discounts/sources/house.move +++ b/packages/discounts/sources/house.move @@ -7,7 +7,13 @@ module discounts::house { use sui::clock::{Clock}; - use suins::{domain::Domain, registry::Registry, suins::{Self, AdminCap, SuiNS}, config, suins_registration::SuinsRegistration}; + use suins::{ + domain::Domain, + registry::Registry, + suins::{Self, AdminCap, SuiNS}, + config, + suins_registration::SuinsRegistration + }; // The `free_claims` module can use the shared object to attach configuration & claim names. /* friend discounts::free_claims; */ diff --git a/packages/registration/tests/register_tests.move b/packages/registration/tests/register_tests.move index 5b0a2044..f33a3210 100644 --- a/packages/registration/tests/register_tests.move +++ b/packages/registration/tests/register_tests.move @@ -9,7 +9,17 @@ module registration::register_tests { use sui::{test_scenario::{Self, Scenario, ctx}, clock::{Self, Clock}, coin, sui::SUI}; use registration::register::{Self, Register, register}; - use suins::{constants::{mist_per_sui, grace_period_ms, year_ms}, suins::{Self, SuiNS, total_balance, AdminCap}, suins_registration::SuinsRegistration, suins_registration, domain, registry, config, auction_tests, auction::{Self, App as AuctionApp}}; + use suins::{ + constants::{mist_per_sui, grace_period_ms, year_ms}, + suins::{Self, SuiNS, total_balance, AdminCap}, + suins_registration::SuinsRegistration, + suins_registration, + domain, + registry, + config, + auction_tests, + auction::{Self, App as AuctionApp} + }; const SUINS_ADDRESS: address = @0xA001; const AUCTIONED_DOMAIN_NAME: vector = b"tes-t2.sui"; diff --git a/packages/renewal/sources/renew.move b/packages/renewal/sources/renew.move index 0c0fa599..729b88de 100644 --- a/packages/renewal/sources/renew.move +++ b/packages/renewal/sources/renew.move @@ -8,7 +8,14 @@ module renewal::renew { use sui::{coin::{Self, Coin}, clock::Clock, sui::SUI}; - use suins::{constants, domain::Domain, registry::Registry, suins::{Self, SuiNS, AdminCap}, config::{Self, Config}, suins_registration::SuinsRegistration}; + use suins::{ + constants, + domain::Domain, + registry::Registry, + suins::{Self, SuiNS, AdminCap}, + config::{Self, Config}, + suins_registration::SuinsRegistration + }; /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; diff --git a/packages/renewal/tests/renew_tests.move b/packages/renewal/tests/renew_tests.move index 4cb7534f..2a4d95ae 100644 --- a/packages/renewal/tests/renew_tests.move +++ b/packages/renewal/tests/renew_tests.move @@ -7,7 +7,14 @@ module renewal::renew_tests { use sui::{coin, sui::SUI, clock::{Self, Clock}}; - use suins::{constants::{mist_per_sui, year_ms, grace_period_ms}, suins::{Self, SuiNS}, suins_registration::{Self as nft, SuinsRegistration}, registry, domain, config}; + use suins::{ + constants::{mist_per_sui, year_ms, grace_period_ms}, + suins::{Self, SuiNS}, + suins_registration::{Self as nft, SuinsRegistration}, + registry, + domain, + config + }; use renewal::renew::{Self as renewal, Renew}; diff --git a/packages/subdomains/sources/subdomains.move b/packages/subdomains/sources/subdomains.move index b3182196..8dc90b16 100644 --- a/packages/subdomains/sources/subdomains.move +++ b/packages/subdomains/sources/subdomains.move @@ -29,7 +29,14 @@ module subdomains::subdomains { use sui::{clock::Clock, dynamic_field as df, vec_map::VecMap}; - use suins::{domain::{Self, Domain, is_subdomain}, registry::Registry, suins::{Self, SuiNS, AdminCap}, suins_registration::SuinsRegistration, subdomain_registration::SubDomainRegistration, constants::{subdomain_allow_extension_key, subdomain_allow_creation_key}}; + use suins::{ + domain::{Self, Domain, is_subdomain}, + registry::Registry, + suins::{Self, SuiNS, AdminCap}, + suins_registration::SuinsRegistration, + subdomain_registration::SubDomainRegistration, + constants::{subdomain_allow_extension_key, subdomain_allow_creation_key} + }; use subdomains::config::{Self, SubDomainConfig}; diff --git a/packages/subdomains/tests/subdomain_tests.move b/packages/subdomains/tests/subdomain_tests.move index 26a5895f..5dcb4364 100644 --- a/packages/subdomains/tests/subdomain_tests.move +++ b/packages/subdomains/tests/subdomain_tests.move @@ -7,7 +7,15 @@ module subdomains::subdomain_tests { use sui::{test_scenario::{Self as ts, Scenario, ctx}, clock::{Self, Clock}}; - use suins::{domain, constants::{grace_period_ms, year_ms}, suins::{Self, SuiNS, AdminCap}, registry::{Self, Registry}, suins_registration::{Self, SuinsRegistration}, subdomain_registration::{Self, SubDomainRegistration}, registry_tests::{burn_nfts}}; + use suins::{ + domain, + constants::{grace_period_ms, year_ms}, + suins::{Self, SuiNS, AdminCap}, + registry::{Self, Registry}, + suins_registration::{Self, SuinsRegistration}, + subdomain_registration::{Self, SubDomainRegistration}, + registry_tests::{burn_nfts} + }; use denylist::denylist; diff --git a/packages/suins/sources/auction.move b/packages/suins/sources/auction.move index d78a333c..bae81e83 100644 --- a/packages/suins/sources/auction.move +++ b/packages/suins/sources/auction.move @@ -6,9 +6,22 @@ module suins::auction { use std::{option::{none, some, is_some}, string::String}; - use sui::{balance::{Self, Balance}, coin::{Self, Coin}, clock::Clock, event, sui::SUI, linked_table::{Self, LinkedTable}}; - - use suins::{config::{Self, Config}, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, registry::Registry, domain::{Self, Domain}}; + use sui::{ + balance::{Self, Balance}, + coin::{Self, Coin}, + clock::Clock, + event, + sui::SUI, + linked_table::{Self, LinkedTable} + }; + + use suins::{ + config::{Self, Config}, + suins::{Self, AdminCap, SuiNS}, + suins_registration::SuinsRegistration, + registry::Registry, + domain::{Self, Domain} + }; /// One year is the default duration for a domain. const DEFAULT_DURATION: u8 = 1; diff --git a/packages/suins/sources/registry.move b/packages/suins/sources/registry.move index 62e05f80..0e988f3b 100644 --- a/packages/suins/sources/registry.move +++ b/packages/suins/sources/registry.move @@ -6,7 +6,13 @@ module suins::registry { use sui::{table::{Self, Table}, clock::Clock, vec_map::VecMap}; - use suins::{suins_registration::{Self as nft, SuinsRegistration}, name_record::{Self, NameRecord}, domain::Domain, suins::AdminCap, subdomain_registration::{Self, SubDomainRegistration}}; + use suins::{ + suins_registration::{Self as nft, SuinsRegistration}, + name_record::{Self, NameRecord}, + domain::Domain, + suins::AdminCap, + subdomain_registration::{Self, SubDomainRegistration} + }; /// The `SuinsRegistration` has expired. const ENftExpired: u64 = 0; diff --git a/packages/suins/tests/auction_tests.move b/packages/suins/tests/auction_tests.move index 21bf58f1..b32f81cd 100644 --- a/packages/suins/tests/auction_tests.move +++ b/packages/suins/tests/auction_tests.move @@ -12,8 +12,17 @@ module suins::auction_tests { use suins::{ auction::{ - Self, App as AuctionApp, place_bid, claim, AuctionHouse, start_auction_and_place_bid, total_balance, - admin_finalize_auction, admin_try_finalize_auctions, admin_withdraw_funds, collect_winning_auction_fund + Self, + App as AuctionApp, + place_bid, + claim, + AuctionHouse, + start_auction_and_place_bid, + total_balance, + admin_finalize_auction, + admin_try_finalize_auctions, + admin_withdraw_funds, + collect_winning_auction_fund }, suins_registration::SuinsRegistration, config, diff --git a/packages/suins/tests/unit/registry_tests.move b/packages/suins/tests/unit/registry_tests.move index 34b12213..5eb7a335 100644 --- a/packages/suins/tests/unit/registry_tests.move +++ b/packages/suins/tests/unit/registry_tests.move @@ -6,7 +6,12 @@ module suins::registry_tests { use std::{string::utf8, option::{some}}; use sui::{clock::{Self, Clock}, test_utils::assert_eq}; - use suins::{suins_registration::{Self as nft, SuinsRegistration}, name_record as record, registry::{Self, Registry}, domain::{Self, Domain}, constants}; + use suins::{ + suins_registration::{Self as nft, SuinsRegistration}, + name_record as record, + registry::{Self, Registry}, + domain::{Self, Domain}, constants + }; // === Registry + Record Addition === diff --git a/packages/suins/tests/v2/renew.move b/packages/suins/tests/v2/renew.move index 6373b5c7..275ef961 100644 --- a/packages/suins/tests/v2/renew.move +++ b/packages/suins/tests/v2/renew.move @@ -6,7 +6,15 @@ module suins::renew { use std::string; use sui::{coin::{Self, Coin}, clock::{timestamp_ms, Clock}, sui::SUI}; - use suins::{domain, constants, name_record, registry::{Self, Registry}, suins::{Self, SuiNS}, config::{Self, Config}, suins_registration::{Self as nft, SuinsRegistration}}; + use suins::{ + domain, + constants, + name_record, + registry::{Self, Registry}, + suins::{Self, SuiNS}, + config::{Self, Config}, + suins_registration::{Self as nft, SuinsRegistration} + }; /// Number of years passed is not within [1-5] interval. const EInvalidYearsArgument: u64 = 0; From 00a5e1f6c5065dee3c9317ce0793f5ae2f63cfa2 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 17:48:15 -0400 Subject: [PATCH 34/38] update --- packages/coupons/sources/coupons.move | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index ae5045ac..446eb54b 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -108,15 +108,15 @@ module coupons::coupons { // We need to do a total of 5 checks, based on `CouponRules` // Our checks work with `AND`, all of the conditions must pass for a coupon to be used. // 1. Validate domain size. - rules::assert_coupon_valid_for_domain_size(&coupon.rules, domain_length); + coupon.rules.assert_coupon_valid_for_domain_size(domain_length); // 2. Decrease available claims. Will ABORT if the coupon doesn't have enough available claims. - rules::decrease_available_claims(&mut coupon.rules); + coupon.rules.decrease_available_claims(); // 3. Validate the coupon is valid for the specified user. - rules::assert_coupon_valid_for_address(&coupon.rules, ctx.sender()); + coupon.rules.assert_coupon_valid_for_address(ctx.sender()); // 4. Validate the coupon hasn't expired (Based on clock) - rules::assert_coupon_is_not_expired(&coupon.rules, clock); + coupon.rules.assert_coupon_is_not_expired(clock); // 5. Validate years are valid for the coupon. - rules::assert_coupon_valid_for_domain_years(&coupon.rules, no_years); + coupon.rules.assert_coupon_valid_for_domain_years(no_years); // Validate name can be registered (is main domain (no subdomain) and length is valid) config::assert_valid_user_registerable_domain(&domain); @@ -124,17 +124,17 @@ module coupons::coupons { let original_price = config::calculate_price(config, domain_length, no_years); let sale_price = internal_calculate_sale_price(original_price, coupon); - assert!(coin::value(&payment) == sale_price, EIncorrectAmount); - suins::app_add_balance(CouponsApp {}, suins, coin::into_balance(payment)); + assert!(payment.value() == sale_price, EIncorrectAmount); + suins::app_add_balance(CouponsApp {}, suins, payment.into_balance()); // Clean up our registry by removing the coupon if no more available claims! if(!coupon.rules.has_available_claims()){ // remove the coupon, since it's no longer usable. - internal_remove_coupon(&mut self.data, coupon_code); + self.data.internal_remove_coupon(coupon_code); }; let registry = suins::app_registry_mut(CouponsApp {}, suins); - registry::add_record(registry, domain, no_years, clock, ctx) + registry.add_record(domain, no_years, clock, ctx) } // A convenient helper to calculate the price in a PTB. From ebe129c9892e9024e220c8ae14b2f60d3eff5911 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 17:51:44 -0400 Subject: [PATCH 35/38] coupon update --- packages/coupons/sources/coupons.move | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/coupons/sources/coupons.move b/packages/coupons/sources/coupons.move index 446eb54b..88000b80 100644 --- a/packages/coupons/sources/coupons.move +++ b/packages/coupons/sources/coupons.move @@ -11,10 +11,10 @@ module coupons::coupons { use std::string::String; - use sui::{table::{Self, Table}, dynamic_field::{Self as df}, clock::Clock, sui::SUI, coin::{Self, Coin}}; + use sui::{table::{Self, Table}, dynamic_field::{Self as df}, clock::Clock, sui::SUI, coin::Coin}; use coupons::{rules::{Self, CouponRules}, constants}; - use suins::{domain, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, config::Self, registry::{Self, Registry}}; + use suins::{domain, suins::{Self, AdminCap, SuiNS}, suins_registration::SuinsRegistration, config::Self, registry::Registry}; /// Coupon already exists const ECouponAlreadyExists: u64 = 0; @@ -91,7 +91,7 @@ module coupons::coupons { assert!(self.data.coupons.contains(coupon_code), ECouponNotExists); // Verify coupon house is authorized to buy names. - suins::assert_app_is_authorized(suins); + suins.assert_app_is_authorized(); // Validate registration years are in [0,5] range. assert!(no_years > 0 && no_years <= 5, EInvalidYearsArgument); From 349ffe248007fe4fabe04fc8b48fd1e4bd9ea25e Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 17:53:49 -0400 Subject: [PATCH 36/38] rules update --- packages/coupons/sources/rules.move | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/coupons/sources/rules.move b/packages/coupons/sources/rules.move index 7e21b15f..5e0be1cd 100644 --- a/packages/coupons/sources/rules.move +++ b/packages/coupons/sources/rules.move @@ -82,7 +82,7 @@ module coupons::rules { /// We shouldn't get here ever, as we're checking this on the coupon creation, but /// keeping it as a sanity check (e.g. created a coupon with 0 available claims). public fun decrease_available_claims(rules: &mut CouponRules) { - if(option::is_some(&rules.available_claims)){ + if(rules.available_claims.is_some()){ assert!(has_available_claims(rules), ENoMoreAvailableClaims); // Decrease available claims by 1. let available_claims = *rules.available_claims.borrow(); @@ -93,7 +93,7 @@ module coupons::rules { // Checks whether a coupon has available claims. // Returns true if the rule is not set OR it has used all the available claims. public fun has_available_claims(rules: &CouponRules): bool { - if(option::is_none(&rules.available_claims)) return true; + if(rules.available_claims.is_none()) return true; *rules.available_claims.borrow() > 0 } From e324db790850f77289f0f967cc28cb60264e0648 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 17:56:52 -0400 Subject: [PATCH 37/38] update --- packages/coupons/tests/setup.move | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/coupons/tests/setup.move b/packages/coupons/tests/setup.move index 0c62c9e7..d00edd23 100644 --- a/packages/coupons/tests/setup.move +++ b/packages/coupons/tests/setup.move @@ -197,7 +197,7 @@ module coupons::setup { rules::new_empty_rules(), ctx(scenario) ); - test_scenario::return_to_sender(scenario, cap); + scenario.return_to_sender(cap); test_scenario::return_shared(coupon_house); } // Adds a 0 rule coupon that gives 15% discount to test admin additions. @@ -210,7 +210,7 @@ module coupons::setup { &mut coupon_house, code_name ); - test_scenario::return_to_sender(scenario, cap); + scenario.return_to_sender(cap); test_scenario::return_shared(coupon_house); } From 5b908440d55f7d1fee2027159ef674d8ee0ce768 Mon Sep 17 00:00:00 2001 From: Tony Lee Date: Tue, 16 Apr 2024 17:58:49 -0400 Subject: [PATCH 38/38] discounts --- packages/discounts/sources/discounts.move | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/discounts/sources/discounts.move b/packages/discounts/sources/discounts.move index 99d6ad1c..caf77eb7 100644 --- a/packages/discounts/sources/discounts.move +++ b/packages/discounts/sources/discounts.move @@ -123,12 +123,12 @@ module discounts::discounts { clock: &Clock, ctx: &mut TxContext ): SuinsRegistration { - house::assert_version_is_valid(self); + self.assert_version_is_valid(); // validate that there's a configuration for type T. assert_config_exists(self); let domain = domain::new(domain_name); - let price = calculate_price(df::borrow(house::uid_mut(self), DiscountKey{}), (domain.sld().length() as u8)); + let price = calculate_price(df::borrow(self.uid_mut(), DiscountKey{}), (domain.sld().length() as u8)); assert!(payment.value() == price, EIncorrectAmount); suins::app_add_balance(house::suins_app_auth(), suins, payment.into_balance());