Skip to content

Commit

Permalink
add a unit test to fix ci.
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan committed Jan 8, 2025
1 parent 6ea367f commit d8101de
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/utilities/type_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,32 @@ pub fn calculate_type_id(input: packed::CellInput, outputs_count: usize) -> [u8;
blake2b.finalize(&mut ret);
ret
}

mod tests {
use super::*;
use ckb_types::packed::CellInput;
use ckb_types::{h256, H256};

#[test]
fn test_calculate_type_id() {
let previous_output = packed::OutPoint::new_builder()
.tx_hash(
h256!("0x806600be4ae8330e8ce3893f208d169684e0b998acf9549c07b9fd5357eb157e").pack(),
)
.index(1u32.pack())
.build();

let input = CellInput::new_builder()
.previous_output(previous_output)
.since(0u64.pack())
.build();
let outputs_count = 33;
let type_id = calculate_type_id(input.clone(), outputs_count);

// Expected value calculated manually or from a trusted source
let expected_type_id: H256 =
h256!("0xac4cd5342895c4861631310f2fd731b8f8c71682577e384b78ca3ee3361ec3a1");

assert_eq!(type_id, expected_type_id.as_bytes());
}
}

0 comments on commit d8101de

Please sign in to comment.