Skip to content

Commit

Permalink
test: add test for altcoin_renew_subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Mar 6, 2024
1 parent 6cd4a04 commit 10e091f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ mod Naming {
let domain_data = self._domain_data.read(hashed_domain);

// check caller is a whitelisted altcoin auto renewal contract
assert(self._whitelisted_renewal_contracts.read(get_caller_address()), 'Caller not whitelisted');
assert(
self._whitelisted_renewal_contracts.read(get_caller_address()),
'Caller not whitelisted'
);

// we need a u256 to be able to perform safe divisions
let domain_len = self.get_chars_len(domain.into());
Expand Down
34 changes: 30 additions & 4 deletions src/tests/naming/test_altcoin.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ fn test_subscription_with_strk() {
1162637274776062843434229637044893256148643831598397603392524411337131005673
);

// we whitelist renewal contract
let renewal_contract = contract_address_const::<0x456>();
naming.whitelist_renewal_contract(renewal_contract);

//we mint the ids id
identity.mint(id1);

Expand Down Expand Up @@ -378,6 +374,10 @@ fn test_subscription_with_strk() {
let (_, price_in_eth) = pricing.compute_buy_price(7, 365);
let price_in_strk: Wad = Wad { val: price_in_eth.low } / quote.into();

// we whitelist renewal contract
let renewal_contract = contract_address_const::<0x456>();
naming.whitelist_renewal_contract(renewal_contract);

// to test, we transfer the price of the domain in STRK to the renewal contract
// we allow the naming to take the price of the domain in STRK
strk.transfer(renewal_contract, price_in_strk.into());
Expand All @@ -401,3 +401,29 @@ fn test_subscription_with_strk() {
'invalid renew expiry'
);
}

#[test]
#[available_gas(2000000000)]
#[should_panic(expected: ('Caller not whitelisted', 'ENTRYPOINT_FAILED'))]
fn test_subscription_not_whitelisted() {
// setup
let (eth, pricing, identity, naming) = deploy();
let strk = deploy_stark();
let caller = contract_address_const::<0x123>();
set_contract_address(caller);
let id1: u128 = 1;
let th0rgal: felt252 = 33133781693;
naming
.set_server_pub_key(
1162637274776062843434229637044893256148643831598397603392524411337131005673
);

//we mint the ids id
identity.mint(id1);

// we try to renew domain but we're not whitelisted
naming
.altcoin_renew_subscription(
th0rgal, 365, ContractAddressZeroable::zero(), 0, 0, strk.contract_address, 1.into()
);
}

0 comments on commit 10e091f

Please sign in to comment.