@@ -25,6 +25,7 @@ async fn test_submit_block_v1() -> Result<()> {
2525 HashSet :: from ( [ EncodingType :: Json ] ) ,
2626 HashSet :: from ( [ EncodingType :: Ssz , EncodingType :: Json ] ) ,
2727 EncodingType :: Json ,
28+ 1 ,
2829 )
2930 . await ?;
3031 assert_eq ! ( res. status( ) , StatusCode :: OK ) ;
@@ -42,11 +43,12 @@ async fn test_submit_block_v1() -> Result<()> {
4243#[ tokio:: test]
4344async fn test_submit_block_v2 ( ) -> Result < ( ) > {
4445 let res = submit_block_impl (
45- 3850 ,
46+ 3810 ,
4647 BuilderApiVersion :: V2 ,
4748 HashSet :: from ( [ EncodingType :: Json ] ) ,
4849 HashSet :: from ( [ EncodingType :: Ssz , EncodingType :: Json ] ) ,
4950 EncodingType :: Json ,
51+ 1 ,
5052 )
5153 . await ?;
5254 assert_eq ! ( res. status( ) , StatusCode :: ACCEPTED ) ;
@@ -57,11 +59,12 @@ async fn test_submit_block_v2() -> Result<()> {
5759#[ tokio:: test]
5860async fn test_submit_block_v1_ssz ( ) -> Result < ( ) > {
5961 let res = submit_block_impl (
60- 3810 ,
62+ 3820 ,
6163 BuilderApiVersion :: V1 ,
6264 HashSet :: from ( [ EncodingType :: Ssz ] ) ,
6365 HashSet :: from ( [ EncodingType :: Ssz , EncodingType :: Json ] ) ,
6466 EncodingType :: Ssz ,
67+ 1 ,
6568 )
6669 . await ?;
6770 assert_eq ! ( res. status( ) , StatusCode :: OK ) ;
@@ -80,18 +83,114 @@ async fn test_submit_block_v1_ssz() -> Result<()> {
8083#[ tokio:: test]
8184async fn test_submit_block_v2_ssz ( ) -> Result < ( ) > {
8285 let res = submit_block_impl (
83- 3860 ,
86+ 3830 ,
8487 BuilderApiVersion :: V2 ,
8588 HashSet :: from ( [ EncodingType :: Ssz ] ) ,
8689 HashSet :: from ( [ EncodingType :: Ssz , EncodingType :: Json ] ) ,
8790 EncodingType :: Ssz ,
91+ 1 ,
8892 )
8993 . await ?;
9094 assert_eq ! ( res. status( ) , StatusCode :: ACCEPTED ) ;
9195 assert_eq ! ( res. bytes( ) . await ?. len( ) , 0 ) ;
9296 Ok ( ( ) )
9397}
9498
99+ /// Test that a v1 submit block request in SSZ is converted to JSON if the relay
100+ /// only supports JSON
101+ #[ tokio:: test]
102+ async fn test_submit_block_v1_ssz_into_json ( ) -> Result < ( ) > {
103+ let res = submit_block_impl (
104+ 3840 ,
105+ BuilderApiVersion :: V1 ,
106+ HashSet :: from ( [ EncodingType :: Ssz ] ) ,
107+ HashSet :: from ( [ EncodingType :: Json ] ) ,
108+ EncodingType :: Ssz ,
109+ 2 ,
110+ )
111+ . await ?;
112+ assert_eq ! ( res. status( ) , StatusCode :: OK ) ;
113+
114+ let signed_blinded_block = load_test_signed_blinded_block ( ) ;
115+
116+ let response_body =
117+ PayloadAndBlobs :: from_ssz_bytes_by_fork ( & res. bytes ( ) . await ?, ForkName :: Electra ) . unwrap ( ) ;
118+ assert_eq ! (
119+ response_body. execution_payload. block_hash( ) ,
120+ signed_blinded_block. block_hash( ) . into( )
121+ ) ;
122+ Ok ( ( ) )
123+ }
124+
125+ /// Test that a v2 submit block request in SSZ is converted to JSON if the relay
126+ /// only supports JSON
127+ #[ tokio:: test]
128+ async fn test_submit_block_v2_ssz_into_json ( ) -> Result < ( ) > {
129+ let res = submit_block_impl (
130+ 3850 ,
131+ BuilderApiVersion :: V2 ,
132+ HashSet :: from ( [ EncodingType :: Ssz ] ) ,
133+ HashSet :: from ( [ EncodingType :: Json ] ) ,
134+ EncodingType :: Ssz ,
135+ 2 ,
136+ )
137+ . await ?;
138+ assert_eq ! ( res. status( ) , StatusCode :: ACCEPTED ) ;
139+ assert_eq ! ( res. bytes( ) . await ?. len( ) , 0 ) ;
140+ Ok ( ( ) )
141+ }
142+
143+ /// Test v1 requesting multiple types when the relay supports SSZ, which should
144+ /// return SSZ
145+ #[ tokio:: test]
146+ async fn test_submit_block_v1_multitype_ssz ( ) -> Result < ( ) > {
147+ let res = submit_block_impl (
148+ 3860 ,
149+ BuilderApiVersion :: V1 ,
150+ HashSet :: from ( [ EncodingType :: Ssz , EncodingType :: Json ] ) ,
151+ HashSet :: from ( [ EncodingType :: Ssz ] ) ,
152+ EncodingType :: Ssz ,
153+ 1 ,
154+ )
155+ . await ?;
156+ assert_eq ! ( res. status( ) , StatusCode :: OK ) ;
157+
158+ let signed_blinded_block = load_test_signed_blinded_block ( ) ;
159+
160+ let response_body =
161+ PayloadAndBlobs :: from_ssz_bytes_by_fork ( & res. bytes ( ) . await ?, ForkName :: Electra ) . unwrap ( ) ;
162+ assert_eq ! (
163+ response_body. execution_payload. block_hash( ) ,
164+ signed_blinded_block. block_hash( ) . into( )
165+ ) ;
166+ Ok ( ( ) )
167+ }
168+
169+ /// Test v1 requesting multiple types when the relay supports SSZ, which should
170+ /// return JSON
171+ #[ tokio:: test]
172+ async fn test_submit_block_v1_multitype_json ( ) -> Result < ( ) > {
173+ let res = submit_block_impl (
174+ 3870 ,
175+ BuilderApiVersion :: V1 ,
176+ HashSet :: from ( [ EncodingType :: Ssz , EncodingType :: Json ] ) ,
177+ HashSet :: from ( [ EncodingType :: Json ] ) ,
178+ EncodingType :: Json ,
179+ 1 ,
180+ )
181+ . await ?;
182+ assert_eq ! ( res. status( ) , StatusCode :: OK ) ;
183+
184+ let signed_blinded_block = load_test_signed_blinded_block ( ) ;
185+
186+ let response_body = serde_json:: from_slice :: < SubmitBlindedBlockResponse > ( & res. bytes ( ) . await ?) ?;
187+ assert_eq ! (
188+ response_body. data. execution_payload. block_hash( ) ,
189+ signed_blinded_block. block_hash( ) . into( )
190+ ) ;
191+ Ok ( ( ) )
192+ }
193+
95194#[ tokio:: test]
96195async fn test_submit_block_too_large ( ) -> Result < ( ) > {
97196 setup_test_env ( ) ;
@@ -135,6 +234,7 @@ async fn submit_block_impl(
135234 accept_types : HashSet < EncodingType > ,
136235 relay_types : HashSet < EncodingType > ,
137236 serialization_mode : EncodingType ,
237+ expected_try_count : u64 ,
138238) -> Result < Response > {
139239 // Setup test environment
140240 setup_test_env ( ) ;
@@ -184,6 +284,6 @@ async fn submit_block_impl(
184284 . await ?
185285 }
186286 } ;
187- assert_eq ! ( mock_state. received_submit_block( ) , 1 ) ;
287+ assert_eq ! ( mock_state. received_submit_block( ) , expected_try_count ) ;
188288 Ok ( res)
189289}
0 commit comments