Diff
Not logged in

Differences From Artifact [fce3a8f6f9]:

To Artifact [aba2fb2bdf]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19


20
21
22
23
24
25
26
27
28
29
30
31
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
...
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160

161
162
163
164
165
166
167
// Copyright 2016 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement, version 1.1.  This, along with the
// Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.

// These tests are almost straight up copied from crust::service::tests



use maidsafe_utilities::event_sender::{MaidSafeEventCategory, MaidSafeObserver};
use std::collections::HashSet;
use std::sync::mpsc::{self, Receiver};
use super::crust::{CrustEventSender, CrustUser, Event, Service};
use super::support::{Config, Network};

fn get_event_sender() -> (CrustEventSender, Receiver<MaidSafeEventCategory>, Receiver<Event>) {
    let (category_tx, category_rx) = mpsc::channel();
    let (event_tx, event_rx) = mpsc::channel();

    (MaidSafeObserver::new(event_tx, MaidSafeEventCategory::Crust, category_tx),
     category_rx,
................................................................................

    let mut service_1 = unwrap!(Service::with_handle(&handle1, event_sender_1));

    unwrap!(service_1.start_bootstrap(HashSet::new(), CrustUser::Node));
    let id_0 = expect_event!(event_rx_1, Event::BootstrapConnect(id, _) => id);
    let id_1 = expect_event!(event_rx_0, Event::BootstrapAccept(id, CrustUser::Node) => id);

    assert!(id_0 != id_1);

    // send data from 0 to 1
    let data_sent = vec![0, 1, 255, 254, 222, 1];
    unwrap!(service_0.send(id_1, data_sent.clone(), 0));

    // 1 should rx data
    let (data_recvd, peer_id) = expect_event!(event_rx_1,

                      Event::NewMessage(their_id, msg) => (msg, their_id));

    assert_eq!(data_recvd, data_sent);
    assert_eq!(peer_id, id_0);

    // send data from 1 to 0
    let data_sent = vec![10, 11, 155, 214, 202];
    unwrap!(service_1.send(id_0, data_sent.clone(), 0));

    // 0 should rx data
    let (data_recvd, peer_id) = expect_event!(event_rx_0,

                      Event::NewMessage(their_id, msg) => (msg, their_id));

    assert_eq!(data_recvd, data_sent);
    assert_eq!(peer_id, id_1);

    assert!(service_0.disconnect(id_1));
    expect_event!(event_rx_1, Event::LostPeer(id) => assert_eq!(id, id_0));
................................................................................
    let id_0 = expect_event!(event_rx_1, Event::ConnectSuccess(id) => id);

    // send data from 0 to 1
    let data_sent = vec![0, 1, 255, 254, 222, 1];
    unwrap!(service_0.send(id_1, data_sent.clone(), 0));

    // 1 should rx data
    let (data_recvd, peer_id) = expect_event!(event_rx_1,

                      Event::NewMessage(their_id, msg) => (msg, their_id));

    assert_eq!(data_recvd, data_sent);
    assert_eq!(peer_id, id_0);

    // send data from 1 to 0
    let data_sent = vec![10, 11, 155, 214, 202];
    unwrap!(service_1.send(id_0, data_sent.clone(), 0));

    // 0 should rx data
    let (data_recvd, peer_id) = expect_event!(event_rx_0,

                      Event::NewMessage(their_id, msg) => (msg, their_id));

    assert_eq!(data_recvd, data_sent);
    assert_eq!(peer_id, id_1);
}

#[test]







|
|










>
>



<
<







 







|






|
>










|
>







 







|
>










|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


25
26
27
28
29
30
31
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2016 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement.  This, along with the Licenses can be
// found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.
//
// Please review the Licences for the specific language governing permissions and limitations
// relating to use of the SAFE Network Software.

// These tests are almost straight up copied from crust::service::tests

use super::crust::{CrustEventSender, CrustUser, Event, Service};
use super::support::{Config, Network};
use maidsafe_utilities::event_sender::{MaidSafeEventCategory, MaidSafeObserver};
use std::collections::HashSet;
use std::sync::mpsc::{self, Receiver};



fn get_event_sender() -> (CrustEventSender, Receiver<MaidSafeEventCategory>, Receiver<Event>) {
    let (category_tx, category_rx) = mpsc::channel();
    let (event_tx, event_rx) = mpsc::channel();

    (MaidSafeObserver::new(event_tx, MaidSafeEventCategory::Crust, category_tx),
     category_rx,
................................................................................

    let mut service_1 = unwrap!(Service::with_handle(&handle1, event_sender_1));

    unwrap!(service_1.start_bootstrap(HashSet::new(), CrustUser::Node));
    let id_0 = expect_event!(event_rx_1, Event::BootstrapConnect(id, _) => id);
    let id_1 = expect_event!(event_rx_0, Event::BootstrapAccept(id, CrustUser::Node) => id);

    assert_ne!(id_0, id_1);

    // send data from 0 to 1
    let data_sent = vec![0, 1, 255, 254, 222, 1];
    unwrap!(service_0.send(id_1, data_sent.clone(), 0));

    // 1 should rx data
    let (data_recvd, peer_id) =
        expect_event!(event_rx_1,
                      Event::NewMessage(their_id, msg) => (msg, their_id));

    assert_eq!(data_recvd, data_sent);
    assert_eq!(peer_id, id_0);

    // send data from 1 to 0
    let data_sent = vec![10, 11, 155, 214, 202];
    unwrap!(service_1.send(id_0, data_sent.clone(), 0));

    // 0 should rx data
    let (data_recvd, peer_id) =
        expect_event!(event_rx_0,
                      Event::NewMessage(their_id, msg) => (msg, their_id));

    assert_eq!(data_recvd, data_sent);
    assert_eq!(peer_id, id_1);

    assert!(service_0.disconnect(id_1));
    expect_event!(event_rx_1, Event::LostPeer(id) => assert_eq!(id, id_0));
................................................................................
    let id_0 = expect_event!(event_rx_1, Event::ConnectSuccess(id) => id);

    // send data from 0 to 1
    let data_sent = vec![0, 1, 255, 254, 222, 1];
    unwrap!(service_0.send(id_1, data_sent.clone(), 0));

    // 1 should rx data
    let (data_recvd, peer_id) =
        expect_event!(event_rx_1,
                      Event::NewMessage(their_id, msg) => (msg, their_id));

    assert_eq!(data_recvd, data_sent);
    assert_eq!(peer_id, id_0);

    // send data from 1 to 0
    let data_sent = vec![10, 11, 155, 214, 202];
    unwrap!(service_1.send(id_0, data_sent.clone(), 0));

    // 0 should rx data
    let (data_recvd, peer_id) =
        expect_event!(event_rx_0,
                      Event::NewMessage(their_id, msg) => (msg, their_id));

    assert_eq!(data_recvd, data_sent);
    assert_eq!(peer_id, id_1);
}

#[test]