Skip to content

Commit

Permalink
Proper testing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
manolisliolios committed Dec 2, 2024
1 parent c97caf1 commit 16a1274
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 293 deletions.
72 changes: 36 additions & 36 deletions packages/discounts/sources/free_claims.move
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,42 @@ public fun free_claim_with_day_one(
self.internal_apply_full_discount<DayOne>(suins, intent, object::id(day_one), ctx);
}

/// An admin action to authorize a type T for free claiming of names by
/// presenting
/// an object of type `T`.
public fun authorize_type<T: key>(
self: &mut DiscountHouse,
_: &AdminCap,
domain_length_range: Range,
ctx: &mut TxContext,
) {
self.assert_version_is_valid();
assert!(!self.uid_mut().exists_(FreeClaimsKey<T>()), EConfigExists);

self
.uid_mut()
.add(
FreeClaimsKey<T>(),
FreeClaimsConfig {
domain_length_range,
used_objects: linked_table::new(ctx),
},
);
}

/// Force-deauthorize type T from free claims.
/// Drops the linked_table.
public fun deauthorize_type<T>(self: &mut DiscountHouse, _: &AdminCap): LinkedTable<ID, bool> {
self.assert_version_is_valid();
self.assert_config_exists<T>();

let FreeClaimsConfig { used_objects, domain_length_range: _ } = self
.uid_mut()
.remove(FreeClaimsKey<T>());

used_objects
}

/// Internal helper that checks if there's a valid configuration for T,
/// validates that the domain name is of vlaid length, and then does the
/// registration.
Expand Down Expand Up @@ -122,42 +158,6 @@ fun internal_apply_full_discount<T: key>(
);
}

/// An admin action to authorize a type T for free claiming of names by
/// presenting
/// an object of type `T`.
public fun authorize_type<T: key>(
_: &AdminCap,
self: &mut DiscountHouse,
domain_length_range: Range,
ctx: &mut TxContext,
) {
self.assert_version_is_valid();
assert!(!self.uid_mut().exists_(FreeClaimsKey<T>()), EConfigExists);

self
.uid_mut()
.add(
FreeClaimsKey<T>(),
FreeClaimsConfig {
domain_length_range,
used_objects: linked_table::new(ctx),
},
);
}

/// Force-deauthorize type T from free claims.
/// Drops the linked_table.
public fun force_deauthorize_type<T>(_: &AdminCap, self: &mut DiscountHouse) {
self.assert_version_is_valid();
self.assert_config_exists<T>();

let FreeClaimsConfig { used_objects, domain_length_range: _ } = self
.uid_mut()
.remove(FreeClaimsKey<T>());

used_objects.drop();
}

fun config_mut<T>(self: &mut DiscountHouse): &mut FreeClaimsConfig {
self.uid_mut().borrow_mut<_, FreeClaimsConfig>(FreeClaimsKey<T>())
}
Expand Down
12 changes: 4 additions & 8 deletions packages/discounts/sources/house.move
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ fun init(ctx: &mut TxContext) {
})
}

public(package) macro fun discount_house_key(): String {
b"object_discount".to_string()
}

public fun set_version(self: &mut DiscountHouse, _: &AdminCap, version: u8) {
self.version = version;
}

public(package) fun assert_version_is_valid(self: &DiscountHouse) {
assert!(self.version == VERSION, EInvalidVersion);
public(package) macro fun discount_house_key(): String {
b"object_discount".to_string()
}

public(package) fun uid(self: &DiscountHouse): &UID {
&self.id
public(package) fun assert_version_is_valid(self: &DiscountHouse) {
assert!(self.version == VERSION, EInvalidVersion);
}

/// A helper function to get a mutable reference to the UID.
Expand Down
Loading

0 comments on commit 16a1274

Please sign in to comment.