Skip to content
Open
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
33 changes: 33 additions & 0 deletions contract/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,8 @@ fn test_custom_sac_token_end_to_end_flow() {
// Verify subscription is still active after pay_per_use
let sub_final = client.get_subscription(&user).unwrap();
assert!(sub_final.active, "subscription should remain active after pay_per_use");
}

// ─────────────────────────────────────────────────────────────
// Issue #237: get_token() read function tests
// ─────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -1285,3 +1287,34 @@ fn test_set_grace_period_emits_event() {
assert_eq!(topic_symbol, Symbol::new(&env, "grace_period_updated"));
assert_eq!(emitted_seconds, 7200u64);
}

// ─────────────────────────────────────────────
// Issue #232: charge() insufficient-allowance error path
// ─────────────────────────────────────────────

/// If a user's token allowance drops below `sub.amount` between subscribe and
/// charge time, `transfer_from` must fail and propagate the error.
#[test]
#[should_panic]
fn test_charge_insufficient_allowance() {
let (env, contract_id, token_addr, user, merchant) = setup();
let client = FlowPayClient::new(&env, &contract_id);

let amount: i128 = 5_0000000;
let interval: u64 = 86400;

// Subscribe with sufficient allowance
client.subscribe(&user, &merchant, &amount, &interval, &token_addr, &None, &None);

// Revoke allowance — set it to 0
let token = TokenClient::new(&env, &token_addr);
token.approve(&user, &contract_id, &0, &200);

// Advance ledger past the interval
env.ledger().with_mut(|l| {
l.timestamp += interval + 1;
});

// charge() should panic because transfer_from fails with insufficient allowance
client.charge(&user);
}