message: refactor: integration test - consensus
diff: use crate::{Net, Spec};
  use ckb_chain_spec::ChainSpec;
  use ckb_types::{
  - core::{capacity_bytes, BlockView, Capacity},
  + core::{capacity_bytes, Capacity},
  packed::CellOutput,
  prelude::*,
  };
  -use log::info;
  use std::convert::Into;
  pub struct InsufficientReward;
  impl Spec for InsufficientReward {
  crate::name!("insufficient_reward");
  + // Case: block which reward is insufficient could not be submitted
  + // 1. submit block with insufficient reward in current epoch should failed;
  + // 2. submit block with empty reward should success.
  fn before_run(&self, net: &mut Net) {
  let node = &net.nodes[0];
  @@ -21,41 +23,53 @@ impl Spec for InsufficientReward {
  .join("insufficient_reward.json")
  .to_string_lossy()
  .to_string();
  - info!("import {}", data_path);
  node.import(data_path);
  - info!("import finished");
  }
  fn run(&self, net: &mut Net) {
  let node = &net.nodes[0];
  - let hash = node.generate_block();
  -
  - let blk: BlockView = node.rpc_client().get_block(hash).unwrap().into();
  - let cellbase = &blk.transactions()[0];
  -
  - assert_eq!(blk.number(), 101);
  - assert!(cellbase.outputs().is_empty());
  + let new_block_builder = node.new_block_builder(None, None, None);
  + // build a block with insufficient reward
  let output = CellOutput::new_builder()
  - .capacity(capacity_bytes!(100).pack())
  + .capacity(capacity_bytes!(1).pack())
  .lock(Default::default())
  .build();
  -
  - let new_builder = node.new_block_builder(None, None, None);
  - let template = new_builder.clone().build();
  - let cellbase = template.transactions()[0]
  + let cellbase = new_block_builder.clone().build().transactions()[0]
  .as_advanced_builder()
  .output(output)
  .build();
  - let new_block = new_builder.set_transactions(vec![cellbase]).build();
  -
  + let new_block = new_block_builder
  + .clone()
  + .set_transactions(vec![cellbase])
  + .build();
  let result = node
  .rpc_client()
  .submit_block("".to_owned(), new_block.data().into());
  - assert!(result
  +
  + assert!(
  + result
  .expect_err("invalid block submit failed")
  .to_string()
  - .contains("Block(Cellbase(InvalidOutputQuantity))"));
  + .contains("Block(Cellbase(InvalidOutputQuantity))"),
  + "Insufficient reward block should be submitted failed, but not"
  + );
  +
  + // build a block with empty reward
  + let new_block = new_block_builder.build();
  + let cellbase = &new_block.transactions()[0];
  + let result = node
  + .rpc_client()
  + .submit_block("".to_owned(), new_block.data().into());
  +
  + assert!(
  + cellbase.outputs().is_empty(),
  + "Cellbase output should be empty"
  + );
  + assert!(
  + result.is_ok(),
  + "Empty reward block should be submitted successfully, but not"
  + )
  }
  // export data
  