Skip to content

Commit

Permalink
feat(cast): pretty print other receipt fields (#9589)
Browse files Browse the repository at this point in the history
* fix(cast): pretty print other receipt fields

Signed-off-by: jsvisa <[email protected]>

* feat(cast): add other receipt fields pretty test

Signed-off-by: jsvisa <[email protected]>

* fix(ui): receipt column length 20

Signed-off-by: jsvisa <[email protected]>

* fmt

Signed-off-by: jsvisa <[email protected]>

* fix receipt indent test

Signed-off-by: jsvisa <[email protected]>

* fix test case /2

Signed-off-by: jsvisa <[email protected]>

* fix revert reason indent

Signed-off-by: jsvisa <[email protected]>

---------

Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa authored Dec 24, 2024
1 parent f922a34 commit 3ba3d5f
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 59 deletions.
74 changes: 37 additions & 37 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#]]);

Expand All @@ -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"
"#]]);
});
Expand Down
99 changes: 78 additions & 21 deletions crates/common/fmt/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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
}
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion crates/common/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl UIfmt for TransactionReceiptWithRevertReason {
if let Some(revert_reason) = &self.revert_reason {
format!(
"{}
revertReason {}",
revertReason {}",
self.receipt.pretty(),
revert_reason
)
Expand Down

0 comments on commit 3ba3d5f

Please sign in to comment.