Skip to main content

foundry_common_fmt/
ui.rs

1//! Helper trait and functions to format Ethereum types.
2
3use crate::configurable_account::ConfigurableAccountSignatureDetails;
4use alloy_consensus::{
5    BlockHeader, Eip658Value, Signed, Transaction as TxTrait, TxEip1559, TxEip2930, TxEip4844,
6    TxEip4844Variant, TxEip7702, TxEnvelope, TxLegacy, TxReceipt, Typed2718,
7    transaction::TxHashRef,
8};
9use alloy_eips::eip7702::SignedAuthorization;
10use alloy_network::{
11    AnyRpcBlock, AnyRpcHeader, AnyRpcTransaction, AnyTransactionReceipt, AnyTxEnvelope,
12    BlockResponse, Network, ReceiptResponse, primitives::HeaderResponse,
13};
14use alloy_primitives::{
15    Address, Bloom, Bytes, FixedBytes, I256, Signature, U8, U64, U256, Uint, hex,
16};
17use alloy_rpc_types::{
18    AccessListItem, Block, BlockTransactions, Header, Log, Transaction, TransactionReceipt,
19};
20use alloy_serde::{OtherFields, WithOtherFields};
21use serde::{Deserialize, Serialize};
22use std::num::NonZeroU64;
23use tempo_alloy::{
24    primitives::{
25        AASigned, TempoSignature, TempoTransaction, TempoTxEnvelope,
26        transaction::{Call, PrimitiveSignature},
27    },
28    rpc::{TempoHeaderResponse, TempoTransactionReceipt},
29};
30
31#[cfg(feature = "base")]
32use base_common_consensus::{
33    BaseReceipt, BaseTxEnvelope, TxBaseSigned, TxDeposit as BaseTxDeposit,
34};
35#[cfg(feature = "base")]
36use base_common_rpc_types::{BaseTransactionReceipt, Transaction as BaseRpcTransaction};
37
38#[cfg(feature = "optimism")]
39use op_alloy_consensus::{OpTxEnvelope, TxDeposit, TxPostExec};
40
41/// length of the name column for pretty formatting `{:>20}{value}`
42const NAME_COLUMN_LEN: usize = 20usize;
43
44/// Helper trait to format Ethereum types.
45///
46/// # Examples
47///
48/// ```
49/// use foundry_common_fmt::UIfmt;
50///
51/// let boolean: bool = true;
52/// let string = boolean.pretty();
53/// ```
54pub trait UIfmt {
55    /// Return a prettified string version of the value
56    fn pretty(&self) -> String;
57}
58
59impl<T: UIfmt> UIfmt for &T {
60    fn pretty(&self) -> String {
61        (*self).pretty()
62    }
63}
64
65impl<T: UIfmt> UIfmt for Option<T> {
66    fn pretty(&self) -> String {
67        if let Some(inner) = self { inner.pretty() } else { String::new() }
68    }
69}
70
71impl<T: UIfmt> UIfmt for [T] {
72    fn pretty(&self) -> String {
73        if self.is_empty() {
74            "[]".to_string()
75        } else {
76            let mut s = String::with_capacity(self.len() * 64);
77            s.push_str("[\n");
78            for item in self {
79                for line in item.pretty().lines() {
80                    s.push('\t');
81                    s.push_str(line);
82                    s.push('\n');
83                }
84            }
85            s.push(']');
86            s
87        }
88    }
89}
90
91impl UIfmt for String {
92    fn pretty(&self) -> String {
93        self.clone()
94    }
95}
96
97impl UIfmt for u64 {
98    fn pretty(&self) -> String {
99        self.to_string()
100    }
101}
102
103impl UIfmt for NonZeroU64 {
104    fn pretty(&self) -> String {
105        self.get().pretty()
106    }
107}
108
109impl UIfmt for u128 {
110    fn pretty(&self) -> String {
111        self.to_string()
112    }
113}
114
115impl UIfmt for bool {
116    fn pretty(&self) -> String {
117        self.to_string()
118    }
119}
120
121impl<const BITS: usize, const LIMBS: usize> UIfmt for Uint<BITS, LIMBS> {
122    fn pretty(&self) -> String {
123        self.to_string()
124    }
125}
126
127impl UIfmt for I256 {
128    fn pretty(&self) -> String {
129        self.to_string()
130    }
131}
132
133impl UIfmt for Address {
134    fn pretty(&self) -> String {
135        self.to_string()
136    }
137}
138
139impl UIfmt for Bloom {
140    fn pretty(&self) -> String {
141        self.to_string()
142    }
143}
144
145impl UIfmt for Vec<u8> {
146    fn pretty(&self) -> String {
147        self[..].pretty()
148    }
149}
150
151impl UIfmt for Bytes {
152    fn pretty(&self) -> String {
153        self[..].pretty()
154    }
155}
156
157impl<const N: usize> UIfmt for [u8; N] {
158    fn pretty(&self) -> String {
159        self[..].pretty()
160    }
161}
162
163impl<const N: usize> UIfmt for FixedBytes<N> {
164    fn pretty(&self) -> String {
165        self[..].pretty()
166    }
167}
168
169impl UIfmt for [u8] {
170    fn pretty(&self) -> String {
171        hex::encode_prefixed(self)
172    }
173}
174
175impl UIfmt for Eip658Value {
176    fn pretty(&self) -> String {
177        match self {
178            Self::Eip658(status) => if *status { "1 (success)" } else { "0 (failed)" }.to_string(),
179            Self::PostState(state) => state.pretty(),
180        }
181    }
182}
183
184impl UIfmt for Signature {
185    fn pretty(&self) -> String {
186        format!("[r: {}, s: {}, y_parity: {}]", self.r(), self.s(), self.v())
187    }
188}
189
190/// Pretty-prints the common fields of any `TransactionReceipt<T>`.
191fn pretty_receipt<T: TxReceipt>(receipt: &TransactionReceipt<T>, tx_type: u8) -> String
192where
193    T::Log: Serialize,
194{
195    let mut pretty = format!(
196        "
197blockHash            {}
198blockNumber          {}
199contractAddress      {}
200cumulativeGasUsed    {}
201effectiveGasPrice    {}
202from                 {}
203gasUsed              {}
204logs                 {}
205logsBloom            {}
206root                 {}
207status               {}
208transactionHash      {}
209transactionIndex     {}
210type                 {}
211blobGasPrice         {}
212blobGasUsed          {}",
213        receipt.block_hash.pretty(),
214        receipt.block_number.pretty(),
215        receipt.contract_address.pretty(),
216        receipt.inner.cumulative_gas_used().pretty(),
217        receipt.effective_gas_price.pretty(),
218        receipt.from.pretty(),
219        receipt.gas_used.pretty(),
220        serde_json::to_string(receipt.inner.logs()).unwrap(),
221        receipt.inner.bloom().pretty(),
222        receipt.inner.status_or_post_state().as_post_state().pretty(),
223        receipt.inner.status_or_post_state().pretty(),
224        receipt.transaction_hash.pretty(),
225        receipt.transaction_index.pretty(),
226        tx_type,
227        receipt.blob_gas_price.pretty(),
228        receipt.blob_gas_used.pretty()
229    );
230
231    if let Some(to) = receipt.to {
232        pretty.push_str(&format!("\nto                   {}", to.pretty()));
233    }
234
235    pretty
236}
237
238impl UIfmt for TransactionReceipt {
239    fn pretty(&self) -> String {
240        pretty_receipt(self, self.transaction_type() as u8)
241    }
242}
243
244#[cfg(feature = "base")]
245impl UIfmt for BaseTransactionReceipt {
246    fn pretty(&self) -> String {
247        let (deposit_nonce, deposit_receipt_version) = match &self.inner.inner.receipt {
248            BaseReceipt::Deposit(receipt) => {
249                (receipt.deposit_nonce, receipt.deposit_receipt_version)
250            }
251            _ => (None, None),
252        };
253        format!(
254            "{}
255l1GasPrice           {}
256l1GasUsed            {}
257l1Fee                {}
258l1FeeScalar          {}
259l1BaseFeeScalar      {}
260l1BlobBaseFee        {}
261l1BlobBaseFeeScalar  {}
262operatorFeeScalar    {}
263operatorFeeConstant  {}
264daFootprintGasScalar {}
265depositNonce         {}
266depositReceiptVersion {}
267payer                {}
268phaseStatuses        {}
269metadata             {}",
270            pretty_receipt(&self.inner, self.inner.inner.receipt.tx_type() as u8).trim_end(),
271            self.l1_block_info.l1_gas_price.pretty(),
272            self.l1_block_info.l1_gas_used.pretty(),
273            self.l1_block_info.l1_fee.pretty(),
274            self.l1_block_info.l1_fee_scalar.map(|value| value.to_string()).unwrap_or_default(),
275            self.l1_block_info.l1_base_fee_scalar.pretty(),
276            self.l1_block_info.l1_blob_base_fee.pretty(),
277            self.l1_block_info.l1_blob_base_fee_scalar.pretty(),
278            self.l1_block_info.operator_fee_scalar.pretty(),
279            self.l1_block_info.operator_fee_constant.pretty(),
280            self.l1_block_info
281                .da_footprint_gas_scalar
282                .map(|value| value.to_string())
283                .unwrap_or_default(),
284            deposit_nonce.pretty(),
285            deposit_receipt_version.pretty(),
286            self.payer.pretty(),
287            self.phase_statuses.pretty(),
288            self.metadata.pretty(),
289        )
290    }
291}
292
293impl UIfmt for AnyTransactionReceipt {
294    fn pretty(&self) -> String {
295        let mut pretty = pretty_receipt(&self.inner, self.inner.inner.r#type);
296        pretty.push_str(&self.other.pretty());
297        pretty
298    }
299}
300
301impl UIfmt for Log {
302    fn pretty(&self) -> String {
303        format!(
304            "
305address: {}
306blockHash: {}
307blockNumber: {}
308data: {}
309logIndex: {}
310removed: {}
311topics: {}
312transactionHash: {}
313transactionIndex: {}",
314            self.address().pretty(),
315            self.block_hash.pretty(),
316            self.block_number.pretty(),
317            self.data().data.pretty(),
318            self.log_index.pretty(),
319            self.removed.pretty(),
320            self.topics().pretty(),
321            self.transaction_hash.pretty(),
322            self.transaction_index.pretty(),
323        )
324    }
325}
326
327impl<T: UIfmt, H: HeaderResponse + UIfmtHeaderExt> UIfmt for Block<T, H> {
328    fn pretty(&self) -> String {
329        format!(
330            "
331{}
332transactions:        {}",
333            pretty_generic_header_response(&self.header),
334            self.transactions.pretty()
335        )
336    }
337}
338
339impl<T: UIfmt> UIfmt for BlockTransactions<T> {
340    fn pretty(&self) -> String {
341        match self {
342            Self::Hashes(hashes) => hashes.pretty(),
343            Self::Full(transactions) => transactions.pretty(),
344            Self::Uncle => String::new(),
345        }
346    }
347}
348
349impl UIfmt for OtherFields {
350    fn pretty(&self) -> String {
351        let mut s = String::with_capacity(self.len() * 30);
352        if !self.is_empty() {
353            s.push('\n');
354        }
355        for (key, value) in self {
356            let val = EthValue::from(value.clone()).pretty();
357            let offset = NAME_COLUMN_LEN.saturating_sub(key.len());
358            s.push_str(key);
359            s.extend(std::iter::repeat_n(' ', offset + 1));
360            s.push_str(&val);
361            s.push('\n');
362        }
363        s
364    }
365}
366
367impl UIfmt for AccessListItem {
368    fn pretty(&self) -> String {
369        let mut s = String::with_capacity(42 + self.storage_keys.len() * 66);
370        s.push_str(self.address.pretty().as_str());
371        s.push_str(" => ");
372        s.push_str(self.storage_keys.pretty().as_str());
373        s
374    }
375}
376
377impl UIfmt for TxLegacy {
378    fn pretty(&self) -> String {
379        format!(
380            "
381chainId              {}
382nonce                {}
383gasPrice             {}
384gasLimit             {}
385to                   {}
386value                {}
387input                {}",
388            self.chain_id.pretty(),
389            self.nonce.pretty(),
390            self.gas_price.pretty(),
391            self.gas_limit.pretty(),
392            self.to().pretty(),
393            self.value.pretty(),
394            self.input.pretty(),
395        )
396    }
397}
398
399impl UIfmt for TxEip2930 {
400    fn pretty(&self) -> String {
401        format!(
402            "
403chainId              {}
404nonce                {}
405gasPrice             {}
406gasLimit             {}
407to                   {}
408value                {}
409accessList           {}
410input                {}",
411            self.chain_id.pretty(),
412            self.nonce.pretty(),
413            self.gas_price.pretty(),
414            self.gas_limit.pretty(),
415            self.to().pretty(),
416            self.value.pretty(),
417            self.access_list.pretty(),
418            self.input.pretty(),
419        )
420    }
421}
422
423impl UIfmt for TxEip1559 {
424    fn pretty(&self) -> String {
425        format!(
426            "
427chainId              {}
428nonce                {}
429gasLimit             {}
430maxFeePerGas         {}
431maxPriorityFeePerGas {}
432to                   {}
433value                {}
434accessList           {}
435input                {}",
436            self.chain_id.pretty(),
437            self.nonce.pretty(),
438            self.gas_limit.pretty(),
439            self.max_fee_per_gas.pretty(),
440            self.max_priority_fee_per_gas.pretty(),
441            self.to().pretty(),
442            self.value.pretty(),
443            self.access_list.pretty(),
444            self.input.pretty(),
445        )
446    }
447}
448
449impl UIfmt for TxEip4844Variant {
450    fn pretty(&self) -> String {
451        let tx: &TxEip4844 = match self {
452            Self::TxEip4844(tx) => tx,
453            Self::TxEip4844WithSidecar(tx) => tx.tx(),
454        };
455        format!(
456            "
457chainId              {}
458nonce                {}
459gasLimit             {}
460maxFeePerGas         {}
461maxPriorityFeePerGas {}
462to                   {}
463value                {}
464accessList           {}
465blobVersionedHashes  {}
466maxFeePerBlobGas     {}
467input                {}",
468            tx.chain_id.pretty(),
469            tx.nonce.pretty(),
470            tx.gas_limit.pretty(),
471            tx.max_fee_per_gas.pretty(),
472            tx.max_priority_fee_per_gas.pretty(),
473            tx.to.pretty(),
474            tx.value.pretty(),
475            tx.access_list.pretty(),
476            tx.blob_versioned_hashes.pretty(),
477            tx.max_fee_per_blob_gas.pretty(),
478            tx.input.pretty(),
479        )
480    }
481}
482
483impl UIfmt for TxEip7702 {
484    fn pretty(&self) -> String {
485        format!(
486            "
487chainId              {}
488nonce                {}
489gasLimit             {}
490maxFeePerGas         {}
491maxPriorityFeePerGas {}
492to                   {}
493value                {}
494accessList           {}
495authorizationList    {}
496input                {}",
497            self.chain_id.pretty(),
498            self.nonce.pretty(),
499            self.gas_limit.pretty(),
500            self.max_fee_per_gas.pretty(),
501            self.max_priority_fee_per_gas.pretty(),
502            self.to.pretty(),
503            self.value.pretty(),
504            self.access_list.pretty(),
505            self.authorization_list.pretty(),
506            self.input.pretty(),
507        )
508    }
509}
510
511#[cfg(feature = "optimism")]
512impl UIfmt for TxDeposit {
513    fn pretty(&self) -> String {
514        format!(
515            "
516sourceHash           {}
517from                 {}
518to                   {}
519mint                 {}
520value                {}
521gasLimit             {}
522isSystemTransaction  {}
523input                {}",
524            self.source_hash.pretty(),
525            self.from.pretty(),
526            self.to().pretty(),
527            self.mint.pretty(),
528            self.value.pretty(),
529            self.gas_limit.pretty(),
530            self.is_system_transaction,
531            self.input.pretty(),
532        )
533    }
534}
535
536#[cfg(feature = "base")]
537impl UIfmt for BaseTxDeposit {
538    fn pretty(&self) -> String {
539        format!(
540            "
541sourceHash           {}
542from                 {}
543to                   {}
544mint                 {}
545value                {}
546gasLimit             {}
547isSystemTransaction  {}
548input                {}",
549            self.source_hash.pretty(),
550            self.from.pretty(),
551            self.to().pretty(),
552            self.mint.pretty(),
553            self.value.pretty(),
554            self.gas_limit.pretty(),
555            self.is_system_transaction,
556            self.input.pretty(),
557        )
558    }
559}
560
561#[cfg(feature = "base")]
562impl UIfmt for TxBaseSigned {
563    fn pretty(&self) -> String {
564        let tx = self.tx();
565        // `calls` is grouped into phases, and `accountChanges` can be long, so both are summarized
566        // by count rather than dumped inline.
567        format!(
568            "
569chainId              {}
570sender               {}
571payer                {}
572nonceKey             {}
573nonceSequence        {}
574validAfter           {}
575validBefore          {}
576maxFeePerGas         {}
577maxPriorityFeePerGas {}
578gasLimit             {}
579accountChanges       {}
580callPhases           {}
581calls                {}
582metadata             {}
583senderAuth           {}
584payerAuth            {}",
585            tx.chain_id.pretty(),
586            tx.sender.pretty(),
587            tx.payer.pretty(),
588            tx.nonce_key.pretty(),
589            tx.nonce_sequence.pretty(),
590            tx.valid_after.pretty(),
591            tx.valid_before.pretty(),
592            tx.max_fee_per_gas.pretty(),
593            tx.max_priority_fee_per_gas.pretty(),
594            tx.gas_limit.pretty(),
595            tx.account_changes.len(),
596            tx.calls.len(),
597            tx.calls.iter().map(Vec::len).sum::<usize>(),
598            tx.metadata.pretty(),
599            self.sender_auth().pretty(),
600            self.payer_auth().pretty(),
601        )
602    }
603}
604
605#[cfg(feature = "optimism")]
606impl UIfmt for TxPostExec {
607    fn pretty(&self) -> String {
608        format!(
609            "
610blockNumber          {}
611gasRefundEntries     {:?}
612input                {}",
613            self.payload.block_number.pretty(),
614            self.payload.gas_refund_entries,
615            self.input.pretty(),
616        )
617    }
618}
619
620impl UIfmt for Call {
621    fn pretty(&self) -> String {
622        format!(
623            "to: {}, value: {}, input: {}",
624            self.to.into_to().pretty(),
625            self.value.pretty(),
626            self.input.pretty(),
627        )
628    }
629}
630
631impl UIfmt for TempoTransaction {
632    fn pretty(&self) -> String {
633        format!(
634            "
635chainId              {}
636feeToken             {}
637maxPriorityFeePerGas {}
638maxFeePerGas         {}
639gasLimit             {}
640calls                {}
641accessList           {}
642nonceKey             {}
643nonce                {}
644feePayerSignature    {}
645validBefore          {}
646validAfter           {}",
647            self.chain_id.pretty(),
648            self.fee_token.pretty(),
649            self.max_priority_fee_per_gas.pretty(),
650            self.max_fee_per_gas.pretty(),
651            self.gas_limit.pretty(),
652            self.calls.pretty(),
653            self.access_list.pretty(),
654            self.nonce_key.pretty(),
655            self.nonce.pretty(),
656            self.fee_payer_signature.pretty(),
657            self.valid_before.pretty(),
658            self.valid_after.pretty(),
659        )
660    }
661}
662
663impl UIfmt for TempoSignature {
664    fn pretty(&self) -> String {
665        serde_json::to_string(self).unwrap_or_default()
666    }
667}
668
669impl UIfmt for AASigned {
670    fn pretty(&self) -> String {
671        // A configurable account signature serializes as its opaque RLP encoding, so it is shown
672        // decoded instead.
673        let signature =
674            match ConfigurableAccountSignatureDetails::from_tx(self.tx(), self.signature()) {
675                Some(details) => details.pretty(),
676                None => self.signature().pretty(),
677            };
678        format!(
679            "
680hash                 {}
681type                 {}
682{}
683tempoSignature       {}",
684            self.hash().pretty(),
685            self.tx().ty(),
686            self.tx().pretty().trim_start(),
687            signature,
688        )
689    }
690}
691
692impl<T: UIfmt + Typed2718> UIfmt for Signed<T>
693where
694    Self: TxHashRef,
695{
696    fn pretty(&self) -> String {
697        format!(
698            "
699hash                 {}
700type                 {}
701{}
702r                    {}
703s                    {}
704yParity              {}",
705            self.tx_hash().pretty(),
706            self.ty(),
707            self.tx().pretty().trim_start(),
708            FixedBytes::from(self.signature().r()).pretty(),
709            FixedBytes::from(self.signature().s()).pretty(),
710            (if self.signature().v() { 1u64 } else { 0 }).pretty(),
711        )
712    }
713}
714
715impl UIfmt for TxEnvelope {
716    fn pretty(&self) -> String {
717        match self {
718            Self::Legacy(tx) => tx.pretty(),
719            Self::Eip2930(tx) => tx.pretty(),
720            Self::Eip1559(tx) => tx.pretty(),
721            Self::Eip4844(tx) => tx.pretty(),
722            Self::Eip7702(tx) => tx.pretty(),
723        }
724    }
725}
726
727#[cfg(feature = "base")]
728impl UIfmt for BaseTxEnvelope {
729    fn pretty(&self) -> String {
730        match self {
731            Self::Legacy(tx) => tx.pretty(),
732            Self::Eip2930(tx) => tx.pretty(),
733            Self::Eip1559(tx) => tx.pretty(),
734            Self::Eip7702(tx) => tx.pretty(),
735            Self::Deposit(tx) => tx.inner().pretty(),
736            Self::Base(tx) => tx.pretty(),
737        }
738    }
739}
740
741impl UIfmt for AnyTxEnvelope {
742    fn pretty(&self) -> String {
743        match self {
744            Self::Ethereum(envelop) => envelop.pretty(),
745            Self::Unknown(tx) => {
746                // Tempo transactions reach here when not fetched as Tempo, with their
747                // configurable account signature as opaque RLP among the fields.
748                let details = serde_json::to_value(tx.inner.fields())
749                    .ok()
750                    .and_then(|fields| ConfigurableAccountSignatureDetails::from_json(&fields));
751                let mut fields = tx.inner.fields().clone();
752                if details.is_some() {
753                    fields.remove("signature");
754                }
755                format!(
756                    "
757hash                 {}
758type               {:#x}
759{}{}
760                    ",
761                    tx.hash.pretty(),
762                    tx.ty(),
763                    fields.pretty().trim_start(),
764                    details
765                        .map(|details| format!("tempoSignature       {}\n", details.pretty()))
766                        .unwrap_or_default(),
767                )
768            }
769        }
770    }
771}
772
773#[cfg(feature = "optimism")]
774impl UIfmt for OpTxEnvelope {
775    fn pretty(&self) -> String {
776        match self {
777            Self::Legacy(tx) => tx.pretty(),
778            Self::Eip2930(tx) => tx.pretty(),
779            Self::Eip1559(tx) => tx.pretty(),
780            Self::Eip7702(tx) => tx.pretty(),
781            Self::Deposit(tx) => tx.pretty(),
782            Self::PostExec(tx) => tx.pretty(),
783        }
784    }
785}
786
787impl UIfmt for TempoTxEnvelope {
788    fn pretty(&self) -> String {
789        match self {
790            Self::Legacy(tx) => tx.pretty(),
791            Self::Eip2930(tx) => tx.pretty(),
792            Self::Eip1559(tx) => tx.pretty(),
793            Self::Eip7702(tx) => tx.pretty(),
794            Self::AA(tx) => tx.pretty(),
795        }
796    }
797}
798
799impl<T: UIfmt> UIfmt for Transaction<T> {
800    fn pretty(&self) -> String {
801        format!(
802            "
803blockHash            {}
804blockNumber          {}
805from                 {}
806transactionIndex     {}
807effectiveGasPrice    {}
808{}",
809            self.block_hash.pretty(),
810            self.block_number.pretty(),
811            self.inner.signer().pretty(),
812            self.transaction_index.pretty(),
813            self.effective_gas_price.pretty(),
814            self.inner.inner().pretty().trim_start(),
815        )
816    }
817}
818
819#[cfg(feature = "base")]
820impl UIfmt for BaseRpcTransaction {
821    fn pretty(&self) -> String {
822        format!(
823            "
824depositNonce         {}
825depositReceiptVersion {}
826{}",
827            self.deposit_nonce.pretty(),
828            self.deposit_receipt_version.pretty(),
829            self.inner.pretty().trim_start(),
830        )
831    }
832}
833
834#[cfg(feature = "optimism")]
835impl<T: UIfmt> UIfmt for op_alloy_rpc_types::Transaction<T> {
836    fn pretty(&self) -> String {
837        format!(
838            "
839depositNonce         {}
840depositReceiptVersion {}
841{}",
842            self.deposit_nonce.pretty(),
843            self.deposit_receipt_version.pretty(),
844            self.inner.pretty().trim_start(),
845        )
846    }
847}
848
849impl UIfmt for AnyRpcBlock {
850    fn pretty(&self) -> String {
851        self.0.pretty()
852    }
853}
854
855impl UIfmt for AnyRpcTransaction {
856    fn pretty(&self) -> String {
857        self.0.pretty()
858    }
859}
860
861impl<T: UIfmt> UIfmt for WithOtherFields<T> {
862    fn pretty(&self) -> String {
863        format!("{}{}", self.inner.pretty(), self.other.pretty())
864    }
865}
866
867/// Various numerical ethereum types used for pretty printing
868#[derive(Clone, Debug, Deserialize)]
869#[serde(untagged)]
870#[expect(missing_docs)]
871pub enum EthValue {
872    U64(U64),
873    Address(Address),
874    U256(U256),
875    U64Array(Vec<U64>),
876    U256Array(Vec<U256>),
877    Other(serde_json::Value),
878}
879
880impl From<serde_json::Value> for EthValue {
881    fn from(val: serde_json::Value) -> Self {
882        serde_json::from_value(val).expect("infallible")
883    }
884}
885
886impl UIfmt for EthValue {
887    fn pretty(&self) -> String {
888        match self {
889            Self::U64(num) => num.pretty(),
890            Self::U256(num) => num.pretty(),
891            Self::Address(addr) => addr.pretty(),
892            Self::U64Array(arr) => arr.pretty(),
893            Self::U256Array(arr) => arr.pretty(),
894            Self::Other(val) => val.to_string().trim_matches('"').to_string(),
895        }
896    }
897}
898
899impl UIfmt for SignedAuthorization {
900    fn pretty(&self) -> String {
901        let signed_authorization = serde_json::to_string(self).unwrap_or("<invalid>".to_string());
902
903        match self.recover_authority() {
904            Ok(authority) => format!(
905                "{{recoveredAuthority: {authority}, signedAuthority: {signed_authorization}}}",
906            ),
907            Err(e) => format!(
908                "{{recoveredAuthority: <error: {e}>, signedAuthority: {signed_authorization}}}",
909            ),
910        }
911    }
912}
913
914pub trait UIfmtHeaderExt {
915    fn size_pretty(&self) -> String;
916    fn total_difficulty_pretty(&self) -> String;
917}
918
919impl UIfmtHeaderExt for Header {
920    fn size_pretty(&self) -> String {
921        self.size.pretty()
922    }
923
924    fn total_difficulty_pretty(&self) -> String {
925        self.total_difficulty.unwrap_or_else(|| self.difficulty()).pretty()
926    }
927}
928
929impl UIfmtHeaderExt for AnyRpcHeader {
930    fn size_pretty(&self) -> String {
931        self.size.pretty()
932    }
933
934    fn total_difficulty_pretty(&self) -> String {
935        self.total_difficulty.unwrap_or_else(|| self.difficulty()).pretty()
936    }
937}
938
939impl UIfmtHeaderExt for TempoHeaderResponse {
940    fn size_pretty(&self) -> String {
941        self.inner.size.pretty()
942    }
943
944    fn total_difficulty_pretty(&self) -> String {
945        self.inner.total_difficulty.unwrap_or_else(|| self.inner.difficulty()).pretty()
946    }
947}
948
949pub trait UIfmtSignatureExt {
950    fn signature_pretty(&self) -> Option<(String, String, String)>;
951}
952
953impl UIfmtSignatureExt for TxEnvelope {
954    fn signature_pretty(&self) -> Option<(String, String, String)> {
955        Some(pretty_signature_fields(self.signature()))
956    }
957}
958
959impl UIfmtSignatureExt for AnyTxEnvelope {
960    fn signature_pretty(&self) -> Option<(String, String, String)> {
961        self.as_envelope().and_then(|envelope| envelope.signature_pretty())
962    }
963}
964
965#[cfg(feature = "base")]
966impl UIfmtSignatureExt for BaseTxEnvelope {
967    fn signature_pretty(&self) -> Option<(String, String, String)> {
968        self.signature().map(pretty_signature_fields)
969    }
970}
971
972#[cfg(feature = "optimism")]
973impl UIfmtSignatureExt for OpTxEnvelope {
974    fn signature_pretty(&self) -> Option<(String, String, String)> {
975        self.signature().map(pretty_signature_fields)
976    }
977}
978
979impl UIfmtSignatureExt for TempoTxEnvelope {
980    fn signature_pretty(&self) -> Option<(String, String, String)> {
981        let sig = match self {
982            Self::Legacy(tx) => Some(tx.signature()),
983            Self::Eip2930(tx) => Some(tx.signature()),
984            Self::Eip1559(tx) => Some(tx.signature()),
985            Self::Eip7702(tx) => Some(tx.signature()),
986            Self::AA(tempo_tx) => {
987                if let TempoSignature::Primitive(PrimitiveSignature::Secp256k1(sig)) =
988                    tempo_tx.signature()
989                {
990                    Some(sig)
991                } else {
992                    None
993                }
994            }
995        }?;
996        Some(pretty_signature_fields(sig))
997    }
998}
999
1000fn pretty_signature_fields(signature: &Signature) -> (String, String, String) {
1001    (
1002        FixedBytes::from(signature.r()).pretty(),
1003        FixedBytes::from(signature.s()).pretty(),
1004        U8::from_le_slice(&signature.as_bytes()[64..]).pretty(),
1005    )
1006}
1007
1008pub trait UIfmtReceiptExt {
1009    fn logs_pretty(&self) -> String;
1010    fn logs_bloom_pretty(&self) -> String;
1011    fn tx_type_pretty(&self) -> String;
1012}
1013
1014fn receipt_logs_pretty<T: TxReceipt>(receipt: &TransactionReceipt<T>) -> String
1015where
1016    T::Log: Serialize,
1017{
1018    serde_json::to_string(receipt.inner.logs()).unwrap_or_default()
1019}
1020
1021fn receipt_logs_bloom_pretty<T: TxReceipt>(receipt: &TransactionReceipt<T>) -> String {
1022    receipt.inner.bloom().pretty()
1023}
1024
1025impl UIfmtReceiptExt for TransactionReceipt {
1026    fn logs_pretty(&self) -> String {
1027        receipt_logs_pretty(self)
1028    }
1029
1030    fn logs_bloom_pretty(&self) -> String {
1031        receipt_logs_bloom_pretty(self)
1032    }
1033
1034    fn tx_type_pretty(&self) -> String {
1035        self.transaction_type().to_string()
1036    }
1037}
1038
1039#[cfg(feature = "base")]
1040impl UIfmtReceiptExt for BaseTransactionReceipt {
1041    fn logs_pretty(&self) -> String {
1042        receipt_logs_pretty(&self.inner)
1043    }
1044
1045    fn logs_bloom_pretty(&self) -> String {
1046        receipt_logs_bloom_pretty(&self.inner)
1047    }
1048
1049    fn tx_type_pretty(&self) -> String {
1050        self.inner.inner.receipt.tx_type().to_string()
1051    }
1052}
1053
1054impl UIfmtReceiptExt for AnyTransactionReceipt {
1055    fn logs_pretty(&self) -> String {
1056        receipt_logs_pretty(&self.inner)
1057    }
1058
1059    fn logs_bloom_pretty(&self) -> String {
1060        receipt_logs_bloom_pretty(&self.inner)
1061    }
1062
1063    fn tx_type_pretty(&self) -> String {
1064        self.inner.inner.r#type.to_string()
1065    }
1066}
1067
1068impl UIfmt for TempoTransactionReceipt {
1069    fn pretty(&self) -> String {
1070        let receipt = &self.inner;
1071
1072        let mut pretty = format!(
1073            "
1074blockHash            {}
1075blockNumber          {}
1076contractAddress      {}
1077cumulativeGasUsed    {}
1078effectiveGasPrice    {}
1079from                 {}
1080gasUsed              {}
1081logs                 {}
1082logsBloom            {}
1083root                 {}
1084status               {}
1085transactionHash      {}
1086transactionIndex     {}
1087type                 {}
1088feePayer             {}
1089feeToken             {}",
1090            receipt.block_hash().pretty(),
1091            receipt.block_number().pretty(),
1092            receipt.contract_address().pretty(),
1093            receipt.cumulative_gas_used().pretty(),
1094            receipt.effective_gas_price().pretty(),
1095            receipt.from().pretty(),
1096            receipt.gas_used().pretty(),
1097            serde_json::to_string(receipt.inner.logs()).unwrap(),
1098            receipt.inner.logs_bloom.pretty(),
1099            self.state_root().pretty(),
1100            receipt.status().pretty(),
1101            receipt.transaction_hash().pretty(),
1102            receipt.transaction_index().pretty(),
1103            receipt.inner.receipt.tx_type as u8,
1104            self.fee_payer.pretty(),
1105            self.fee_token.pretty(),
1106        );
1107
1108        if let Some(to) = receipt.to() {
1109            pretty.push_str(&format!("\nto                   {}", to.pretty()));
1110        }
1111
1112        pretty
1113    }
1114}
1115
1116impl UIfmtReceiptExt for TempoTransactionReceipt {
1117    fn logs_pretty(&self) -> String {
1118        receipt_logs_pretty(&self.inner)
1119    }
1120
1121    fn logs_bloom_pretty(&self) -> String {
1122        self.inner.inner.logs_bloom.pretty()
1123    }
1124
1125    fn tx_type_pretty(&self) -> String {
1126        (self.inner.inner.receipt.tx_type as u8).to_string()
1127    }
1128}
1129
1130/// Returns the `UiFmt::pretty()` formatted attribute of the transactions
1131pub fn get_pretty_tx_attr<N>(transaction: &N::TransactionResponse, attr: &str) -> Option<String>
1132where
1133    N: Network,
1134    N::TxEnvelope: UIfmtSignatureExt,
1135{
1136    let (r, s, v) = transaction.as_ref().signature_pretty().unwrap_or_default();
1137    match attr {
1138        "blockHash" | "block_hash" => {
1139            Some(alloy_network::TransactionResponse::block_hash(transaction).pretty())
1140        }
1141        "blockNumber" | "block_number" => {
1142            Some(alloy_network::TransactionResponse::block_number(transaction).pretty())
1143        }
1144        "from" => Some(alloy_network::TransactionResponse::from(transaction).pretty()),
1145        "gas" => Some(TxTrait::gas_limit(transaction).pretty()),
1146        "gasPrice" | "gas_price" => Some(TxTrait::max_fee_per_gas(transaction).pretty()),
1147        "hash" => Some(alloy_network::TransactionResponse::tx_hash(transaction).pretty()),
1148        "input" => Some(TxTrait::input(transaction).pretty()),
1149        "nonce" => Some(TxTrait::nonce(transaction).to_string()),
1150        "s" => Some(s),
1151        "r" => Some(r),
1152        "to" => Some(TxTrait::to(transaction).pretty()),
1153        "transactionIndex" | "transaction_index" => {
1154            Some(alloy_network::TransactionResponse::transaction_index(transaction).pretty())
1155        }
1156        "v" => Some(v),
1157        "value" => Some(TxTrait::value(transaction).pretty()),
1158        _ => None,
1159    }
1160}
1161
1162pub fn get_pretty_block_attr<N>(block: &N::BlockResponse, attr: &str) -> Option<String>
1163where
1164    N: Network,
1165    N::BlockResponse: BlockResponse<Header = N::HeaderResponse>,
1166    N::HeaderResponse: UIfmtHeaderExt,
1167{
1168    match attr {
1169        "baseFeePerGas" | "base_fee_per_gas" => Some(block.header().base_fee_per_gas().pretty()),
1170        "difficulty" => Some(block.header().difficulty().pretty()),
1171        "extraData" | "extra_data" => Some(block.header().extra_data().pretty()),
1172        "gasLimit" | "gas_limit" => Some(block.header().gas_limit().pretty()),
1173        "gasUsed" | "gas_used" => Some(block.header().gas_used().pretty()),
1174        "hash" => Some(block.header().hash().pretty()),
1175        "logsBloom" | "logs_bloom" => Some(block.header().logs_bloom().pretty()),
1176        "miner" | "author" => Some(block.header().beneficiary().pretty()),
1177        "mixHash" | "mix_hash" => Some(block.header().mix_hash().pretty()),
1178        "nonce" => Some(block.header().nonce().pretty()),
1179        "number" => Some(block.header().number().pretty()),
1180        "parentHash" | "parent_hash" => Some(block.header().parent_hash().pretty()),
1181        "transactionsRoot" | "transactions_root" => {
1182            Some(block.header().transactions_root().pretty())
1183        }
1184        "receiptsRoot" | "receipts_root" => Some(block.header().receipts_root().pretty()),
1185        "sha3Uncles" | "sha_3_uncles" => Some(block.header().ommers_hash().pretty()),
1186        "size" => Some(block.header().size_pretty()),
1187        "stateRoot" | "state_root" => Some(block.header().state_root().pretty()),
1188        "timestamp" => Some(block.header().timestamp().pretty()),
1189        "totalDifficulty" | "total_difficulty" => Some(block.header().total_difficulty_pretty()),
1190        "blobGasUsed" | "blob_gas_used" => Some(block.header().blob_gas_used().pretty()),
1191        "excessBlobGas" | "excess_blob_gas" => Some(block.header().excess_blob_gas().pretty()),
1192        "requestsHash" | "requests_hash" => Some(block.header().requests_hash().pretty()),
1193        other => {
1194            if let Some(value) = block.other_fields().and_then(|fields| fields.get(other)) {
1195                let val = EthValue::from(value.clone());
1196                return Some(val.pretty());
1197            }
1198            None
1199        }
1200    }
1201}
1202
1203pub fn get_pretty_receipt_attr<N>(receipt: &N::ReceiptResponse, attr: &str) -> Option<String>
1204where
1205    N: Network,
1206    N::ReceiptResponse: ReceiptResponse + UIfmtReceiptExt,
1207{
1208    match attr {
1209        "blockHash" | "block_hash" => Some(receipt.block_hash().pretty()),
1210        "blockNumber" | "block_number" => Some(receipt.block_number().pretty()),
1211        "contractAddress" | "contract_address" => Some(receipt.contract_address().pretty()),
1212        "cumulativeGasUsed" | "cumulative_gas_used" => Some(receipt.cumulative_gas_used().pretty()),
1213        "effectiveGasPrice" | "effective_gas_price" => Some(receipt.effective_gas_price().pretty()),
1214        "from" => Some(receipt.from().pretty()),
1215        "gasUsed" | "gas_used" => Some(receipt.gas_used().pretty()),
1216        "logs" => Some(receipt.logs_pretty()),
1217        "logsBloom" | "logs_bloom" => Some(receipt.logs_bloom_pretty()),
1218        "root" | "stateRoot" | "state_root" => Some(receipt.state_root().pretty()),
1219        "status" | "statusCode" | "status_code" => Some(receipt.status().pretty()),
1220        "transactionHash" | "transaction_hash" => Some(receipt.transaction_hash().pretty()),
1221        "transactionIndex" | "transaction_index" => Some(receipt.transaction_index().pretty()),
1222        "to" => Some(receipt.to().pretty()),
1223        "type" | "transaction_type" => Some(receipt.tx_type_pretty()),
1224        "blobGasPrice" | "blob_gas_price" => Some(receipt.blob_gas_price().pretty()),
1225        "blobGasUsed" | "blob_gas_used" => Some(receipt.blob_gas_used().pretty()),
1226        _ => None,
1227    }
1228}
1229
1230fn pretty_generic_header_response<H: HeaderResponse + UIfmtHeaderExt>(header: &H) -> String {
1231    format!(
1232        "
1233baseFeePerGas        {}
1234difficulty           {}
1235extraData            {}
1236gasLimit             {}
1237gasUsed              {}
1238hash                 {}
1239logsBloom            {}
1240miner                {}
1241mixHash              {}
1242nonce                {}
1243number               {}
1244parentHash           {}
1245parentBeaconRoot     {}
1246transactionsRoot     {}
1247receiptsRoot         {}
1248sha3Uncles           {}
1249size                 {}
1250stateRoot            {}
1251timestamp            {} ({})
1252withdrawalsRoot      {}
1253totalDifficulty      {}
1254blobGasUsed          {}
1255excessBlobGas        {}
1256requestsHash         {}",
1257        header.base_fee_per_gas().pretty(),
1258        header.difficulty().pretty(),
1259        header.extra_data().pretty(),
1260        header.gas_limit().pretty(),
1261        header.gas_used().pretty(),
1262        header.hash().pretty(),
1263        header.logs_bloom().pretty(),
1264        header.beneficiary().pretty(),
1265        header.mix_hash().pretty(),
1266        header.nonce().pretty(),
1267        header.number().pretty(),
1268        header.parent_hash().pretty(),
1269        header.parent_beacon_block_root().pretty(),
1270        header.transactions_root().pretty(),
1271        header.receipts_root().pretty(),
1272        header.ommers_hash().pretty(),
1273        header.size_pretty(),
1274        header.state_root().pretty(),
1275        header.timestamp().pretty(),
1276        fmt_timestamp(header.timestamp()),
1277        header.withdrawals_root().pretty(),
1278        header.total_difficulty_pretty(),
1279        header.blob_gas_used().pretty(),
1280        header.excess_blob_gas().pretty(),
1281        header.requests_hash().pretty(),
1282    )
1283}
1284
1285/// Formats the timestamp to string
1286///
1287/// Assumes timestamp is seconds, but handles millis if it is too large
1288fn fmt_timestamp(timestamp: u64) -> String {
1289    // Tue Jan 19 2038 03:14:07 GMT+0000
1290    if timestamp > 2147483647 {
1291        // assume this is in millis, incorrectly set to millis by a node
1292        chrono::DateTime::from_timestamp_millis(timestamp as i64)
1293            .expect("block timestamp in range")
1294            .to_rfc3339()
1295    } else {
1296        // assume this is still in seconds
1297        chrono::DateTime::from_timestamp(timestamp as i64, 0)
1298            .expect("block timestamp in range")
1299            .to_rfc2822()
1300    }
1301}
1302
1303#[cfg(test)]
1304mod tests {
1305
1306    use super::*;
1307    use alloy_network::Ethereum;
1308    use alloy_primitives::{B256, address, bytes};
1309    use alloy_rpc_types::Authorization;
1310    use similar_asserts::assert_eq;
1311
1312    #[cfg(feature = "base")]
1313    use base_common_consensus::{Call as BaseCall, TxBase};
1314
1315    #[test]
1316    fn format_date_time() {
1317        // Fri Aug 29 2025 08:05:38 GMT+0000
1318        let timestamp = 1756454738u64;
1319
1320        let datetime = fmt_timestamp(timestamp);
1321        assert_eq!(datetime, "Fri, 29 Aug 2025 08:05:38 +0000");
1322        let datetime = fmt_timestamp(timestamp * 1000);
1323        assert_eq!(datetime, "2025-08-29T08:05:38+00:00");
1324    }
1325
1326    #[test]
1327    fn can_format_bytes32() {
1328        let val = hex::decode("7465737400000000000000000000000000000000000000000000000000000000")
1329            .unwrap();
1330        let mut b32 = [0u8; 32];
1331        b32.copy_from_slice(&val);
1332
1333        assert_eq!(
1334            b32.pretty(),
1335            "0x7465737400000000000000000000000000000000000000000000000000000000"
1336        );
1337        let b: Bytes = val.into();
1338        assert_eq!(b.pretty(), b32.pretty());
1339    }
1340
1341    #[cfg(feature = "base")]
1342    #[test]
1343    fn can_pretty_print_eip8130_transaction() {
1344        let base_call = BaseCall { to: Address::ZERO, value: U256::ZERO, data: Bytes::new() };
1345        let tx = TxBase {
1346            chain_id: 8453,
1347            sender: Some(Address::with_last_byte(0x11)),
1348            payer: Some(Address::with_last_byte(0x22)),
1349            nonce_key: U256::from(7),
1350            nonce_sequence: 3,
1351            valid_after: 100,
1352            valid_before: 200,
1353            max_fee_per_gas: 1_000,
1354            max_priority_fee_per_gas: 10,
1355            gas_limit: 21_000,
1356            metadata: Bytes::from_static(&[0xab]),
1357            calls: vec![vec![base_call.clone(), base_call.clone()], vec![base_call]],
1358            ..Default::default()
1359        };
1360        let signed =
1361            TxBaseSigned::new(tx, Bytes::from_static(&[0x01]), Bytes::from_static(&[0x02]));
1362
1363        assert_eq!(
1364            signed.pretty().trim(),
1365            r"chainId              8453
1366sender               0x0000000000000000000000000000000000000011
1367payer                0x0000000000000000000000000000000000000022
1368nonceKey             7
1369nonceSequence        3
1370validAfter           100
1371validBefore          200
1372maxFeePerGas         1000
1373maxPriorityFeePerGas 10
1374gasLimit             21000
1375accountChanges       0
1376callPhases           2
1377calls                3
1378metadata             0xab
1379senderAuth           0x01
1380payerAuth            0x02"
1381        );
1382    }
1383
1384    #[cfg(feature = "base")]
1385    #[test]
1386    fn can_pretty_print_base_deposit_receipt_fields() {
1387        let receipt: BaseTransactionReceipt = serde_json::from_value(serde_json::json!({
1388            "blockHash": "0x9e6a0fb7e22159d943d760608cc36a0fb596d1ab3c997146f5b7c55c8c718c67",
1389            "blockNumber": "0x6cfef89",
1390            "contractAddress": null,
1391            "cumulativeGasUsed": "0xfa0d",
1392            "depositNonce": "0x8a2d11",
1393            "depositReceiptVersion": "0x1",
1394            "effectiveGasPrice": "0x0",
1395            "from": "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001",
1396            "gasUsed": "0xfa0d",
1397            "logs": [{
1398                "address": "0x4200000000000000000000000000000000000015",
1399                "topics": [],
1400                "data": "0x",
1401                "removed": false,
1402                "blockTimestampMs": "0x18bcfe568c8",
1403                "blockNumber": "0x6cfef89",
1404                "blockHash": null,
1405                "transactionHash": null,
1406                "transactionIndex": null,
1407                "logIndex": null
1408            }],
1409            "logsBloom": format!("0x{}", "00".repeat(256)),
1410            "status": "0x1",
1411            "to": "0x4200000000000000000000000000000000000015",
1412            "transactionHash": "0xb7c74afdeb7c89fb9de2c312f49b38cb7a850ba36e064734c5223a477e83fdc9",
1413            "transactionIndex": "0x0",
1414            "type": "0x7e",
1415            "l1GasPrice": "0x3ef12787",
1416            "l1GasUsed": "0x1177",
1417            "l1Fee": "0x5bf1ab43d",
1418            "l1BaseFeeScalar": "0x1",
1419            "l1BlobBaseFee": "0x600ab8f05e64",
1420            "l1BlobBaseFeeScalar": "0x1",
1421            "operatorFeeScalar": "0x1",
1422            "operatorFeeConstant": "0x1",
1423            "daFootprintGasScalar": "0x1"
1424        }))
1425        .unwrap();
1426
1427        let pretty = receipt.pretty();
1428        let logs = receipt.logs_pretty();
1429        assert_eq!(
1430            serde_json::from_str::<serde_json::Value>(&logs).unwrap()[0]["blockTimestampMs"],
1431            "0x18bcfe568c8"
1432        );
1433        assert!(pretty.contains(&format!("logs                 {logs}")), "{pretty}");
1434        assert_eq!(receipt.logs_bloom_pretty(), receipt_logs_bloom_pretty(&receipt.inner));
1435        assert!(pretty.contains("l1Fee                24681034813"), "{pretty}");
1436        assert!(pretty.contains("operatorFeeScalar    1"), "{pretty}");
1437        assert!(pretty.contains("depositNonce         9055505"), "{pretty}");
1438        assert!(pretty.contains("depositReceiptVersion 1"), "{pretty}");
1439    }
1440
1441    #[cfg(feature = "optimism")]
1442    #[test]
1443    fn can_pretty_print_optimism_tx() {
1444        let s = r#"
1445        {
1446        "blockHash": "0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae",
1447        "blockNumber": "0x1b4",
1448        "from": "0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6",
1449        "gas": "0x11cbbdc",
1450        "gasPrice": "0x0",
1451        "hash": "0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f",
1452        "input": "0xd294f093",
1453        "nonce": "0xa2",
1454        "to": "0x4a16A42407AA491564643E1dfc1fd50af29794eF",
1455        "transactionIndex": "0x0",
1456        "value": "0x0",
1457        "v": "0x38",
1458        "r": "0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee",
1459        "s": "0xe804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583",
1460        "depositNonce": "",
1461        "depositReceiptVersion": "0x1"
1462    }
1463        "#;
1464
1465        let tx: op_alloy_rpc_types::Transaction<OpTxEnvelope> = serde_json::from_str(s).unwrap();
1466        assert_eq!(
1467            tx.pretty().trim(),
1468            r"
1469depositNonce         
1470depositReceiptVersion 1
1471blockHash            0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae
1472blockNumber          436
1473from                 0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6
1474transactionIndex     0
1475effectiveGasPrice    0
1476hash                 0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f
1477type                 0
1478chainId              10
1479nonce                162
1480gasPrice             0
1481gasLimit             18660316
1482to                   0x4a16A42407AA491564643E1dfc1fd50af29794eF
1483value                0
1484input                0xd294f093
1485r                    0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee
1486s                    0x0e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583
1487yParity              1
1488"
1489            .trim()
1490        );
1491    }
1492
1493    #[cfg(feature = "optimism")]
1494    #[test]
1495    fn can_pretty_print_optimism_tx_through_any() {
1496        let s = r#"
1497        {
1498        "blockHash": "0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae",
1499        "blockNumber": "0x1b4",
1500        "from": "0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6",
1501        "gas": "0x11cbbdc",
1502        "gasPrice": "0x0",
1503        "hash": "0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f",
1504        "input": "0xd294f093",
1505        "nonce": "0xa2",
1506        "to": "0x4a16A42407AA491564643E1dfc1fd50af29794eF",
1507        "transactionIndex": "0x0",
1508        "value": "0x0",
1509        "v": "0x38",
1510        "r": "0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee",
1511        "s": "0xe804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583",
1512        "queueOrigin": "sequencer",
1513        "txType": "",
1514        "l1TxOrigin": null,
1515        "l1BlockNumber": "0xc1a65c",
1516        "l1Timestamp": "0x60d34b60",
1517        "index": "0x1b3",
1518        "queueIndex": null,
1519        "rawTransaction": "0xf86681a28084011cbbdc944a16a42407aa491564643e1dfc1fd50af29794ef8084d294f09338a06fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2beea00e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583"
1520    }
1521        "#;
1522
1523        let tx: WithOtherFields<Transaction<AnyTxEnvelope>> = serde_json::from_str(s).unwrap();
1524        assert_eq!(tx.pretty().trim(),
1525                   r"
1526blockHash            0x02b853cf50bc1c335b70790f93d5a390a35a166bea9c895e685cc866e4961cae
1527blockNumber          436
1528from                 0x3b179DcfC5fAa677044c27dCe958e4BC0ad696A6
1529transactionIndex     0
1530effectiveGasPrice    0
1531hash                 0x2642e960d3150244e298d52b5b0f024782253e6d0b2c9a01dd4858f7b4665a3f
1532type                 0
1533chainId              10
1534nonce                162
1535gasPrice             0
1536gasLimit             18660316
1537to                   0x4a16A42407AA491564643E1dfc1fd50af29794eF
1538value                0
1539input                0xd294f093
1540r                    0x6fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2bee
1541s                    0x0e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583
1542yParity              1
1543index                435
1544l1BlockNumber        12691036
1545l1Timestamp          1624460128
1546l1TxOrigin           null
1547queueIndex           null
1548queueOrigin          sequencer
1549rawTransaction       0xf86681a28084011cbbdc944a16a42407aa491564643e1dfc1fd50af29794ef8084d294f09338a06fca94073a0cf3381978662d46cf890602d3e9ccf6a31e4b69e8ecbd995e2beea00e804161a2b56a37ca1f6f4c4b8bce926587afa0d9b1acc5165e6556c959d583
1550txType               0
1551".trim()
1552        );
1553    }
1554
1555    #[test]
1556    fn can_pretty_print_eip2930() {
1557        let s = r#"{
1558        "type": "0x1",
1559        "blockHash": "0x2b27fe2bbc8ce01ac7ae8bf74f793a197cf7edbe82727588811fa9a2c4776f81",
1560        "blockNumber": "0x12b1d",
1561        "from": "0x2b371c0262ceab27face32fbb5270ddc6aa01ba4",
1562        "gas": "0x6bdf",
1563        "gasPrice": "0x3b9aca00",
1564        "hash": "0xbddbb685774d8a3df036ed9fb920b48f876090a57e9e90ee60921e0510ef7090",
1565        "input": "0x9c0e3f7a0000000000000000000000000000000000000000000000000000000000000078000000000000000000000000000000000000000000000000000000000000002a",
1566        "nonce": "0x1c",
1567        "to": "0x8e730df7c70d33118d9e5f79ab81aed0be6f6635",
1568        "transactionIndex": "0x2",
1569        "value": "0x0",
1570        "v": "0x1",
1571        "r": "0x2a98c51c2782f664d3ce571fef0491b48f5ebbc5845fa513192e6e6b24ecdaa1",
1572        "s": "0x29b8e0c67aa9c11327e16556c591dc84a7aac2f6fc57c7f93901be8ee867aebc",
1573        "chainId": "0x66a",
1574        "accessList": [
1575            { "address": "0x2b371c0262ceab27face32fbb5270ddc6aa01ba4", "storageKeys": ["0x1122334455667788990011223344556677889900112233445566778899001122", "0x0000000000000000000000000000000000000000000000000000000000000000"] },
1576            { "address": "0x8e730df7c70d33118d9e5f79ab81aed0be6f6635", "storageKeys": [] }
1577        ]
1578      }
1579        "#;
1580        let tx: Transaction = serde_json::from_str(s).unwrap();
1581        assert_eq!(tx.pretty().trim(),
1582                   r"
1583blockHash            0x2b27fe2bbc8ce01ac7ae8bf74f793a197cf7edbe82727588811fa9a2c4776f81
1584blockNumber          76573
1585from                 0x2b371c0262CEAb27fAcE32FBB5270dDc6Aa01ba4
1586transactionIndex     2
1587effectiveGasPrice    1000000000
1588hash                 0xbddbb685774d8a3df036ed9fb920b48f876090a57e9e90ee60921e0510ef7090
1589type                 1
1590chainId              1642
1591nonce                28
1592gasPrice             1000000000
1593gasLimit             27615
1594to                   0x8E730Df7C70D33118D9e5F79ab81aEd0bE6F6635
1595value                0
1596accessList           [
1597	0x2b371c0262CEAb27fAcE32FBB5270dDc6Aa01ba4 => [
1598		0x1122334455667788990011223344556677889900112233445566778899001122
1599		0x0000000000000000000000000000000000000000000000000000000000000000
1600	]
1601	0x8E730Df7C70D33118D9e5F79ab81aEd0bE6F6635 => []
1602]
1603input                0x9c0e3f7a0000000000000000000000000000000000000000000000000000000000000078000000000000000000000000000000000000000000000000000000000000002a
1604r                    0x2a98c51c2782f664d3ce571fef0491b48f5ebbc5845fa513192e6e6b24ecdaa1
1605s                    0x29b8e0c67aa9c11327e16556c591dc84a7aac2f6fc57c7f93901be8ee867aebc
1606yParity              1
1607".trim()
1608        );
1609    }
1610
1611    #[test]
1612    fn can_pretty_print_eip1559() {
1613        let s = r#"{
1614        "type": "0x2",
1615        "blockHash": "0x61abbe5e22738de0462046f5a5d6c4cd6bc1f3a6398e4457d5e293590e721125",
1616        "blockNumber": "0x7647",
1617        "from": "0xbaadf00d42264eeb3fafe6799d0b56cf55df0f00",
1618        "gas": "0x186a0",
1619        "hash": "0xa7231d4da0576fade5d3b9481f4cd52459ec59b9bbdbf4f60d6cd726b2a3a244",
1620        "input": "0x48600055323160015500",
1621        "nonce": "0x12c",
1622        "to": null,
1623        "transactionIndex": "0x41",
1624        "value": "0x0",
1625        "v": "0x1",
1626        "yParity": "0x1",
1627        "r": "0x396864e5f9132327defdb1449504252e1fa6bce73feb8cd6f348a342b198af34",
1628        "s": "0x44dbba72e6d3304104848277143252ee43627c82f02d1ef8e404e1bf97c70158",
1629        "gasPrice": "0x4a817c800",
1630        "maxFeePerGas": "0x4a817c800",
1631        "maxPriorityFeePerGas": "0x4a817c800",
1632        "chainId": "0x66a",
1633        "accessList": [
1634          {
1635            "address": "0xc141a9a7463e6c4716d9fc0c056c054f46bb2993",
1636            "storageKeys": [
1637              "0x0000000000000000000000000000000000000000000000000000000000000000"
1638            ]
1639          }
1640        ]
1641      }
1642"#;
1643        let tx: Transaction = serde_json::from_str(s).unwrap();
1644        assert_eq!(
1645            tx.pretty().trim(),
1646            r"
1647blockHash            0x61abbe5e22738de0462046f5a5d6c4cd6bc1f3a6398e4457d5e293590e721125
1648blockNumber          30279
1649from                 0xBaaDF00d42264eEb3FAFe6799d0b56cf55DF0F00
1650transactionIndex     65
1651effectiveGasPrice    20000000000
1652hash                 0xa7231d4da0576fade5d3b9481f4cd52459ec59b9bbdbf4f60d6cd726b2a3a244
1653type                 2
1654chainId              1642
1655nonce                300
1656gasLimit             100000
1657maxFeePerGas         20000000000
1658maxPriorityFeePerGas 20000000000
1659to                   
1660value                0
1661accessList           [
1662	0xC141a9A7463e6C4716d9FC0C056C054F46Bb2993 => [
1663		0x0000000000000000000000000000000000000000000000000000000000000000
1664	]
1665]
1666input                0x48600055323160015500
1667r                    0x396864e5f9132327defdb1449504252e1fa6bce73feb8cd6f348a342b198af34
1668s                    0x44dbba72e6d3304104848277143252ee43627c82f02d1ef8e404e1bf97c70158
1669yParity              1
1670"
1671            .trim()
1672        );
1673    }
1674
1675    #[test]
1676    fn can_pretty_print_eip4884() {
1677        let s = r#"{
1678        "blockHash": "0xfc2715ff196e23ae613ed6f837abd9035329a720a1f4e8dce3b0694c867ba052",
1679        "blockNumber": "0x2a1cb",
1680        "from": "0xad01b55d7c3448b8899862eb335fbb17075d8de2",
1681        "gas": "0x5208",
1682        "gasPrice": "0x1d1a94a201c",
1683        "maxFeePerGas": "0x1d1a94a201c",
1684        "maxPriorityFeePerGas": "0x1d1a94a201c",
1685        "maxFeePerBlobGas": "0x3e8",
1686        "hash": "0x5ceec39b631763ae0b45a8fb55c373f38b8fab308336ca1dc90ecd2b3cf06d00",
1687        "input": "0x",
1688        "nonce": "0x1b483",
1689        "to": "0x000000000000000000000000000000000000f1c1",
1690        "transactionIndex": "0x0",
1691        "value": "0x0",
1692        "type": "0x3",
1693        "accessList": [],
1694        "chainId": "0x1a1f0ff42",
1695        "blobVersionedHashes": [
1696          "0x01a128c46fc61395706686d6284f83c6c86dfc15769b9363171ea9d8566e6e76"
1697        ],
1698        "v": "0x0",
1699        "r": "0x343c6239323a81ef61293cb4a4d37b6df47fbf68114adb5dd41581151a077da1",
1700        "s": "0x48c21f6872feaf181d37cc4f9bbb356d3f10b352ceb38d1c3b190d749f95a11b",
1701        "yParity": "0x0"
1702      }
1703"#;
1704        let tx: Transaction = serde_json::from_str(s).unwrap();
1705        assert_eq!(
1706            tx.pretty().trim(),
1707            r"
1708blockHash            0xfc2715ff196e23ae613ed6f837abd9035329a720a1f4e8dce3b0694c867ba052
1709blockNumber          172491
1710from                 0xAD01b55d7c3448B8899862eb335FBb17075d8DE2
1711transactionIndex     0
1712effectiveGasPrice    2000000000028
1713hash                 0x5ceec39b631763ae0b45a8fb55c373f38b8fab308336ca1dc90ecd2b3cf06d00
1714type                 3
1715chainId              7011893058
1716nonce                111747
1717gasLimit             21000
1718maxFeePerGas         2000000000028
1719maxPriorityFeePerGas 2000000000028
1720to                   0x000000000000000000000000000000000000f1C1
1721value                0
1722accessList           []
1723blobVersionedHashes  [
1724	0x01a128c46fc61395706686d6284f83c6c86dfc15769b9363171ea9d8566e6e76
1725]
1726maxFeePerBlobGas     1000
1727input                0x
1728r                    0x343c6239323a81ef61293cb4a4d37b6df47fbf68114adb5dd41581151a077da1
1729s                    0x48c21f6872feaf181d37cc4f9bbb356d3f10b352ceb38d1c3b190d749f95a11b
1730yParity              0
1731"
1732            .trim()
1733        );
1734    }
1735
1736    #[test]
1737    fn print_block_w_txs() {
1738        let block = r#"{"number":"0x3","hash":"0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972","parentHash":"0x689c70c080ca22bc0e681694fa803c1aba16a69c8b6368fed5311d279eb9de90","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x7270c1c4440180f2bd5215809ee3d545df042b67329499e1ab97eb759d31610d","stateRoot":"0x29f32984517a7d25607da485b23cefabfd443751422ca7e603395e1de9bc8a4b","receiptsRoot":"0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2","miner":"0x0000000000000000000000000000000000000000","difficulty":"0x0","totalDifficulty":"0x0","extraData":"0x","size":"0x3e8","gasLimit":"0x6691b7","gasUsed":"0x5208","timestamp":"0x5ecedbb9","transactions":[{"hash":"0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067","nonce":"0x2","blockHash":"0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972","blockNumber":"0x3","transactionIndex":"0x0","from":"0xfdcedc3bfca10ecb0890337fbdd1977aba84807a","to":"0xdca8ce283150ab773bcbeb8d38289bdb5661de1e","value":"0x0","gas":"0x15f90","gasPrice":"0x4a817c800","input":"0x","v":"0x25","r":"0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88","s":"0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e"}],"uncles":[]}"#;
1739        let block: Block = serde_json::from_str(block).unwrap();
1740        let output = "
1741blockHash            0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972
1742blockNumber          3
1743from                 0xFdCeDC3bFca10eCb0890337fbdD1977aba84807a
1744transactionIndex     0
1745effectiveGasPrice    20000000000
1746hash                 0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067
1747type                 0
1748chainId              1
1749nonce                2
1750gasPrice             20000000000
1751gasLimit             90000
1752to                   0xdca8ce283150AB773BCbeB8d38289bdB5661dE1e
1753value                0
1754input                0x
1755r                    0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88
1756s                    0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e
1757yParity              0"
1758            .to_string();
1759        let txs = match block.transactions() {
1760            BlockTransactions::Full(txs) => txs,
1761            _ => panic!("not full transactions"),
1762        };
1763        let generated = txs[0].pretty();
1764        assert_eq!(generated.as_str(), output.as_str());
1765    }
1766
1767    #[test]
1768    fn uifmt_option_u64() {
1769        assert_eq!(None::<U64>.pretty(), "");
1770        assert_eq!(U64::from(100).pretty(), "100");
1771        assert_eq!(Some(U64::from(100)).pretty(), "100");
1772    }
1773
1774    #[test]
1775    fn uifmt_option_h64() {
1776        assert_eq!(None::<B256>.pretty(), "");
1777        assert_eq!(
1778            B256::with_last_byte(100).pretty(),
1779            "0x0000000000000000000000000000000000000000000000000000000000000064",
1780        );
1781        assert_eq!(
1782            Some(B256::with_last_byte(100)).pretty(),
1783            "0x0000000000000000000000000000000000000000000000000000000000000064",
1784        );
1785    }
1786
1787    #[test]
1788    fn uifmt_option_bytes() {
1789        assert_eq!(None::<Bytes>.pretty(), "");
1790        assert_eq!(
1791            bytes!("0x0000000000000000000000000000000000000000000000000000000000000064").pretty(),
1792            "0x0000000000000000000000000000000000000000000000000000000000000064",
1793        );
1794        assert_eq!(
1795            Some(bytes!("0x0000000000000000000000000000000000000000000000000000000000000064"))
1796                .pretty(),
1797            "0x0000000000000000000000000000000000000000000000000000000000000064",
1798        );
1799    }
1800
1801    #[test]
1802    fn test_pretty_tx_attr() {
1803        let block = r#"{"number":"0x3","hash":"0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972","parentHash":"0x689c70c080ca22bc0e681694fa803c1aba16a69c8b6368fed5311d279eb9de90","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","transactionsRoot":"0x7270c1c4440180f2bd5215809ee3d545df042b67329499e1ab97eb759d31610d","stateRoot":"0x29f32984517a7d25607da485b23cefabfd443751422ca7e603395e1de9bc8a4b","receiptsRoot":"0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2","miner":"0x0000000000000000000000000000000000000000","difficulty":"0x0","totalDifficulty":"0x0","extraData":"0x","size":"0x3e8","gasLimit":"0x6691b7","gasUsed":"0x5208","timestamp":"0x5ecedbb9","transactions":[{"hash":"0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067","nonce":"0x2","blockHash":"0xda53da08ef6a3cbde84c33e51c04f68c3853b6a3731f10baa2324968eee63972","blockNumber":"0x3","transactionIndex":"0x0","from":"0xfdcedc3bfca10ecb0890337fbdd1977aba84807a","to":"0xdca8ce283150ab773bcbeb8d38289bdb5661de1e","value":"0x0","gas":"0x15f90","gasPrice":"0x4a817c800","input":"0x","v":"0x25","r":"0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88","s":"0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e"}],"uncles":[]}"#;
1804        let block: Block = serde_json::from_str(block).unwrap();
1805        let txs = match block.transactions() {
1806            BlockTransactions::Full(txes) => txes,
1807            _ => panic!("not full transactions"),
1808        };
1809
1810        assert_eq!(None, get_pretty_tx_attr::<Ethereum>(&txs[0], ""));
1811        assert_eq!(Some("3".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "blockNumber"));
1812        assert_eq!(
1813            Some("0xFdCeDC3bFca10eCb0890337fbdD1977aba84807a".to_string()),
1814            get_pretty_tx_attr::<Ethereum>(&txs[0], "from")
1815        );
1816        assert_eq!(Some("90000".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "gas"));
1817        assert_eq!(
1818            Some("20000000000".to_string()),
1819            get_pretty_tx_attr::<Ethereum>(&txs[0], "gasPrice")
1820        );
1821        assert_eq!(
1822            Some("0xc3c5f700243de37ae986082fd2af88d2a7c2752a0c0f7b9d6ac47c729d45e067".to_string()),
1823            get_pretty_tx_attr::<Ethereum>(&txs[0], "hash")
1824        );
1825        assert_eq!(Some("0x".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "input"));
1826        assert_eq!(Some("2".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "nonce"));
1827        assert_eq!(
1828            Some("0x19f2694eb9113656dbea0b925e2e7ceb43df83e601c4116aee9c0dd99130be88".to_string()),
1829            get_pretty_tx_attr::<Ethereum>(&txs[0], "r")
1830        );
1831        assert_eq!(
1832            Some("0x73e5764b324a4f7679d890a198ba658ba1c8cd36983ff9797e10b1b89dbb448e".to_string()),
1833            get_pretty_tx_attr::<Ethereum>(&txs[0], "s")
1834        );
1835        assert_eq!(
1836            Some("0xdca8ce283150AB773BCbeB8d38289bdB5661dE1e".into()),
1837            get_pretty_tx_attr::<Ethereum>(&txs[0], "to")
1838        );
1839        assert_eq!(
1840            Some("0".to_string()),
1841            get_pretty_tx_attr::<Ethereum>(&txs[0], "transactionIndex")
1842        );
1843        assert_eq!(Some("27".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "v"));
1844        assert_eq!(Some("0".to_string()), get_pretty_tx_attr::<Ethereum>(&txs[0], "value"));
1845    }
1846
1847    #[test]
1848    fn test_pretty_block_attr() {
1849        let json = serde_json::json!(
1850        {
1851            "baseFeePerGas": "0x7",
1852            "miner": "0x0000000000000000000000000000000000000001",
1853            "number": "0x1b4",
1854            "hash": "0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
1855            "parentHash": "0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5",
1856            "mixHash": "0x1010101010101010101010101010101010101010101010101010101010101010",
1857            "nonce": "0x0000000000000000",
1858            "sealFields": [
1859              "0xe04d296d2460cfb8472af2c5fd05b5a214109c25688d3704aed5484f9a7792f2",
1860              "0x0000000000000042"
1861            ],
1862            "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
1863            "logsBloom":  "0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
1864            "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
1865            "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
1866            "stateRoot": "0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff",
1867            "difficulty": "0x1",
1868            "totalDifficulty": "0x27f07",
1869            "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
1870            "size": "0x27f07",
1871            "gasLimit": "0x9f759",
1872            "minGasPrice": "0x9f759",
1873            "gasUsed": "0x9f759",
1874            "timestamp": "0x54e34e8e",
1875            "transactions": [],
1876            "uncles": [],
1877          }
1878        );
1879
1880        let block: Block = serde_json::from_value(json).unwrap();
1881
1882        assert_eq!(None, get_pretty_block_attr::<Ethereum>(&block, ""));
1883        assert_eq!(
1884            Some("7".to_string()),
1885            get_pretty_block_attr::<Ethereum>(&block, "baseFeePerGas")
1886        );
1887        assert_eq!(Some("1".to_string()), get_pretty_block_attr::<Ethereum>(&block, "difficulty"));
1888        assert_eq!(
1889            Some("0x0000000000000000000000000000000000000000000000000000000000000000".to_string()),
1890            get_pretty_block_attr::<Ethereum>(&block, "extraData")
1891        );
1892        assert_eq!(
1893            Some("653145".to_string()),
1894            get_pretty_block_attr::<Ethereum>(&block, "gasLimit")
1895        );
1896        assert_eq!(
1897            Some("653145".to_string()),
1898            get_pretty_block_attr::<Ethereum>(&block, "gasUsed")
1899        );
1900        assert_eq!(
1901            Some("0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331".to_string()),
1902            get_pretty_block_attr::<Ethereum>(&block, "hash")
1903        );
1904        assert_eq!(Some("0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331".to_string()), get_pretty_block_attr::<Ethereum>(&block, "logsBloom"));
1905        assert_eq!(
1906            Some("0x0000000000000000000000000000000000000001".to_string()),
1907            get_pretty_block_attr::<Ethereum>(&block, "miner")
1908        );
1909        assert_eq!(
1910            Some("0x1010101010101010101010101010101010101010101010101010101010101010".to_string()),
1911            get_pretty_block_attr::<Ethereum>(&block, "mixHash")
1912        );
1913        assert_eq!(
1914            Some("0x0000000000000000".to_string()),
1915            get_pretty_block_attr::<Ethereum>(&block, "nonce")
1916        );
1917        assert_eq!(Some("436".to_string()), get_pretty_block_attr::<Ethereum>(&block, "number"));
1918        assert_eq!(
1919            Some("0x9646252be9520f6e71339a8df9c55e4d7619deeb018d2a3f2d21fc165dde5eb5".to_string()),
1920            get_pretty_block_attr::<Ethereum>(&block, "parentHash")
1921        );
1922        assert_eq!(
1923            Some("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_string()),
1924            get_pretty_block_attr::<Ethereum>(&block, "transactionsRoot")
1925        );
1926        assert_eq!(
1927            Some("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".to_string()),
1928            get_pretty_block_attr::<Ethereum>(&block, "receiptsRoot")
1929        );
1930        assert_eq!(
1931            Some("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".to_string()),
1932            get_pretty_block_attr::<Ethereum>(&block, "sha3Uncles")
1933        );
1934        assert_eq!(Some("163591".to_string()), get_pretty_block_attr::<Ethereum>(&block, "size"));
1935        assert_eq!(
1936            Some("0xd5855eb08b3387c0af375e9cdb6acfc05eb8f519e419b874b6ff2ffda7ed1dff".to_string()),
1937            get_pretty_block_attr::<Ethereum>(&block, "stateRoot")
1938        );
1939        assert_eq!(
1940            Some("1424182926".to_string()),
1941            get_pretty_block_attr::<Ethereum>(&block, "timestamp")
1942        );
1943        assert_eq!(
1944            Some("163591".to_string()),
1945            get_pretty_block_attr::<Ethereum>(&block, "totalDifficulty")
1946        );
1947
1948        let pretty = pretty_generic_header_response(block.header());
1949        assert!(pretty.contains("difficulty           1"), "{pretty}");
1950        assert!(pretty.contains("totalDifficulty      163591"), "{pretty}");
1951    }
1952
1953    #[test]
1954    fn test_receipt_other_fields_alignment() {
1955        let receipt_json = serde_json::json!(
1956        {
1957          "status": "0x1",
1958          "cumulativeGasUsed": "0x74e483",
1959          "logs": [],
1960          "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
1961          "type": "0x2",
1962          "transactionHash": "0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d",
1963          "transactionIndex": "0x10",
1964          "blockHash": "0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d",
1965          "blockNumber": "0x7b1ab93",
1966          "gasUsed": "0xc222",
1967          "effectiveGasPrice": "0x18961",
1968          "from": "0x2d815240a61731c75fa01b2793e1d3ed09f289d0",
1969          "to": "0x4200000000000000000000000000000000000000",
1970          "contractAddress": null,
1971          "l1BaseFeeScalar": "0x146b",
1972          "l1BlobBaseFee": "0x6a83078",
1973          "l1BlobBaseFeeScalar": "0xf79c5",
1974          "l1Fee": "0x51a9af7fd3",
1975          "l1GasPrice": "0x972fe4acc",
1976          "l1GasUsed": "0x640"
1977        });
1978
1979        let receipt: AnyTransactionReceipt = serde_json::from_value(receipt_json).unwrap();
1980        let formatted = receipt.pretty();
1981
1982        let expected = r#"
1983blockHash            0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d
1984blockNumber          129084307
1985contractAddress      
1986cumulativeGasUsed    7660675
1987effectiveGasPrice    100705
1988from                 0x2D815240A61731c75Fa01b2793E1D3eD09F289d0
1989gasUsed              49698
1990logs                 []
1991logsBloom            0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1992root                 
1993status               1 (success)
1994transactionHash      0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d
1995transactionIndex     16
1996type                 2
1997blobGasPrice         
1998blobGasUsed          
1999to                   0x4200000000000000000000000000000000000000
2000l1BaseFeeScalar      5227
2001l1BlobBaseFee        111685752
2002l1BlobBaseFeeScalar  1014213
2003l1Fee                350739202003
2004l1GasPrice           40583973580
2005l1GasUsed            1600
2006"#;
2007
2008        assert_eq!(formatted.trim(), expected.trim());
2009    }
2010
2011    #[test]
2012    fn test_uifmt_for_signed_authorization() {
2013        let inner = Authorization {
2014            chain_id: U256::ONE,
2015            address: address!("0x000000000000000000000000000000000000dead"),
2016            nonce: 42,
2017        };
2018        let signed_authorization =
2019            SignedAuthorization::new_unchecked(inner, 1, U256::from(20), U256::from(30));
2020
2021        assert_eq!(
2022            signed_authorization.pretty(),
2023            r#"{recoveredAuthority: 0xf3eaBD0de6Ca1aE7fC4D81FfD6C9a40e5D5D7e30, signedAuthority: {"chainId":"0x1","address":"0x000000000000000000000000000000000000dead","nonce":"0x2a","yParity":"0x1","r":"0x14","s":"0x1e"}}"#
2024        );
2025    }
2026
2027    #[test]
2028    fn can_pretty_print_tempo_tx() {
2029        let s = r#"{
2030            "type":"0x76",
2031            "chainId":"0xa5bd",
2032            "feeToken":"0x20c0000000000000000000000000000000000001",
2033            "maxPriorityFeePerGas":"0x0",
2034            "maxFeePerGas":"0x2cb417800",
2035            "gas":"0x2d178",
2036            "calls":[
2037                {
2038                    "data":null,
2039                    "input":"0x095ea7b3000000000000000000000000dec00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000989680",
2040                    "to":"0x20c0000000000000000000000000000000000000",
2041                    "value":"0x0"
2042                },
2043                {
2044                    "data":null,
2045                    "input":"0xf8856c0f00000000000000000000000020c000000000000000000000000000000000000000000000000000000000000020c00000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000989680000000000000000000000000000000000000000000000000000000000097d330",
2046                    "to":"0xdec0000000000000000000000000000000000000",
2047                    "value":"0x0"
2048                }
2049            ],
2050            "accessList":[],
2051            "nonceKey":"0x0",
2052            "nonce":"0x0",
2053            "feePayerSignature":null,
2054            "validBefore":null,
2055            "validAfter":null,
2056            "keyAuthorization":null,
2057            "aaAuthorizationList":[],
2058            "signature":{
2059                "pubKeyX":"0xaacc80b21e45fb11f349424dce3a2f23547f60c0ff2f8bcaede2a247545ce8dd",
2060                "pubKeyY":"0x87abf0dbb7a5c9507efae2e43833356651b45ac576c2e61cec4e9c0f41fcbf6e",
2061                "r":"0xcfd45c3b19745a42f80b134dcb02a8ba099a0e4e7be1984da54734aa81d8f29f",
2062                "s":"0x74bb9170ae6d25bd510c83fe35895ee5712efe13980a5edc8094c534e23af85e",
2063                "type":"webAuthn",
2064                "webauthnData":"0x7b98b7a8e6c68d7eac741a52e6fdae0560ce3c16ef5427ad46d7a54d0ed86dd41d000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2238453071464a7a50585167546e645473643649456659457776323173516e626966374c4741776e4b43626b222c226f726967696e223a2268747470733a2f2f74656d706f2d6465782e76657263656c2e617070222c2263726f73734f726967696e223a66616c73657d"
2065            },
2066            "hash":"0x6d6d8c102064e6dee44abad2024a8b1d37959230baab80e70efbf9b0c739c4fd",
2067            "blockHash":"0xc82b23589ceef5341ed307d33554714db6f9eefd4187a9ca8abc910a325b4689",
2068            "blockNumber":"0x321fde",
2069            "transactionIndex":"0x0",
2070            "from":"0x566ff0f4a6114f8072ecdc8a7a8a13d8d0c6b45f",
2071            "gasPrice":"0x2540be400"
2072        }"#;
2073
2074        let tx: Transaction<TempoTxEnvelope> = serde_json::from_str(s).unwrap();
2075
2076        assert_eq!(
2077            tx.pretty().trim(),
2078            r#"
2079blockHash            0xc82b23589ceef5341ed307d33554714db6f9eefd4187a9ca8abc910a325b4689
2080blockNumber          3284958
2081from                 0x566Ff0f4a6114F8072ecDC8A7A8A13d8d0C6B45F
2082transactionIndex     0
2083effectiveGasPrice    10000000000
2084hash                 0x6d6d8c102064e6dee44abad2024a8b1d37959230baab80e70efbf9b0c739c4fd
2085type                 118
2086chainId              42429
2087feeToken             0x20C0000000000000000000000000000000000001
2088maxPriorityFeePerGas 0
2089maxFeePerGas         12000000000
2090gasLimit             184696
2091calls                [
2092	to: 0x20C0000000000000000000000000000000000000, value: 0, input: 0x095ea7b3000000000000000000000000dec00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000989680
2093	to: 0xDEc0000000000000000000000000000000000000, value: 0, input: 0xf8856c0f00000000000000000000000020c000000000000000000000000000000000000000000000000000000000000020c00000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000989680000000000000000000000000000000000000000000000000000000000097d330
2094]
2095accessList           []
2096nonceKey             0
2097nonce                0
2098feePayerSignature    
2099validBefore          
2100validAfter           
2101tempoSignature       {"type":"webAuthn","r":"0xcfd45c3b19745a42f80b134dcb02a8ba099a0e4e7be1984da54734aa81d8f29f","s":"0x74bb9170ae6d25bd510c83fe35895ee5712efe13980a5edc8094c534e23af85e","pubKeyX":"0xaacc80b21e45fb11f349424dce3a2f23547f60c0ff2f8bcaede2a247545ce8dd","pubKeyY":"0x87abf0dbb7a5c9507efae2e43833356651b45ac576c2e61cec4e9c0f41fcbf6e","webauthnData":"0x7b98b7a8e6c68d7eac741a52e6fdae0560ce3c16ef5427ad46d7a54d0ed86dd41d000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2238453071464a7a50585167546e645473643649456659457776323173516e626966374c4741776e4b43626b222c226f726967696e223a2268747470733a2f2f74656d706f2d6465782e76657263656c2e617070222c2263726f73734f726967696e223a66616c73657d"}
2102"#
2103                .trim()
2104        );
2105    }
2106
2107    #[test]
2108    fn can_pretty_print_tempo_receipt() {
2109        let s = r#"{"type":"0x76","status":"0x1","cumulativeGasUsed":"0x176d7f4","logs":[{"address":"0x20c0000000000000000000000000000000000000","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000a70ab0448e66cd77995bfbba5c5b64b41a85f3fd","0x0000000000000000000000000000000000000000000000000000000000000001"],"data":"0x00000000000000000000000000000000000000000000000000000000000003e8","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","blockTimestamp":"0x69a5d790","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","logIndex":"0xb8","removed":false},{"address":"0x20c0000000000000000000000000000000000003","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000a70ab0448e66cd77995bfbba5c5b64b41a85f3fd","0x000000000000000000000000feec000000000000000000000000000000000000"],"data":"0x0000000000000000000000000000000000000000000000000000000000000417","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","blockTimestamp":"0x69a5d790","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","logIndex":"0xb9","removed":false}],"logsBloom":"0x00000000000000000000000000000000000000000000010000000000000000000000000000000000000000000100000000000000000000000000000000040008000004200000000000000008000000000000000000040000000000000400000000000002000000000000000000000000000000000000000000000010000000000000000000000000000000000020000000000000800000000000000000000000000020000000000000000000000000000000000400000000000000000000000000000002000000000000000400000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","gasUsed":"0xcc6a","effectiveGasPrice":"0x4a817c802","from":"0xa70ab0448e66cd77995bfbba5c5b64b41a85f3fd","to":"0x20c0000000000000000000000000000000000000","contractAddress":null,"feeToken":"0x20c0000000000000000000000000000000000003","feePayer":"0xa70ab0448e66cd77995bfbba5c5b64b41a85f3fd"}"#;
2110
2111        let tx: TempoTransactionReceipt = serde_json::from_str(s).unwrap();
2112
2113        assert_eq!(
2114            tx.pretty().trim(),
2115            r#"
2116blockHash            0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66
2117blockNumber          6922711
2118contractAddress      
2119cumulativeGasUsed    24565748
2120effectiveGasPrice    20000000002
2121from                 0xa70ab0448e66cD77995bfBBa5c5b64B41a85F3fd
2122gasUsed              52330
2123logs                 [{"address":"0x20c0000000000000000000000000000000000000","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000a70ab0448e66cd77995bfbba5c5b64b41a85f3fd","0x0000000000000000000000000000000000000000000000000000000000000001"],"data":"0x00000000000000000000000000000000000000000000000000000000000003e8","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","blockTimestamp":"0x69a5d790","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","logIndex":"0xb8","removed":false},{"address":"0x20c0000000000000000000000000000000000003","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x000000000000000000000000a70ab0448e66cd77995bfbba5c5b64b41a85f3fd","0x000000000000000000000000feec000000000000000000000000000000000000"],"data":"0x0000000000000000000000000000000000000000000000000000000000000417","blockHash":"0x860f788b251ece768e63b0d3906d156f652d843848b71c7fe81faacd49139d66","blockNumber":"0x69a1d7","blockTimestamp":"0x69a5d790","transactionHash":"0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f","transactionIndex":"0x63","logIndex":"0xb9","removed":false}]
2124logsBloom            0x00000000000000000000000000000000000000000000010000000000000000000000000000000000000000000100000000000000000000000000000000040008000004200000000000000008000000000000000000040000000000000400000000000002000000000000000000000000000000000000000000000010000000000000000000000000000000000020000000000000800000000000000000000000000020000000000000000000000000000000000400000000000000000000000000000002000000000000000400000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000
2125root                 
2126status               true
2127transactionHash      0x04548a0ea27e2cccc1479af3c2ff02da4d4d3ea46af8e8d7edaa49f6ea27073f
2128transactionIndex     99
2129type                 118
2130feePayer             0xa70ab0448e66cD77995bfBBa5c5b64B41a85F3fd
2131feeToken             0x20C0000000000000000000000000000000000003
2132to                   0x20C0000000000000000000000000000000000000
2133"#
2134                .trim()
2135        );
2136    }
2137
2138    #[test]
2139    fn test_ethereum_receipt_uifmt() {
2140        let s = r#"{"type":"0x2","status":"0x1","cumulativeGasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","transactionHash":"0x1234567890123456789012345678901234567890123456789012345678901234","transactionIndex":"0x0","blockHash":"0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd","blockNumber":"0x1","gasUsed":"0x5208","effectiveGasPrice":"0x3b9aca00","from":"0x1234567890123456789012345678901234567890","to":"0x0987654321098765432109876543210987654321","contractAddress":null}"#;
2141        let receipt: TransactionReceipt = serde_json::from_str(s).unwrap();
2142
2143        let pretty_output = receipt.pretty();
2144
2145        assert!(pretty_output.contains("blockHash"));
2146        assert!(pretty_output.contains("blockNumber"));
2147        assert!(pretty_output.contains("status"));
2148        assert!(pretty_output.contains("gasUsed"));
2149        assert!(pretty_output.contains("transactionHash"));
2150        assert!(pretty_output.contains("type"));
2151        assert!(
2152            pretty_output
2153                .contains("0x1234567890123456789012345678901234567890123456789012345678901234")
2154        );
2155        assert!(pretty_output.contains("1 (success)"));
2156        assert!(pretty_output.contains("0x0987654321098765432109876543210987654321"));
2157    }
2158
2159    #[test]
2160    fn test_get_pretty_receipt_attr() {
2161        let receipt_json = serde_json::json!({
2162            "type": "0x2",
2163            "status": "0x1",
2164            "cumulativeGasUsed": "0x5208",
2165            "logs": [],
2166            "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
2167            "transactionHash": "0x1234567890123456789012345678901234567890123456789012345678901234",
2168            "transactionIndex": "0x0",
2169            "blockHash": "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd",
2170            "blockNumber": "0x1",
2171            "gasUsed": "0x5208",
2172            "effectiveGasPrice": "0x3b9aca00",
2173            "from": "0x1234567890123456789012345678901234567890",
2174            "to": "0x0987654321098765432109876543210987654321",
2175            "contractAddress": null
2176        });
2177
2178        let receipt: TransactionReceipt = serde_json::from_value(receipt_json).unwrap();
2179
2180        // Test basic receipt attributes
2181        assert_eq!(
2182            Some("0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd".to_string()),
2183            get_pretty_receipt_attr::<Ethereum>(&receipt, "blockHash")
2184        );
2185        assert_eq!(
2186            Some("1".to_string()),
2187            get_pretty_receipt_attr::<Ethereum>(&receipt, "blockNumber")
2188        );
2189        assert_eq!(
2190            Some("0x1234567890123456789012345678901234567890123456789012345678901234".to_string()),
2191            get_pretty_receipt_attr::<Ethereum>(&receipt, "transactionHash")
2192        );
2193        assert_eq!(
2194            Some("21000".to_string()),
2195            get_pretty_receipt_attr::<Ethereum>(&receipt, "gasUsed")
2196        );
2197        assert_eq!(
2198            Some("true".to_string()),
2199            get_pretty_receipt_attr::<Ethereum>(&receipt, "status")
2200        );
2201        assert_eq!(
2202            Some("EIP-1559".to_string()),
2203            get_pretty_receipt_attr::<Ethereum>(&receipt, "type")
2204        );
2205        assert_eq!(Some("[]".to_string()), get_pretty_receipt_attr::<Ethereum>(&receipt, "logs"));
2206        assert!(get_pretty_receipt_attr::<Ethereum>(&receipt, "logsBloom").is_some());
2207    }
2208}