Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
fix to since (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan authored Oct 31, 2021
1 parent a789c54 commit 2872c7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/rpc/src/rpc_impl/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ pub fn to_since(config: SinceConfig) -> InnerResult<u64> {
(SinceFlag::Absolute, SinceType::Timestamp) => 0b0100_0000u64,
(SinceFlag::Relative, SinceType::Timestamp) => 0b1100_0000u64,
};
if config.value > 0xffff_ffff_ffffu64 {
if config.value > 0xff_ffff_ffff_ffffu64 {
return Err(RpcErrorMessage::InvalidRpcParams(
"the value in the since config is too large".to_string(),
));
Expand Down
18 changes: 18 additions & 0 deletions core/rpc/src/tests/utils_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use crate::rpc_impl::utils;
use crate::types::{SinceConfig, SinceFlag, SinceType};

use ckb_types::core::EpochNumberWithFraction;

Expand Down Expand Up @@ -103,3 +104,20 @@ async fn test_epoch_number_into_u256() {
let epoch_number: EpochNumberWithFraction = EpochNumberWithFraction::new(0, 3201, 1600);
assert_eq!(epoch_number_rational_u256, epoch_number.to_rational());
}

#[tokio::test]
async fn test_to_since() {
let deposit_epoch = EpochNumberWithFraction::new(2, 648, 1677);
let withdraw_epoch = EpochNumberWithFraction::new(47, 382, 1605);
let unlock_epoch_number = utils::calculate_unlock_epoch_number(
deposit_epoch.full_value(),
withdraw_epoch.full_value(),
);
assert_eq!(0x68d02880000b6u64, unlock_epoch_number);
let since = utils::to_since(SinceConfig {
type_: SinceType::EpochNumber,
flag: SinceFlag::Absolute,
value: unlock_epoch_number,
});
assert_eq!(Ok(0x20068d02880000b6u64), since)
}

0 comments on commit 2872c7e

Please sign in to comment.