From 81387c129a7938440859ef5a600e08a45576552a Mon Sep 17 00:00:00 2001 From: Adegbite Ademola Kelvin Date: Tue, 28 May 2024 16:49:50 +0100 Subject: [PATCH] ft: add post implementation --- src/base/types.cairo | 8 ++++---- src/publication/publication.cairo | 14 +++++++++----- tests/test_publication.cairo | 25 ++++++++++++++++++------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/base/types.cairo b/src/base/types.cairo index a9238d7..2e80209 100644 --- a/src/base/types.cairo +++ b/src/base/types.cairo @@ -33,11 +33,11 @@ pub struct Profile { #[derive(Debug, Drop, Serde, starknet::Store)] pub struct Publication { pointed_profile_address: ContractAddress, - pointedPubId: u256, - contentURI: ByteArray, - pubType: Option, + pointed_pub_id: u256, + content_URI: ByteArray, + pub_Type: PublicationType, root_profile_address: ContractAddress, - rootPubId: u256 + root_pub_id: u256 } diff --git a/src/publication/publication.cairo b/src/publication/publication.cairo index 7a0d958..5bef031 100644 --- a/src/publication/publication.cairo +++ b/src/publication/publication.cairo @@ -109,11 +109,15 @@ pub mod Publications { contract_address: profile_contract_address } .increment_publication_count(); - let mut post = self.publication.read((profile_address, pubIdAssigned)); - post.contentURI = contentURI; - post.pubType = Option::Some(PublicationType::Post); - - self.publication.write((profile_address, pubIdAssigned), post); + let new_post = Publication { + pointed_profile_address: 0.try_into().unwrap(), + pointed_pub_id: 0, + content_URI: contentURI, + pub_Type: PublicationType::Post, + root_profile_address: 0.try_into().unwrap(), + root_pub_id: 0 + }; + self.publication.write((profile_address, pubIdAssigned), new_post); pubIdAssigned } fn get_publication( diff --git a/tests/test_publication.cairo b/tests/test_publication.cairo index 992af62..caed05d 100644 --- a/tests/test_publication.cairo +++ b/tests/test_publication.cairo @@ -124,14 +124,25 @@ fn test_post() { contract_address: publication_contract_address }; let contentURI: ByteArray = "ipfs://helloworld"; - // let post1 = publication_dispatcher.post(contentURI, profile_address, profile_contract_address); - // let post2 = publication_dispatcher.post("ell", profile_address, profile_contract_address); - // let post3 = publication_dispatcher.post("hi", profile_address, profile_contract_address); - - // let post_publication_1 = IKarstPublicationsDispatcher{contract_address:publication_contract_address}.get_publication(profile_address, post1); - // let post_publication_2 = IKarstPublicationsDispatcher{contract_address:publication_contract_address}.get_publication(profile_address, post2); - // let post_publication_3 = IKarstPublicationsDispatcher{contract_address:publication_contract_address}.get_publication(profile_address, post3); + let post1 = publication_dispatcher.post(contentURI, profile_address, profile_contract_address); + let post2 = publication_dispatcher.post("ell", profile_address, profile_contract_address); + let post3 = publication_dispatcher.post("hi", profile_address, profile_contract_address); + let _post_publication_1 = IKarstPublicationsDispatcher { + contract_address: publication_contract_address + } + .get_publication(profile_address, post1); + let _post_publication_2 = IKarstPublicationsDispatcher { + contract_address: publication_contract_address + } + .get_publication(profile_address, post2); + let _post_publication_3 = IKarstPublicationsDispatcher { + contract_address: publication_contract_address + } + .get_publication(profile_address, post3); + assert(post1 == 0, 'invalid pub_count'); + assert(post2 == 1, 'invalid pub_count'); + assert(post3 == 2, 'invalid pub_count'); stop_prank( CheatTarget::Multiple(array![publication_contract_address, profile_contract_address]), );