From 81102f318afd237b3743ce8e8da62543273b70ee Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Mon, 22 Apr 2024 17:59:39 +0100 Subject: [PATCH] test claim function --- onchain/src/quests/template_quest.cairo | 9 ++++----- onchain/src/tests/template_quest.cairo | 12 ++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/onchain/src/quests/template_quest.cairo b/onchain/src/quests/template_quest.cairo index 67dd8eff..944003d0 100644 --- a/onchain/src/quests/template_quest.cairo +++ b/onchain/src/quests/template_quest.cairo @@ -77,11 +77,10 @@ pub mod TemplateQuest { } fn claim(ref self: ContractState, user: ContractAddress, calldata: Span) -> 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; } diff --git a/onchain/src/tests/template_quest.cairo b/onchain/src/tests/template_quest.cairo index 9ef3e400..75319ea7 100644 --- a/onchain/src/tests/template_quest.cairo +++ b/onchain/src/tests/template_quest.cairo @@ -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'); +} +