From 95815db83c8f4e36e42d3ea2e46c67f9f07ceeff Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Sat, 9 Oct 2021 16:10:11 +0800 Subject: [PATCH] test: declared wrong cycles --- test/src/main.rs | 2 + .../specs/tx_pool/declared_wrong_cycles.rs | 67 +++++++++++++++++++ test/src/specs/tx_pool/mod.rs | 2 + 3 files changed, 71 insertions(+) create mode 100644 test/src/specs/tx_pool/declared_wrong_cycles.rs diff --git a/test/src/main.rs b/test/src/main.rs index d85af4983e..9a1269ceb2 100644 --- a/test/src/main.rs +++ b/test/src/main.rs @@ -389,6 +389,8 @@ fn all_specs() -> Vec> { Box::new(BlockTemplates), Box::new(BootstrapCellbase), Box::new(TemplateSizeLimit), + Box::new(DeclaredWrongCycles), + Box::new(DeclaredWrongCyclesChunk), Box::new(OrphanTxAccepted), Box::new(OrphanTxRejected), Box::new(GetRawTxPool), diff --git a/test/src/specs/tx_pool/declared_wrong_cycles.rs b/test/src/specs/tx_pool/declared_wrong_cycles.rs new file mode 100644 index 0000000000..ebdedb2524 --- /dev/null +++ b/test/src/specs/tx_pool/declared_wrong_cycles.rs @@ -0,0 +1,67 @@ +use crate::util::{mining::mine_until_out_bootstrap_period, transaction::relay_tx}; +use crate::utils::wait_until; +use crate::{Net, Node, Spec}; +use ckb_network::SupportProtocols; + +const ALWAYS_SUCCESS_SCRIPT_CYCLE: u64 = 537; + +pub struct DeclaredWrongCycles; + +impl Spec for DeclaredWrongCycles { + crate::setup!(num_nodes: 1); + + fn run(&self, nodes: &mut Vec) { + let node0 = &mut nodes[0]; + mine_until_out_bootstrap_period(node0); + + let mut net = Net::new( + self.name(), + node0.consensus(), + vec![SupportProtocols::Relay], + ); + net.connect(node0); + + let tx = node0.new_transaction_spend_tip_cellbase(); + + relay_tx(&net, &node0, tx, ALWAYS_SUCCESS_SCRIPT_CYCLE + 1); + + let result = wait_until(5, || { + let tx_pool_info = node0.get_tip_tx_pool_info(); + tx_pool_info.orphan.value() == 0 && tx_pool_info.pending.value() == 0 + }); + assert!(result, "Declared wrong cycles should be rejected"); + } +} + +pub struct DeclaredWrongCyclesChunk; + +impl Spec for DeclaredWrongCyclesChunk { + crate::setup!(num_nodes: 1); + + fn run(&self, nodes: &mut Vec) { + let node0 = &mut nodes[0]; + mine_until_out_bootstrap_period(node0); + + let mut net = Net::new( + self.name(), + node0.consensus(), + vec![SupportProtocols::Relay], + ); + net.connect(node0); + + let tx = node0.new_transaction_spend_tip_cellbase(); + + relay_tx(&net, &node0, tx, ALWAYS_SUCCESS_SCRIPT_CYCLE + 1); + + let result = wait_until(5, || { + let tx_pool_info = node0.get_tip_tx_pool_info(); + tx_pool_info.orphan.value() == 0 && tx_pool_info.pending.value() == 0 + }); + assert!(result, "Declared wrong cycles should be rejected"); + } + + fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) { + config.network.connect_outbound_interval_secs = 0; + config.tx_pool.max_tx_verify_cycles = 500; // ALWAYS_SUCCESS_SCRIPT_CYCLE: u64 = 537 + } +} diff --git a/test/src/specs/tx_pool/mod.rs b/test/src/specs/tx_pool/mod.rs index 7e83fda4bb..d8c93901e4 100644 --- a/test/src/specs/tx_pool/mod.rs +++ b/test/src/specs/tx_pool/mod.rs @@ -1,6 +1,7 @@ mod cellbase_maturity; mod collision; mod dead_cell_deps; +mod declared_wrong_cycles; mod depend_tx_in_same_block; mod descendant; mod different_txs_with_same_input; @@ -27,6 +28,7 @@ mod valid_since; pub use cellbase_maturity::*; pub use collision::*; pub use dead_cell_deps::*; +pub use declared_wrong_cycles::*; pub use depend_tx_in_same_block::*; pub use descendant::*; pub use different_txs_with_same_input::*;