Skip to content

Commit

Permalink
chore: fix follow NFT metadata, update addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Darlington02 committed Dec 17, 2024
1 parent a0bbdc0 commit 680f7f0
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 50 deletions.
4 changes: 2 additions & 2 deletions addresses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Hub Address - 0x00fde7695a162a807214e78cd1f3a09c21fc0b7a07aeeb875049dcfaaa1a07a2
Coloniz NFT - 0x01d3ec880419c6714800fc406d0696dde969f51c0521ca0b5c76b1f69af3eb46
Handles - 0x752dd216dcebb660204c7302ff0a99494e7f8c464cb4fe48112d39e12f3df14
Handles Registry - 0x4b5eef8900d4329f8fe60d3d79a6ef8ac79c2d979fce15da18f53ab25e79e83
Follow NFT -
Community NFT -
Follow NFT (classhash) - 0x05dffad824556defac917572ffe4644a3b652662779bafd346888d09306dfe0d
Community NFT (classhash) - 0x050bea932528781b2da6f85e376df259cee7053f71528e0dbe617b13bae79a21
Admin - 0x02F659cf8CCE41168B8c0A8BedCE468E33BE1B7bd26E920266C025Dc0F8FBD1b
13 changes: 11 additions & 2 deletions src/follownft/follownft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub mod Follow {
ownable: OwnableComponent::Storage,
admin: ContractAddress,
followed_profile_address: ContractAddress,
token_id: u256,
follower_count: u256,
follow_id_by_follower_profile_address: Map<ContractAddress, u256>,
follow_data_by_follow_id: Map<u256, FollowData>,
Expand Down Expand Up @@ -118,12 +119,18 @@ pub mod Follow {
ref self: ContractState,
hub: ContractAddress,
profile_address: ContractAddress,
token_id: u256,
admin: ContractAddress
) {
self.admin.write(admin);
self.erc721.initializer("Coloniz Followers", "CLZ:FOLLOWERS", "");
self.token_id.write(token_id);
self.coloniz_hub.write(hub);
self.followed_profile_address.write(profile_address);

let prefix: ByteArray = "Coloniz Followers | #";
let profile_id: felt252 = self.token_id.read().low.into();
let name = format!("{}{}", prefix, profile_id);
self.erc721.initializer(name, "CLZ:FOLLOWERS", "");
}

// *************************************************************************
Expand Down Expand Up @@ -277,7 +284,9 @@ pub mod Follow {
// *************************************************************************
/// @notice returns the collection name
fn name(self: @ContractState) -> ByteArray {
return "Coloniz Followers";
let prefix: ByteArray = "Coloniz Followers | #";
let profile_id: felt252 = self.token_id.read().low.into();
format!("{}{}", prefix, profile_id)
}

/// @notice returns the collection symbol
Expand Down
6 changes: 5 additions & 1 deletion src/profile/profile.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ pub mod ProfileComponent {

// deploy follow nft contract
let mut constructor_calldata: Array<felt252> = array![
self.hub_address.read().into(), profile_address.into(), recipient.into()
self.hub_address.read().into(),
profile_address.into(),
token_id.low.into(),
token_id.high.into(),
recipient.into()
];
let (follow_nft_address, _) = deploy_syscall(
self.follow_nft_classhash.read(),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_coloniznft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ fn test_metadata() {
start_cheat_caller_address(nft_contract_address, ADMIN.try_into().unwrap());
let nft_name = dispatcher.name();
let nft_symbol = dispatcher.symbol();
assert(nft_name == "coloniz", 'invalid name');
assert(nft_symbol == "KST", 'invalid symbol');
assert(nft_name == "Coloniz", 'invalid name');
assert(nft_symbol == "CLZ:PROFILE", 'invalid symbol');
stop_cheat_caller_address(nft_contract_address);
}

Expand Down
7 changes: 4 additions & 3 deletions tests/test_follownft.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const FOLLOWER4: felt252 = 24262;

fn __setup__() -> ContractAddress {
let follow_nft_contract = declare("Follow").unwrap().contract_class();
let mut follow_nft_constructor_calldata = array![HUB_ADDRESS, FOLLOWED_ADDRESS, ADMIN];
let mut follow_nft_constructor_calldata = array![HUB_ADDRESS, FOLLOWED_ADDRESS, 10, 0, ADMIN];
let (follow_nft_contract_address, _) = follow_nft_contract
.deploy(@follow_nft_constructor_calldata)
.unwrap();
Expand Down Expand Up @@ -209,8 +209,9 @@ fn test_metadata() {
let dispatcher = IFollowNFTDispatcher { contract_address: follow_nft_contract_address };
let nft_name = dispatcher.name();
let nft_symbol = dispatcher.symbol();
assert(nft_name == "coloniz:FOLLOWER", 'invalid name');
assert(nft_symbol == "KFL", 'invalid symbol');
println!("{:?}", nft_name);
assert(nft_name == "Coloniz Followers | #10", 'invalid name');
assert(nft_symbol == "CLZ:FOLLOWERS", 'invalid symbol');
stop_cheat_caller_address(follow_nft_contract_address);
}

Expand Down
44 changes: 15 additions & 29 deletions tests/test_handle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,21 @@ fn test_mint_handle() {
let handles_contract_address = __setup__();
let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address };

start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap());
let token_id = handles_dispatcher.mint_handle(TEST_LOCAL_NAME);
let token_id = handles_dispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());

let local_name: felt252 = handles_dispatcher.get_local_name(token_id);
assert(local_name == TEST_LOCAL_NAME, 'invalid local name');

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_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap());
let token_id = handles_dispatcher.mint_handle(TEST_LOCAL_NAME_TWO);
let token_id = handles_dispatcher
.mint_handle(TEST_LOCAL_NAME_TWO, USER_ONE.try_into().unwrap());

let local_name: felt252 = handles_dispatcher.get_local_name(token_id);
assert(local_name == TEST_LOCAL_NAME_TWO, 'invalid local name two');

stop_cheat_caller_address(handles_contract_address);
}

#[test]
Expand All @@ -71,17 +66,15 @@ fn test_mint_handle_with_bad_local_name_1() {
let handles_contract_address = __setup__();
let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address };

start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap());
handles_dispatcher.mint_handle(TEST_BAD_LOCAL_NAME_1);
handles_dispatcher.mint_handle(TEST_BAD_LOCAL_NAME_1, USER_ONE.try_into().unwrap());
}
#[test]
#[should_panic(expected: ('coloniz: invalid local name!',))]
fn test_mint_handle_with_bad_local_name_2() {
let handles_contract_address = __setup__();
let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address };

