From 1d76b1663692886ccecf6e7a961422c9755c0bca Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Tue, 7 May 2024 16:30:03 +0100 Subject: [PATCH] test: resetting subdomains multiple levels --- src/tests/naming/test_abuses.cairo | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/tests/naming/test_abuses.cairo b/src/tests/naming/test_abuses.cairo index ce22568..0fcd1c7 100644 --- a/src/tests/naming/test_abuses.cairo +++ b/src/tests/naming/test_abuses.cairo @@ -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'); +} +