@@ -46,6 +46,8 @@ pub struct MockRelayState {
4646 pub chain : Chain ,
4747 pub signer : BlsSecretKey ,
4848 large_body : bool ,
49+ supports_submit_block_v2 : bool ,
50+ use_not_found_for_submit_block : bool ,
4951 received_get_header : Arc < AtomicU64 > ,
5052 received_get_status : Arc < AtomicU64 > ,
5153 received_register_validator : Arc < AtomicU64 > ,
@@ -69,6 +71,12 @@ impl MockRelayState {
6971 pub fn large_body ( & self ) -> bool {
7072 self . large_body
7173 }
74+ pub fn supports_submit_block_v2 ( & self ) -> bool {
75+ self . supports_submit_block_v2
76+ }
77+ pub fn use_not_found_for_submit_block ( & self ) -> bool {
78+ self . use_not_found_for_submit_block
79+ }
7280 pub fn set_response_override ( & self , status : StatusCode ) {
7381 * self . response_override . write ( ) . unwrap ( ) = Some ( status) ;
7482 }
@@ -80,6 +88,8 @@ impl MockRelayState {
8088 chain,
8189 signer,
8290 large_body : false ,
91+ supports_submit_block_v2 : true ,
92+ use_not_found_for_submit_block : false ,
8393 received_get_header : Default :: default ( ) ,
8494 received_get_status : Default :: default ( ) ,
8595 received_register_validator : Default :: default ( ) ,
@@ -91,6 +101,14 @@ impl MockRelayState {
91101 pub fn with_large_body ( self ) -> Self {
92102 Self { large_body : true , ..self }
93103 }
104+
105+ pub fn with_no_submit_block_v2 ( self ) -> Self {
106+ Self { supports_submit_block_v2 : false , ..self }
107+ }
108+
109+ pub fn with_not_found_for_submit_block ( self ) -> Self {
110+ Self { use_not_found_for_submit_block : true , ..self }
111+ }
94112}
95113
96114pub fn mock_relay_app_router ( state : Arc < MockRelayState > ) -> Router {
@@ -100,7 +118,11 @@ pub fn mock_relay_app_router(state: Arc<MockRelayState>) -> Router {
100118 . route ( REGISTER_VALIDATOR_PATH , post ( handle_register_validator) )
101119 . route ( SUBMIT_BLOCK_PATH , post ( handle_submit_block_v1) ) ;
102120
103- let v2_builder_routes = Router :: new ( ) . route ( SUBMIT_BLOCK_PATH , post ( handle_submit_block_v2) ) ;
121+ let v2_builder_routes = if state. supports_submit_block_v2 {
122+ Router :: new ( ) . route ( SUBMIT_BLOCK_PATH , post ( handle_submit_block_v2) )
123+ } else {
124+ Router :: new ( )
125+ } ;
104126
105127 let builder_router_v1 = Router :: new ( ) . nest ( BUILDER_V1_API_PATH , v1_builder_routes) ;
106128 let builder_router_v2 = Router :: new ( ) . nest ( BUILDER_V2_API_PATH , v2_builder_routes) ;
@@ -165,6 +187,9 @@ async fn handle_submit_block_v1(
165187 State ( state) : State < Arc < MockRelayState > > ,
166188 Json ( submit_block) : Json < SignedBlindedBeaconBlock > ,
167189) -> Response {
190+ if state. use_not_found_for_submit_block ( ) {
191+ return StatusCode :: NOT_FOUND . into_response ( ) ;
192+ }
168193 state. received_submit_block . fetch_add ( 1 , Ordering :: Relaxed ) ;
169194 if state. large_body ( ) {
170195 ( StatusCode :: OK , Json ( vec ! [ 1u8 ; 1 + MAX_SIZE_SUBMIT_BLOCK_RESPONSE ] ) ) . into_response ( )
@@ -192,6 +217,9 @@ async fn handle_submit_block_v1(
192217 }
193218}
194219async fn handle_submit_block_v2 ( State ( state) : State < Arc < MockRelayState > > ) -> Response {
220+ if state. use_not_found_for_submit_block ( ) {
221+ return StatusCode :: NOT_FOUND . into_response ( ) ;
222+ }
195223 state. received_submit_block . fetch_add ( 1 , Ordering :: Relaxed ) ;
196224 ( StatusCode :: ACCEPTED , "" ) . into_response ( )
197225}
0 commit comments