Skip to content

Commit

Permalink
Merge pull request #5 from Fantom-foundation/nonerror
Browse files Browse the repository at this point in the history
Added Nonerror
  • Loading branch information
Maxime2 authored Sep 13, 2019
2 parents 94541c0 + a2c4908 commit 0f2a24d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/generic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use libcommon_rs::peer::{Peer, PeerList};
use serde::{Deserialize, Serialize};
use std::ops::{Index, IndexMut};
use std::{thread, time};
use core::fmt;

// Dummy data struct. Simply uses a u32 for instantiation.
#[derive(Clone, Debug, Deserialize, Serialize, Eq, Hash, PartialEq, PartialOrd, Ord)]
Expand Down Expand Up @@ -133,9 +134,9 @@ impl PeerList<Id, Error> for TestPeerList<Id> {
pub fn common_test<
// C: TransportConfiguration<Data>,
T: Transport<Id, Data, Error, TestPeerList<Id>>,
>(
> (
net_addrs: Vec<String>,
) {
) -> Result<(), Error> {
let n_peers = net_addrs.len();
// Create a new TestPeerList
let mut pl: TestPeerList<Id> = TestPeerList::new();
Expand All @@ -144,9 +145,8 @@ pub fn common_test<
// Iterate over all peers, create a config for each one and create a Transport to handle
// messaging.
for i in 0..n_peers {
pl.add(TestPeer::new(i.into(), net_addrs[i].clone()))
.unwrap();
trns.push(T::new(net_addrs[i].clone()).unwrap());
pl.add(TestPeer::new(i.into(), net_addrs[i].clone()))?;
trns.push(T::new(net_addrs[i].clone())?);
}

// Wait three seconds.
Expand All @@ -158,7 +158,7 @@ pub fn common_test<
// Create Data to send.
let d: Data = Data(55);
// Broadcast data.
trns[0].broadcast(&mut pl, d.clone()).unwrap();
trns[0].broadcast(&mut pl, d.clone())?;
for i in 0..n_peers {
// Asynchronously check if all peers have received the message.
block_on(async {
Expand All @@ -175,7 +175,7 @@ pub fn common_test<
println!("Unicast test");
let u: Data = Data(0xaa);
// Send directed data between two peers.
trns[1].send(pl[0].net_addr.clone(), u.clone()).unwrap();
trns[1].send(pl[0].net_addr.clone(), u.clone())?;
// Asynchronously check whether the receiver got the sent message.
block_on(async {
let n = trns[0].next().await;
Expand All @@ -184,4 +184,6 @@ pub fn common_test<
None => panic!("unexpected None"),
}
});

Ok(())
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where
Pl: PeerList<Id, Error>,
Data: Serialize + DeserializeOwned,
{
/// Creates a new Transport type using a preset configuration type.
/// Creates a new Transport type. Takes in a net address to be bound to a listener
fn new(set_bind_net_addr: String) -> Result<Self>
where
Self: Sized;
Expand Down

0 comments on commit 0f2a24d

Please sign in to comment.