Skip to content

Commit

Permalink
Update gossipsub topics to v0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning committed Apr 1, 2020
1 parent bcdc109 commit 10b68ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
28 changes: 16 additions & 12 deletions beacon_node/eth2-libp2p/tests/gossipsub_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ fn test_gossipsub_forward() {
message: empty_block,
signature: Signature::empty_signature(),
};
let data = PubsubData::BeaconBlock(Box::new(signed_block));
let pubsub_message = PubsubMessage::new(GossipEncoding::SSZ, data);
let publishing_topic: String = "/eth2/beacon_block/ssz".into();
let pubsub_message = PubsubMessage::BeaconBlock(Box::new(signed_block));
let publishing_topic: String = pubsub_message
.topics(GossipEncoding::SSZ, [0, 0, 0, 0])
.first()
.unwrap()
.clone()
.into();
let mut subscribed_count = 0;
tokio::run(futures::future::poll_fn(move || -> Result<_, ()> {
for node in nodes.iter_mut() {
Expand Down Expand Up @@ -65,10 +69,8 @@ fn test_gossipsub_forward() {
}
}
Async::Ready(Some(Libp2pEvent::PeerSubscribed(_, topic))) => {
// Received topics is one of subscribed eth2 topics
assert!(topic.clone().into_string().starts_with("/eth2/"));
// Publish on beacon block topic
if topic == TopicHash::from_raw("/eth2/beacon_block/ssz") {
if topic == TopicHash::from_raw(publishing_topic.clone()) {
subscribed_count += 1;
// Every node except the corner nodes are connected to 2 nodes.
if subscribed_count == (num_nodes * 2) - 2 {
Expand Down Expand Up @@ -104,9 +106,13 @@ fn test_gossipsub_full_mesh_publish() {
message: empty_block,
signature: Signature::empty_signature(),
};
let data = PubsubData::BeaconBlock(Box::new(signed_block));
let pubsub_message = PubsubMessage::new(GossipEncoding::SSZ, data);
let publishing_topic: String = "/eth2/beacon_block/ssz".into();
let pubsub_message = PubsubMessage::BeaconBlock(Box::new(signed_block));
let publishing_topic: String = pubsub_message
.topics(GossipEncoding::SSZ, [0, 0, 0, 0])
.first()
.unwrap()
.clone()
.into();
let mut subscribed_count = 0;
let mut received_count = 0;
tokio::run(futures::future::poll_fn(move || -> Result<_, ()> {
Expand All @@ -132,10 +138,8 @@ fn test_gossipsub_full_mesh_publish() {
while let Async::Ready(Some(Libp2pEvent::PeerSubscribed(_, topic))) =
publishing_node.poll().unwrap()
{
// Received topics is one of subscribed eth2 topics
assert!(topic.clone().into_string().starts_with("/eth2/"));
// Publish on beacon block topic
if topic == TopicHash::from_raw("/eth2/beacon_block/ssz") {
if topic == TopicHash::from_raw(publishing_topic.clone()) {
subscribed_count += 1;
if subscribed_count == num_nodes - 1 {
publishing_node.swarm.publish(vec![pubsub_message.clone()]);
Expand Down
6 changes: 2 additions & 4 deletions beacon_node/eth2-libp2p/tests/rpc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn test_status_rpc() {

// Dummy STATUS RPC message
let rpc_request = RPCRequest::Status(StatusMessage {
fork_version: [0; 4],
fork_digest: [0; 4],
finalized_root: Hash256::from_low_u64_be(0),
finalized_epoch: Epoch::new(1),
head_root: Hash256::from_low_u64_be(0),
Expand All @@ -38,7 +38,7 @@ fn test_status_rpc() {

// Dummy STATUS RPC message
let rpc_response = RPCResponse::Status(StatusMessage {
fork_version: [0; 4],
fork_digest: [0; 4],
finalized_root: Hash256::from_low_u64_be(0),
finalized_epoch: Epoch::new(1),
head_root: Hash256::from_low_u64_be(0),
Expand Down Expand Up @@ -142,7 +142,6 @@ fn test_blocks_by_range_chunked_rpc() {

// BlocksByRange Request
let rpc_request = RPCRequest::BlocksByRange(BlocksByRangeRequest {
head_block_root: Hash256::from_low_u64_be(0),
start_slot: 0,
count: messages_to_send,
step: 0,
Expand Down Expand Up @@ -275,7 +274,6 @@ fn test_blocks_by_range_single_empty_rpc() {

// BlocksByRange Request
let rpc_request = RPCRequest::BlocksByRange(BlocksByRangeRequest {
head_block_root: Hash256::from_low_u64_be(0),
start_slot: 0,
count: 10,
step: 0,
Expand Down

0 comments on commit 10b68ab

Please sign in to comment.