|
3 | 3 | use crate::utils::{http_provider, http_provider_with_signer}; |
4 | 4 | use alloy_eips::eip2718::Encodable2718; |
5 | 5 | use alloy_network::{EthereumWallet, TransactionBuilder}; |
6 | | -use alloy_primitives::{Address, TxHash, TxKind, U256, b256}; |
| 6 | +use alloy_primitives::{Address, Bloom, TxHash, TxKind, U256, b256}; |
7 | 7 | use alloy_provider::Provider; |
8 | 8 | use alloy_rpc_types::TransactionRequest; |
9 | 9 | use alloy_serde::WithOtherFields; |
10 | 10 | use anvil::{NodeConfig, spawn}; |
11 | 11 | use foundry_evm_networks::NetworkConfigs; |
12 | 12 | use op_alloy_consensus::TxDeposit; |
13 | 13 | use op_alloy_rpc_types::OpTransactionFields; |
| 14 | +use serde_json::{Value, json}; |
14 | 15 |
|
15 | 16 | #[tokio::test(flavor = "multi_thread")] |
16 | 17 | async fn test_deposits_not_supported_if_optimism_disabled() { |
@@ -224,3 +225,48 @@ async fn test_deposit_tx_checks_sufficient_funds_after_applying_deposited_value( |
224 | 225 | // recipient should've received the entire deposited value |
225 | 226 | assert_eq!(recipient_new_balance, U256::from(send_value)); |
226 | 227 | } |
| 228 | + |
| 229 | +#[test] |
| 230 | +fn preserves_op_fields_in_convert_to_anvil_receipt() { |
| 231 | + let receipt_json = json!({ |
| 232 | + "status": "0x1", |
| 233 | + "cumulativeGasUsed": "0x74e483", |
| 234 | + "logs": [], |
| 235 | + "logsBloom": Bloom::default(), |
| 236 | + "type": "0x2", |
| 237 | + "transactionHash": "0x91181b0dca3b29aa136eeb2f536be5ce7b0aebc949be1c44b5509093c516097d", |
| 238 | + "transactionIndex": "0x10", |
| 239 | + "blockHash": "0x54bafb12e8cea9bb355fbf03a4ac49e42a2a1a80fa6cf4364b342e2de6432b5d", |
| 240 | + "blockNumber": "0x7b1ab93", |
| 241 | + "gasUsed": "0xc222", |
| 242 | + "effectiveGasPrice": "0x18961", |
| 243 | + "from": "0x2d815240a61731c75fa01b2793e1d3ed09f289d0", |
| 244 | + "to": "0x4200000000000000000000000000000000000000", |
| 245 | + "contractAddress": Value::Null, |
| 246 | + "l1BaseFeeScalar": "0x146b", |
| 247 | + "l1BlobBaseFee": "0x6a83078", |
| 248 | + "l1BlobBaseFeeScalar": "0xf79c5", |
| 249 | + "l1Fee": "0x51a9af7fd3", |
| 250 | + "l1GasPrice": "0x972fe4acc", |
| 251 | + "l1GasUsed": "0x640", |
| 252 | + }); |
| 253 | + |
| 254 | + let receipt: alloy_network::AnyTransactionReceipt = |
| 255 | + serde_json::from_value(receipt_json).expect("valid receipt json"); |
| 256 | + |
| 257 | + let converted = anvil_core::eth::transaction::convert_to_anvil_receipt(receipt) |
| 258 | + .expect("conversion should succeed"); |
| 259 | + let converted_json = serde_json::to_value(&converted).expect("serialize to json"); |
| 260 | + |
| 261 | + for (key, expected) in [ |
| 262 | + ("l1Fee", "0x51a9af7fd3"), |
| 263 | + ("l1GasPrice", "0x972fe4acc"), |
| 264 | + ("l1GasUsed", "0x640"), |
| 265 | + ("l1BaseFeeScalar", "0x146b"), |
| 266 | + ("l1BlobBaseFee", "0x6a83078"), |
| 267 | + ("l1BlobBaseFeeScalar", "0xf79c5"), |
| 268 | + ] { |
| 269 | + let got = converted_json.get(key).and_then(Value::as_str); |
| 270 | + assert_eq!(got, Some(expected), "field `{key}` mismatch"); |
| 271 | + } |
| 272 | +} |
0 commit comments