diff --git a/contracts/crowdfunding/src/lib.rs b/contracts/crowdfunding/src/lib.rs index 0e68a7d18..9f2744507 100644 --- a/contracts/crowdfunding/src/lib.rs +++ b/contracts/crowdfunding/src/lib.rs @@ -302,10 +302,12 @@ mod propchain_crowdfunding { } #[ink(event)] - pub struct AccreditationVerified { + pub struct CampaignShared { #[ink(topic)] - investor: AccountId, - verified_by: AccountId, + campaign_id: u64, + #[ink(topic)] + sharer: AccountId, + platform: String, } impl RealEstateCrowdfunding { @@ -1366,4 +1368,29 @@ mod tests { assert_eq!(metrics.released_capital, 40_000); assert!(!metrics.is_funded); } + + #[ink::test] + fn test_share_campaign() { + let mut contract = setup(); + let accounts = test::default_accounts::(); + + let campaign_id = contract + .create_campaign("Viral Project".into(), 500_000) + .unwrap(); + + test::set_caller::(accounts.bob); + assert!(contract.share_campaign(campaign_id, "Twitter".into()).is_ok()); + + let emitted_events = test::recorded_events().count(); + assert_eq!(emitted_events, 2); // CampaignCreated + CampaignShared + } + + #[ink::test] + fn test_share_nonexistent_campaign_fails() { + let contract = setup(); + assert_eq!( + contract.share_campaign(999, "Facebook".into()), + Err(CrowdfundingError::CampaignNotFound) + ); + } }