Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checks for the 25-year maximum purchase are inconsistent #61

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);
}
Loading