Skip to content

Commit

Permalink
Merge pull request #705 from nervosnetwork/quake/more-integration-test
Browse files Browse the repository at this point in the history
test: add transaction_relay_multiple test and fix integration test broken
  • Loading branch information
zhangsoledad committed May 11, 2019
2 parents f93c882 + e9fddd2 commit ff8fd34
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 76 deletions.
1 change: 1 addition & 0 deletions test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bytes = "0.4.12"
crossbeam-channel = "0.3"
flatbuffers = "0.6.0"
regex = "1"
rayon = "1.0"

# Prevent this from interfering with workspaces
[workspace]
Expand Down
2 changes: 2 additions & 0 deletions test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn main() {
"pool_reconcile" => Box::new(PoolReconcile),
"pool_resurrect" => Box::new(PoolResurrect),
"transaction_relay_basic" => Box::new(TransactionRelayBasic),
"transaction_relay_multiple" => Box::new(TransactionRelayMultiple),
"discovery" => Box::new(Discovery),
"disconnect" => Box::new(Disconnect),
"malformed_message" => Box::new(MalformedMessage),
Expand All @@ -49,6 +50,7 @@ fn main() {
Box::new(PoolReconcile),
Box::new(PoolResurrect),
Box::new(TransactionRelayBasic),
Box::new(TransactionRelayMultiple),
Box::new(Discovery),
Box::new(Disconnect),
Box::new(MalformedMessage),
Expand Down
10 changes: 10 additions & 0 deletions test/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,14 @@ impl Node {
self.rewrite_spec(&spec_config_path)?;
Ok(())
}

pub fn assert_tx_pool_size(&self, pending_size: u64, staging_size: u64) {
let tx_pool_info = self
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.pending.0, pending_size);
assert_eq!(tx_pool_info.staging.0, staging_size);
}
}
2 changes: 1 addition & 1 deletion test/src/specs/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mod transaction_relay;

pub use block_relay::BlockRelayBasic;
pub use compact_block::CompactBlockBasic;
pub use transaction_relay::TransactionRelayBasic;
pub use transaction_relay::{TransactionRelayBasic, TransactionRelayMultiple};
78 changes: 78 additions & 0 deletions test/src/specs/relay/transaction_relay.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{sleep, Net, Spec};
use ckb_core::transaction::{CellInput, OutPoint, TransactionBuilder};
use ckb_core::Capacity;
use log::info;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};

pub struct TransactionRelayBasic;

Expand Down Expand Up @@ -39,3 +42,78 @@ impl Spec for TransactionRelayBasic {
.is_none());
}
}

const TXS_NUM: usize = 1000;

pub struct TransactionRelayMultiple;

impl Spec for TransactionRelayMultiple {
fn run(&self, net: Net) {
info!("Running TransactionRelayMultiple");

let node0 = &net.nodes[0];
// generate 1 block on node0, to exit IBD mode.
node0.generate_block();
net.waiting_for_sync(10);

info!("Use generated block's cellbase as tx input");
let tip_block = node0.get_tip_block();
let parent_hash = tip_block.transactions()[0].hash().to_owned();
let temp_transaction = node0.new_transaction(parent_hash);
let mut output = temp_transaction.outputs()[0].clone();
output.capacity = Capacity::shannons(output.capacity.as_u64() / TXS_NUM as u64);
let mut tb = TransactionBuilder::from_transaction(temp_transaction).outputs_clear();
for _ in 0..TXS_NUM {
tb = tb.output(output.clone());
}
let transaction = tb.build();
node0
.rpc_client()
.send_transaction((&transaction).into())
.call()
.expect("rpc call send_transaction failed");
node0.generate_block();
node0.generate_block();
node0.generate_block();
net.waiting_for_sync(10);

info!("Send multiple transactions to node0");
let tx_hash = transaction.hash().to_owned();
transaction
.outputs()
.par_iter()
.enumerate()
.for_each(|(i, output)| {
let tx = TransactionBuilder::default()
.dep(transaction.deps()[0].clone())
.output(output.clone())
.input(CellInput::new(
OutPoint::new_cell(tx_hash.clone(), i as u32),
0,
vec![],
))
.build();
node0
.rpc_client()
.send_transaction((&tx).into())
.call()
.expect("rpc call send_transaction failed");
});

node0.generate_block();
node0.generate_block();
node0.generate_block();
net.waiting_for_sync(10);

info!("All transactions should be relayed and mined");
node0.assert_tx_pool_size(0, 0);

net.nodes
.iter()
.for_each(|node| assert_eq!(node.get_tip_block().transactions().len(), TXS_NUM + 1));
}

fn num_nodes(&self) -> usize {
5
}
}
21 changes: 3 additions & 18 deletions test/src/specs/tx_pool/cellbase_maturity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,16 @@ impl Spec for CellbaseMaturity {
.call()
.unwrap();
assert_eq!(tx_hash, tx.hash().to_owned());
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.pending, 1);
node.assert_tx_pool_size(1, 0);

