diff --git a/linera-base/src/identifiers.rs b/linera-base/src/identifiers.rs index 2b46e5bc26a6..7846240da87b 100644 --- a/linera-base/src/identifiers.rs +++ b/linera-base/src/identifiers.rs @@ -30,7 +30,7 @@ use crate::{ }; /// An account owner. -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, WitLoad, WitStore, WitType)] +#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd, WitLoad, WitStore, WitType)] #[cfg_attr(with_testing, derive(test_strategy::Arbitrary))] pub enum AccountOwner { /// Short addresses reserved for the protocol. @@ -38,10 +38,19 @@ pub enum AccountOwner { /// 32-byte account address. Address32(CryptoHash), /// 20-byte account EVM-compatible address. - #[debug(with = "hex_debug")] Address20([u8; 20]), } +impl fmt::Debug for AccountOwner { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Reserved(byte) => f.debug_tuple("Reserved").field(byte).finish(), + Self::Address32(hash) => write!(f, "Address32({:?}..)", hash), + Self::Address20(bytes) => write!(f, "Address20({}..)", hex::encode(&bytes[..8])), + } + } +} + impl AccountOwner { /// Returns the default chain address. pub const CHAIN: AccountOwner = AccountOwner::Reserved(0); diff --git a/linera-base/src/unit_tests.rs b/linera-base/src/unit_tests.rs index 92962ab8a8fa..4a2d901f9502 100644 --- a/linera-base/src/unit_tests.rs +++ b/linera-base/src/unit_tests.rs @@ -155,3 +155,14 @@ fn chain_ownership_test_case() -> ChainOwnership { }, } } + +#[test] +fn account_owner_debug_format() { + assert_eq!(&format!("{:?}", AccountOwner::Reserved(10)), "Reserved(10)"); + let addr32 = AccountOwner::Address32(CryptoHash::from([10u8; 32])); + let debug32 = "Address32(0a0a0a0a0a0a0a0a..)"; + assert_eq!(&format!("{addr32:?}"), debug32); + let addr20 = AccountOwner::Address20([10u8; 20]); + let debug20 = "Address20(0a0a0a0a0a0a0a0a..)"; + assert_eq!(&format!("{addr20:?}"), debug20); +}