diff --git a/core/archipelago/src/api/rpc/content_tests.rs b/core/archipelago/src/api/rpc/content_tests.rs index a335bb03..de65c8d7 100644 --- a/core/archipelago/src/api/rpc/content_tests.rs +++ b/core/archipelago/src/api/rpc/content_tests.rs @@ -201,14 +201,30 @@ async fn onchain_delivery_streams_to_owned_cache_and_preserves_incomplete_recove .body(hyper::Body::from(vec![71u8; 2 * 1024 * 1024])) .unwrap() .into(); - let item = cache_peer_response(dir.path(), "seller.onion", "film", "film.mp4", "video/mp4", 1, "onchain", response).await.unwrap(); + let item = cache_peer_response( + dir.path(), + "seller.onion", + "film", + "film.mp4", + "video/mp4", + 1, + "onchain", + response, + ) + .await + .unwrap(); assert!(item.download_complete); assert_eq!(item.ecash_backend, "onchain"); - let (_, mut file) = crate::content_owned::open_owned(dir.path(), "seller.onion", "film").await.unwrap().unwrap(); + let (_, mut file) = crate::content_owned::open_owned(dir.path(), "seller.onion", "film") + .await + .unwrap() + .unwrap(); let mut bytes = Vec::new(); file.read_to_end(&mut bytes).await.unwrap(); assert_eq!(bytes, vec![71u8; 2 * 1024 * 1024]); - let reply = cached_purchase_response(dir.path(), "seller.onion", "film", true, 0).await.unwrap(); + let reply = cached_purchase_response(dir.path(), "seller.onion", "film", true, 0) + .await + .unwrap(); assert_eq!(reply["owned"], true); assert!(reply.get("data").is_none()); @@ -216,12 +232,38 @@ async fn onchain_delivery_streams_to_owned_cache_and_preserves_incomplete_recove .header("content-length", "100") .body(hyper::Body::wrap_stream(futures_util::stream::iter([ Ok(bytes::Bytes::from_static(b"short")), - Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "connection closed before delivery completed")), + Err(std::io::Error::new( + std::io::ErrorKind::UnexpectedEof, + "connection closed before delivery completed", + )), ]))) .unwrap() .into(); - assert!(cache_peer_response(dir.path(), "seller.onion", "interrupted", "film.mp4", "video/mp4", 1, "onchain", truncated).await.is_err()); - let entries = crate::content_owned::list_owned_checked(dir.path()).await.unwrap(); - assert!(!entries.iter().find(|item| item.content_id == "interrupted").unwrap().download_complete); - assert!(existing_paid_content(dir.path(), "seller.onion", "interrupted", None, true).await.is_err()); + assert!(cache_peer_response( + dir.path(), + "seller.onion", + "interrupted", + "film.mp4", + "video/mp4", + 1, + "onchain", + truncated + ) + .await + .is_err()); + let entries = crate::content_owned::list_owned_checked(dir.path()) + .await + .unwrap(); + assert!( + !entries + .iter() + .find(|item| item.content_id == "interrupted") + .unwrap() + .download_complete + ); + assert!( + existing_paid_content(dir.path(), "seller.onion", "interrupted", None, true) + .await + .is_err() + ); } diff --git a/core/archipelago/src/content_server.rs b/core/archipelago/src/content_server.rs index acf8c7a2..4f973dfb 100644 --- a/core/archipelago/src/content_server.rs +++ b/core/archipelago/src/content_server.rs @@ -436,7 +436,9 @@ where } if !authorized { if let Some(hash) = invoice_hash { - if let Some(method) = crate::content_invoice::paid_method_for(data_dir, hash, id).await { + if let Some(method) = + crate::content_invoice::paid_method_for(data_dir, hash, id).await + { authorized = method_accepted(&item.access, method.as_str()); } } @@ -1316,7 +1318,7 @@ mod paid_read_order_tests { #[tokio::test] async fn durable_payment_uses_its_recorded_method_for_seller_acceptance() { - use crate::content_invoice::{record_pending_method, mark_paid, PaymentMethod}; + use crate::content_invoice::{mark_paid, record_pending_method, PaymentMethod}; for (paid_with, accepted, expected) in [ (PaymentMethod::Onchain, "onchain", true), (PaymentMethod::Onchain, "lightning", false), @@ -1325,15 +1327,33 @@ mod paid_read_order_tests { ] { let dir = fixture(b"paid bytes").await; let mut catalog = load_catalog(dir.path()).await.unwrap(); - catalog.items[0].access = AccessControl::Paid { price_sats: 10, accepted: vec![accepted.into()] }; + catalog.items[0].access = AccessControl::Paid { + price_sats: 10, + accepted: vec![accepted.into()], + }; save_catalog(dir.path(), &catalog).await.unwrap(); - record_pending_method(dir.path(), "receipt", "paid", 10, paid_with).await.unwrap(); + record_pending_method(dir.path(), "receipt", "paid", 10, paid_with) + .await + .unwrap(); mark_paid(dir.path(), "receipt").await.unwrap(); - let result = serve_content_with(dir.path(), "paid", None, Some("receipt"), None, None, false, + let result = serve_content_with( + dir.path(), + "paid", + None, + Some("receipt"), + None, + None, + false, |path, range, mime| prepare_content(dir.path(), path, range, mime), - |_, _| async { panic!("must not redeem another payment") }).await.unwrap(); - if expected { assert!(matches!(result, ServeResult::Ok(bytes, _) if bytes == b"paid bytes")); } - else { assert!(matches!(result, ServeResult::PaymentRequired(10))); } + |_, _| async { panic!("must not redeem another payment") }, + ) + .await + .unwrap(); + if expected { + assert!(matches!(result, ServeResult::Ok(bytes, _) if bytes == b"paid bytes")); + } else { + assert!(matches!(result, ServeResult::PaymentRequired(10))); + } } }