Skip to content

Commit

Permalink
checks for the 25-year maximum purchase are inconsistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Jun 11, 2024
1 parent 6993eee commit aa6830a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/naming/asserts.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl AssertionsImpl of AssertionsTrait {
assert(data.owner == 0 || data.expiry < now, 'unexpired domain');

// Verify expiration range
assert(days < 365 * 25, 'max purchase of 25 years');
assert(days <= 365 * 25, 'max purchase of 25 years');
assert(days > 2 * 30, 'min purchase of 2 month');
return (hashed_domain, now, now + 86400 * days.into());
}
Expand Down
13 changes: 5 additions & 8 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ mod Naming {
domain_data.expiry + 86400 * days.into()
};
// 25*365 = 9125
assert(new_expiry <= now + 86400 * 9125, 'purchase too long');
assert(days >= 6 * 30, 'purchase too short');
assert(new_expiry <= now + 365 * 25 * 86400, 'max purchase of 25 years');
assert(days >= 6 * 30, 'min purchase of 6 months');

let data = DomainData {
owner: domain_data.owner,
Expand Down Expand Up @@ -456,9 +456,8 @@ mod Naming {
} else {
domain_data.expiry + 86400 * days.into()
};
// 25*365 = 9125
assert(new_expiry <= now + 86400 * 9125, 'purchase too long');
assert(days >= 6 * 30, 'purchase too short');
assert(new_expiry <= now + 365 * 25 * 86400, 'max purchase of 25 years');
assert(days >= 6 * 30, 'min purchase of 6 months');

let data = DomainData {
owner: domain_data.owner,
Expand Down Expand Up @@ -707,9 +706,7 @@ mod Naming {

// ADMIN

fn set_expiry(
ref self: ContractState, root_domain: felt252, expiry: u64
) {
fn set_expiry(ref self: ContractState, root_domain: felt252, expiry: u64) {
self.ownable.assert_only_owner();
let hashed_domain = self.hash_domain(array![root_domain].span());
let domain_data = self._domain_data.read(hashed_domain);
Expand Down
14 changes: 11 additions & 3 deletions src/tests/naming/test_abuses.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn test_non_owner_cannot_transfer_domain() {

#[test]
#[available_gas(2000000000)]
#[should_panic(expected: ('purchase too short', 'ENTRYPOINT_FAILED'))]
#[should_panic(expected: ('min purchase of 6 months', 'ENTRYPOINT_FAILED'))]
fn test_renewal_period_too_short() {
// setup
let (eth, pricing, identity, naming) = deploy();
Expand All @@ -190,7 +190,7 @@ fn test_renewal_period_too_short() {

#[test]
#[available_gas(2000000000)]
#[should_panic(expected: ('purchase too long', 'ENTRYPOINT_FAILED'))]
#[should_panic(expected: ('max purchase of 25 years', 'ENTRYPOINT_FAILED'))]
fn test_renewal_period_too_long() {
// setup
let (eth, pricing, identity, naming) = deploy();
Expand Down Expand Up @@ -334,5 +334,13 @@ fn test_buy_empty_domain() {

// we buy with no resolver, no sponsor, no discount and empty metadata
naming
.buy(1, empty_domain, 365, ContractAddressZeroable::zero(), ContractAddressZeroable::zero(), 0, 0);
.buy(
1,
empty_domain,
365,
ContractAddressZeroable::zero(),
ContractAddressZeroable::zero(),
0,
0
);
}

0 comments on commit aa6830a

Please sign in to comment.