Skip to content

Commit

Permalink
test: buying twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Aug 22, 2023
1 parent 6d20f6a commit bd6c7e0
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/tests/test_naming.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

0 comments on commit bd6c7e0

Please sign in to comment.