From 81fa55ee6cb686386a72addc8ac4373a238bc528 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 4 Mar 2024 16:28:39 +0800 Subject: [PATCH] Use generate_epochs for dao related integration test Signed-off-by: Eval EXEC --- test/src/miner.rs | 12 +++++++++++- test/src/spec/dao.rs | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/src/miner.rs b/test/src/miner.rs index c0bce25b..9c7767f2 100644 --- a/test/src/miner.rs +++ b/test/src/miner.rs @@ -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, @@ -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(|_| { diff --git a/test/src/spec/dao.rs b/test/src/spec/dao.rs index a2717da5..180802ee 100644 --- a/test/src/spec/dao.rs +++ b/test/src/spec/dao.rs @@ -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); @@ -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::>(); @@ -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))