Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
blocks_are_not_announced_by_light_nodes
  • Loading branch information
svyatonik committed Jun 7, 2018
commit d4252badf04497756c4551abdf6b4862ba64bf9f
20 changes: 12 additions & 8 deletions substrate/network/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,22 @@ impl TestNet {
};

for _ in 0..n {
let client = Arc::new(test_client::new());
let tx_pool = Arc::new(EmptyTransactionPool);
let sync = Protocol::new(config.clone(), client.clone(), None, tx_pool).unwrap();
net.peers.push(Arc::new(Peer {
sync: sync,
client: client,
queue: RwLock::new(VecDeque::new()),
}));
net.add_peer(&config);
}
net
}

pub fn add_peer(&mut self, config: &ProtocolConfig) {
let client = Arc::new(test_client::new());
let tx_pool = Arc::new(EmptyTransactionPool);
let sync = Protocol::new(config.clone(), client.clone(), None, tx_pool).unwrap();
self.peers.push(Arc::new(Peer {
sync: sync,
client: client,
queue: RwLock::new(VecDeque::new()),
}));
}

pub fn peer(&self, i: usize) -> &Peer {
&self.peers[i]
}
Expand Down
34 changes: 34 additions & 0 deletions substrate/network/src/test/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use client::backend::Backend;
use client::blockchain::Backend as BlockchainBackend;
use sync::SyncState;
use {Role};
use super::*;

#[test]
Expand Down Expand Up @@ -85,3 +87,35 @@ fn sync_after_fork_works() {
assert!(net.peer(2).client.backend().blockchain().canon_equals_to(&peer1_chain));
}

#[test]
fn blocks_are_not_announced_by_light_nodes() {
::env_logger::init().ok();
let mut net = TestNet::new(0);

// full peer0 is connected to light peer
// light peer1 is connected to full peer2
let mut light_config = ProtocolConfig::default();
light_config.roles = Role::LIGHT;
net.add_peer(&ProtocolConfig::default());
net.add_peer(&light_config);
net.add_peer(&ProtocolConfig::default());

net.peer(0).push_blocks(1, false);
net.peer(0).start();
net.peer(1).start();
net.peer(2).start();
net.peer(0).on_connect(1);
net.peer(1).on_connect(2);

// generate block at peer0 && run sync
while !net.done() {
net.sync_step();
}

// peer 0 has the best chain
// peer 1 has the best chain
// peer 2 has genesis-chain only
assert_eq!(net.peer(0).client.backend().blockchain().info().unwrap().best_number, 1);
assert_eq!(net.peer(1).client.backend().blockchain().info().unwrap().best_number, 1);
assert_eq!(net.peer(2).client.backend().blockchain().info().unwrap().best_number, 0);
}