From d8b91460c6196cb43ad2515ca7c84f7525dfb56a Mon Sep 17 00:00:00 2001 From: AvivYossef-starkware Date: Mon, 17 Jun 2024 13:26:37 +0300 Subject: [PATCH] build: impl display for fee and contractaddress structs --- src/core.rs | 3 +++ src/core_test.rs | 13 +++++++++++++ src/transaction.rs | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core.rs b/src/core.rs index d3349e0..ab9f375 100644 --- a/src/core.rs +++ b/src/core.rs @@ -84,6 +84,7 @@ pub const BLOCK_HASH_TABLE_ADDRESS: ContractAddress = ContractAddress(PatriciaKe Default, Copy, Clone, + Display, Eq, PartialEq, Hash, @@ -296,6 +297,7 @@ pub struct StateDiffCommitment(pub PoseidonHash); #[derive( Copy, Clone, + Display, Eq, PartialEq, Default, @@ -306,6 +308,7 @@ pub struct StateDiffCommitment(pub PoseidonHash); Ord, derive_more:: Deref, )] +#[display(fmt = "{}", "_0.to_fixed_hex_string()")] pub struct PatriciaKey(StarkHash); // 2**251 diff --git a/src/core_test.rs b/src/core_test.rs index 953a883..543d137 100644 --- a/src/core_test.rs +++ b/src/core_test.rs @@ -81,3 +81,16 @@ fn nonce_overflow() { let overflowed_nonce = max_nonce.try_increment(); assert_matches!(overflowed_nonce, Err(StarknetApiError::OutOfRange { string: _err_str })); } + +#[test] +fn test_patricia_key_display() { + assert_eq!(format!("{}", patricia_key!(7_u8)), String::from("0x") + &"0".repeat(63) + "7"); +} + +#[test] +fn test_contract_address_display() { + assert_eq!( + format!("{}", ContractAddress(patricia_key!(16_u8))), + String::from("0x") + &"0".repeat(62) + "10" + ); +} diff --git a/src/transaction.rs b/src/transaction.rs index ffc0d22..5eb6b1e 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -2,7 +2,7 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::Display; use std::sync::Arc; -use derive_more::From; +use derive_more::{Display, From}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use starknet_types_core::felt::Felt; use strum::IntoEnumIterator; @@ -646,6 +646,7 @@ pub struct RevertedTransactionExecutionStatus { Copy, Clone, Default, + Display, Eq, PartialEq, Hash,