reth_e2e_test_utils/
rpc.rs
1use alloy_consensus::TxEnvelope;
2use alloy_network::eip2718::Decodable2718;
3use alloy_primitives::{Bytes, B256};
4use reth_chainspec::EthereumHardforks;
5use reth_node_api::{BlockTy, FullNodeComponents};
6use reth_node_builder::{rpc::RpcRegistry, NodeTypes};
7use reth_provider::BlockReader;
8use reth_rpc_api::DebugApiServer;
9use reth_rpc_eth_api::{
10 helpers::{EthApiSpec, EthTransactions, TraceExt},
11 EthApiTypes,
12};
13
14#[expect(missing_debug_implementations)]
15pub struct RpcTestContext<Node: FullNodeComponents, EthApi: EthApiTypes> {
16 pub inner: RpcRegistry<Node, EthApi>,
17}
18
19impl<Node, EthApi> RpcTestContext<Node, EthApi>
20where
21 Node: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
22 EthApi: EthApiSpec<Provider: BlockReader<Block = BlockTy<Node::Types>>>
23 + EthTransactions
24 + TraceExt,
25{
26 pub async fn inject_tx(&self, raw_tx: Bytes) -> Result<B256, EthApi::Error> {
28 let eth_api = self.inner.eth_api();
29 eth_api.send_raw_transaction(raw_tx).await
30 }
31
32 pub async fn envelope_by_hash(&self, hash: B256) -> eyre::Result<TxEnvelope> {
34 let tx = self.inner.debug_api().raw_transaction(hash).await?.unwrap();
35 let tx = tx.to_vec();
36 Ok(TxEnvelope::decode_2718(&mut tx.as_ref()).unwrap())
37 }
38}