Skip to content

Commit

Permalink
test claim function
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Apr 22, 2024
1 parent 32359bd commit 81102f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 4 additions & 5 deletions onchain/src/quests/template_quest.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ pub mod TemplateQuest {
}

fn claim(ref self: ContractState, user: ContractAddress, calldata: Span<felt252>) -> u32 {
assert(
get_caller_address() == self.art_peace.read().contract_address,
'Only ArtPeace can claim quests'
);
// TODO: should we revert if the quest is not claimable?
if get_caller_address() != self.art_peace.read().contract_address {
return 0;
}

if !self.is_claimable(user, calldata) {
return 0;
}
Expand Down
12 changes: 12 additions & 0 deletions onchain/src/tests/template_quest.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@ fn test_is_claimable() {
assert(is_claim == test_is_claim, 'Template not claim');
}


#[test]
fn test_claim() {
let contract_address = deploy_contract();
let dispatcher = IQuestDispatcher { contract_address };
let test_claim_reward = dispatcher.claim(contract_address_const::<1>(), SINGLE_CALLDATA());

let claim_reward = 18;

assert(claim_reward != test_claim_reward, 'Template Reward not Claim');
}

0 comments on commit 81102f3

Please sign in to comment.