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

fix: user could buy empty domain #53

Merged
merged 1 commit into from
May 28, 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: 2 additions & 0 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ mod Naming {
let (hashed_domain, now, expiry) = self.assert_purchase_is_possible(id, domain, days);
// we need a u256 to be able to perform safe divisions
let domain_len = self.get_chars_len(domain.into());
assert(domain_len != 0, 'domain can\' be empty');
// find domain cost
let (erc20, price) = IPricingDispatcher {
contract_address: self._pricing_contract.read()
Expand Down Expand Up @@ -311,6 +312,7 @@ mod Naming {
let (hashed_domain, now, expiry) = self.assert_purchase_is_possible(id, domain, days);
// we need a u256 to be able to perform safe divisions
let domain_len = self.get_chars_len(domain.into());
assert(domain_len != 0, 'domain can\' be empty');

// check quote timestamp is still valid
assert(get_block_timestamp() <= max_validity, 'quotation expired');
Expand Down
26 changes: 26 additions & 0 deletions src/tests/naming/test_abuses.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,29 @@ fn test_use_reset_subdomains() {
naming.transfer_domain(subsubdomain2, 4);
}

#[test]
#[available_gas(2000000000)]
#[should_panic(expected: ('domain can\' be empty', 'ENTRYPOINT_FAILED'))]
fn test_buy_empty_domain() {
// setup
let (eth, pricing, identity, naming) = deploy();
let alpha = contract_address_const::<0x123>();

// we mint the id
set_contract_address(alpha);
identity.mint(1);

set_contract_address(alpha);
let empty_domain: felt252 = 0;

// we check how much a domain costs
let (_, price) = pricing.compute_buy_price(0, 365);

// we allow the naming to take our money
eth.approve(naming.contract_address, price);

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

Loading