Skip to content

Commit

Permalink
chore(test): Adjust cellbase maturity format
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Oct 8, 2019
1 parent 58abfac commit ac694e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions test/src/specs/mining/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Spec for FeeOfTransaction {
// `block[i + 1 + FINALIZATION_DELAY_LENGTH]`
// 5. Expect that the miner receives the committed reward of `tx` from
// `block[i + 1 + PROPOSAL_WINDOW_CLOSEST + FINALIZATION_DELAY_LENGTH]`
fn run(&self, net: Net) {
fn run(&self, net: &mut Net) {
let node = &net.nodes[0];
let closest = node.consensus().tx_proposal_window().closest();
let finalization_delay_length = node.consensus().finalization_delay_length();
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Spec for FeeOfMaxBlockProposalsLimit {
// 1. Submit `MAX_BLOCK_PROPOSALS_LIMIT` transactions into transactions_pool after height `i`
// 2. Expect that the miner receives the proposed reward of `tx` from
// `block[i + 1 + FINALIZATION_DELAY_LENGTH]`
fn run(&self, net: Net) {
fn run(&self, net: &mut Net) {
let node = &net.nodes[0];
let max_block_proposals_limit = node.consensus().max_block_proposals_limit();
let finalization_delay_length = node.consensus().finalization_delay_length();
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Spec for FeeOfMultipleMaxBlockProposalsLimit {
// 1. Submit `3 * MAX_BLOCK_PROPOSALS_LIMIT` transactions into transactions_pool after height `i`
// 2. Expect that the miner propose those transactions in the next `3` blocks, every block
// contains `MAX_BLOCK_PROPOSALS_LIMIT` transactions
fn run(&self, net: Net) {
fn run(&self, net: &mut Net) {
let node = &net.nodes[0];
let max_block_proposals_limit = node.consensus().max_block_proposals_limit();
let finalization_delay_length = node.consensus().finalization_delay_length();
Expand Down Expand Up @@ -115,7 +115,7 @@ impl Spec for ProposeButNotCommit {
crate::setup!(num_nodes: 2, connect_all: false);

// Case: Propose a transaction but never commit it
fn run(&self, net: Net) {
fn run(&self, net: &mut Net) {
let target_node = &net.nodes[0];
let feed_node = &net.nodes[1];

Expand Down Expand Up @@ -154,7 +154,7 @@ impl Spec for ProposeDuplicated {
crate::name!("propose_duplicated");

// Case: Uncle contains a proposal, and the new block contains the same one.
fn run(&self, net: Net) {
fn run(&self, net: &mut Net) {
let node = &net.nodes[0];
let txs = generate_utxo_set(node, 1).bang_random_fee(vec![node.always_success_cell_dep()]);
let tx = &txs[0];
Expand Down
8 changes: 6 additions & 2 deletions test/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,20 @@ pub fn temp_path() -> String {
pub fn generate_utxo_set(node: &Node, n: usize) -> TXOSet {
// Ensure all the cellbases will be used later are already mature.
let cellbase_maturity = node.consensus().cellbase_maturity();
node.generate_blocks(cellbase_maturity as usize);
node.generate_blocks(cellbase_maturity.index() as usize);

// Explode these mature cellbases into multiple cells
let mut n_outputs = 0;
let mut txs = Vec::new();
while n > n_outputs {
node.generate_block();
let mature_number = node.get_tip_block_number() - cellbase_maturity;
let mature_number = node.get_tip_block_number() - cellbase_maturity.index();
let mature_block = node.get_block_by_number(mature_number);
let mature_cellbase = mature_block.transaction(0).unwrap();
if mature_cellbase.outputs().len() == 0 {
continue;
}

let mature_utxos: TXOSet = TXOSet::from(&mature_cellbase);
let tx = mature_utxos.boom(vec![node.always_success_cell_dep()]);
n_outputs += tx.outputs().len();
Expand Down

0 comments on commit ac694e7

Please sign in to comment.