// Copyright 2020-2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 use core::str::FromStr; use iota_types::block::BlockId; use packable::PackableExt; const BLOCK_ID: &str = "0x52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649"; #[test] fn debug_impl() { assert_eq!( format!("{:?}", BlockId::from_str(BLOCK_ID).unwrap()), "BlockId(0x52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c649)" ); } #[test] fn from_str_valid() { BlockId::from_str(BLOCK_ID).unwrap(); } #[test] fn null() { assert_eq!( format!("{:?}", BlockId::null()), "BlockId(0x0000000000000000000000000000000000000000000000000000000000000000)" ); } #[test] fn from_to_str() { assert_eq!(BLOCK_ID, BlockId::from_str(BLOCK_ID).unwrap().to_string()); } // Validate that the length of a packed `BlockId` matches the declared `packed_len()`. #[test] fn packed_len() { let block_id = BlockId::from_str(BLOCK_ID).unwrap(); assert_eq!(block_id.packed_len(), 32); assert_eq!(block_id.pack_to_vec().len(), 32); } // Validate that a `unpack` ∘ `pack` round-trip results in the original block id. #[test] fn pack_unpack_valid() { let block_id = BlockId::from_str(BLOCK_ID).unwrap(); let packed_block_id = block_id.pack_to_vec(); assert_eq!(packed_block_id.len(), block_id.packed_len()); assert_eq!( block_id, PackableExt::unpack_verified(packed_block_id.as_slice(), &()).unwrap() ); }