Skip to content

Commit

Permalink
chore: add test workflow, format contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed May 22, 2024
1 parent 396f065 commit fee8668
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test_contract.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test

on: [push, pull_request]
permissions: read-all

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
- uses: foundry-rs/setup-snfoundry@v3
with:
starknet-foundry-version: 0.22.0
- name: Run cairo tests
run: snforge test
22 changes: 14 additions & 8 deletions tests/test_follownft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use core::option::OptionTrait;
use core::starknet::SyscallResultTrait;
use core::result::ResultTrait;
use core::traits::{TryInto, Into};
use starknet::{ ContractAddress };
use snforge_std::{declare, ContractClassTrait, CheatTarget, start_prank, stop_prank, start_warp, stop_warp};
use starknet::{ContractAddress};
use snforge_std::{
declare, ContractClassTrait, CheatTarget, start_prank, stop_prank, start_warp, stop_warp
};

use karst::interfaces::IFollowNFT::{ IFollowNFTDispatcher, IFollowNFTDispatcherTrait };
use karst::interfaces::IFollowNFT::{IFollowNFTDispatcher, IFollowNFTDispatcherTrait};
use karst::follownft::follownft::Follow;
use karst::base::types::FollowData;

Expand All @@ -19,7 +21,9 @@ const FOLLOWER4: felt252 = 24262;
fn __setup__() -> ContractAddress {
let follow_nft_contract = declare("Follow").unwrap();
let mut follow_nft_constructor_calldata = array![HUB_ADDRESS];
let (follow_nft_contract_address, _) = follow_nft_contract.deploy(@follow_nft_constructor_calldata).unwrap();
let (follow_nft_contract_address, _) = follow_nft_contract
.deploy(@follow_nft_constructor_calldata)
.unwrap();
return (follow_nft_contract_address);
}

Expand Down Expand Up @@ -113,10 +117,12 @@ fn test_follow_data() {
let follow_id = dispatcher.get_follow_id(FOLLOWER1.try_into().unwrap());
let follow_data = dispatcher.get_follow_data(follow_id);
let data = FollowData {
follower_profile_address: FOLLOWER1.try_into().unwrap(),
follow_timestamp: 100
follower_profile_address: FOLLOWER1.try_into().unwrap(), follow_timestamp: 100
};
assert(follow_data.follower_profile_address == data.follower_profile_address, 'invalid follower profile');
assert(
follow_data.follower_profile_address == data.follower_profile_address,
'invalid follower profile'
);
assert(follow_data.follow_timestamp == data.follow_timestamp, 'invalid follow timestamp');
stop_prank(CheatTarget::One(follow_nft_contract_address));
stop_warp(CheatTarget::One(follow_nft_contract_address));
Expand Down Expand Up @@ -169,5 +175,5 @@ fn test_metadata() {
assert(nft_symbol == "KFL", 'invalid symbol');
stop_prank(CheatTarget::One(follow_nft_contract_address));
}
// TODO: test for emitted events

// TODO: test for emitted events

0 comments on commit fee8668

Please sign in to comment.