@@ -28,6 +28,7 @@ use sensitive_url::SensitiveUrl;
2828use slot_clock:: SlotClock ;
2929use state_processing:: per_block_processing:: get_expected_withdrawals;
3030use state_processing:: per_slot_processing;
31+ use state_processing:: state_advance:: partial_state_advance;
3132use std:: convert:: TryInto ;
3233use std:: sync:: Arc ;
3334use tokio:: time:: Duration ;
@@ -4341,6 +4342,72 @@ impl ApiTester {
43414342 self
43424343 }
43434344
4345+ pub async fn test_get_expected_withdrawals_invalid_state ( self ) -> Self {
4346+ let state_id = CoreStateId :: Root ( Hash256 :: zero ( ) ) ;
4347+
4348+ let result = self . client . get_expected_withdrawals ( & state_id) . await ;
4349+
4350+ match result {
4351+ Err ( e) => {
4352+ assert_eq ! ( e. status( ) . unwrap( ) , 404 ) ;
4353+ }
4354+ _ => panic ! ( "query did not fail correctly" ) ,
4355+ }
4356+
4357+ self
4358+ }
4359+
4360+ pub async fn test_get_expected_withdrawals_capella ( self ) -> Self {
4361+ let slot = self . chain . slot ( ) . unwrap ( ) ;
4362+ let state_id = CoreStateId :: Slot ( slot) ;
4363+
4364+ // calculate the expected withdrawals
4365+ let ( mut state, _, _) = StateId ( state_id) . state ( & self . chain ) . unwrap ( ) ;
4366+ let proposal_slot = state. slot ( ) + 1 ;
4367+ let proposal_epoch = proposal_slot. epoch ( E :: slots_per_epoch ( ) ) ;
4368+ let ( state_root, _, _) = StateId ( state_id) . root ( & self . chain ) . unwrap ( ) ;
4369+ if proposal_epoch != state. current_epoch ( ) {
4370+ let _ = partial_state_advance (
4371+ & mut state,
4372+ Some ( state_root) ,
4373+ proposal_slot,
4374+ & self . chain . spec ,
4375+ ) ;
4376+ }
4377+ let expected_withdrawals = get_expected_withdrawals ( & state, & self . chain . spec ) . unwrap ( ) ;
4378+
4379+ // fetch expected withdrawals from the client
4380+ let result = self . client . get_expected_withdrawals ( & state_id) . await ;
4381+ match result {
4382+ Ok ( withdrawal_response) => {
4383+ assert_eq ! ( withdrawal_response. execution_optimistic, Some ( false ) ) ;
4384+ assert_eq ! ( withdrawal_response. finalized, Some ( false ) ) ;
4385+ assert_eq ! ( withdrawal_response. data, expected_withdrawals. to_vec( ) ) ;
4386+ }
4387+ Err ( e) => {
4388+ println ! ( "{:?}" , e) ;
4389+ panic ! ( "query failed incorrectly" ) ;
4390+ }
4391+ }
4392+
4393+ self
4394+ }
4395+
4396+ pub async fn test_get_expected_withdrawals_pre_capella ( self ) -> Self {
4397+ let state_id = CoreStateId :: Head ;
4398+
4399+ let result = self . client . get_expected_withdrawals ( & state_id) . await ;
4400+
4401+ match result {
4402+ Err ( e) => {
4403+ assert_eq ! ( e. status( ) . unwrap( ) , 400 ) ;
4404+ }
4405+ _ => panic ! ( "query did not fail correctly" ) ,
4406+ }
4407+
4408+ self
4409+ }
4410+
43444411 pub async fn test_get_events_altair ( self ) -> Self {
43454412 let topics = vec ! [ EventTopic :: ContributionAndProof ] ;
43464413 let mut events_future = self
@@ -5123,3 +5190,37 @@ async fn optimistic_responses() {
51235190 . test_check_optimistic_responses ( )
51245191 . await ;
51255192}
5193+
5194+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
5195+ async fn expected_withdrawals_invalid_pre_capella ( ) {
5196+ let mut config = ApiTesterConfig :: default ( ) ;
5197+ config. spec . altair_fork_epoch = Some ( Epoch :: new ( 0 ) ) ;
5198+ ApiTester :: new_from_config ( config)
5199+ . await
5200+ . test_get_expected_withdrawals_pre_capella ( )
5201+ . await ;
5202+ }
5203+
5204+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
5205+ async fn expected_withdrawals_invalid_state ( ) {
5206+ let mut config = ApiTesterConfig :: default ( ) ;
5207+ config. spec . altair_fork_epoch = Some ( Epoch :: new ( 0 ) ) ;
5208+ config. spec . bellatrix_fork_epoch = Some ( Epoch :: new ( 0 ) ) ;
5209+ config. spec . capella_fork_epoch = Some ( Epoch :: new ( 0 ) ) ;
5210+ ApiTester :: new_from_config ( config)
5211+ . await
5212+ . test_get_expected_withdrawals_invalid_state ( )
5213+ . await ;
5214+ }
5215+
5216+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
5217+ async fn expected_withdrawals_valid_capella ( ) {
5218+ let mut config = ApiTesterConfig :: default ( ) ;
5219+ config. spec . altair_fork_epoch = Some ( Epoch :: new ( 0 ) ) ;
5220+ config. spec . bellatrix_fork_epoch = Some ( Epoch :: new ( 0 ) ) ;
5221+ config. spec . capella_fork_epoch = Some ( Epoch :: new ( 0 ) ) ;
5222+ ApiTester :: new_from_config ( config)
5223+ . await
5224+ . test_get_expected_withdrawals_capella ( )
5225+ . await ;
5226+ }
0 commit comments