Skip to content

Commit

Permalink
ft: add post implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Adegbite Ademola Kelvin authored and Adegbite Ademola Kelvin committed May 28, 2024
1 parent ff2e15d commit 81387c1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/base/types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<PublicationType>,
pointed_pub_id: u256,
content_URI: ByteArray,
pub_Type: PublicationType,
root_profile_address: ContractAddress,
rootPubId: u256
root_pub_id: u256
}


Expand Down
14 changes: 9 additions & 5 deletions src/publication/publication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 18 additions & 7 deletions tests/test_publication.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
);
Expand Down

0 comments on commit 81387c1

Please sign in to comment.