use std::io::Cursor;
use anyhow::Result;
use futures_util::TryStreamExt;
use ipfs_api_backend_hyper::{IpfsApi, IpfsClient};
use tokio::time::{Duration, sleep};
#[tokio::test(flavor = "multi_thread")]
#[ignore = "Proof of Concept only. Needs a running IPFS daemon (kubo) on 127.0.0.1:5001"]
async fn ipfs_immutable_roundtrip() -> Result<()> {
let client = IpfsClient::default();
let original: &[u8] = b"hello from ipfs (immutable)";
let add_res = client.add(Cursor::new(original)).await?;
let cid = add_res.hash;
sleep(Duration::from_millis(100)).await;
let mut stream = client.cat(&cid);
let mut roundtrip = Vec::new();
while let Some(chunk) = stream.try_next().await? {
roundtrip.extend_from_slice(&chunk);
}
assert_eq!(roundtrip.as_slice(), original, "CID roundtrip mismatch");
Ok(())
}