Skip to content

Commit

Permalink
run scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
manlikeHB committed Sep 1, 2024
1 parent 0736b6c commit 0694be6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions onchain/cairo/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub mod sha256;
pub mod social;
pub mod utils;
pub mod quests {
pub mod factory;
pub mod authority_quest;
pub mod chain_faction_quest;
pub mod faction_quest;
pub mod factory;
pub mod hodl_quest;
pub mod nft_quest;
pub mod pixel_quest;
Expand All @@ -25,10 +25,10 @@ pub mod interfaces {
pub mod erc20;
pub mod erc20_mintable;
pub mod jediswap;
pub mod quest;
pub mod nfts;
pub mod pixel;
pub mod pixel_template;
pub mod quest;
pub mod quests;
pub mod username_store;
pub mod vault;
Expand Down
12 changes: 8 additions & 4 deletions onchain/cairo/src/quests/factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ pub mod QuestFactory {
fn claim_reward(ref self: ContractState, quest_id: u32) {
let caller = get_caller_address();
let quest = self.get_quest(quest_id);
// let quest_dispathcer = IQuestDispatcher { contract_address: quest.address };

// let quest_dispathcer = IQuestDispatcher { contract_address: quest.address };
let quest_nft_dispatcher = IQuestNFTDispatcher {
contract_address: self.quest_nft.read()
};
let vault_dispatcher = IERCVaultDispatcher { contract_address: self.vault.read() };

// check if caller is eligible to claim reward
assert(IQuestDispatcher { contract_address: quest.address }.is_claimable(caller), 'Quest not claimable');
assert(
IQuestDispatcher { contract_address: quest.address }.is_claimable(caller),
'Quest not claimable'
);

let (token_reward, nft_reward) = self.get_reward(quest.address);

Expand Down Expand Up @@ -102,6 +105,7 @@ pub mod QuestFactory {
}

fn get_user_quest_info(self: @ContractState, quest_id: u32) -> UserQuestInfo {
self.user_quest_info.read((get_caller_address(), quest_id))}
self.user_quest_info.read((get_caller_address(), quest_id))
}
}
}
4 changes: 1 addition & 3 deletions onchain/cairo/src/quests/tap.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

#[starknet::contract]
mod TapQuests {
use core::num::traits::Zero;

use afk::interfaces::quest::{ITapQuests, IQuest};
use afk::types::tap_types::{TapUserStats, TapDailyEvent};
use core::num::traits::Zero;
use starknet::{
ContractAddress, get_caller_address, storage_access::StorageBaseAddress,
contract_address_const, get_block_timestamp, get_contract_address, ClassHash
Expand Down
29 changes: 17 additions & 12 deletions onchain/cairo/src/tests/quest_factory_test.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#[cfg(test)]
mod quest_factory_tests {
use afk::interfaces::erc20_mintable::{IERC20MintableDispatcher, IERC20MintableDispatcherTrait};
use afk::interfaces::erc20_mintable::{IERC20MintableDispatcher, IERC20MintableDispatcherTrait};
use afk::interfaces::quest::{
IQuestFactoryDispatcher, IQuestFactoryDispatcherTrait, IQuestDispatcher,
IQuestDispatcherTrait, IQuestNFTDispatcher, IQuestNFTDispatcherTrait, ITapQuests, ITapQuestsDispatcher, ITapQuestsDispatcherTrait
IQuestDispatcherTrait, IQuestNFTDispatcher, IQuestNFTDispatcherTrait, ITapQuests,
ITapQuestsDispatcher, ITapQuestsDispatcherTrait
};

use afk::interfaces::vault::{IERCVault, IERCVaultDispatcher, IERCVaultDispatcherTrait};
Expand Down Expand Up @@ -50,7 +51,12 @@ use afk::interfaces::erc20_mintable::{IERC20MintableDispatcher, IERC20MintableDi
);
let tap_quest_addr = deploy_tap_quest();

(factory_dispatcher, tap_quest_addr, IERC721Dispatcher {contract_address: quest_nft_addr}, IERC20Dispatcher {contract_address: token_address})
(
factory_dispatcher,
tap_quest_addr,
IERC721Dispatcher { contract_address: quest_nft_addr },
IERC20Dispatcher { contract_address: token_address }
)
}

fn deploy_tap_quest() -> ContractAddress {
Expand Down Expand Up @@ -136,7 +142,7 @@ use afk::interfaces::erc20_mintable::{IERC20MintableDispatcher, IERC20MintableDi

#[test]
fn test_add_quest() {
let (factory_dispatcher, tap_quest_addr, _,_) = setup();
let (factory_dispatcher, tap_quest_addr, _, _) = setup();

factory_dispatcher.add_quest(quest_info(tap_quest_addr));

Expand Down Expand Up @@ -189,22 +195,21 @@ use afk::interfaces::erc20_mintable::{IERC20MintableDispatcher, IERC20MintableDi
let quests = factory_dispatcher.get_quests();

start_cheat_caller_address(*quests.at(0).address, CALLER());
ITapQuestsDispatcher {contract_address: tap_quest_addr}.handle_tap_daily();
ITapQuestsDispatcher { contract_address: tap_quest_addr }.handle_tap_daily();
stop_cheat_caller_address(*quests.at(0).address);

start_cheat_caller_address(factory_dispatcher.contract_address, CALLER());
factory_dispatcher.claim_reward(*quests.at(0).quest_id);

//asert token rewar was minted
assert(token_dispacher.balance_of(CALLER()) == 5, 'wrong balance');

// assert nft was minted
assert(quest_nft_dispatcher.balance_of(CALLER()) == 1, 'wrong numder of nfts');

let user_quest_info = factory_dispatcher.get_user_quest_info(*quests.at(0).quest_id);
stop_cheat_caller_address(factory_dispatcher.contract_address);


stop_cheat_caller_address(factory_dispatcher.contract_address);

assert(user_quest_info.quest_id == *quests.at(0).quest_id, 'wrong quest id');
assert(user_quest_info.is_complete, 'wrong complete status');
assert(user_quest_info.claimed_token == 5, 'wrong complete status');
Expand Down

0 comments on commit 0694be6

Please sign in to comment.