start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap());
handles_dispatcher.mint_handle(TEST_BAD_LOCAL_NAME_2);
handles_dispatcher.mint_handle(TEST_BAD_LOCAL_NAME_2, USER_ONE.try_into().unwrap());
}

#[test]
Expand All @@ -90,8 +83,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_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap());
handles_dispatcher.mint_handle(TEST_BAD_LOCAL_NAME_3);
handles_dispatcher.mint_handle(TEST_BAD_LOCAL_NAME_3, USER_ONE.try_into().unwrap());
}

#[test]
Expand All @@ -112,8 +104,7 @@ fn test_handle_id_exists_after_mint() {
let dispatcher = IHandleDispatcher { contract_address };
let _erc721Dispatcher = IERC721Dispatcher { contract_address };

start_cheat_caller_address(contract_address, ADMIN_ADDRESS.try_into().unwrap());
let handle_id: u256 = dispatcher.mint_handle('handle');
let handle_id: u256 = dispatcher.mint_handle('handle', ADMIN_ADDRESS.try_into().unwrap());

assert(dispatcher.exists(handle_id), 'Handle ID does not exist');
}
Expand All @@ -126,7 +117,7 @@ fn test_total_supply() {
let current_total_supply: u256 = dispatcher.total_supply();

start_cheat_caller_address(contract_address, USER_ONE.try_into().unwrap());
let handle_id: u256 = dispatcher.mint_handle('handle');
let handle_id: u256 = dispatcher.mint_handle('handle', USER_ONE.try_into().unwrap());
let total_supply_after_mint: u256 = dispatcher.total_supply();
assert(total_supply_after_mint == current_total_supply + 1, 'WRONG_TOTAL_SUPPLY');

Expand All @@ -142,8 +133,7 @@ fn test_burn() {
let dispatcher = IHandleDispatcher { contract_address };
let _erc721Dispatcher = IERC721Dispatcher { contract_address };

start_cheat_caller_address(contract_address, USER_ONE.try_into().unwrap());
let handle_id: u256 = dispatcher.mint_handle('handle');
let handle_id: u256 = dispatcher.mint_handle('handle', USER_ONE.try_into().unwrap());

assert(dispatcher.exists(handle_id) == true, 'Handle ID does not exist');
assert(_erc721Dispatcher.owner_of(handle_id) == USER_ONE.try_into().unwrap(), 'Wrong Owner');
Expand All @@ -162,7 +152,7 @@ fn test_cannot_burn_if_not_owner_of() {
let _erc721Dispatcher = IERC721Dispatcher { contract_address };

start_cheat_caller_address(contract_address, USER_TWO.try_into().unwrap());
let handle_id: u256 = dispatcher.mint_handle('handle');
let handle_id: u256 = dispatcher.mint_handle('handle', USER_TWO.try_into().unwrap());
stop_cheat_caller_address(contract_address);

start_cheat_caller_address(contract_address, USER_ONE.try_into().unwrap());
Expand All @@ -177,14 +167,11 @@ fn test_get_handle() {

let handles_dispatcher = IHandleDispatcher { contract_address: handles_contract_address };

start_cheat_caller_address(handles_contract_address, USER_ONE.try_into().unwrap());
let token_id = handles_dispatcher.mint_handle(TEST_LOCAL_NAME);
let token_id = handles_dispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());

let handle: ByteArray = handles_dispatcher.get_handle(token_id);

assert(handle == "coloniz.kst", 'Invalid handle');

stop_cheat_caller_address(handles_contract_address);
}

#[test]
Expand All @@ -206,10 +193,10 @@ fn test_mint_handle_event() {

let handles_dispatcher = IHandleDispatcher { contract_address: 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(TEST_LOCAL_NAME);
let test_token_id = handles_dispatcher
.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());
let expected_event = Handles::Event::HandleMinted(
Handles::HandleMinted {
local_name: TEST_LOCAL_NAME,
Expand All @@ -220,8 +207,6 @@ fn test_mint_handle_event() {
);

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

stop_cheat_caller_address(handles_contract_address);
}

#[test]
Expand All @@ -233,7 +218,8 @@ fn test_burn_handle_event() {
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(TEST_LOCAL_NAME);
let test_token_id = handles_dispatcher
.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());

let mut expected_event = Handles::Event::HandleMinted(
Handles::HandleMinted {
Expand Down
16 changes: 8 additions & 8 deletions tests/test_handle_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn test_resolve() {

// Mint Handle to USER_ONE
start_cheat_caller_address(handle_contract_address, USER_ONE.try_into().unwrap());
let token_id = handle_dispatcher.mint_handle(TEST_LOCAL_NAME);
let token_id = handle_dispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());

// Link handle to USER_ONE
handle_registry_dispatcher.link(token_id, USER_ONE.try_into().unwrap());
Expand All @@ -92,7 +92,7 @@ fn test_link() {

// mint handle
start_cheat_caller_address(handle_contract_address, USER_ONE.try_into().unwrap());
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME);
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());

// link token to profile
start_cheat_caller_address(handle_registry_address, USER_ONE.try_into().unwrap());
Expand All @@ -115,7 +115,7 @@ fn test_linking_fails_if_profile_address_is_not_owner() {

// mint handle
start_cheat_caller_address(handle_contract_address, USER_TWO.try_into().unwrap());
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME);
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME, USER_TWO.try_into().unwrap());
stop_cheat_caller_address(handle_contract_address);

// link token to profile
Expand All @@ -135,7 +135,7 @@ fn test_does_not_link_twice_for_same_handle() {

// mint handle
start_cheat_caller_address(handle_contract_address, USER_ONE.try_into().unwrap());
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME);
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());

// link token to profile
start_cheat_caller_address(handle_registry_address, USER_ONE.try_into().unwrap());
Expand All @@ -156,7 +156,7 @@ fn test_unlink() {

// mint handle
start_cheat_caller_address(handle_contract_address, USER_ONE.try_into().unwrap());
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME);
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());
stop_cheat_caller_address(handle_contract_address);

// link token to profile
Expand All @@ -183,7 +183,7 @@ fn test_unlink_fails_if_caller_is_not_owner() {

// mint handle
start_cheat_caller_address(handle_contract_address, USER_ONE.try_into().unwrap());
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME);
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());
stop_cheat_caller_address(handle_contract_address);

// link token to profile
Expand All @@ -206,7 +206,7 @@ fn test_linked_event_emission() {

// mint handle
start_cheat_caller_address(handle_contract_address, USER_ONE.try_into().unwrap());
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME);
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());
stop_cheat_caller_address(handle_contract_address);

