diff --git a/contracts/stellar-micropay-contract/src/lib.rs b/contracts/stellar-micropay-contract/src/lib.rs index d069cd0..0794a65 100644 --- a/contracts/stellar-micropay-contract/src/lib.rs +++ b/contracts/stellar-micropay-contract/src/lib.rs @@ -657,6 +657,69 @@ mod tests { client.send_tip(&token_id, &from, &to, &amount); } + /// Issue #202 — send_tip must emit a tip event containing both sender and + /// recipient without a borrow/move conflict on `from`. + #[test] + fn test_send_tip_emits_event_with_from_and_to() { + use soroban_sdk::{testutils::Events, vec, IntoVal}; + + let env = Env::default(); + let contract_id = env.register_contract(None, MicroPayContract); + let client = MicroPayContractClient::new(&env, &contract_id); + + let admin = Address::generate(&env); + client.initialize(&admin); + + let from = Address::generate(&env); + let to = Address::generate(&env); + let amount: i128 = 250; + + env.mock_all_auths(); + let token_id = create_token(&env, &admin, &from, amount); + client.send_tip(&token_id, &from, &to, &amount); + + let events = env.events().all(); + // Two events: init (from initialize) + tip. + assert_eq!(events.len(), 2); + let tip_event = events.get(1).unwrap(); + // Topic must be (Symbol("tip"), from, to). + let expected_topics = (Symbol::new(&env, "tip"), from.clone(), to.clone()).into_val(&env); + assert_eq!(tip_event.1, expected_topics); + // Data must be the amount. + let expected_data = amount.into_val(&env); + assert_eq!(tip_event.2, expected_data); + } + + /// Issue #201 — TipTotal and TipCount must survive across separate env + /// storage reads (persistent, not instance). Verifies the keys don't + /// collide or disappear between calls. + #[test] + fn test_tip_totals_are_per_recipient_persistent() { + let env = Env::default(); + let contract_id = env.register_contract(None, MicroPayContract); + let client = MicroPayContractClient::new(&env, &contract_id); + + let admin = Address::generate(&env); + client.initialize(&admin); + + let from = Address::generate(&env); + let alice = Address::generate(&env); + let bob = Address::generate(&env); + + env.mock_all_auths(); + let token_id = create_token(&env, &admin, &from, 1000); + + client.send_tip(&token_id, &from, &alice, &300); + client.send_tip(&token_id, &from, &alice, &200); + client.send_tip(&token_id, &from, &bob, &400); + + // Alice and Bob totals must be independent (persistent per-address keys). + assert_eq!(client.get_tip_total(&alice), 500); + assert_eq!(client.get_tip_count(&alice), 2); + assert_eq!(client.get_tip_total(&bob), 400); + assert_eq!(client.get_tip_count(&bob), 1); + } + // ── Escrow tests ──────────────────────────────────────────────────────── fn advance_ledger(env: &Env, to_sequence: u32) {