add: salvaged exchange_block
This is from davids non-mergeable branch. Co-authored-by: David Craven <david@craven.ch>
This commit is contained in:
parent
0c9b997ea4
commit
85bd2cd705
@ -740,6 +740,12 @@ mod node {
|
||||
&self.ipfs
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DerefMut for Node {
|
||||
fn deref_mut(&mut self) -> &mut <Self as std::ops::Deref>::Target {
|
||||
&mut self.ipfs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
28
tests/exchange_block.rs
Normal file
28
tests/exchange_block.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use ipfs::{Block, Node};
|
||||
use libipld::cid::{Cid, Codec};
|
||||
use multihash::Sha2_256;
|
||||
|
||||
/// Discovers a peer via mdns and exchanges a block through bitswap.
|
||||
#[async_std::test]
|
||||
async fn exchange_block() {
|
||||
env_logger::init();
|
||||
let mdns = false;
|
||||
|
||||
let data = b"hello block\n".to_vec().into_boxed_slice();
|
||||
let cid = Cid::new_v1(Codec::Raw, Sha2_256::digest(&data));
|
||||
|
||||
let mut a = Node::new(mdns).await;
|
||||
let mut b = Node::new(mdns).await;
|
||||
|
||||
let (_, mut addrs) = b.identity().await.unwrap();
|
||||
|
||||
a.connect(addrs.pop().expect("b must have address to connect to"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
a.put_block(Block { cid: cid.clone(), data: data.clone() }).await.unwrap();
|
||||
|
||||
let Block { data: data2, .. } = b.get_block(&cid).await.unwrap();
|
||||
|
||||
assert_eq!(data, data2);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user