Skip to content

Commit

Permalink
Improve the code based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan committed Sep 7, 2023
1 parent 0cca328 commit 8a0ed56
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 5 additions & 5 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3220,9 +3220,7 @@ Response
* `num_epochs`: [`EpochNumberWithFraction`](#type-epochnumberwithfraction)
* result: [`EpochNumberWithFraction`](#type-epochnumberwithfraction)

Generate epochs during development, can be useful for scenarios

like testing DAO-related functionalities.
Generate epochs during development, can be useful for scenarios like testing DAO-related functionalities.

Returns the updated epoch number after generating the specified number of epochs.

Expand All @@ -3234,7 +3232,7 @@ Returns the updated epoch number after generating the specified number of epochs

Request

generating 2 epochs:
Generating 2 epochs:


```
Expand All @@ -3247,7 +3245,9 @@ generating 2 epochs:
```


generating 1/2 epoch:
The input parameter “0x2” will be normalized to “0x10000000002”(the correct [`EpochNumberWithFraction`](#type-epochnumberwithfraction) type) within the method. Therefore, if you want to generate epochs as integers, you can simply pass an integer as long as it does not exceed 16777215 (24 bits).

Generating 1/2 epoch:


```
Expand Down
10 changes: 7 additions & 3 deletions rpc/src/module/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ pub trait IntegrationTestRpc {
fn generate_block(&self) -> Result<H256>;

/// Generate epochs during development, can be useful for scenarios
///
/// like testing DAO-related functionalities.
///
/// Returns the updated epoch number after generating the specified number of epochs.
Expand All @@ -184,7 +183,7 @@ pub trait IntegrationTestRpc {
///
/// Request
///
/// generating 2 epochs:
/// Generating 2 epochs:
///
/// ```json
/// {
Expand All @@ -195,7 +194,12 @@ pub trait IntegrationTestRpc {
/// }
/// ```
///
/// generating 1/2 epoch:
/// The input parameter "0x2" will be normalized to "0x10000000002"(the correct
/// [`EpochNumberWithFraction`](#type-epochnumberwithfraction) type) within the method.
/// Therefore, if you want to generate epochs as integers, you can simply pass an integer
/// as long as it does not exceed 16777215 (24 bits).
///
/// Generating 1/2 epoch:
///
/// ```text
/// {
Expand Down
9 changes: 6 additions & 3 deletions rpc/src/tests/module/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use ckb_store::ChainStore;
use ckb_test_chain_utils::always_success_consensus;
use ckb_types::{
core::{Capacity, EpochNumberWithFraction},
prelude::Unpack,
utilities::DIFF_TWO,
};

Expand Down Expand Up @@ -40,6 +39,10 @@ fn test_generate_epochs() {
method: "generate_epochs".to_string(),
params: vec!["0x10000000001".into()],
});
assert_eq!(
"0x10000000001".to_string(),
Into::<ckb_jsonrpc_types::Uint64>::into(EpochNumberWithFraction::new(1, 0, 1)).to_string(),
);
assert_eq!(
get_current_epoch(&suite),
EpochNumberWithFraction::new(2, 20, GENESIS_EPOCH_LENGTH)
Expand Down Expand Up @@ -104,9 +107,9 @@ fn setup_rpc() -> RpcTestSuite {

fn get_current_epoch(suite: &RpcTestSuite) -> EpochNumberWithFraction {
let store = suite.shared.store();
let tip_block_number = store.get_tip_header().unwrap().data().raw().number();
let tip_block_number = store.get_tip_header().unwrap().number();
store
.get_current_epoch_ext()
.unwrap()
.number_with_fraction(tip_block_number.unpack())
.number_with_fraction(tip_block_number)
}

0 comments on commit 8a0ed56

Please sign in to comment.