alloy_provider/ext/
testing.rs1use crate::Provider;
6use alloy_json_rpc::RpcRecv;
7use alloy_network::Network;
8use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV5, TestingBuildBlockRequestV1};
9use alloy_transport::TransportResult;
10
11#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
13#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
14pub trait TestingApi<N>: Send + Sync {
15 async fn build_block<R: RpcRecv>(
17 &self,
18 method: &'static str,
19 request: TestingBuildBlockRequestV1,
20 ) -> TransportResult<R>;
21
22 async fn build_block_v1(
24 &self,
25 request: TestingBuildBlockRequestV1,
26 ) -> TransportResult<ExecutionPayloadEnvelopeV5>;
27}
28
29#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
30#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
31impl<N, P> TestingApi<N> for P
32where
33 N: Network,
34 P: Provider<N>,
35{
36 async fn build_block<R: RpcRecv>(
37 &self,
38 method: &'static str,
39 request: TestingBuildBlockRequestV1,
40 ) -> TransportResult<R> {
41 self.client().request(method, (request,)).await
42 }
43
44 async fn build_block_v1(
45 &self,
46 request: TestingBuildBlockRequestV1,
47 ) -> TransportResult<ExecutionPayloadEnvelopeV5> {
48 self.build_block("testing_buildBlockV1", request).await
49 }
50}