Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : include test cases 🌵(#1) #18

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/smart-contracts.test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#[test]
fn test_create_success() -> Result<(), ProgramError> {
// 1. Create a mock context with required accounts
let mut context = MockContext::default();
let user_key = context.payer.key();
let campaign_key = Pubkey::new(&[1u8; 32]); // Replace with a unique key

// 2. Set up campaign data
let name = "Test Campaign".to_string();
let description = "This is a test campaign for demonstration purposes.".to_string();
let target_amount = 1000000000; // 1 SOL
let project_url = "https://example.com/project".to_string();
let progress_update_url = "https://example.com/updates".to_string();
let project_image_url = "https://example.com/image.jpg".to_string();
let category = "Technology".to_string();

// 3. Create accounts with mock data
let mut campaign_account = Account::new_empty(9000);
context.accounts.campaign = campaign_account.to_account_info().clone();
context.accounts.user = context.payer.to_account_info().clone();

// 4. Call the create instruction
smart_contracts::create(context.clone(), name, description, target_amount, project_url, progress_update_url, project_image_url, category)?;

// 5. Assert campaign data is set correctly
let campaign_data = &context.accounts.campaign.data.borrow()[..];
let campaign: Campaign = Account::<Campaign>::try_deserialize(&mut &campaign_data[..])?;
assert_eq!(campaign.name, name);
assert_eq!(campaign.description, description);
assert_eq!(campaign.target_amount, target_amount);
assert_eq!(campaign.project_url, project_url);
assert_eq!(campaign.progress_update_url, progress_update_url);
assert_eq!(campaign.project_image_url, project_image_url);
assert_eq!(campaign.category, category);
assert_eq!(campaign.admin, user_key);
assert_eq!(campaign.amount_donated, 0);
assert_eq!(campaign.amount_withdrawn, 0);

Ok(())
}



16 changes: 0 additions & 16 deletions tests/smart-contracts.ts

This file was deleted.

Loading