Skip to content

Commit

Permalink
Merge pull request #102 from manlikeHB/profile-component-test
Browse files Browse the repository at this point in the history
 update profile component tests #95
  • Loading branch information
Darlington02 authored Jul 31, 2024
2 parents 7521c49 + 51db7a0 commit 3202107
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/test_profile.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ use core::starknet::SyscallResultTrait;
use core::result::ResultTrait;
use core::traits::{TryInto, Into};

use starknet::{ContractAddress, class_hash::ClassHash};
use snforge_std::{declare, ContractClassTrait, CheatTarget, start_prank, stop_prank};
use starknet::{ContractAddress, class_hash::ClassHash, get_block_timestamp};
use snforge_std::{
declare, ContractClassTrait, CheatTarget, start_prank, stop_prank, spy_events, SpyOn,
EventAssertions
};

use karst::interfaces::IKarstNFT::{IKarstNFTDispatcher, IKarstNFTDispatcherTrait};
use karst::karstnft::karstnft::KarstNFT;
use karst::follownft::follownft::Follow;
use karst::profile::profile::ProfileComponent::{Event as ProfileEvent, CreatedProfile};
use karst::interfaces::IERC721::{IERC721Dispatcher, IERC721DispatcherTrait};
use karst::interfaces::IProfile::{IProfileDispatcher, IProfileDispatcherTrait};

Expand Down Expand Up @@ -99,6 +103,9 @@ fn test_profile_creation() {
assert(profile.profile_address == profile_address, 'invalid profile address');
assert(profile.profile_owner == USER.try_into().unwrap(), 'invalid profile address');

// test follow nft contract is deployed
assert(profile.follow_nft != 0.try_into().unwrap(), 'follow nft not deployed');

stop_prank(CheatTarget::Multiple(array![profile_contract_address, nft_contract_address]));
}

Expand Down Expand Up @@ -133,3 +140,37 @@ fn test_profile_metadata() {

stop_prank(CheatTarget::Multiple(array![profile_contract_address, nft_contract_address]));
}

#[test]
fn test_profile_creation_event() {
let (
nft_contract_address, _, registry_class_hash, account_class_hash, profile_contract_address
) =
__setup__();
let karstNFTDispatcher = IKarstNFTDispatcher { contract_address: nft_contract_address };
let profileDispatcher = IProfileDispatcher { contract_address: profile_contract_address };
let mut spy = spy_events(SpyOn::One(profile_contract_address));

//user 1 create profile
start_prank(
CheatTarget::Multiple(array![profile_contract_address, nft_contract_address]),
USER.try_into().unwrap()
);
let profile_address = profileDispatcher
.create_profile(nft_contract_address, registry_class_hash, account_class_hash, 2456,);

let token_id = karstNFTDispatcher.get_user_token_id(USER.try_into().unwrap());

let expected_event = ProfileEvent::CreatedProfile(
CreatedProfile {
owner: USER.try_into().unwrap(),
profile_address,
token_id,
timestamp: get_block_timestamp()
}
);

spy.assert_emitted(@array![(profile_contract_address, expected_event)]);

stop_prank(CheatTarget::Multiple(array![profile_contract_address, nft_contract_address]));
}

0 comments on commit 3202107

Please sign in to comment.