Skip to content

Commit

Permalink
Use generate_epochs for dao related integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Mar 4, 2024
1 parent a08c298 commit 81fa55e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion test/src/miner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::util::temp_dir;
use ckb_app_config::BlockAssemblerConfig;
use ckb_jsonrpc_types::{BlockTemplate, ProposalShortId};
use ckb_jsonrpc_types::{BlockTemplate, EpochNumberWithFraction, ProposalShortId};
use ckb_sdk::{Address, AddressPayload, CkbRpcClient, NetworkType};
use ckb_types::{
core::BlockNumber,
Expand Down Expand Up @@ -48,6 +48,16 @@ impl Miner {
.expect("RPC generate_block")
}

pub fn generate_epochs(&self, num_epochs: u64, epoch_length: u64) -> EpochNumberWithFraction {
let epoch_number_with_fraction =
ckb_types::core::EpochNumberWithFraction::new(num_epochs, 0, epoch_length);
self.rpc
.lock()
.unwrap()
.generate_epochs(epoch_number_with_fraction.into())
.expect("RPC generate_epoch")
}

pub fn generate_blocks(&self, count: u64) {
log::info!("generating {} blocks...", count);
(0..count).for_each(|_| {
Expand Down
6 changes: 3 additions & 3 deletions test/src/spec/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Spec for DaoPrepareOne {
// Drive the chain until since mature and then withdraw
setup
.miner()
.generate_blocks(LOCK_PERIOD_EPOCHES * EPOCH_LENGTH);
.generate_epochs(LOCK_PERIOD_EPOCHES, EPOCH_LENGTH);
let out_points = vec![new_out_point(prepare_tx_hash, 0)];
let _withdraw_tx_hash = withdraw(setup, &out_points);
assert_eq!(deposited_capacity(setup), 0);
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Spec for DaoPrepareMultiple {
// Drive the chain until since mature and then withdraw
setup
.miner()
.generate_blocks(LOCK_PERIOD_EPOCHES * EPOCH_LENGTH);
.generate_epochs(LOCK_PERIOD_EPOCHES, EPOCH_LENGTH);
let out_points = (0..shannons.len())
.map(|i| new_out_point(&prepare_tx_hash, i))
.collect::<Vec<_>>();
Expand Down Expand Up @@ -135,7 +135,7 @@ impl Spec for DaoWithdrawMultiple {
// Drive the chain until since mature and then withdraw
setup
.miner()
.generate_blocks(LOCK_PERIOD_EPOCHES * EPOCH_LENGTH);
.generate_epochs(LOCK_PERIOD_EPOCHES, EPOCH_LENGTH);
let out_points = prepare_tx_hashes
.into_iter()
.map(|hash| new_out_point(hash, 0))
Expand Down

0 comments on commit 81fa55e

Please sign in to comment.