info!("Tx will be added to staging pool in N + {} block", MATURITY);
(0..DEFAULT_TX_PROPOSAL_WINDOW.0).for_each(|_| {
node.generate_block();
});
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.staging, 1);

node.assert_tx_pool_size(0, 1);
node.generate_block();
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.staging, 0);
node.assert_tx_pool_size(0, 0);
}

fn num_nodes(&self) -> usize {
Expand Down
24 changes: 3 additions & 21 deletions test/src/specs/tx_pool/pool_resurrect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,16 @@ impl Spec for PoolResurrect {
net.waiting_for_sync(10);

info!("6 txs should be returned to node0 pending pool");
let tx_pool_info = node0
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.pending.0, txs_hash.len() as u64);
assert_eq!(tx_pool_info.staging.0, 0);
node0.assert_tx_pool_size(txs_hash.len() as u64, 0);

info!("Generate 2 blocks on node0, 6 txs should be added to staging pool");
node0.generate_block();
node0.generate_block();
let tx_pool_info = node0
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.pending.0, 0);
assert_eq!(tx_pool_info.staging.0, txs_hash.len() as u64);
node0.assert_tx_pool_size(0, txs_hash.len() as u64);

info!("Generate 1 block on node0, 6 txs should be included in this block");
node0.generate_block();
let tx_pool_info = node0
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.pending.0, 0);
assert_eq!(tx_pool_info.staging.0, 0);
node0.assert_tx_pool_size(0, 0);
}

fn num_nodes(&self) -> usize {
Expand Down
42 changes: 6 additions & 36 deletions test/src/specs/tx_pool/valid_since.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ impl Spec for ValidSince {
.call()
.unwrap();
assert_eq!(tx_hash, tx.hash().to_owned());
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.pending, 1);
node.assert_tx_pool_size(1, 0);

info!(
"Tx will be added to staging pool in N + {} block",
Expand All @@ -56,20 +51,10 @@ impl Spec for ValidSince {
(0..DEFAULT_TX_PROPOSAL_WINDOW.0).for_each(|_| {
node.generate_block();
});
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.staging, 1);
node.assert_tx_pool_size(0, 1);

node.generate_block();
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.staging, 0);
node.assert_tx_pool_size(0, 0);

// test absolute block number since
let tip_number: BlockNumber = node
Expand Down Expand Up @@ -110,12 +95,7 @@ impl Spec for ValidSince {
.call()
.unwrap();
assert_eq!(tx_hash, tx.hash().to_owned());
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.pending, 1);
node.assert_tx_pool_size(1, 0);

info!(
"Tx will be added to staging pool in {} block",
Expand All @@ -124,20 +104,10 @@ impl Spec for ValidSince {
(0..DEFAULT_TX_PROPOSAL_WINDOW.0).for_each(|_| {
node.generate_block();
});
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.staging, 1);
node.assert_tx_pool_size(0, 1);

node.generate_block();
let tx_pool_info = node
.rpc_client()
.tx_pool_info()
.call()
.expect("rpc call tx_pool_info failed");
assert_eq!(tx_pool_info.staging, 0);
node.assert_tx_pool_size(0, 0);
}

fn num_nodes(&self) -> usize {
Expand Down

0 comments on commit ff8fd34

Please sign in to comment.