Skip to content

Commit 3ba3d5f

Browse files
authored
feat(cast): pretty print other receipt fields (foundry-rs#9589)
* 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]>
1 parent f922a34 commit 3ba3d5f

File tree

3 files changed

+116
-59
lines changed

3 files changed

+116
-59
lines changed

crates/cast/tests/cli/main.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -810,24 +810,24 @@ casttest!(receipt_revert_reason, |_prj, cmd| {
810810
.assert_success()
811811
.stdout_eq(str![[r#"
812812
813-
blockHash 0x2cfe65be49863676b6dbc04d58176a14f39b123f1e2f4fea0383a2d82c2c50d0
814-
blockNumber 16239315
815-
contractAddress
816-
cumulativeGasUsed 10743428
817-
effectiveGasPrice 10539984136
818-
from 0x199D5ED7F45F4eE35960cF22EAde2076e95B253F
819-
gasUsed 21000
820-
logs []
821-
logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
822-
root
823-
status 1 (success)
824-
transactionHash 0x44f2aaa351460c074f2cb1e5a9e28cbc7d83f33e425101d2de14331c7b7ec31e
825-
transactionIndex 116
826-
type 0
827-
blobGasPrice
828-
blobGasUsed
829-
authorizationList
830-
to 0x91da5bf3F8Eb72724E6f50Ec6C3D199C6355c59c
813+
blockHash 0x2cfe65be49863676b6dbc04d58176a14f39b123f1e2f4fea0383a2d82c2c50d0
814+
blockNumber 16239315
815+
contractAddress
816+
cumulativeGasUsed 10743428
817+
effectiveGasPrice 10539984136
818+
from 0x199D5ED7F45F4eE35960cF22EAde2076e95B253F
819+
gasUsed 21000
820+
logs []
821+
logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
822+
root
823+
status 1 (success)
824+
transactionHash 0x44f2aaa351460c074f2cb1e5a9e28cbc7d83f33e425101d2de14331c7b7ec31e
825+
transactionIndex 116
826+
type 0
827+
blobGasPrice
828+
blobGasUsed
829+
authorizationList
830+
to 0x91da5bf3F8Eb72724E6f50Ec6C3D199C6355c59c
831831
832832
"#]]);
833833

@@ -844,25 +844,25 @@ to 0x91da5bf3F8Eb72724E6f50Ec6C3D199C6355c59c
844844
.assert_success()
845845
.stdout_eq(str![[r#"
846846
847-
blockHash 0x883f974b17ca7b28cb970798d1c80f4d4bb427473dc6d39b2a7fe24edc02902d
848-
blockNumber 14839405
849-
contractAddress
850-
cumulativeGasUsed 20273649
851-
effectiveGasPrice 21491736378
852-
from 0x3cF412d970474804623bb4e3a42dE13F9bCa5436
853-
gasUsed 24952
854-
logs []
855-
logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
856-
root
857-
status 0 (failed)
858-
transactionHash 0x0e07d8b53ed3d91314c80e53cf25bcde02084939395845cbb625b029d568135c
859-
transactionIndex 173
860-
type 2
861-
blobGasPrice
862-
blobGasUsed
863-
authorizationList
864-
to 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45
865-
revertReason Transaction too old, data: "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000135472616e73616374696f6e20746f6f206f6c6400000000000000000000000000"
847+
blockHash 0x883f974b17ca7b28cb970798d1c80f4d4bb427473dc6d39b2a7fe24edc02902d
848+
blockNumber 14839405
849+
contractAddress
850+
cumulativeGasUsed 20273649
851+
effectiveGasPrice 21491736378
852+
from 0x3cF412d970474804623bb4e3a42dE13F9bCa5436
853+
gasUsed 24952
854+
logs []
855+
logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
856+
root
857+
status 0 (failed)
858+
transactionHash 0x0e07d8b53ed3d91314c80e53cf25bcde02084939395845cbb625b029d568135c
859+
transactionIndex 173
860+
type 2
861+
blobGasPrice
862+
blobGasUsed
863+
authorizationList
864+
to 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45
865+
revertReason Transaction too old, data: "0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000135472616e73616374696f6e20746f6f206f6c6400000000000000000000000000"
866866
867867
"#]]);
868868
});

crates/common/fmt/src/ui.rs

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,23 @@ impl UIfmt for AnyTransactionReceipt {
193193

194194
let mut pretty = format!(
195195
"
196-
blockHash {}
197-
blockNumber {}
198-
contractAddress {}
199-
cumulativeGasUsed {}
200-
effectiveGasPrice {}
201-
from {}
202-
gasUsed {}
203-
logs {}
204-
logsBloom {}
205-
root {}
206-
status {}
207-
transactionHash {}
208-
transactionIndex {}
209-
type {}
210-
blobGasPrice {}
211-
blobGasUsed {}
212-
authorizationList {}",
196+
blockHash {}
197+
blockNumber {}
198+
contractAddress {}
199+
cumulativeGasUsed {}
200+
effectiveGasPrice {}
201+
from {}
202+
gasUsed {}
203+
logs {}
204+
logsBloom {}
205+
root {}
206+
status {}
207+
transactionHash {}
208+
transactionIndex {}
209+
type {}
210+
blobGasPrice {}
211+
blobGasUsed {}
212+
authorizationList {}",
213213
block_hash.pretty(),
214214
block_number.pretty(),
215215
contract_address.pretty(),
@@ -233,13 +233,11 @@ authorizationList {}",
233233
);
234234

235235
if let Some(to) = to {
236-
pretty.push_str(&format!("\nto {}", to.pretty()));
236+
pretty.push_str(&format!("\nto {}", to.pretty()));
237237
}
238238

239239
// additional captured fields
240-
for (key, val) in other.iter() {
241-
pretty.push_str(&format!("\n{key} {val}"));
242-
}
240+
pretty.push_str(&other.pretty());
243241

244242
pretty
245243
}
@@ -1415,4 +1413,63 @@ value 0".to_string();
14151413
assert_eq!(Some("1424182926".to_string()), get_pretty_block_attr(&block, "timestamp"));
14161414
assert_eq!(Some("163591".to_string()), get_pretty_block_attr(&block, "totalDifficulty"));
14171415
}
1416+
1417+
#[test]
1418+
fn test_receipt_other_fields_alignment() {
1419+
let receipt_json = serde_json::json!(
1420+
{
1421+
"status": "0x1",
1422+
"cumulativeGasUsed": "0x74e483",
1423+
"logs": [],
1424+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
1425+
"type": "0x2",
1426+
"transactionHash": "0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d",
1427+
"transactionIndex": "0x10",
1428+
"blockHash": "0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d",
1429+
"blockNumber": "0x7b1ab93",
1430+
"gasUsed": "0xc222",
1431+
"effectiveGasPrice": "0x18961",
1432+
"from": "0x2d815240a61731c75fa01b2793e1d3ed09f289d0",
1433+
"to": "0x4200000000000000000000000000000000000000",
1434+
"contractAddress": null,
1435+
"l1BaseFeeScalar": "0x146b",
1436+
"l1BlobBaseFee": "0x6a83078",
1437+
"l1BlobBaseFeeScalar": "0xf79c5",
1438+
"l1Fee": "0x51a9af7fd3",
1439+
"l1GasPrice": "0x972fe4acc",
1440+
"l1GasUsed": "0x640"
1441+
});
1442+
1443+
let receipt: AnyTransactionReceipt = serde_json::from_value(receipt_json).unwrap();
1444+
let formatted = receipt.pretty();
1445+
1446+
let expected = r#"
1447+
blockHash 0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d
1448+
blockNumber 129084307
1449+
contractAddress
1450+
cumulativeGasUsed 7660675
1451+
effectiveGasPrice 100705
1452+
from 0x2D815240A61731c75Fa01b2793E1D3eD09F289d0
1453+
gasUsed 49698
1454+
logs []
1455+
logsBloom 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1456+
root
1457+
status 1 (success)
1458+
transactionHash 0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d
1459+
transactionIndex 16
1460+
type 2
1461+
blobGasPrice
1462+
blobGasUsed
1463+
authorizationList
1464+
to 0x4200000000000000000000000000000000000000
1465+
l1BaseFeeScalar 5227
1466+
l1BlobBaseFee 111685752
1467+
l1BlobBaseFeeScalar 1014213
1468+
l1Fee 350739202003
1469+
l1GasPrice 40583973580
1470+
l1GasUsed 1600
1471+
"#;
1472+
1473+
assert_eq!(formatted.trim(), expected.trim());
1474+
}
14181475
}

crates/common/src/transactions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl UIfmt for TransactionReceiptWithRevertReason {
8888
if let Some(revert_reason) = &self.revert_reason {
8989
format!(
9090
"{}
91-
revertReason {}",
91+
revertReason {}",
9292
self.receipt.pretty(),
9393
revert_reason
9494
)

0 commit comments

Comments
 (0)