// link token to profile
Expand Down Expand Up @@ -238,7 +238,7 @@ fn test_unlinked_event_emission() {

// mint handle
start_cheat_caller_address(handle_contract_address, USER_ONE.try_into().unwrap());
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME);
let handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME, USER_ONE.try_into().unwrap());
stop_cheat_caller_address(handle_contract_address);

// link token to profile
Expand Down
4 changes: 1 addition & 3 deletions tests/test_hub.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ fn __setup__() -> (ContractAddress, ContractAddress, ContractAddress, ContractAd
stop_cheat_caller_address(hub_contract_address);

// mint and link handle for user_one
start_cheat_caller_address(handle_contract_address, user_one_profile_address);
let handleDispatcher = IHandleDispatcher { contract_address: handle_contract_address };
let handleRegistryDispatcher = IHandleRegistryDispatcher {
contract_address: handle_registry_contract_address
};
let minted_handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME);
stop_cheat_caller_address(handle_contract_address);
let minted_handle_id = handleDispatcher.mint_handle(TEST_LOCAL_NAME, user_one_profile_address);

start_cheat_caller_address(handle_registry_contract_address, user_one_profile_address);
handleRegistryDispatcher.link(minted_handle_id, user_one_profile_address);
Expand Down

0 comments on commit 680f7f0

Please sign in to comment.