Skip to content

Commit

Permalink
test: resetting subdomains multiple levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed May 7, 2024
1 parent 02d547b commit 1d76b16
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/tests/naming/test_abuses.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,68 @@ fn test_use_reset_subdomains() {
naming.transfer_domain(subsubdomain2, 4);
}


#[test]
#[available_gas(2000000000)]
//#[should_panic(expected: ('a parent domain was reset', 'ENTRYPOINT_FAILED'))]
fn test_use_reset_subdomains_multiple_levels() {
// setup
let (eth, pricing, identity, naming) = deploy();
let alpha = contract_address_const::<0x123>();
let bravo = contract_address_const::<0x456>();
let charlie = contract_address_const::<0x789>();
// In this example we will use utf-8 encoded strings like 'toto' which is not
// what is actually defined in the starknetid standard, it's just easier for testings

// we mint the ids
set_contract_address(alpha);
identity.mint(1);
set_contract_address(bravo);
identity.mint(2);
set_contract_address(charlie);
identity.mint(3);

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

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

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

let root_domain = array!['ccccc'].span();
let subdomain = array!['bbbbb', 'ccccc'].span();

// we transfer bb.cc.stark to id2
naming.transfer_domain(subdomain, 2);

// and make sure the owner has been updated
assert(naming.domain_to_id(subdomain) == 2, 'owner not updated correctly');

set_contract_address(bravo);
// we transfer aa.bb.cc.stark to id3
let subsubdomain = array!['aaaaa', 'bbbbb', 'ccccc'].span();
naming.transfer_domain(subsubdomain, 3);

// now charlie should be able to create a subbsubsubdomain (example.aa.bb.cc.stark):
set_contract_address(charlie);
let subsubsubdomain = array!['example', 'aaaaa', 'bbbbb', 'ccccc'].span();
naming.transfer_domain(subsubsubdomain, 4);

// alpha resets subdomains of aller.stark
set_contract_address(alpha);
naming.reset_subdomains(root_domain);

// ensure root domain still resolves
assert(naming.domain_to_id(root_domain) == 1, 'owner not updated correctly');
// ensure the subdomain was reset
assert(naming.domain_to_id(subdomain) == 0, 'owner not updated correctly');
// ensure the subsubdomain was reset
assert(naming.domain_to_id(subsubdomain) == 0, 'owner not updated correctly');
}

0 comments on commit 1d76b16

Please sign in to comment.