Skip to content

Commit

Permalink
test: simple header field json format check
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad committed Oct 10, 2019
1 parent 1633a16 commit e5e9f7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions util/jsonrpc-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ jsonrpc-core = "10.1"
[dev-dependencies]
proptest = "0.9"
regex = "1.1"
lazy_static = "1.3"
12 changes: 12 additions & 0 deletions util/jsonrpc-types/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,9 @@ impl From<core::BlockReward> for BlockReward {
mod tests {
use super::*;
use ckb_types::{bytes::Bytes, core::TransactionBuilder, packed::Byte32};
use lazy_static::lazy_static;
use proptest::{collection::size_range, prelude::*};
use regex::Regex;

fn mock_script(arg: Bytes) -> packed::Script {
packed::ScriptBuilder::default()
Expand Down Expand Up @@ -737,11 +739,21 @@ mod tests {
let encoded = serde_json::to_string(&json_block).unwrap();
let decode: BlockView = serde_json::from_str(&encoded).unwrap();
let decode_block: core::BlockView = decode.into();
header_field_format_check(&encoded);
prop_assert_eq!(decode_block.data(), block.data());
prop_assert_eq!(decode_block, block);
Ok(())
}

fn header_field_format_check(json: &str) {
lazy_static! {
static ref RE: Regex = Regex::new("\"(version|compact_target|parent_hash|timestamp|number|epoch|transactions_root|proposals_hash|uncles_hash|dao|nonce)\":\"(?P<value>.*?\")").unwrap();
}
for caps in RE.captures_iter(json) {
assert!(&caps["value"].starts_with("0x"));
}
}

proptest! {
#[test]
fn test_block_convert(
Expand Down

0 comments on commit e5e9f7d

Please sign in to comment.