From bd6c7e0af318832d3907e9ca5660318b6dfc7102 Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Tue, 22 Aug 2023 13:40:35 +0100 Subject: [PATCH] test: buying twice --- src/tests/test_naming.cairo | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/tests/test_naming.cairo b/src/tests/test_naming.cairo index fc966ca..4885975 100644 --- a/src/tests/test_naming.cairo +++ b/src/tests/test_naming.cairo @@ -128,3 +128,72 @@ fn test_not_enough_eth() { naming .buy(id, th0rgal, 365, ContractAddressZeroable::zero(), ContractAddressZeroable::zero(), 0); } + + +#[cfg(test)] +#[test] +#[available_gas(2000000000)] +#[should_panic(expected: ('unexpired domain', 'ENTRYPOINT_FAILED'))] +fn test_buying_domain_twice() { + // setup + let (eth, pricing, identity, naming) = deploy(); + let caller = contract_address_const::<0x123>(); + set_contract_address(caller); + let id1: u128 = 1; + let id2: u128 = 2; + let th0rgal: felt252 = 33133781693; + + //we mint the ids + identity.mint(id1); + identity.mint(id2); + + // we check how much a domain costs + let (_, price) = pricing.compute_buy_price(th0rgal, 365); + + // we allow the naming to take our money + eth.approve(naming.contract_address, price); + + // we buy with no resolver, no sponsor and empty metadata + naming + .buy( + id1, th0rgal, 365, ContractAddressZeroable::zero(), ContractAddressZeroable::zero(), 0 + ); + + // buying again + naming + .buy( + id2, th0rgal, 365, ContractAddressZeroable::zero(), ContractAddressZeroable::zero(), 0 + ); +} + + +#[cfg(test)] +#[test] +#[available_gas(2000000000)] +#[should_panic(expected: ('this id holds a domain', 'ENTRYPOINT_FAILED'))] +fn test_buying_twice_on_same_id() { + // setup + let (eth, pricing, identity, naming) = deploy(); + let caller = contract_address_const::<0x123>(); + set_contract_address(caller); + let id: u128 = 1; + let th0rgal: felt252 = 33133781693; + let altdomain: felt252 = 57437602667574; + + //we mint an id + identity.mint(id); + + // we check how much a domain costs + let (_, price) = pricing.compute_buy_price(th0rgal, 365); + + // we allow the naming to take our money + eth.approve(naming.contract_address, price); + + // we buy with no resolver, no sponsor and empty metadata + naming + .buy(id, th0rgal, 365, ContractAddressZeroable::zero(), ContractAddressZeroable::zero(), 0); + naming + .buy( + id, altdomain, 365, ContractAddressZeroable::zero(), ContractAddressZeroable::zero(), 0 + ); +}