-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77a2769
commit ecc0d7d
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use crate::{Net, Spec, TestProtocol}; | ||
use ckb_sync::NetworkProtocol; | ||
use ckb_types::{ | ||
core::UncleBlockView, | ||
packed::{self, RelayMessage}, | ||
prelude::*, | ||
}; | ||
|
||
pub struct MissingUncleRequest; | ||
|
||
impl Spec for MissingUncleRequest { | ||
crate::name!("missing_uncle_request"); | ||
|
||
crate::setup!(protocols: vec![TestProtocol::sync(), TestProtocol::relay()]); | ||
|
||
// Case: Send to node GetBlockTransactions with missing uncle index, node should response BlockTransactions with uncles | ||
fn run(&self, net: &mut Net) { | ||
net.exit_ibd_mode(); | ||
let node = &net.nodes[0]; | ||
net.connect(node); | ||
let (peer_id, _, _) = net.receive(); | ||
|
||
node.generate_block(); | ||
let _ = net.receive(); | ||
|
||
let builder = node.new_block_builder(None, None, None); | ||
let block1 = builder.clone().nonce(0.pack()).build(); | ||
let block2 = builder.clone().nonce(1.pack()).build(); | ||
node.submit_block(&block1.data()); | ||
node.submit_block(&block2.data()); | ||
|
||
let builder = node.new_block_builder(None, None, None); | ||
let block = builder | ||
.clone() | ||
.set_uncles(vec![block2.as_uncle()]) | ||
.nonce(0.pack()) | ||
.build(); | ||
node.submit_block(&block.data()); | ||
|
||
let content = packed::GetBlockTransactions::new_builder() | ||
.block_hash(block.hash()) | ||
.uncle_indexes(vec![0u32].pack()) | ||
.build(); | ||
let message = packed::RelayMessage::new_builder().set(content).build(); | ||
|
||
(0..3).for_each(|_| { | ||
net.receive(); // ignore three new block announce | ||
}); | ||
|
||
net.send( | ||
NetworkProtocol::RELAY.into(), | ||
peer_id, | ||
message.as_slice().into(), | ||
); | ||
|
||
let (_, _, data) = net.receive(); | ||
let message = RelayMessage::from_slice(&data).unwrap(); | ||
|
||
assert_eq!( | ||
message.to_enum().item_name(), | ||
packed::BlockTransactions::NAME, | ||
"Node should reponse BlockTransactions message", | ||
); | ||
|
||
if let packed::RelayMessageUnionReader::BlockTransactions(reader) = | ||
message.to_enum().as_reader() | ||
{ | ||
let block_transactions = reader.to_entity(); | ||
let received_uncles: Vec<UncleBlockView> = block_transactions | ||
.uncles() | ||
.into_iter() | ||
.map(|uncle| uncle.into_view()) | ||
.collect(); | ||
assert_eq!(received_uncles[0], block2.as_uncle()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
mod block_relay; | ||
mod compact_block; | ||
mod get_block_transactions_process; | ||
mod transaction_relay; | ||
|
||
pub use block_relay::*; | ||
pub use compact_block::*; | ||
pub use get_block_transactions_process::*; | ||
pub use transaction_relay::*; |