forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.rs
More file actions
72 lines (58 loc) · 2.28 KB
/
Copy pathtest.rs
File metadata and controls
72 lines (58 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#![cfg(test)]
use super::*;
use soroban_sdk::{testutils::Address as _, Address, Env, String, Vec};
#[test]
fn test_reminder_flow() {
let env = Env::default();
env.mock_all_auths();
let contract_id = env.register_contract(None, ReminderContract);
let client = ReminderContractClient::new(&env, &contract_id);
let split_id = String::from_str(&env, "split_123");
let participant_1 = Address::generate(&env);
let participant_2 = Address::generate(&env);
let mut participants = Vec::new(&env);
participants.push_back(EscrowParticipant {
address: participant_1.clone(),
amount_owed: 100,
amount_paid: 0,
paid_at: None,
reminder_requested: false,
});
participants.push_back(EscrowParticipant {
address: participant_2.clone(),
amount_owed: 200,
amount_paid: 200,
paid_at: Some(env.ledger().timestamp()),
reminder_requested: false,
});
client.create_reminder_escrow(&split_id, &participants);
// Initial state check
assert!(!client.get_reminder_requested(&split_id, &participant_1));
assert!(!client.get_reminder_requested(&split_id, &participant_2));
// Request reminder for participant_1 (unpaid)
client.request_reminder(&split_id, &participant_1);
assert!(client.get_reminder_requested(&split_id, &participant_1));
// Cancel reminder for participant_1
client.cancel_reminder(&split_id, &participant_1);
assert!(!client.get_reminder_requested(&split_id, &participant_1));
}
#[test]
#[should_panic(expected = "Participant not found or already paid")]
fn test_request_reminder_already_paid_fails() {
let env = Env::default();
env.mock_all_auths();
let contract_id = env.register_contract(None, ReminderContract);
let client = ReminderContractClient::new(&env, &contract_id);
let split_id = String::from_str(&env, "split_123");
let participant = Address::generate(&env);
let mut participants = Vec::new(&env);
participants.push_back(EscrowParticipant {
address: participant.clone(),
amount_owed: 100,
amount_paid: 100,
paid_at: None,
reminder_requested: false,
});
client.create_reminder_escrow(&split_id, &participants);
client.request_reminder(&split_id, &participant);
}