reth_e2e_test_utils/
rpc.rs1use alloy_consensus::{EthereumTxEnvelope, TxEip4844Variant};
2use alloy_eips::eip7594::BlobTransactionSidecarVariant;
3use alloy_network::eip2718::Decodable2718;
4use alloy_primitives::{Bytes, B256};
5use reth_chainspec::EthereumHardforks;
6use reth_node_api::{BlockTy, FullNodeComponents};
7use reth_node_builder::{rpc::RpcRegistry, NodeTypes};
8use reth_provider::BlockReader;
9use reth_rpc_api::DebugApiServer;
10use reth_rpc_eth_api::{
11 helpers::{EthApiSpec, EthTransactions, LoadReceipt, TraceExt},
12 EthApiTypes, RpcReceipt,
13};
14
15#[expect(missing_debug_implementations)]
16pub struct RpcTestContext<Node: FullNodeComponents, EthApi: EthApiTypes> {
17 pub inner: RpcRegistry<Node, EthApi>,
18}
19
20impl<Node, EthApi> RpcTestContext<Node, EthApi>
21where
22 Node: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
23 EthApi: EthApiSpec<Provider: BlockReader<Block = BlockTy<Node::Types>>>
24 + EthTransactions
25 + TraceExt,
26{
27 pub async fn inject_tx(&self, raw_tx: Bytes) -> Result<B256, EthApi::Error> {
29 let eth_api = self.inner.eth_api();
30 eth_api.send_raw_transaction(raw_tx).await
31 }
32
33 pub async fn envelope_by_hash(
36 &self,
37 hash: B256,
38 ) -> eyre::Result<EthereumTxEnvelope<TxEip4844Variant<BlobTransactionSidecarVariant>>> {
39 self.decoded_transaction_by_hash(hash).await
40 }
41
42 pub async fn decoded_transaction_by_hash<T: Decodable2718>(
47 &self,
48 hash: B256,
49 ) -> eyre::Result<T> {
50 let tx = self
51 .inner
52 .debug_api()
53 .raw_transaction(hash)
54 .await?
55 .ok_or_else(|| eyre::eyre!("transaction {hash} not found"))?;
56 Ok(T::decode_2718_exact(&tx)?)
57 }
58
59 pub async fn transaction_receipt(
62 &self,
63 hash: B256,
64 ) -> Result<Option<RpcReceipt<EthApi::NetworkTypes>>, EthApi::Error>
65 where
66 EthApi: LoadReceipt + 'static,
67 {
68 self.inner.eth_api().transaction_receipt(hash).await
69 }
70}