From f0896b38eb50b1212fdf7752d68618fe201500f7 Mon Sep 17 00:00:00 2001 From: PavitraAgarwal21 Date: Wed, 2 Oct 2024 05:12:53 +0530 Subject: [PATCH 1/2] Test Upgrade to v2.8.3 --- Scarb.toml | 2 +- src/follownft/follownft.cairo | 42 ++++---- src/karstnft/karstnft.cairo | 9 +- src/namespaces/handle_registry.cairo | 16 +-- src/namespaces/handles.cairo | 18 ++-- src/profile/profile.cairo | 8 +- src/publication/publication.cairo | 36 +++---- tests/test_follownft.cairo | 107 +++++++++++--------- tests/test_handle.cairo | 66 ++++++------- tests/test_handle_registry.cairo | 36 ++++--- tests/test_hub.cairo | 58 ++++++----- tests/test_karstnft.cairo | 71 ++++---------- tests/test_profile.cairo | 55 +++++------ tests/test_profile_token_uri.cairo | 6 +- tests/test_publication.cairo | 140 +++++++++++++-------------- 15 files changed, 316 insertions(+), 354 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index 0eb0ea5..575ff04 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -17,7 +17,7 @@ alexandria_bytes = { git = "https://github.com/keep-starknet-strange/alexandria. [dev-dependencies] snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.31.0" } -cairo_test = "2.8.2" + [sncast.default] url= "https://starknet-sepolia.public.blastapi.io" diff --git a/src/follownft/follownft.cairo b/src/follownft/follownft.cairo index 18e4658..51e8ff8 100644 --- a/src/follownft/follownft.cairo +++ b/src/follownft/follownft.cairo @@ -65,7 +65,7 @@ pub mod Follow { // ************************************************************************* #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { #[flat] ERC721Event: ERC721Component::Event, #[flat] @@ -79,35 +79,35 @@ pub mod Follow { } #[derive(Drop, starknet::Event)] - struct Followed { - followed_address: ContractAddress, - follower_address: ContractAddress, - follow_id: u256, - timestamp: u64, + pub struct Followed { + pub followed_address: ContractAddress, + pub follower_address: ContractAddress, + pub follow_id: u256, + pub timestamp: u64, } #[derive(Drop, starknet::Event)] - struct Unfollowed { - unfollowed_address: ContractAddress, - unfollower_address: ContractAddress, - follow_id: u256, - timestamp: u64, + pub struct Unfollowed { + pub unfollowed_address: ContractAddress, + pub unfollower_address: ContractAddress, + pub follow_id: u256, + pub timestamp: u64, } #[derive(Drop, starknet::Event)] - struct FollowerBlocked { - followed_address: ContractAddress, - blocked_follower: ContractAddress, - follow_id: u256, - timestamp: u64, + pub struct FollowerBlocked { + pub followed_address: ContractAddress, + pub blocked_follower: ContractAddress, + pub follow_id: u256, + pub timestamp: u64, } #[derive(Drop, starknet::Event)] - struct FollowerUnblocked { - followed_address: ContractAddress, - unblocked_follower: ContractAddress, - follow_id: u256, - timestamp: u64, + pub struct FollowerUnblocked { + pub followed_address: ContractAddress, + pub unblocked_follower: ContractAddress, + pub follow_id: u256, + pub timestamp: u64, } // ************************************************************************* diff --git a/src/karstnft/karstnft.cairo b/src/karstnft/karstnft.cairo index e1c4c34..16ba774 100644 --- a/src/karstnft/karstnft.cairo +++ b/src/karstnft/karstnft.cairo @@ -13,7 +13,8 @@ pub mod KarstNFT { use core::num::traits::zero::Zero; use karst::interfaces::IKarstNFT; use karst::base::{ - constants::errors::Errors::ALREADY_MINTED, token_uris::profile_token_uri::ProfileTokenUri, + constants::errors::Errors::ALREADY_MINTED, + token_uris::profile_token_uri::ProfileTokenUri::get_token_uri, }; use openzeppelin::{ access::ownable::OwnableComponent, token::erc721::{ERC721Component, ERC721HooksEmptyImpl}, @@ -124,18 +125,18 @@ pub mod KarstNFT { // ************************************************************************* /// @notice returns the collection name fn name(self: @ContractState) -> ByteArray { - return "Karst Handles"; + return "Karst"; } /// @notice returns the collection symbol fn symbol(self: @ContractState) -> ByteArray { - return "KARST"; + return "KST"; } /// @notice returns the token_uri for a particular token_id fn token_uri(self: @ContractState, token_id: u256) -> ByteArray { let mint_timestamp: u64 = self.get_token_mint_timestamp(token_id); - ProfileTokenUri::get_token_uri(token_id, mint_timestamp) + get_token_uri(token_id, mint_timestamp) } } } diff --git a/src/namespaces/handle_registry.cairo b/src/namespaces/handle_registry.cairo index f65818d..6f95784 100644 --- a/src/namespaces/handle_registry.cairo +++ b/src/namespaces/handle_registry.cairo @@ -38,18 +38,18 @@ pub mod HandleRegistry { #[derive(Drop, starknet::Event)] pub struct HandleLinked { - handle_id: u256, - profile_address: ContractAddress, - caller: ContractAddress, - timestamp: u64 + pub handle_id: u256, + pub profile_address: ContractAddress, + pub caller: ContractAddress, + pub timestamp: u64 } #[derive(Drop, starknet::Event)] pub struct HandleUnlinked { - handle_id: u256, - profile_address: ContractAddress, - caller: ContractAddress, - timestamp: u64 + pub handle_id: u256, + pub profile_address: ContractAddress, + pub caller: ContractAddress, + pub timestamp: u64 } // ************************************************************************* diff --git a/src/namespaces/handles.cairo b/src/namespaces/handles.cairo index b4dbba4..1669dbc 100644 --- a/src/namespaces/handles.cairo +++ b/src/namespaces/handles.cairo @@ -76,7 +76,7 @@ pub mod Handles { // ************************************************************************* #[event] #[derive(Drop, starknet::Event)] - enum Event { + pub enum Event { #[flat] ERC721Event: ERC721Component::Event, #[flat] @@ -89,18 +89,18 @@ pub mod Handles { #[derive(Drop, starknet::Event)] pub struct HandleMinted { - local_name: felt252, - token_id: u256, - to: ContractAddress, - block_timestamp: u64, + pub local_name: felt252, + pub token_id: u256, + pub to: ContractAddress, + pub block_timestamp: u64, } #[derive(Drop, starknet::Event)] pub struct HandleBurnt { - local_name: felt252, - token_id: u256, - owner: ContractAddress, - block_timestamp: u64, + pub local_name: felt252, + pub token_id: u256, + pub owner: ContractAddress, + pub block_timestamp: u64, } // ************************************************************************* diff --git a/src/profile/profile.cairo b/src/profile/profile.cairo index c536109..f2fe6de 100644 --- a/src/profile/profile.cairo +++ b/src/profile/profile.cairo @@ -41,11 +41,11 @@ pub mod ProfileComponent { #[derive(Drop, starknet::Event)] pub struct CreatedProfile { #[key] - owner: ContractAddress, + pub owner: ContractAddress, #[key] - profile_address: ContractAddress, - token_id: u256, - timestamp: u64 + pub profile_address: ContractAddress, + pub token_id: u256, + pub timestamp: u64 } // ************************************************************************* diff --git a/src/publication/publication.cairo b/src/publication/publication.cairo index c3f1f2c..f49bd57 100644 --- a/src/publication/publication.cairo +++ b/src/publication/publication.cairo @@ -44,40 +44,40 @@ pub mod PublicationComponent { #[derive(Drop, starknet::Event)] pub struct Post { - post: PostParams, - publication_id: u256, - transaction_executor: ContractAddress, - block_timestamp: u64, + pub post: PostParams, + pub publication_id: u256, + pub transaction_executor: ContractAddress, + pub block_timestamp: u64, } #[derive(Drop, starknet::Event)] pub struct RepostCreated { - repostParams: RepostParams, - publication_id: u256, - transaction_executor: ContractAddress, - block_timestamp: u64, + pub repostParams: RepostParams, + pub publication_id: u256, + pub transaction_executor: ContractAddress, + pub block_timestamp: u64, } #[derive(Drop, starknet::Event)] pub struct CommentCreated { - commentParams: CommentParams, - publication_id: u256, - transaction_executor: ContractAddress, - block_timestamp: u64, + pub commentParams: CommentParams, + pub publication_id: u256, + pub transaction_executor: ContractAddress, + pub block_timestamp: u64, } #[derive(Drop, starknet::Event)] pub struct Upvoted { - publication_id: u256, - transaction_executor: ContractAddress, - block_timestamp: u64, + pub publication_id: u256, + pub transaction_executor: ContractAddress, + pub block_timestamp: u64, } #[derive(Drop, starknet::Event)] pub struct Downvoted { - publication_id: u256, - transaction_executor: ContractAddress, - block_timestamp: u64, + pub publication_id: u256, + pub transaction_executor: ContractAddress, + pub block_timestamp: u64, } // ************************************************************************* diff --git a/tests/test_follownft.cairo b/tests/test_follownft.cairo index 390f5c3..71b9a0e 100644 --- a/tests/test_follownft.cairo +++ b/tests/test_follownft.cairo @@ -6,9 +6,11 @@ use core::starknet::SyscallResultTrait; use core::result::ResultTrait; use core::traits::{TryInto, Into}; use starknet::{ContractAddress, get_block_timestamp}; + use snforge_std::{ - declare, ContractClassTrait, CheatTarget, start_prank, stop_prank, start_warp, stop_warp, - spy_events, SpyOn, EventAssertions, EventFetcher + declare, start_cheat_caller_address, stop_cheat_caller_address, spy_events, + EventSpyAssertionsTrait, ContractClassTrait, DeclareResultTrait, start_cheat_block_timestamp, + stop_cheat_block_timestamp }; use karst::interfaces::IFollowNFT::{IFollowNFTDispatcher, IFollowNFTDispatcherTrait}; @@ -29,7 +31,7 @@ const FOLLOWER3: felt252 = 24552; const FOLLOWER4: felt252 = 24262; fn __setup__() -> ContractAddress { - let follow_nft_contract = declare("Follow").unwrap(); + let follow_nft_contract = declare("Follow").unwrap().contract_class(); let mut follow_nft_constructor_calldata = array![HUB_ADDRESS, FOLLOWED_ADDRESS, ADMIN]; let (follow_nft_contract_address, _) = follow_nft_contract .deploy(@follow_nft_constructor_calldata) @@ -53,9 +55,9 @@ fn test_follower_count_on_init_is_zero() { fn test_cannot_call_follow_if_not_hub() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), FOLLOWER2.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, FOLLOWER2.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] @@ -63,9 +65,9 @@ fn test_cannot_call_follow_if_not_hub() { fn test_cannot_call_unfollow_if_not_hub() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), FOLLOWER2.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, FOLLOWER2.try_into().unwrap()); dispatcher.unfollow(FOLLOWER1.try_into().unwrap()); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] @@ -73,46 +75,49 @@ fn test_cannot_call_unfollow_if_not_hub() { fn test_cannot_follow_if_already_following() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); // follow dispatcher.follow(FOLLOWER1.try_into().unwrap()); // try to follow again dispatcher.follow(FOLLOWER1.try_into().unwrap()); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_follow() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); let follower_profile_address = dispatcher.get_follower_profile_address(follow_id); assert(follow_id == 1, 'invalid follow ID'); - assert(follower_profile_address == FOLLOWER1.try_into().unwrap(), 'invalid follower profile'); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + assert( + follower_profile_address == FOLLOWER1.try_into().unwrap(), 'invalid follower + profile' + ); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_follower_count() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); dispatcher.follow(FOLLOWER2.try_into().unwrap()); dispatcher.follow(FOLLOWER3.try_into().unwrap()); dispatcher.follow(FOLLOWER4.try_into().unwrap()); let follower_count = dispatcher.get_follower_count(); assert(follower_count == 4, 'invalid follower count'); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_is_following() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); let is_following_should_be_true = dispatcher.is_following(FOLLOWER1.try_into().unwrap()); let is_following_should_be_false = dispatcher.is_following(FOLLOWER2.try_into().unwrap()); @@ -124,8 +129,8 @@ fn test_is_following() { fn test_follow_data() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); - start_warp(CheatTarget::One(follow_nft_contract_address), 100); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); + start_cheat_block_timestamp(follow_nft_contract_address, 100); dispatcher.follow(FOLLOWER1.try_into().unwrap()); let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); let follow_data = dispatcher.get_follow_data(follow_id); @@ -145,15 +150,15 @@ fn test_follow_data() { ); assert(follow_data.follow_timestamp == data.follow_timestamp, 'invalid follow timestamp'); assert(follow_data.block_status == data.block_status, 'invalid block status'); - stop_prank(CheatTarget::One(follow_nft_contract_address)); - stop_warp(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); + stop_cheat_block_timestamp(follow_nft_contract_address); } #[test] fn test_unfollow() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); dispatcher.follow(FOLLOWER2.try_into().unwrap()); dispatcher.unfollow(FOLLOWER1.try_into().unwrap()); @@ -161,7 +166,7 @@ fn test_unfollow() { let follower_count = dispatcher.get_follower_count(); assert(follow_id == 0, 'unfollow operation failed'); assert(follower_count == 1, 'invalid follower count'); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] @@ -169,35 +174,35 @@ fn test_unfollow() { fn test_cannot_unfollow_if_not_following() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.unfollow(FOLLOWER1.try_into().unwrap()); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_process_block() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); dispatcher.process_block(FOLLOWER1.try_into().unwrap()); let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); let follow_data = dispatcher.get_follow_data(follow_id); assert(follow_data.block_status == true, 'block operation failed'); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_process_unblock() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); dispatcher.process_unblock(FOLLOWER1.try_into().unwrap()); let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); let follow_data = dispatcher.get_follow_data(follow_id); assert(follow_data.block_status == false, 'unblock operation failed'); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] @@ -208,21 +213,21 @@ fn test_metadata() { let nft_symbol = dispatcher.symbol(); assert(nft_name == "KARST:FOLLOWER", 'invalid name'); assert(nft_symbol == "KFL", 'invalid symbol'); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_is_blocked() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); dispatcher.process_block(FOLLOWER1.try_into().unwrap()); assert( dispatcher.is_blocked(FOLLOWER1.try_into().unwrap()) == true, 'incorrect value for is_blocked' ); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] @@ -230,28 +235,31 @@ fn test_follow_mints_nft() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; let _erc721Dispatcher = IERC721Dispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); let follower_profile_address = dispatcher.get_follower_profile_address(follow_id); assert( - _erc721Dispatcher.owner_of(follow_id) == follower_profile_address, 'Follow did not mint NFT' + _erc721Dispatcher.owner_of(follow_id) == follower_profile_address, + 'Follow did not mint + NFT' ); } - #[test] #[should_panic(expected: ('ERC721: invalid token ID',))] fn test_unfollow_burns_nft() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; let _erc721Dispatcher = IERC721Dispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); let follower_profile_address = dispatcher.get_follower_profile_address(follow_id); assert( - _erc721Dispatcher.owner_of(follow_id) == follower_profile_address, 'Follow did not mint NFT' + _erc721Dispatcher.owner_of(follow_id) == follower_profile_address, + 'Follow did not mint + NFT' ); dispatcher.unfollow(FOLLOWER1.try_into().unwrap()); _erc721Dispatcher.owner_of(follow_id); @@ -261,12 +269,13 @@ fn test_unfollow_burns_nft() { fn test_followed_event() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); - let mut spy = spy_events(SpyOn::One(follow_nft_contract_address)); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); + + let mut spy = spy_events(); dispatcher.follow(FOLLOWER1.try_into().unwrap()); + let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); let follower_profile_address = dispatcher.get_follower_profile_address(follow_id); - let expected_event = FollowEvent::Followed( Followed { followed_address: FOLLOWED_ADDRESS.try_into().unwrap(), @@ -275,16 +284,18 @@ fn test_followed_event() { timestamp: get_block_timestamp() } ); + spy.assert_emitted(@array![(follow_nft_contract_address, expected_event)]); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_unfollowed_event() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); - let mut spy = spy_events(SpyOn::One(follow_nft_contract_address)); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); + let mut spy = spy_events(); dispatcher.follow(FOLLOWER1.try_into().unwrap()); dispatcher.follow(FOLLOWER2.try_into().unwrap()); dispatcher.unfollow(FOLLOWER1.try_into().unwrap()); @@ -298,16 +309,16 @@ fn test_unfollowed_event() { } ); spy.assert_emitted(@array![(follow_nft_contract_address, expected_event)]); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_block_event() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); - let mut spy = spy_events(SpyOn::One(follow_nft_contract_address)); + let mut spy = spy_events(); dispatcher.process_block(FOLLOWER1.try_into().unwrap()); let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); @@ -320,16 +331,16 @@ fn test_block_event() { } ); spy.assert_emitted(@array![(follow_nft_contract_address, expected_event)]); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } #[test] fn test_unblock_event() { let follow_nft_contract_address = __setup__(); let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address }; - start_prank(CheatTarget::One(follow_nft_contract_address), HUB_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(follow_nft_contract_address, HUB_ADDRESS.try_into().unwrap()); dispatcher.follow(FOLLOWER1.try_into().unwrap()); - let mut spy = spy_events(SpyOn::One(follow_nft_contract_address)); + let mut spy = spy_events(); dispatcher.process_unblock(FOLLOWER1.try_into().unwrap()); let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap()); @@ -342,5 +353,5 @@ fn test_unblock_event() { } ); spy.assert_emitted(@array![(follow_nft_contract_address, expected_event)]); - stop_prank(CheatTarget::One(follow_nft_contract_address)); + stop_cheat_caller_address(follow_nft_contract_address); } diff --git a/tests/test_handle.cairo b/tests/test_handle.cairo index 8a72e81..3ecd0c8 100644 --- a/tests/test_handle.cairo +++ b/tests/test_handle.cairo @@ -3,9 +3,10 @@ use core::starknet::SyscallResultTrait; use core::result::ResultTrait; use core::traits::{TryInto, Into}; use starknet::{ContractAddress, get_block_timestamp}; + use snforge_std::{ - declare, ContractClassTrait, CheatTarget, start_prank, stop_prank, start_warp, stop_warp, - spy_events, SpyOn, EventAssertions + declare, ContractClassTrait, start_cheat_caller_address, stop_cheat_caller_address, spy_events, + EventSpyAssertionsTrait, DeclareResultTrait }; use karst::interfaces::IHandle::{IHandleDispatcher, IHandleDispatcherTrait}; @@ -26,10 +27,9 @@ const TEST_BAD_LOCAL_NAME_3: felt252 = 'karst-'; const TEST_TOKEN_ID: u256 = 2821396919044486126129003092173544296283884532301009869065707438220168412703; - fn __setup__() -> ContractAddress { // deploy handles contract - let handles_class_hash = declare("Handles").unwrap(); + let handles_class_hash = declare("Handles").unwrap().contract_class(); let mut calldata: Array = array![ADMIN_ADDRESS]; let (handles_contract_address, _) = handles_class_hash.deploy(@calldata).unwrap_syscall(); handles_contract_address @@ -43,28 +43,27 @@ fn test_mint_handle() { let handles_contract_address = __setup__(); let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); let token_id = handles_dispatcher.mint_handle(USER_ONE.try_into().unwrap(), TEST_LOCAL_NAME); let local_name: felt252 = handles_dispatcher.get_local_name(token_id); assert(local_name == TEST_LOCAL_NAME, 'invalid local name'); - stop_prank(CheatTarget::One(handles_contract_address)); + stop_cheat_caller_address(handles_contract_address); } - fn test_mint_handle_two() { let handles_contract_address = __setup__(); let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); let token_id = handles_dispatcher .mint_handle(USER_ONE.try_into().unwrap(), TEST_LOCAL_NAME_TWO); let local_name: felt252 = handles_dispatcher.get_local_name(token_id); assert(local_name == TEST_LOCAL_NAME_TWO, 'invalid local name two'); - stop_prank(CheatTarget::One(handles_contract_address)); + stop_cheat_caller_address(handles_contract_address); } #[test] @@ -73,7 +72,7 @@ fn test_mint_handle_with_bad_local_name_1() { let handles_contract_address = __setup__(); let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); handles_dispatcher.mint_handle(USER_ONE.try_into().unwrap(), TEST_BAD_LOCAL_NAME_1); } @@ -83,7 +82,7 @@ fn test_mint_handle_with_bad_local_name_2() { let handles_contract_address = __setup__(); let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); handles_dispatcher.mint_handle(USER_ONE.try_into().unwrap(), TEST_BAD_LOCAL_NAME_2); } @@ -93,7 +92,7 @@ fn test_mint_handle_with_bad_local_name_3() { let handles_contract_address = __setup__(); let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); handles_dispatcher.mint_handle(USER_ONE.try_into().unwrap(), TEST_BAD_LOCAL_NAME_3); } @@ -102,21 +101,20 @@ fn test_get_token_id() { let handles_contract_address = __setup__(); let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); let token_id = handles_dispatcher.get_token_id(TEST_LOCAL_NAME); assert!(token_id == TEST_TOKEN_ID, "Invalid token ID"); - stop_prank(CheatTarget::One(handles_contract_address)); + stop_cheat_caller_address(handles_contract_address); } - #[test] fn test_handle_id_exists_after_mint() { let contract_address = __setup__(); let dispatcher = IHandleDispatcher { contract_address }; let _erc721Dispatcher = IERC721Dispatcher { contract_address }; - start_prank(CheatTarget::One(contract_address), ADMIN_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(contract_address, ADMIN_ADDRESS.try_into().unwrap()); let handle_id: u256 = dispatcher.mint_handle(USER_ONE.try_into().unwrap(), 'handle'); assert(dispatcher.exists(handle_id), 'Handle ID does not exist'); @@ -129,12 +127,12 @@ fn test_total_supply() { let current_total_supply: u256 = dispatcher.total_supply(); - start_prank(CheatTarget::One(contract_address), ADMIN_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(contract_address, ADMIN_ADDRESS.try_into().unwrap()); let handle_id: u256 = dispatcher.mint_handle(USER_ONE.try_into().unwrap(), 'handle'); let total_supply_after_mint: u256 = dispatcher.total_supply(); assert(total_supply_after_mint == current_total_supply + 1, 'WRONG_TOTAL_SUPPLY'); - start_prank(CheatTarget::One(contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(contract_address, USER_ONE.try_into().unwrap()); dispatcher.burn_handle(handle_id); let total_supply_after_burn: u256 = dispatcher.total_supply(); @@ -147,13 +145,13 @@ fn test_burn() { let dispatcher = IHandleDispatcher { contract_address }; let _erc721Dispatcher = IERC721Dispatcher { contract_address }; - start_prank(CheatTarget::One(contract_address), ADMIN_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(contract_address, ADMIN_ADDRESS.try_into().unwrap()); let handle_id: u256 = dispatcher.mint_handle(USER_ONE.try_into().unwrap(), 'handle'); assert(dispatcher.exists(handle_id) == true, 'Handle ID does not exist'); assert(_erc721Dispatcher.owner_of(handle_id) == USER_ONE.try_into().unwrap(), 'Wrong Owner'); - start_prank(CheatTarget::One(contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(contract_address, USER_ONE.try_into().unwrap()); dispatcher.burn_handle(handle_id); assert(dispatcher.exists(handle_id) == false, 'BURN FAILED'); @@ -166,29 +164,30 @@ fn test_cannot_burn_if_not_owner_of() { let dispatcher = IHandleDispatcher { contract_address }; let _erc721Dispatcher = IERC721Dispatcher { contract_address }; - start_prank(CheatTarget::One(contract_address), ADMIN_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(contract_address, ADMIN_ADDRESS.try_into().unwrap()); let handle_id: u256 = dispatcher.mint_handle(USER_ONE.try_into().unwrap(), 'handle'); assert(dispatcher.exists(handle_id), 'Handle ID does not exist'); - start_prank(CheatTarget::One(contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(contract_address, USER_TWO.try_into().unwrap()); dispatcher.burn_handle(handle_id); } - +//todo this test fails #[test] fn test_get_handle() { let handles_contract_address = __setup__(); let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); let token_id = handles_dispatcher.mint_handle(USER_ONE.try_into().unwrap(), TEST_LOCAL_NAME); let handle: ByteArray = handles_dispatcher.get_handle(token_id); + assert(handle == "karst.kst", 'Invalid handle'); - stop_prank(CheatTarget::One(handles_contract_address)); + stop_cheat_caller_address(handles_contract_address); } #[test] @@ -198,10 +197,10 @@ fn test_get_handle_should_panic() { let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); handles_dispatcher.get_handle(TEST_TOKEN_ID); - stop_prank(CheatTarget::One(handles_contract_address)); + stop_cheat_caller_address(handles_contract_address); } #[test] @@ -210,8 +209,8 @@ fn test_mint_handle_event() { let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); - let mut spy = spy_events(SpyOn::One(handles_contract_address)); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); + let mut spy = spy_events(); let test_token_id = handles_dispatcher .mint_handle(USER_ONE.try_into().unwrap(), TEST_LOCAL_NAME); @@ -226,18 +225,17 @@ fn test_mint_handle_event() { spy.assert_emitted(@array![(handles_contract_address, expected_event)]); - stop_prank(CheatTarget::One(handles_contract_address)); + stop_cheat_caller_address(handles_contract_address); } - #[test] fn test_burn_handle_event() { let handles_contract_address = __setup__(); let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address }; - start_prank(CheatTarget::One(handles_contract_address), USER_ONE.try_into().unwrap()); - let mut spy = spy_events(SpyOn::One(handles_contract_address)); + start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap()); + let mut spy = spy_events(); let test_token_id = handles_dispatcher .mint_handle(USER_ONE.try_into().unwrap(), TEST_LOCAL_NAME); @@ -266,5 +264,5 @@ fn test_burn_handle_event() { spy.assert_emitted(@array![(handles_contract_address, expected_event)]); - stop_prank(CheatTarget::One(handles_contract_address)); + stop_cheat_caller_address(handles_contract_address); } diff --git a/tests/test_handle_registry.cairo b/tests/test_handle_registry.cairo index 5dffd9e..94f0d24 100644 --- a/tests/test_handle_registry.cairo +++ b/tests/test_handle_registry.cairo @@ -4,18 +4,17 @@ use core::result::ResultTrait; use core::traits::{TryInto, Into}; use starknet::{ContractAddress, get_block_timestamp}; use snforge_std::{ - declare, ContractClassTrait, CheatTarget, start_prank, stop_prank, start_warp, stop_warp, - spy_events, SpyOn, EventAssertions, EventFetcher + declare, start_cheat_caller_address, stop_cheat_caller_address, spy_events, + EventSpyAssertionsTrait, ContractClassTrait, DeclareResultTrait }; -use starknet::get_caller_address; + use karst::interfaces::IHandleRegistry::{IHandleRegistryDispatcher, IHandleRegistryDispatcherTrait}; use karst::interfaces::IHandle::{IHandleDispatcher, IHandleDispatcherTrait}; -use karst::namespaces::handle_registry::HandleRegistry; + use karst::namespaces::handle_registry::HandleRegistry::{Event as LinkedEvent, HandleLinked}; use karst::namespaces::handle_registry::HandleRegistry::{Event as UnlinkedEvent, HandleUnlinked}; - const ADMIN_ADDRESS: felt252 = 'ADMIN'; const USER_ONE: felt252 = 'BOB'; const USER_TWO: felt252 = 'JOHN'; @@ -28,12 +27,12 @@ const HANDLE_ID: u256 = 1234; fn __setup__() -> (ContractAddress, ContractAddress) { // deploy handle contract - let handle_class_hash = declare("Handles").unwrap(); + let handle_class_hash = declare("Handles").unwrap().contract_class(); let mut calldata: Array = array![ADMIN_ADDRESS]; let (handle_contract_address, _) = handle_class_hash.deploy(@calldata).unwrap_syscall(); // deploy handle registry contract - let handle_registry_class_hash = declare("HandleRegistry").unwrap(); + let handle_registry_class_hash = declare("HandleRegistry").unwrap().contract_class(); let mut calldata: Array = array![handle_contract_address.into()]; let (handle_registry_contract_address, _) = handle_registry_class_hash .deploy(@calldata) @@ -67,7 +66,7 @@ fn test_resolve() { let handle_dispatcher = IHandleDispatcher { contract_address: handle_contract_address }; // Mint Handle to USER_ONE - start_prank(CheatTarget::One(handle_contract_address), ADMIN_ADDRESS.try_into().unwrap()); + start_cheat_caller_address(handle_contract_address, ADMIN_ADDRESS.try_into().unwrap()); let token_id = handle_dispatcher.mint_handle(USER_ONE.try_into().unwrap(), TEST_LOCAL_NAME); // Link handle to USER_ONE @@ -148,16 +147,15 @@ fn test_unlink() { registryDispatcher.link(handle_id, USER_ONE.try_into().unwrap()); // call unlink - start_prank(CheatTarget::One(handle_registry_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handle_registry_address, USER_ONE.try_into().unwrap()); registryDispatcher.unlink(handle_id, USER_ONE.try_into().unwrap()); // check it unlinks successfully let retrieved_handle = registryDispatcher.get_handle(USER_ONE.try_into().unwrap()); assert(retrieved_handle == 0, 'unlinking failed'); - stop_prank(CheatTarget::One(handle_registry_address)); + stop_cheat_caller_address(handle_registry_address); } - #[test] #[should_panic(expected: ('Karst: caller is not owner!',))] fn test_unlink_fails_if_caller_is_not_owner() { @@ -174,9 +172,9 @@ fn test_unlink_fails_if_caller_is_not_owner() { registryDispatcher.link(handle_id, USER_ONE.try_into().unwrap()); // call unlink - start_prank(CheatTarget::One(handle_registry_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(handle_registry_address, USER_TWO.try_into().unwrap()); registryDispatcher.unlink(handle_id, USER_ONE.try_into().unwrap()); - stop_prank(CheatTarget::One(handle_registry_address)); + stop_cheat_caller_address(handle_registry_address); } #[test] @@ -186,12 +184,12 @@ fn test_emmit_linked_event() { contract_address: handle_registry_address }; let handleDispatcher = IHandleDispatcher { contract_address: handle_contract_address }; - let mut spy = spy_events(SpyOn::One(handle_registry_address)); + let mut spy = spy_events(); // mint handle let handle_id = handleDispatcher.mint_handle(USER_ONE.try_into().unwrap(), TEST_LOCAL_NAME); - start_prank(CheatTarget::One(handle_registry_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handle_registry_address, USER_ONE.try_into().unwrap()); // link token to profile registryDispatcher.link(handle_id, USER_ONE.try_into().unwrap()); @@ -205,7 +203,7 @@ fn test_emmit_linked_event() { } ); spy.assert_emitted(@array![(handle_registry_address, expected_event)]); - stop_prank(CheatTarget::One(handle_registry_address)); + stop_cheat_caller_address(handle_registry_address); } #[test] @@ -215,7 +213,7 @@ fn test_emmit_unlinked_event() { contract_address: handle_registry_address }; let handleDispatcher = IHandleDispatcher { contract_address: handle_contract_address }; - let mut spy = spy_events(SpyOn::One(handle_registry_address)); + let mut spy = spy_events(); // mint handle let handle_id = handleDispatcher.mint_handle(USER_ONE.try_into().unwrap(), TEST_LOCAL_NAME); @@ -223,7 +221,7 @@ fn test_emmit_unlinked_event() { // link token to profile registryDispatcher.link(handle_id, USER_ONE.try_into().unwrap()); - start_prank(CheatTarget::One(handle_registry_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(handle_registry_address, USER_ONE.try_into().unwrap()); // call unlink registryDispatcher.unlink(handle_id, USER_ONE.try_into().unwrap()); @@ -237,5 +235,5 @@ fn test_emmit_unlinked_event() { } ); spy.assert_emitted(@array![(handle_registry_address, expected_event)]); - stop_prank(CheatTarget::One(handle_registry_address)); + stop_cheat_caller_address(handle_registry_address); } diff --git a/tests/test_hub.cairo b/tests/test_hub.cairo index 2a8f26f..11accb5 100644 --- a/tests/test_hub.cairo +++ b/tests/test_hub.cairo @@ -5,8 +5,11 @@ use core::option::OptionTrait; use core::starknet::SyscallResultTrait; use core::result::ResultTrait; use core::traits::{TryInto, Into}; -use starknet::{ContractAddress, class_hash::ClassHash, contract_address_const}; -use snforge_std::{declare, ContractClassTrait, CheatTarget, start_prank, stop_prank}; +use starknet::{ContractAddress}; +use snforge_std::{ + declare, DeclareResultTrait, ContractClassTrait, start_cheat_caller_address, + stop_cheat_caller_address +}; use karst::hub::hub::KarstHub; use karst::mocks::registry::Registry; @@ -32,78 +35,72 @@ const TEST_LOCAL_NAME: felt252 = 'user'; // ************************************************************************* fn __setup__() -> (ContractAddress, ContractAddress, ContractAddress, ContractAddress, u256) { // deploy NFT - let nft_class_hash = declare("KarstNFT").unwrap(); - let names: ByteArray = "KarstNFT"; - let symbol: ByteArray = "KNFT"; - let base_uri: ByteArray = ""; + let nft_class_hash = declare("KarstNFT").unwrap().contract_class(); let mut calldata: Array = array![ADMIN]; - names.serialize(ref calldata); - symbol.serialize(ref calldata); - base_uri.serialize(ref calldata); let (nft_contract_address, _) = nft_class_hash.deploy(@calldata).unwrap_syscall(); // deploy handle contract - let handle_class_hash = declare("Handles").unwrap(); + let handle_class_hash = declare("Handles").unwrap().contract_class(); let mut calldata: Array = array![ADMIN]; let (handle_contract_address, _) = handle_class_hash.deploy(@calldata).unwrap_syscall(); // deploy handle registry contract - let handle_registry_class_hash = declare("HandleRegistry").unwrap(); + let handle_registry_class_hash = declare("HandleRegistry").unwrap().contract_class(); let mut calldata: Array = array![handle_contract_address.into()]; let (handle_registry_contract_address, _) = handle_registry_class_hash .deploy(@calldata) .unwrap_syscall(); // deploy tokenbound registry - let registry_class_hash = declare("Registry").unwrap(); + let registry_class_hash = declare("Registry").unwrap().contract_class(); // declare tokenbound account - let account_class_hash = declare("Account").unwrap(); + let account_class_hash = declare("Account").unwrap().contract_class(); // declare follownft - let follow_nft_classhash = declare("Follow").unwrap(); + let follow_nft_classhash = declare("Follow").unwrap().contract_class(); // deploy hub contract - let hub_class_hash = declare("KarstHub").unwrap(); + let hub_class_hash = declare("KarstHub").unwrap().contract_class(); let mut calldata: Array = array![ nft_contract_address.into(), handle_contract_address.into(), handle_registry_contract_address.into(), - follow_nft_classhash.class_hash.into() + (*follow_nft_classhash.class_hash).into() ]; let (hub_contract_address, _) = hub_class_hash.deploy(@calldata).unwrap_syscall(); // create profiles let dispatcher = IHubDispatcher { contract_address: hub_contract_address }; - start_prank(CheatTarget::One(hub_contract_address), ADDRESS1.try_into().unwrap()); + start_cheat_caller_address(hub_contract_address, ADDRESS1.try_into().unwrap()); let user_one_profile_address = dispatcher .create_profile( nft_contract_address, - registry_class_hash.class_hash.into(), - account_class_hash.class_hash.into(), + (*registry_class_hash.class_hash).into(), + (*account_class_hash.class_hash).into(), 2478 ); - stop_prank(CheatTarget::One(hub_contract_address)); + stop_cheat_caller_address(hub_contract_address); - start_prank(CheatTarget::One(hub_contract_address), ADDRESS2.try_into().unwrap()); + start_cheat_caller_address(hub_contract_address, ADDRESS2.try_into().unwrap()); let user_two_profile_address = dispatcher .create_profile( nft_contract_address, - registry_class_hash.class_hash.into(), - account_class_hash.class_hash.into(), + (*registry_class_hash.class_hash).into(), + (*account_class_hash.class_hash).into(), 2478 ); - stop_prank(CheatTarget::One(hub_contract_address)); + stop_cheat_caller_address(hub_contract_address); - start_prank(CheatTarget::One(hub_contract_address), ADDRESS3.try_into().unwrap()); + start_cheat_caller_address(hub_contract_address, ADDRESS3.try_into().unwrap()); let user_three_profile_address = dispatcher .create_profile( nft_contract_address, - registry_class_hash.class_hash.into(), - account_class_hash.class_hash.into(), + (*registry_class_hash.class_hash).into(), + (*account_class_hash.class_hash).into(), 2478 ); - stop_prank(CheatTarget::One(hub_contract_address)); + stop_cheat_caller_address(hub_contract_address); // mint and link handle for user_one let handleDispatcher = IHandleDispatcher { contract_address: handle_contract_address }; @@ -197,12 +194,12 @@ fn test_hub_unfollowing() { dispatcher.follow(user_one_profile_address, profiles_to_follow); // then unfollow them - start_prank(CheatTarget::One(hub_contract_address), user_one_profile_address); + start_cheat_caller_address(hub_contract_address, user_one_profile_address); let profiles_to_unfollow: Array = array![ user_two_profile_address, user_three_profile_address ]; dispatcher.unfollow(profiles_to_unfollow); - stop_prank(CheatTarget::One(hub_contract_address)); + stop_cheat_caller_address(hub_contract_address); // check following status let follow_status_1 = dispatcher @@ -267,6 +264,7 @@ fn test_get_handle_id() { assert(handle_id == minted_handle_id, 'invalid handle id'); } +// todo #[test] fn test_get_handle() { let (hub_contract_address, _, _, _, minted_handle_id) = __setup__(); diff --git a/tests/test_karstnft.cairo b/tests/test_karstnft.cairo index ca3029b..d024b0d 100644 --- a/tests/test_karstnft.cairo +++ b/tests/test_karstnft.cairo @@ -2,7 +2,11 @@ use core::num::traits::zero::Zero; use core::starknet::SyscallResultTrait; use core::traits::{TryInto, Into}; use starknet::{ContractAddress}; -use snforge_std::{declare, ContractClassTrait, CheatTarget, start_prank, stop_prank,}; + +use snforge_std::{ + declare, start_cheat_caller_address, stop_cheat_caller_address, ContractClassTrait, + DeclareResultTrait +}; use openzeppelin::{token::erc721::interface::{ERC721ABIDispatcher, ERC721ABIDispatcherTrait}}; @@ -13,14 +17,8 @@ const ADMIN: felt252 = 'ADMIN'; const USER_ONE: felt252 = 'BOB'; fn __setup__() -> ContractAddress { - let nft_contract = declare("KarstNFT").unwrap(); - let names: ByteArray = "KarstNFT"; - let symbol: ByteArray = "KNFT"; - let base_uri: ByteArray = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZyjaYXr4gQ/"; + let nft_contract = declare("KarstNFT").unwrap().contract_class(); let mut calldata: Array = array![ADMIN]; - names.serialize(ref calldata); - symbol.serialize(ref calldata); - base_uri.serialize(ref calldata); let (nft_contract_address, _) = nft_contract.deploy(@calldata).unwrap_syscall(); (nft_contract_address) } @@ -28,95 +26,66 @@ fn __setup__() -> ContractAddress { #[test] fn test_metadata() { let nft_contract_address = __setup__(); - let dispatcher = ERC721ABIDispatcher { contract_address: nft_contract_address }; - - start_prank(CheatTarget::One(nft_contract_address), ADMIN.try_into().unwrap()); - + start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap()); let nft_name = dispatcher.name(); let nft_symbol = dispatcher.symbol(); - - assert(nft_name == "KarstNFT", 'invalid name'); - assert(nft_symbol == "KNFT", 'invalid symbol'); - - stop_prank(CheatTarget::One(nft_contract_address)); + assert(nft_name == "Karst", 'invalid name'); + assert(nft_symbol == "KST", 'invalid symbol'); + stop_cheat_caller_address(nft_contract_address); } #[test] fn test_last_minted_id_on_init_is_zero() { let nft_contract_address = __setup__(); - let dispatcher = IKarstNFTDispatcher { contract_address: nft_contract_address }; - - start_prank(CheatTarget::One(nft_contract_address), ADMIN.try_into().unwrap()); - + start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap()); let last_minted_id = dispatcher.get_last_minted_id(); - assert(last_minted_id.is_zero(), 'last minted id not zero'); - - stop_prank(CheatTarget::One(nft_contract_address)); + stop_cheat_caller_address(nft_contract_address); } #[test] fn test_mint_karst_nft() { let nft_contract_address = __setup__(); - let dispatcher = IKarstNFTDispatcher { contract_address: nft_contract_address }; let erc721_dispatcher = ERC721ABIDispatcher { contract_address: nft_contract_address }; - - start_prank(CheatTarget::One(nft_contract_address), ADMIN.try_into().unwrap()); - + start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap()); dispatcher.mint_karstnft(USER_ONE.try_into().unwrap()); let balance = erc721_dispatcher.balance_of(USER_ONE.try_into().unwrap()); - assert(balance == 1, 'nft not minted'); - - stop_prank(CheatTarget::One(nft_contract_address)); + stop_cheat_caller_address(nft_contract_address); } #[test] #[should_panic(expected: ('Karst: user already minted!',))] fn test_mint_karst_nft_twice_for_the_same_user() { let nft_contract_address = __setup__(); - let dispatcher = IKarstNFTDispatcher { contract_address: nft_contract_address }; - - start_prank(CheatTarget::One(nft_contract_address), ADMIN.try_into().unwrap()); - + start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap()); dispatcher.mint_karstnft(USER_ONE.try_into().unwrap()); dispatcher.mint_karstnft(USER_ONE.try_into().unwrap()); - - stop_prank(CheatTarget::One(nft_contract_address)); + stop_cheat_caller_address(nft_contract_address); } #[test] fn test_get_last_minted_id_after_minting() { let nft_contract_address = __setup__(); - let dispatcher = IKarstNFTDispatcher { contract_address: nft_contract_address }; - - start_prank(CheatTarget::One(nft_contract_address), ADMIN.try_into().unwrap()); - + start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap()); dispatcher.mint_karstnft(USER_ONE.try_into().unwrap()); let last_minted_id = dispatcher.get_last_minted_id(); - assert(last_minted_id == 1, 'invalid last minted id'); - - stop_prank(CheatTarget::One(nft_contract_address)); + stop_cheat_caller_address(nft_contract_address); } #[test] fn test_get_user_token_id_after_minting() { let nft_contract_address = __setup__(); - let dispatcher = IKarstNFTDispatcher { contract_address: nft_contract_address }; - - start_prank(CheatTarget::One(nft_contract_address), ADMIN.try_into().unwrap()); - + start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap()); dispatcher.mint_karstnft(USER_ONE.try_into().unwrap()); let user_token_id = dispatcher.get_user_token_id(USER_ONE.try_into().unwrap()); - assert(user_token_id == 1, 'invalid user token id'); - - stop_prank(CheatTarget::One(nft_contract_address)); + stop_cheat_caller_address(nft_contract_address); } diff --git a/tests/test_profile.cairo b/tests/test_profile.cairo index 9d7b850..7214cc7 100644 --- a/tests/test_profile.cairo +++ b/tests/test_profile.cairo @@ -4,9 +4,10 @@ use core::result::ResultTrait; use core::traits::{TryInto, Into}; use starknet::{ContractAddress, class_hash::ClassHash, get_block_timestamp}; + use snforge_std::{ - declare, ContractClassTrait, CheatTarget, start_prank, stop_prank, spy_events, SpyOn, - EventAssertions + declare, start_cheat_caller_address, stop_cheat_caller_address, spy_events, + EventSpyAssertionsTrait, ContractClass, ContractClassTrait, DeclareResultTrait }; use karst::interfaces::IKarstNFT::{IKarstNFTDispatcher, IKarstNFTDispatcherTrait}; @@ -33,30 +34,27 @@ const USER: felt252 = 'USER1'; fn __setup__() -> (ContractAddress, ContractAddress, felt252, felt252, ContractAddress) { // deploy NFT - let nft_contract = declare("KarstNFT").unwrap(); + let nft_contract = declare("KarstNFT").unwrap().contract_class(); let names: ByteArray = "KarstNFT"; let symbol: ByteArray = "KNFT"; let base_uri: ByteArray = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZyjaYXr4gQ/"; let mut calldata: Array = array![USER]; - names.serialize(ref calldata); - symbol.serialize(ref calldata); - base_uri.serialize(ref calldata); let (nft_contract_address, _) = nft_contract.deploy(@calldata).unwrap_syscall(); // deploy registry - let registry_class_hash = declare("Registry").unwrap(); + let registry_class_hash = declare("Registry").unwrap().contract_class(); let (registry_contract_address, _) = registry_class_hash.deploy(@array![]).unwrap_syscall(); // declare account - let account_class_hash = declare("Account").unwrap(); + let account_class_hash = declare("Account").unwrap().contract_class(); // declare follownft - let follow_nft_classhash = declare("Follow").unwrap(); + let follow_nft_classhash = declare("Follow").unwrap().contract_class(); // deploy profile - let profile_contract = declare("KarstProfile").unwrap(); + let profile_contract = declare("KarstProfile").unwrap().contract_class(); let mut karst_profile_constructor_calldata = array![ - nft_contract_address.into(), HUB_ADDRESS, follow_nft_classhash.class_hash.into() + nft_contract_address.into(), HUB_ADDRESS, (*follow_nft_classhash.class_hash).into() ]; let (profile_contract_address, _) = profile_contract .deploy(@karst_profile_constructor_calldata) @@ -65,13 +63,12 @@ fn __setup__() -> (ContractAddress, ContractAddress, felt252, felt252, ContractA return ( nft_contract_address, registry_contract_address, - registry_class_hash.class_hash.into(), - account_class_hash.class_hash.into(), + (*registry_class_hash.class_hash).into(), + (*account_class_hash.class_hash).into(), profile_contract_address ); } - // ************************************************************************* // TESTS // ************************************************************************* @@ -85,10 +82,8 @@ fn test_profile_creation() { let profileDispatcher = IProfileDispatcher { contract_address: profile_contract_address }; //user 1 create profile - start_prank( - CheatTarget::Multiple(array![profile_contract_address, nft_contract_address]), - USER.try_into().unwrap() - ); + start_cheat_caller_address(profile_contract_address, USER.try_into().unwrap()); + start_cheat_caller_address(nft_contract_address, USER.try_into().unwrap()); let profile_address = profileDispatcher .create_profile(nft_contract_address, registry_class_hash, account_class_hash, 2456,); @@ -106,7 +101,8 @@ fn test_profile_creation() { // 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])); + stop_cheat_caller_address(profile_contract_address); + stop_cheat_caller_address(nft_contract_address); } #[test] @@ -118,10 +114,8 @@ fn test_profile_metadata() { let profileDispatcher = IProfileDispatcher { contract_address: profile_contract_address }; //user 1 create profile - start_prank( - CheatTarget::Multiple(array![profile_contract_address, nft_contract_address]), - USER.try_into().unwrap() - ); + start_cheat_caller_address(profile_contract_address, USER.try_into().unwrap()); + start_cheat_caller_address(nft_contract_address, USER.try_into().unwrap()); let profile_address = profileDispatcher .create_profile(nft_contract_address, registry_class_hash, account_class_hash, 2456); @@ -138,7 +132,8 @@ fn test_profile_metadata() { 'invalid profile URI' ); - stop_prank(CheatTarget::Multiple(array![profile_contract_address, nft_contract_address])); + stop_cheat_caller_address(profile_contract_address); + stop_cheat_caller_address(nft_contract_address); } #[test] @@ -149,13 +144,12 @@ fn test_profile_creation_event() { __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)); + let mut spy = spy_events(); //user 1 create profile - start_prank( - CheatTarget::Multiple(array![profile_contract_address, nft_contract_address]), - USER.try_into().unwrap() - ); + start_cheat_caller_address(profile_contract_address, USER.try_into().unwrap()); + start_cheat_caller_address(nft_contract_address, USER.try_into().unwrap()); + let profile_address = profileDispatcher .create_profile(nft_contract_address, registry_class_hash, account_class_hash, 2456,); @@ -172,5 +166,6 @@ fn test_profile_creation_event() { spy.assert_emitted(@array![(profile_contract_address, expected_event)]); - stop_prank(CheatTarget::Multiple(array![profile_contract_address, nft_contract_address])); + stop_cheat_caller_address(profile_contract_address); + stop_cheat_caller_address(nft_contract_address); } diff --git a/tests/test_profile_token_uri.cairo b/tests/test_profile_token_uri.cairo index 3d2c509..65006fa 100644 --- a/tests/test_profile_token_uri.cairo +++ b/tests/test_profile_token_uri.cairo @@ -11,7 +11,7 @@ fn test_profile_token_uri() { "data:image/svg+xml;base64,eyJuYW1lIjoiUHJvZmlsZSAjCiIsImRlc2NyaXB0aW9uIjoiUHJvZmlsZSAjYyIsImltYWdlIjoiZGF0YTppbWFnZS9zdmcreG1sO2Jhc2U2NCxQSE4yWnlCM2FXUjBhRDBpTWpBd0lpQm9aV2xuYUhROUlqSXdNQ0lnZUcxc2JuTTlJbWgwZEhBNkx5OTNkM2N1ZHpNdWIzSm5Mekl3TURBdmMzWm5JajQ4WTJseVkyeGxJR040UFNJeE1EQWlJR041UFNJeE1EQWlJSEk5SWpnd0lpQm1hV3hzUFNKeVpXUWlMejQ4TDNOMlp6ND0iLCJhdHRyaWJ1dGVzIjpbeyJkaXNwbGF5X3R5cGUiOiJudW1iZXIiLCJ0cmFpdF90eXBlIjoiSUQiLCJ2YWx1ZSI6IgoifSx7InRyYWl0X3R5cGUiOiJIRVggSUQiLCJ2YWx1ZSI6IgoifSx7InRyYWl0X3R5cGUiOiJESUdJVFMiLCJ2YWx1ZSI6IgEifSx7ImRpc3BsYXlfdHlwZSI6ImRhdGUiLCJ0cmFpdF90eXBlIjoiTUlOVEVEIEFUIiwidmFsdWUiOiJjIn0scGF2aXRyYV19"; let check_token_uri_100_990: ByteArray = "data:image/svg+xml;base64,eyJuYW1lIjoiUHJvZmlsZSAjZCIsImRlc2NyaXB0aW9uIjoiUHJvZmlsZSAjA94iLCJpbWFnZSI6ImRhdGE6aW1hZ2Uvc3ZnK3htbDtiYXNlNjQsUEhOMlp5QjNhV1IwYUQwaU1qQXdJaUJvWldsbmFIUTlJakl3TUNJZ2VHMXNibk05SW1oMGRIQTZMeTkzZDNjdWR6TXViM0puTHpJd01EQXZjM1puSWo0OFkybHlZMnhsSUdONFBTSXhNREFpSUdONVBTSXhNREFpSUhJOUlqZ3dJaUJtYVd4c1BTSnlaV1FpTHo0OEwzTjJaejQ9IiwiYXR0cmlidXRlcyI6W3siZGlzcGxheV90eXBlIjoibnVtYmVyIiwidHJhaXRfdHlwZSI6IklEIiwidmFsdWUiOiJkIn0seyJ0cmFpdF90eXBlIjoiSEVYIElEIiwidmFsdWUiOiJkIn0seyJ0cmFpdF90eXBlIjoiRElHSVRTIiwidmFsdWUiOiIBIn0seyJkaXNwbGF5X3R5cGUiOiJkYXRlIiwidHJhaXRfdHlwZSI6Ik1JTlRFRCBBVCIsInZhbHVlIjoiA94ifSxwYXZpdHJhXX0="; - assert_eq!(token_uri_1_3, check_token_uri_1_3); - assert_eq!(token_uri_10_99, check_token_uri_10_99); - assert_eq!(token_uri_100_990, check_token_uri_100_990); + assert(token_uri_1_3 == check_token_uri_1_3 , 'token_uri_1_3 failed'); + assert(token_uri_10_99 == check_token_uri_10_99 , 'token_uri_10_99 failed'); + assert(token_uri_100_990 == check_token_uri_100_990 , 'token_uri_100_990 failed'); } diff --git a/tests/test_publication.cairo b/tests/test_publication.cairo index 6c8b744..4b145dd 100644 --- a/tests/test_publication.cairo +++ b/tests/test_publication.cairo @@ -6,15 +6,16 @@ use core::starknet::SyscallResultTrait; use core::result::ResultTrait; use core::traits::{TryInto, Into}; use starknet::{ContractAddress, class_hash::ClassHash, contract_address_const, get_block_timestamp}; + use snforge_std::{ - declare, ContractClassTrait, CheatTarget, start_prank, stop_prank, spy_events, SpyOn, EventSpy, - EventAssertions + declare, start_cheat_caller_address, stop_cheat_caller_address, start_cheat_transaction_hash, + start_cheat_nonce, spy_events, EventSpyAssertionsTrait, ContractClass, ContractClassTrait, + DeclareResultTrait, start_cheat_block_timestamp, stop_cheat_block_timestamp, EventSpy }; use karst::publication::publication::PublicationComponent::{ Event as PublicationEvent, Post, CommentCreated, RepostCreated, Upvoted, Downvoted }; - use token_bound_accounts::interfaces::IAccount::{IAccountDispatcher, IAccountDispatcherTrait}; use token_bound_accounts::presets::account::Account; use karst::mocks::registry::Registry; @@ -35,7 +36,6 @@ const USER_FOUR: felt252 = 'DAN'; const USER_FIVE: felt252 = 'RANDY'; const USER_SIX: felt252 = 'JOE'; - // ************************************************************************* // SETUP // ************************************************************************* @@ -52,31 +52,26 @@ fn __setup__() -> ( EventSpy ) { // deploy NFT - let nft_contract = declare("KarstNFT").unwrap(); - let names: ByteArray = "KarstNFT"; - let symbol: ByteArray = "KNFT"; - let base_uri: ByteArray = ""; + let nft_contract = declare("KarstNFT").unwrap().contract_class(); let mut calldata: Array = array![USER_ONE]; - names.serialize(ref calldata); - symbol.serialize(ref calldata); - base_uri.serialize(ref calldata); + let (nft_contract_address, _) = nft_contract.deploy(@calldata).unwrap_syscall(); // deploy registry - let registry_class_hash = declare("Registry").unwrap(); + let registry_class_hash = declare("Registry").unwrap().contract_class(); let (registry_contract_address, _) = registry_class_hash.deploy(@array![]).unwrap_syscall(); // deploy publication - let publication_contract = declare("KarstPublication").unwrap(); + let publication_contract = declare("KarstPublication").unwrap().contract_class(); let mut publication_constructor_calldata = array![]; let (publication_contract_address, _) = publication_contract .deploy(@publication_constructor_calldata) .unwrap_syscall(); // declare account - let account_class_hash = declare("Account").unwrap(); + let account_class_hash = declare("Account").unwrap().contract_class(); // declare follownft - let follow_nft_classhash = declare("Follow").unwrap(); + let follow_nft_classhash = declare("Follow").unwrap().contract_class(); // create dispatcher, initialize profile contract let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; @@ -84,45 +79,46 @@ fn __setup__() -> ( .initializer( nft_contract_address, HUB_ADDRESS.try_into().unwrap(), - follow_nft_classhash.class_hash.into() + (*follow_nft_classhash.class_hash).into() ); // deploying karst Profile for USER 1 - start_prank(CheatTarget::One(publication_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_ONE.try_into().unwrap()); let user_one_profile_address = dispatcher .create_profile( nft_contract_address, - registry_class_hash.class_hash.into(), - account_class_hash.class_hash.into(), + (*registry_class_hash.class_hash).into(), + (*account_class_hash.class_hash).into(), 2478 ); let content_URI: ByteArray = "ipfs://helloworld"; - let mut spy = spy_events(SpyOn::One(publication_contract_address)); + let mut spy = spy_events(); let user_one_first_post_pointed_pub_id = dispatcher .post(PostParams { content_URI: content_URI, profile_address: user_one_profile_address, }); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); // deploying karst Profile for USER 2 - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); let user_two_profile_address = dispatcher .create_profile( nft_contract_address, - registry_class_hash.class_hash.into(), - account_class_hash.class_hash.into(), + (*registry_class_hash.class_hash).into(), + (*account_class_hash.class_hash).into(), 2479 ); let content_URI: ByteArray = "ipfs://helloworld"; dispatcher .post(PostParams { content_URI: content_URI, profile_address: user_two_profile_address, }); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); // deploying karst Profile for USER 3 - start_prank(CheatTarget::One(publication_contract_address), USER_THREE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_THREE.try_into().unwrap()); + let user_three_profile_address = dispatcher .create_profile( nft_contract_address, - registry_class_hash.class_hash.into(), - account_class_hash.class_hash.into(), + (*registry_class_hash.class_hash).into(), + (*account_class_hash.class_hash).into(), 2480 ); let content_URI: ByteArray = "ipfs://helloworld"; @@ -130,14 +126,14 @@ fn __setup__() -> ( .post( PostParams { content_URI: content_URI, profile_address: user_three_profile_address, } ); - stop_prank(CheatTarget::One(publication_contract_address)); + stop_cheat_caller_address(publication_contract_address); return ( nft_contract_address, registry_contract_address, publication_contract_address, - registry_class_hash.class_hash.into(), - account_class_hash.class_hash.into(), + (*registry_class_hash.class_hash).into(), + (*account_class_hash.class_hash).into(), user_one_profile_address, user_two_profile_address, user_three_profile_address, @@ -168,13 +164,13 @@ fn test_post() { let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; - start_prank(CheatTarget::One(publication_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_ONE.try_into().unwrap()); let publication_type = dispatcher .get_publication_type(user_one_profile_address, user_one_first_post_pointed_pub_id); assert(publication_type == PublicationType::Post, 'invalid pub_type'); assert(user_one_first_post_pointed_pub_id == 1_u256, 'invalid pub id'); - stop_prank(CheatTarget::One(publication_contract_address)); + stop_cheat_caller_address(publication_contract_address); } #[test] @@ -194,13 +190,13 @@ fn test_upvote() { __setup__(); let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); dispatcher.upvote(user_one_profile_address, user_one_first_post_pointed_pub_id); - stop_prank(CheatTarget::One(publication_contract_address)); + stop_cheat_caller_address(publication_contract_address); - start_prank(CheatTarget::One(publication_contract_address), USER_THREE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_THREE.try_into().unwrap()); dispatcher.upvote(user_one_profile_address, user_one_first_post_pointed_pub_id); - stop_prank(CheatTarget::One(publication_contract_address)); + stop_cheat_caller_address(publication_contract_address); let upvote_count = dispatcher .get_upvote_count(user_one_profile_address, user_one_first_post_pointed_pub_id); assert(upvote_count == 2, 'invalid upvote count'); @@ -223,20 +219,19 @@ fn test_downvote() { __setup__(); let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; // downvote - start_prank(CheatTarget::One(publication_contract_address), USER_FOUR.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_FOUR.try_into().unwrap()); dispatcher.downvote(user_one_profile_address, user_one_first_post_pointed_pub_id); - stop_prank(CheatTarget::One(publication_contract_address)); + stop_cheat_caller_address(publication_contract_address); - start_prank(CheatTarget::One(publication_contract_address), USER_FIVE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_FIVE.try_into().unwrap()); dispatcher.downvote(user_one_profile_address, user_one_first_post_pointed_pub_id); - stop_prank(CheatTarget::One(publication_contract_address)); + stop_cheat_caller_address(publication_contract_address); let downvote_count = dispatcher .get_downvote_count(user_one_profile_address, user_one_first_post_pointed_pub_id); assert(downvote_count == 2, 'invalid downvote count'); - stop_prank(CheatTarget::One(publication_contract_address)); + stop_cheat_caller_address(publication_contract_address); } - #[test] fn test_upvote_event_emission() { let ( @@ -255,7 +250,7 @@ fn test_upvote_event_emission() { let mut spy = spy; let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; - start_prank(CheatTarget::One(publication_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_ONE.try_into().unwrap()); dispatcher.upvote(user_one_profile_address, user_one_first_post_pointed_pub_id); let expected_event = PublicationEvent::Upvoted( Upvoted { @@ -266,7 +261,7 @@ fn test_upvote_event_emission() { ); spy.assert_emitted(@array![(publication_contract_address, expected_event)]); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); } #[test] @@ -286,7 +281,7 @@ fn test_downvote_event_emission() { __setup__(); let mut spy = spy; - start_prank(CheatTarget::One(publication_contract_address), USER_SIX.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_SIX.try_into().unwrap()); let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; dispatcher.downvote(user_one_profile_address, user_one_first_post_pointed_pub_id); let expected_event = PublicationEvent::Downvoted( @@ -298,7 +293,7 @@ fn test_downvote_event_emission() { ); spy.assert_emitted(@array![(publication_contract_address, expected_event)]); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); } #[test] @@ -340,11 +335,11 @@ fn test_posting_should_fail_if_not_profile_owner() { __setup__(); let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); let content_URI = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZyjaryrga/"; dispatcher .post(PostParams { content_URI: content_URI, profile_address: user_one_profile_address, }); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); } #[test] @@ -365,7 +360,7 @@ fn test_comment() { let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; - start_prank(CheatTarget::One(publication_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_ONE.try_into().unwrap()); let content_URI_1 = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZyjaryrga/"; let content_URI_2 = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZysddewga/"; @@ -380,10 +375,9 @@ fn test_comment() { reference_pub_type: PublicationType::Comment, } ); - stop_prank(CheatTarget::One(publication_contract_address),); - - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + stop_cheat_caller_address(publication_contract_address); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); // user two comment on user_one_post let user_two_comment_on_user_one_assigned_pub_id_2 = dispatcher .comment( @@ -395,7 +389,7 @@ fn test_comment() { reference_pub_type: PublicationType::Comment, } ); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); let user_one_comment = dispatcher .get_publication(user_one_profile_address, user_one_comment_assigned_pub_id_1); @@ -447,7 +441,6 @@ fn test_comment() { ); } - #[test] fn test_comment_event_emission() { let ( @@ -468,7 +461,7 @@ fn test_comment_event_emission() { let mut spy = spy; let content_URI_1 = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZysddewga/"; - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); // user two comment on user_one_post let user_two_comment_on_user_one_assigned_pub_id_2 = dispatcher @@ -481,7 +474,7 @@ fn test_comment_event_emission() { reference_pub_type: PublicationType::Comment, } ); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); let expected_event = PublicationEvent::CommentCreated( CommentCreated { @@ -519,7 +512,7 @@ fn test_nested_comments() { let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); let content_URI_1 = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZyjaryrga/"; let content_URI_2 = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZysddewga/"; let content_URI_3 = "ipfs://VmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZysddewUhje/"; @@ -535,10 +528,10 @@ fn test_nested_comments() { reference_pub_type: PublicationType::Comment, } ); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); // user three comments under user one's comment - start_prank(CheatTarget::One(publication_contract_address), USER_THREE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_THREE.try_into().unwrap()); let user_three_comment_assigned_pub_id = dispatcher .comment( CommentParams { @@ -549,10 +542,10 @@ fn test_nested_comments() { reference_pub_type: PublicationType::Comment, } ); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); // user one comments under user three's comment - start_prank(CheatTarget::One(publication_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_ONE.try_into().unwrap()); let user_one_comment_assigned_pub_id = dispatcher .comment( CommentParams { @@ -563,7 +556,7 @@ fn test_nested_comments() { reference_pub_type: PublicationType::Comment, } ); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); let user_two_comment = dispatcher .get_publication(user_two_profile_address, user_two_comment_assigned_pub_id); @@ -657,7 +650,7 @@ fn test_commenting_should_fail_if_not_profile_owner() { __setup__(); let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); let content_URI = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZyjaryrga/"; dispatcher .comment( @@ -669,10 +662,9 @@ fn test_commenting_should_fail_if_not_profile_owner() { reference_pub_type: PublicationType::Comment, } ); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); } - #[test] #[should_panic(expected: ('Karst: unsupported pub type!',))] fn test_as_reference_pub_params_should_fail_on_wrong_pub_type() { @@ -690,7 +682,7 @@ fn test_as_reference_pub_params_should_fail_on_wrong_pub_type() { ) = __setup__(); let dispatcher = IComposableDispatcher { contract_address: publication_contract_address }; - start_prank(CheatTarget::One(publication_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_ONE.try_into().unwrap()); let content_URI = "ipfs://QmSkDCsS32eLpcymxtn1cEn7Rc5hfefLBgfvZyjaryrga/"; @@ -706,7 +698,7 @@ fn test_as_reference_pub_params_should_fail_on_wrong_pub_type() { } ); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); } #[test] @@ -732,9 +724,9 @@ fn test_repost() { pointed_pub_id: user_one_first_post_pointed_pub_id, }; - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); let pub_assigned_id = dispatcher.repost(repost_params); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); // get the repost publication let user_repost = dispatcher.get_publication(user_two_profile_address, pub_assigned_id); @@ -781,9 +773,9 @@ fn test_repost_event_emission() { pointed_pub_id: user_one_first_post_pointed_pub_id, }; - start_prank(CheatTarget::One(publication_contract_address), USER_TWO.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_TWO.try_into().unwrap()); let pub_assigned_id = dispatcher.repost(repost_params); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); // get the repost publication let user_repost = dispatcher.get_publication(user_two_profile_address, pub_assigned_id); @@ -827,9 +819,9 @@ fn test_reposting_should_fail_if_not_profile_owner() { pointed_pub_id: user_one_first_post_pointed_pub_id, }; - start_prank(CheatTarget::One(publication_contract_address), USER_ONE.try_into().unwrap()); + start_cheat_caller_address(publication_contract_address, USER_ONE.try_into().unwrap()); dispatcher.repost(repost_params); - stop_prank(CheatTarget::One(publication_contract_address),); + stop_cheat_caller_address(publication_contract_address); } #[test] From 1fa425c72d1031641b16483dd2b2e841f408ab42 Mon Sep 17 00:00:00 2001 From: PavitraAgarwal21 Date: Wed, 2 Oct 2024 05:13:43 +0530 Subject: [PATCH 2/2] scarb fmt --- tests/test_profile_token_uri.cairo | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_profile_token_uri.cairo b/tests/test_profile_token_uri.cairo index 65006fa..d747b3b 100644 --- a/tests/test_profile_token_uri.cairo +++ b/tests/test_profile_token_uri.cairo @@ -11,7 +11,7 @@ fn test_profile_token_uri() { "data:image/svg+xml;base64,eyJuYW1lIjoiUHJvZmlsZSAjCiIsImRlc2NyaXB0aW9uIjoiUHJvZmlsZSAjYyIsImltYWdlIjoiZGF0YTppbWFnZS9zdmcreG1sO2Jhc2U2NCxQSE4yWnlCM2FXUjBhRDBpTWpBd0lpQm9aV2xuYUhROUlqSXdNQ0lnZUcxc2JuTTlJbWgwZEhBNkx5OTNkM2N1ZHpNdWIzSm5Mekl3TURBdmMzWm5JajQ4WTJseVkyeGxJR040UFNJeE1EQWlJR041UFNJeE1EQWlJSEk5SWpnd0lpQm1hV3hzUFNKeVpXUWlMejQ4TDNOMlp6ND0iLCJhdHRyaWJ1dGVzIjpbeyJkaXNwbGF5X3R5cGUiOiJudW1iZXIiLCJ0cmFpdF90eXBlIjoiSUQiLCJ2YWx1ZSI6IgoifSx7InRyYWl0X3R5cGUiOiJIRVggSUQiLCJ2YWx1ZSI6IgoifSx7InRyYWl0X3R5cGUiOiJESUdJVFMiLCJ2YWx1ZSI6IgEifSx7ImRpc3BsYXlfdHlwZSI6ImRhdGUiLCJ0cmFpdF90eXBlIjoiTUlOVEVEIEFUIiwidmFsdWUiOiJjIn0scGF2aXRyYV19"; let check_token_uri_100_990: ByteArray = "data:image/svg+xml;base64,eyJuYW1lIjoiUHJvZmlsZSAjZCIsImRlc2NyaXB0aW9uIjoiUHJvZmlsZSAjA94iLCJpbWFnZSI6ImRhdGE6aW1hZ2Uvc3ZnK3htbDtiYXNlNjQsUEhOMlp5QjNhV1IwYUQwaU1qQXdJaUJvWldsbmFIUTlJakl3TUNJZ2VHMXNibk05SW1oMGRIQTZMeTkzZDNjdWR6TXViM0puTHpJd01EQXZjM1puSWo0OFkybHlZMnhsSUdONFBTSXhNREFpSUdONVBTSXhNREFpSUhJOUlqZ3dJaUJtYVd4c1BTSnlaV1FpTHo0OEwzTjJaejQ9IiwiYXR0cmlidXRlcyI6W3siZGlzcGxheV90eXBlIjoibnVtYmVyIiwidHJhaXRfdHlwZSI6IklEIiwidmFsdWUiOiJkIn0seyJ0cmFpdF90eXBlIjoiSEVYIElEIiwidmFsdWUiOiJkIn0seyJ0cmFpdF90eXBlIjoiRElHSVRTIiwidmFsdWUiOiIBIn0seyJkaXNwbGF5X3R5cGUiOiJkYXRlIiwidHJhaXRfdHlwZSI6Ik1JTlRFRCBBVCIsInZhbHVlIjoiA94ifSxwYXZpdHJhXX0="; - assert(token_uri_1_3 == check_token_uri_1_3 , 'token_uri_1_3 failed'); - assert(token_uri_10_99 == check_token_uri_10_99 , 'token_uri_10_99 failed'); - assert(token_uri_100_990 == check_token_uri_100_990 , 'token_uri_100_990 failed'); + assert(token_uri_1_3 == check_token_uri_1_3, 'token_uri_1_3 failed'); + assert(token_uri_10_99 == check_token_uri_10_99, 'token_uri_10_99 failed'); + assert(token_uri_100_990 == check_token_uri_100_990, 'token_uri_100_990 failed'); }