test: add tx receipt roundtrip test (#1360)

This commit is contained in:
Matthias Seitz 2022-06-08 14:13:36 +02:00 committed by GitHub
parent ea1a87271c
commit c7a8a1ea5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 57 additions and 0 deletions

View File

@ -404,6 +404,7 @@ pub struct TransactionReceipt {
/// Status: either 1 (success) or 0 (failure). Only present after activation of [EIP-658](https://eips.ethereum.org/EIPS/eip-658)
pub status: Option<U64>,
/// State root. Only present before activation of [EIP-658](https://eips.ethereum.org/EIPS/eip-658)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub root: Option<H256>,
/// Logs bloom
#[serde(rename = "logsBloom")]
@ -808,4 +809,60 @@ mod tests {
)
.unwrap();
}
#[test]
fn serde_create_transaction_receipt() {
let v: serde_json::Value = serde_json::from_str(
r#"{
"transactionHash": "0x611b173b0e0dfda94da7bfb6cb77c9f1c03e2f2149ba060e6bddfaa219942369",
"blockHash": "0xa11871d61e0e703ae33b358a6a9653c43e4216f277d4a1c7377b76b4d5b4cbf1",
"blockNumber": "0xe3c1d8",
"contractAddress": "0x08f6db30039218894067023a3593baf27d3f4a2b",
"cumulativeGasUsed": "0x1246047",
"effectiveGasPrice": "0xa02ffee00",
"from": "0x0968995a48162a23af60d3ca25cddfa143cd8891",
"gasUsed": "0x1b9229",
"logs": [
{
"address": "0x08f6db30039218894067023a3593baf27d3f4a2b",
"topics": [
"0x40c340f65e17194d14ddddb073d3c9f888e3cb52b5aae0c6c7706b4fbc905fac"
],
"data": "0x0000000000000000000000000968995a48162a23af60d3ca25cddfa143cd88910000000000000000000000000000000000000000000000000000000000002616",
"blockNumber": "0xe3c1d8",
"transactionHash": "0x611b173b0e0dfda94da7bfb6cb77c9f1c03e2f2149ba060e6bddfaa219942369",
"transactionIndex": "0xdf",
"blockHash": "0xa11871d61e0e703ae33b358a6a9653c43e4216f277d4a1c7377b76b4d5b4cbf1",
"logIndex": "0x196",
"removed": false
},
{
"address": "0x08f6db30039218894067023a3593baf27d3f4a2b",
"topics": [
"0x40c340f65e17194d14ddddb073d3c9f888e3cb52b5aae0c6c7706b4fbc905fac"
],
"data": "0x00000000000000000000000059750ac0631f63bfdce0f0867618e468e11ee34700000000000000000000000000000000000000000000000000000000000000fa",
"blockNumber": "0xe3c1d8",
"transactionHash": "0x611b173b0e0dfda94da7bfb6cb77c9f1c03e2f2149ba060e6bddfaa219942369",
"transactionIndex": "0xdf",
"blockHash": "0xa11871d61e0e703ae33b358a6a9653c43e4216f277d4a1c7377b76b4d5b4cbf1",
"logIndex": "0x197",
"removed": false
}
],
"logsBloom": "0x00000000000000800000000040000000000000000000000000000000000000000000008000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": "0x1",
"to": null,
"transactionIndex": "0xdf",
"type": "0x2"
}
"#,
)
.unwrap();
let receipt: TransactionReceipt = serde_json::from_value(v.clone()).unwrap();
assert!(receipt.to.is_none());
let receipt = serde_json::to_value(receipt).unwrap();
assert_eq!(v, receipt);
}
}