From 0694be69c7ddccab9db2432e709c2ce7358411f1 Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Sun, 1 Sep 2024 14:16:27 +0100 Subject: [PATCH] run scarb fmt --- onchain/cairo/src/lib.cairo | 4 +-- onchain/cairo/src/quests/factory.cairo | 12 +++++--- onchain/cairo/src/quests/tap.cairo | 4 +-- .../cairo/src/tests/quest_factory_test.cairo | 29 +++++++++++-------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/onchain/cairo/src/lib.cairo b/onchain/cairo/src/lib.cairo index 7bbf269f..5eadd34f 100644 --- a/onchain/cairo/src/lib.cairo +++ b/onchain/cairo/src/lib.cairo @@ -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; @@ -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; diff --git a/onchain/cairo/src/quests/factory.cairo b/onchain/cairo/src/quests/factory.cairo index 540a74ce..2322b119 100644 --- a/onchain/cairo/src/quests/factory.cairo +++ b/onchain/cairo/src/quests/factory.cairo @@ -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); @@ -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)) + } } } diff --git a/onchain/cairo/src/quests/tap.cairo b/onchain/cairo/src/quests/tap.cairo index eea34687..dc8a6467 100644 --- a/onchain/cairo/src/quests/tap.cairo +++ b/onchain/cairo/src/quests/tap.cairo @@ -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 diff --git a/onchain/cairo/src/tests/quest_factory_test.cairo b/onchain/cairo/src/tests/quest_factory_test.cairo index fe23dec4..d7a4a5cd 100644 --- a/onchain/cairo/src/tests/quest_factory_test.cairo +++ b/onchain/cairo/src/tests/quest_factory_test.cairo @@ -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}; @@ -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 { @@ -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)); @@ -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');