Skip to content

Commit

Permalink
test for test_get_reward
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Apr 22, 2024
1 parent 577dbe1 commit d906c97
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions onchain/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use interfaces::{IArtPeace, IArtPeaceDispatcher, IArtPeaceDispatcherTrait, Pixel
mod quests {
pub mod interfaces;
pub mod pixel_quest;
pub mod template_quest;

use interfaces::{IQuest, IPixelQuest, QuestClaimed, IQuestDispatcher, IQuestDispatcherTrait};
}
Expand Down Expand Up @@ -50,6 +51,7 @@ mod mocks {
mod tests {
mod art_peace;
mod username_store;
mod template_quest;
pub(crate) mod utils;
}

8 changes: 4 additions & 4 deletions onchain/src/quests/template_quest.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use art_peace::templates::interfaces::{
ITemplateVerifierDispatcherTrait, TemplateMetadata
};

use core::array::Span;
use core::traits::{TryInto, Into};

#[starknet::contract]
pub mod TemplateQuest {
Expand Down Expand Up @@ -43,7 +45,7 @@ pub mod TemplateQuest {
}

#[constructor]
fn constructor(ref self: ContractState, init_params: TemplateQuestInitParams,) {
fn constructor(ref self: ContractState, init_params: TemplateQuestInitParams) {
self.reward.write(init_params.reward);
self.art_peace.write(IArtPeaceDispatcher { contract_address: init_params.art_peace });
}
Expand All @@ -57,13 +59,11 @@ pub mod TemplateQuest {
fn is_claimable(
self: @ContractState, user: ContractAddress, calldata: Span<felt252>
) -> bool {
// let art_peace = self.art_peace.read();

if self.claimed.read(user) {
return false;
}

let template_id_felt = calldata[0];
let template_id_felt = *calldata.at(0);

let template_id: u32 = template_id_felt.try_into().unwrap();

Expand Down
30 changes: 30 additions & 0 deletions onchain/src/tests/template_quest.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use snforge_std::{declare, ContractClassTrait};
use art_peace::quests::interfaces::{IQuestDispatcher, IQuestDispatcherTrait};
use art_peace::quests::template_quest::TemplateQuest::TemplateQuestInitParams;

use starknet::{ContractAddress, get_caller_address, get_contract_address, contract_address_const};


const reward_decimals: u32 = 18_u32;

fn deploy_contract() -> ContractAddress {
let contract = declare("TemplateQuest");

let mut template_calldata = array![];
TemplateQuestInitParams { art_peace: contract_address_const::<1>(), reward: reward_decimals, }
.serialize(ref template_calldata);

return contract.deploy(@template_calldata).unwrap();
}


#[test]
fn test_get_reward() {
let contract_address = deploy_contract();
let dispatcher = IQuestDispatcher { contract_address };
let current_reward = dispatcher.get_reward();

let test_reward = 18;

assert(current_reward == test_reward, 'Reward Not set');
}

0 comments on commit d906c97

Please sign in to comment.