From 24b18b95931c130f59c54e32581dfcf6d2b49542 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Mon, 1 Sep 2025 10:20:30 +0200 Subject: [PATCH 1/3] Fix Address20 debug format. --- linera-base/src/identifiers.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linera-base/src/identifiers.rs b/linera-base/src/identifiers.rs index 2b46e5bc26a6..11d285a79d28 100644 --- a/linera-base/src/identifiers.rs +++ b/linera-base/src/identifiers.rs @@ -38,8 +38,7 @@ pub enum AccountOwner { /// 32-byte account address. Address32(CryptoHash), /// 20-byte account EVM-compatible address. - #[debug(with = "hex_debug")] - Address20([u8; 20]), + Address20(#[debug(with = "hex_debug")] [u8; 20]), } impl AccountOwner { From c0f846965167a0d1cfff35217ca28460eaaa5960 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Mon, 1 Sep 2025 11:52:17 +0200 Subject: [PATCH 2/3] Add a test; print full hash by default. --- linera-base/src/crypto/hash.rs | 2 +- linera-base/src/unit_tests.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/linera-base/src/crypto/hash.rs b/linera-base/src/crypto/hash.rs index 3e614091bee2..8e4c0e317f61 100644 --- a/linera-base/src/crypto/hash.rs +++ b/linera-base/src/crypto/hash.rs @@ -168,7 +168,7 @@ impl fmt::Display for CryptoHash { impl fmt::Debug for CryptoHash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", hex::encode(&self.0[..8])) + fmt::Display::fmt(self, f) } } diff --git a/linera-base/src/unit_tests.rs b/linera-base/src/unit_tests.rs index 92962ab8a8fa..5965ce9c6ae1 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(0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a)"; + assert_eq!(&format!("{addr32:?}"), debug32); + let addr20 = AccountOwner::Address20([10u8; 20]); + let debug20 = "Address20(0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a)"; + assert_eq!(&format!("{addr20:?}"), debug20); +} From e0abfd04f29e6986313b9add6f246434721453c1 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Mon, 1 Sep 2025 16:43:32 +0200 Subject: [PATCH 3/3] Limit both variants to 8 bytes. --- linera-base/src/crypto/hash.rs | 2 +- linera-base/src/identifiers.rs | 14 ++++++++++++-- linera-base/src/unit_tests.rs | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/linera-base/src/crypto/hash.rs b/linera-base/src/crypto/hash.rs index 8e4c0e317f61..3e614091bee2 100644 --- a/linera-base/src/crypto/hash.rs +++ b/linera-base/src/crypto/hash.rs @@ -168,7 +168,7 @@ impl fmt::Display for CryptoHash { impl fmt::Debug for CryptoHash { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self, f) + write!(f, "{}", hex::encode(&self.0[..8])) } } diff --git a/linera-base/src/identifiers.rs b/linera-base/src/identifiers.rs index 11d285a79d28..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,7 +38,17 @@ pub enum AccountOwner { /// 32-byte account address. Address32(CryptoHash), /// 20-byte account EVM-compatible address. - Address20(#[debug(with = "hex_debug")] [u8; 20]), + 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 { diff --git a/linera-base/src/unit_tests.rs b/linera-base/src/unit_tests.rs index 5965ce9c6ae1..4a2d901f9502 100644 --- a/linera-base/src/unit_tests.rs +++ b/linera-base/src/unit_tests.rs @@ -160,9 +160,9 @@ fn chain_ownership_test_case() -> ChainOwnership { fn account_owner_debug_format() { assert_eq!(&format!("{:?}", AccountOwner::Reserved(10)), "Reserved(10)"); let addr32 = AccountOwner::Address32(CryptoHash::from([10u8; 32])); - let debug32 = "Address32(0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a)"; + let debug32 = "Address32(0a0a0a0a0a0a0a0a..)"; assert_eq!(&format!("{addr32:?}"), debug32); let addr20 = AccountOwner::Address20([10u8; 20]); - let debug20 = "Address20(0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a)"; + let debug20 = "Address20(0a0a0a0a0a0a0a0a..)"; assert_eq!(&format!("{addr20:?}"), debug20); }