Skip to content

Commit

Permalink
test: declared wrong cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad committed Oct 9, 2021
1 parent 1a95cbc commit 9c4d129
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ fn all_specs() -> Vec<Box<dyn Spec>> {
Box::new(BlockTemplates),
Box::new(BootstrapCellbase),
Box::new(TemplateSizeLimit),
Box::new(DeclaredWrongCycles),
Box::new(OrphanTxAccepted),
Box::new(OrphanTxRejected),
Box::new(GetRawTxPool),
Expand Down
34 changes: 34 additions & 0 deletions test/src/specs/tx_pool/declared_wrong_cycles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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<Node>) {
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");
}
}
2 changes: 2 additions & 0 deletions test/src/specs/tx_pool/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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::*;
Expand Down
5 changes: 5 additions & 0 deletions test/src/specs/tx_pool/send_large_cycles_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ impl Spec for RelayWithWrongTx {
ret,
"The address of net should be removed from node0's peers",
);
let ret = wait_until(5, || {
let tx_pool_info = node0.get_tip_tx_pool_info();
tx_pool_info.pending.value() == 0
});
assert!(ret, "Declared wrong cycles should be rejected",);
}

fn modify_app_config(&self, config: &mut ckb_app_config::CKBAppConfig) {
Expand Down

0 comments on commit 9c4d129

Please sign in to comment.