From 3ba3d5f9e6008779c68b94ef9a0015ca2fe60b6a Mon Sep 17 00:00:00 2001 From: Delweng Date: Tue, 24 Dec 2024 16:27:43 +0800 Subject: [PATCH] feat(cast): pretty print other receipt fields (#9589) * fix(cast): pretty print other receipt fields Signed-off-by: jsvisa * feat(cast): add other receipt fields pretty test Signed-off-by: jsvisa * fix(ui): receipt column length 20 Signed-off-by: jsvisa * fmt Signed-off-by: jsvisa * fix receipt indent test Signed-off-by: jsvisa * fix test case /2 Signed-off-by: jsvisa * fix revert reason indent Signed-off-by: jsvisa --------- Signed-off-by: jsvisa --- crates/cast/tests/cli/main.rs | 74 +++++++++++------------ crates/common/fmt/src/ui.rs | 99 ++++++++++++++++++++++++------- crates/common/src/transactions.rs | 2 +- 3 files changed, 116 insertions(+), 59 deletions(-) diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index 3c3096a363c9..c87c5f7f26de 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -810,24 +810,24 @@ casttest!(receipt_revert_reason, |_prj, cmd| { .assert_success() .stdout_eq(str![[r#" -blockHash 0x2cfe65be49863676b6dbc04d58176a14f39b123f1e2f4fea0383a2d82c2c50d0 -blockNumber 16239315 -contractAddress -cumulativeGasUsed 10743428 -effectiveGasPrice 10539984136 -from 0x199D5ED7F45F4eE35960cF22EAde2076e95B253F -gasUsed 21000 -logs [] -logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -root -status 1 (success) -transactionHash 0x44f2aaa351460c074f2cb1e5a9e28cbc7d83f33e425101d2de14331c7b7ec31e -transactionIndex 116 -type 0 -blobGasPrice -blobGasUsed -authorizationList -to 0x91da5bf3F8Eb72724E6f50Ec6C3D199C6355c59c +blockHash 0x2cfe65be49863676b6dbc04d58176a14f39b123f1e2f4fea0383a2d82c2c50d0 +blockNumber 16239315 +contractAddress +cumulativeGasUsed 10743428 +effectiveGasPrice 10539984136 +from 0x199D5ED7F45F4eE35960cF22EAde2076e95B253F +gasUsed 21000 +logs [] +logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +root +status 1 (success) +transactionHash 0x44f2aaa351460c074f2cb1e5a9e28cbc7d83f33e425101d2de14331c7b7ec31e +transactionIndex 116 +type 0 +blobGasPrice +blobGasUsed +authorizationList +to 0x91da5bf3F8Eb72724E6f50Ec6C3D199C6355c59c "#]]); @@ -844,25 +844,25 @@ to 0x91da5bf3F8Eb72724E6f50Ec6C3D199C6355c59c .assert_success() .stdout_eq(str![[r#" -blockHash 0x883f974b17ca7b28cb970798d1c80f4d4bb427473dc6d39b2a7fe24edc02902d -blockNumber 14839405 -contractAddress -cumulativeGasUsed 20273649 -effectiveGasPrice 21491736378 -from 0x3cF412d970474804623bb4e3a42dE13F9bCa5436 -gasUsed 24952 -logs [] -logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -root -status 0 (failed) -transactionHash 0x0e07d8b53ed3d91314c80e53cf25bcde02084939395845cbb625b029d568135c -transactionIndex 173 -type 2 -blobGasPrice -blobGasUsed -authorizationList -to 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 -revertReason Transaction too old, data: "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000135472616e73616374696f6e20746f6f206f6c6400000000000000000000000000" +blockHash 0x883f974b17ca7b28cb970798d1c80f4d4bb427473dc6d39b2a7fe24edc02902d +blockNumber 14839405 +contractAddress +cumulativeGasUsed 20273649 +effectiveGasPrice 21491736378 +from 0x3cF412d970474804623bb4e3a42dE13F9bCa5436 +gasUsed 24952 +logs [] +logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +root +status 0 (failed) +transactionHash 0x0e07d8b53ed3d91314c80e53cf25bcde02084939395845cbb625b029d568135c +transactionIndex 173 +type 2 +blobGasPrice +blobGasUsed +authorizationList +to 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45 +revertReason Transaction too old, data: "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000135472616e73616374696f6e20746f6f206f6c6400000000000000000000000000" "#]]); }); diff --git a/crates/common/fmt/src/ui.rs b/crates/common/fmt/src/ui.rs index 9962a858397f..0798967c6a0a 100644 --- a/crates/common/fmt/src/ui.rs +++ b/crates/common/fmt/src/ui.rs @@ -193,23 +193,23 @@ impl UIfmt for AnyTransactionReceipt { let mut pretty = format!( " -blockHash {} -blockNumber {} -contractAddress {} -cumulativeGasUsed {} -effectiveGasPrice {} -from {} -gasUsed {} -logs {} -logsBloom {} -root {} -status {} -transactionHash {} -transactionIndex {} -type {} -blobGasPrice {} -blobGasUsed {} -authorizationList {}", +blockHash {} +blockNumber {} +contractAddress {} +cumulativeGasUsed {} +effectiveGasPrice {} +from {} +gasUsed {} +logs {} +logsBloom {} +root {} +status {} +transactionHash {} +transactionIndex {} +type {} +blobGasPrice {} +blobGasUsed {} +authorizationList {}", block_hash.pretty(), block_number.pretty(), contract_address.pretty(), @@ -233,13 +233,11 @@ authorizationList {}", ); if let Some(to) = to { - pretty.push_str(&format!("\nto {}", to.pretty())); + pretty.push_str(&format!("\nto {}", to.pretty())); } // additional captured fields - for (key, val) in other.iter() { - pretty.push_str(&format!("\n{key} {val}")); - } + pretty.push_str(&other.pretty()); pretty } @@ -1415,4 +1413,63 @@ value 0".to_string(); assert_eq!(Some("1424182926".to_string()), get_pretty_block_attr(&block, "timestamp")); assert_eq!(Some("163591".to_string()), get_pretty_block_attr(&block, "totalDifficulty")); } + + #[test] + fn test_receipt_other_fields_alignment() { + let receipt_json = serde_json::json!( + { + "status": "0x1", + "cumulativeGasUsed": "0x74e483", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "type": "0x2", + "transactionHash": "0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d", + "transactionIndex": "0x10", + "blockHash": "0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d", + "blockNumber": "0x7b1ab93", + "gasUsed": "0xc222", + "effectiveGasPrice": "0x18961", + "from": "0x2d815240a61731c75fa01b2793e1d3ed09f289d0", + "to": "0x4200000000000000000000000000000000000000", + "contractAddress": null, + "l1BaseFeeScalar": "0x146b", + "l1BlobBaseFee": "0x6a83078", + "l1BlobBaseFeeScalar": "0xf79c5", + "l1Fee": "0x51a9af7fd3", + "l1GasPrice": "0x972fe4acc", + "l1GasUsed": "0x640" + }); + + let receipt: AnyTransactionReceipt = serde_json::from_value(receipt_json).unwrap(); + let formatted = receipt.pretty(); + + let expected = r#" +blockHash 0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d +blockNumber 129084307 +contractAddress +cumulativeGasUsed 7660675 +effectiveGasPrice 100705 +from 0x2D815240A61731c75Fa01b2793E1D3eD09F289d0 +gasUsed 49698 +logs [] +logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +root +status 1 (success) +transactionHash 0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d +transactionIndex 16 +type 2 +blobGasPrice +blobGasUsed +authorizationList +to 0x4200000000000000000000000000000000000000 +l1BaseFeeScalar 5227 +l1BlobBaseFee 111685752 +l1BlobBaseFeeScalar 1014213 +l1Fee 350739202003 +l1GasPrice 40583973580 +l1GasUsed 1600 +"#; + + assert_eq!(formatted.trim(), expected.trim()); + } } diff --git a/crates/common/src/transactions.rs b/crates/common/src/transactions.rs index b725fc068b17..9148cd6d9a0f 100644 --- a/crates/common/src/transactions.rs +++ b/crates/common/src/transactions.rs @@ -88,7 +88,7 @@ impl UIfmt for TransactionReceiptWithRevertReason { if let Some(revert_reason) = &self.revert_reason { format!( "{} -revertReason {}", +revertReason {}", self.receipt.pretty(), revert_reason )