agent-pay 0.1.0

L402 + DID-signed invoices: agent-to-agent Lightning payments (Rust port of @p-vbordei/agent-pay)
Documentation
use std::sync::Mutex;

use agent_pay::ReplayCache;

#[test]
fn replay_cache_marks_and_detects() {
    let cache = ReplayCache::new(100, Box::new(|| 0));
    assert!(!cache.is_used("hash1"));
    cache.mark_used("hash1", u64::MAX / 2);
    assert!(cache.is_used("hash1"));
}

#[test]
fn replay_cache_evicts_expired_on_access() {
    let now = std::sync::Arc::new(Mutex::new(1000u64));
    let now_clone = now.clone();
    let cache = ReplayCache::new(100, Box::new(move || *now_clone.lock().unwrap()));
    cache.mark_used("h", 2000);
    assert!(cache.is_used("h"));
    *now.lock().unwrap() = 3000;
    assert!(!cache.is_used("h"));
}

#[test]
fn replay_cache_evicts_oldest_when_over_max() {
    let cache = ReplayCache::new(2, Box::new(|| 0));
    cache.mark_used("a", u64::MAX / 2);
    cache.mark_used("b", u64::MAX / 2);
    cache.mark_used("c", u64::MAX / 2);
    assert!(!cache.is_used("a"));
    assert!(cache.is_used("b"));
    assert!(cache.is_used("c"));
}