@@ -910,4 +910,73 @@ mod tests {
910
910
911
911
assert ! ( client_state. status( & ctx, & client_id) . unwrap( ) . is_expired( ) ) ;
912
912
}
913
+
914
+ #[ test]
915
+ fn test_client_update_max_clock_drift ( ) {
916
+ let chain_id_b = ChainId :: new ( "mockgaiaB" , 1 ) . unwrap ( ) ;
917
+
918
+ let client_height = Height :: new ( 1 , 20 ) . unwrap ( ) ;
919
+
920
+ let client_id = ClientId :: new ( tm_client_type ( ) , 0 ) . unwrap ( ) ;
921
+
922
+ let timestamp = Timestamp :: now ( ) ;
923
+
924
+ let max_clock_drift = Duration :: from_secs ( 64 ) ;
925
+
926
+ let ctx_a = MockContextConfig :: builder ( )
927
+ . host_id ( ChainId :: new ( "mockgaiaA" , 1 ) . unwrap ( ) )
928
+ . latest_height ( Height :: new ( 1 , 1 ) . unwrap ( ) )
929
+ . latest_timestamp ( timestamp)
930
+ . build ( )
931
+ . with_client_config (
932
+ MockClientConfig :: builder ( )
933
+ . client_chain_id ( chain_id_b. clone ( ) )
934
+ . client_id ( client_id. clone ( ) )
935
+ . client_state_height ( client_height)
936
+ . client_type ( tm_client_type ( ) )
937
+ . latest_timestamp ( timestamp)
938
+ . max_clock_drift ( max_clock_drift)
939
+ . build ( ) ,
940
+ ) ;
941
+
942
+ let mut ctx_b = MockContextConfig :: builder ( )
943
+ . host_id ( chain_id_b. clone ( ) )
944
+ . host_type ( HostType :: SyntheticTendermint )
945
+ . latest_height ( client_height)
946
+ . latest_timestamp ( timestamp)
947
+ . max_history_size ( u64:: MAX )
948
+ . build ( ) ;
949
+
950
+ while ctx_b. host_timestamp ( ) . expect ( "no error" )
951
+ < ( ctx_a. host_timestamp ( ) . expect ( "no error" ) + max_clock_drift) . expect ( "no error" )
952
+ {
953
+ ctx_b. advance_host_chain_height ( ) ;
954
+ }
955
+
956
+ // include current block
957
+ ctx_b. advance_host_chain_height ( ) ;
958
+
959
+ let update_height = ctx_b. latest_height ( ) ;
960
+
961
+ let signer = get_dummy_account_id ( ) ;
962
+
963
+ let mut block = ctx_b. host_block ( & update_height) . unwrap ( ) . clone ( ) ;
964
+ block. set_trusted_height ( client_height) ;
965
+
966
+ let trusted_next_validator_set = match ctx_b. host_block ( & client_height) . expect ( "no error" ) {
967
+ HostBlock :: SyntheticTendermint ( header) => header. light_block . next_validators . clone ( ) ,
968
+ _ => panic ! ( "unexpected host block type" ) ,
969
+ } ;
970
+
971
+ block. set_trusted_next_validators_set ( trusted_next_validator_set) ;
972
+
973
+ let msg = MsgUpdateClient {
974
+ client_id,
975
+ client_message : block. clone ( ) . into ( ) ,
976
+ signer,
977
+ } ;
978
+
979
+ let res = validate ( & ctx_a, MsgUpdateOrMisbehaviour :: UpdateClient ( msg. clone ( ) ) ) ;
980
+ assert ! ( res. is_err( ) ) ;
981
+ }
913
982
}
0 commit comments