Skip to content

Commit 1dbb107

Browse files
authored
Fix Address20 debug format. (#4453)
## Motivation `AccountOwner::Address20`'s `Debug` impl prints something like: ``` Address20([10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) ``` because the `hex_debug` attribute is in the wrong place. ## Proposal Put the attribute directly on the field, not the enum variant. The `Debug` impl now says: ``` Address20(0a0a0a0a0a0a0a0a..) ``` ## Test Plan Tried it locally. ## Release Plan - Should be backported to testnet and devnet. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 366cf06 commit 1dbb107

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

linera-base/src/identifiers.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,27 @@ use crate::{
3030
};
3131

3232
/// An account owner.
33-
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, WitLoad, WitStore, WitType)]
33+
#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd, WitLoad, WitStore, WitType)]
3434
#[cfg_attr(with_testing, derive(test_strategy::Arbitrary))]
3535
pub enum AccountOwner {
3636
/// Short addresses reserved for the protocol.
3737
Reserved(u8),
3838
/// 32-byte account address.
3939
Address32(CryptoHash),
4040
/// 20-byte account EVM-compatible address.
41-
#[debug(with = "hex_debug")]
4241
Address20([u8; 20]),
4342
}
4443

44+
impl fmt::Debug for AccountOwner {
45+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46+
match self {
47+
Self::Reserved(byte) => f.debug_tuple("Reserved").field(byte).finish(),
48+
Self::Address32(hash) => write!(f, "Address32({:?}..)", hash),
49+
Self::Address20(bytes) => write!(f, "Address20({}..)", hex::encode(&bytes[..8])),
50+
}
51+
}
52+
}
53+
4554
impl AccountOwner {
4655
/// Returns the default chain address.
4756
pub const CHAIN: AccountOwner = AccountOwner::Reserved(0);

linera-base/src/unit_tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,14 @@ fn chain_ownership_test_case() -> ChainOwnership {
155155
},
156156
}
157157
}
158+
159+
#[test]
160+
fn account_owner_debug_format() {
161+
assert_eq!(&format!("{:?}", AccountOwner::Reserved(10)), "Reserved(10)");
162+
let addr32 = AccountOwner::Address32(CryptoHash::from([10u8; 32]));
163+
let debug32 = "Address32(0a0a0a0a0a0a0a0a..)";
164+
assert_eq!(&format!("{addr32:?}"), debug32);
165+
let addr20 = AccountOwner::Address20([10u8; 20]);
166+
let debug20 = "Address20(0a0a0a0a0a0a0a0a..)";
167+
assert_eq!(&format!("{addr20:?}"), debug20);
168+
}

0 commit comments

Comments
 (0)