@@ -21,7 +21,7 @@ use unionlabs::{
2121
2222use crate :: {
2323 client:: { verify_attestation, verify_header} ,
24- contract:: { execute, migrate, query} ,
24+ contract:: { execute, migrate, query, query :: LatestHeight } ,
2525 errors:: Error ,
2626 msg:: { ExecuteMsg , QueryMsg , RestrictedExecuteMsg } ,
2727 types:: { Attestation , AttestationValue } ,
@@ -993,3 +993,93 @@ fn attestors_unique_per_chain() {
993993 . collect :: < BTreeSet < _ > > ( ) ,
994994 ) ;
995995}
996+
997+ #[ test]
998+ fn latest_height ( ) {
999+ let ( mut deps, env) = setup ( ) ;
1000+
1001+ reach_quorum (
1002+ & mut deps,
1003+ & env,
1004+ Attestation {
1005+ chain_id : CHAIN_ID . to_owned ( ) ,
1006+ height : 1 ,
1007+ timestamp : Timestamp :: from_secs ( 1 ) ,
1008+ key : b"key" . into ( ) ,
1009+ value : AttestationValue :: NonExistence ,
1010+ } ,
1011+ [ & * ATTESTOR_1 , & * ATTESTOR_2 ] ,
1012+ ) ;
1013+
1014+ // no heights attested to for this chain
1015+ assert_query_result (
1016+ deps. as_ref ( ) ,
1017+ & env,
1018+ QueryMsg :: LatestHeight {
1019+ chain_id : "998" . to_owned ( ) ,
1020+ } ,
1021+ & None :: < LatestHeight > ,
1022+ ) ;
1023+
1024+ assert_query_result (
1025+ deps. as_ref ( ) ,
1026+ & env,
1027+ QueryMsg :: LatestHeight {
1028+ chain_id : CHAIN_ID . to_owned ( ) ,
1029+ } ,
1030+ & Some ( LatestHeight {
1031+ height : 1 ,
1032+ timestamp : Timestamp :: from_secs ( 1 ) ,
1033+ } ) ,
1034+ ) ;
1035+
1036+ reach_quorum (
1037+ & mut deps,
1038+ & env,
1039+ Attestation {
1040+ chain_id : CHAIN_ID . to_owned ( ) ,
1041+ height : 2 ,
1042+ timestamp : Timestamp :: from_secs ( 1 ) ,
1043+ key : b"key" . into ( ) ,
1044+ value : AttestationValue :: NonExistence ,
1045+ } ,
1046+ [ & * ATTESTOR_1 , & * ATTESTOR_2 ] ,
1047+ ) ;
1048+
1049+ assert_query_result (
1050+ deps. as_ref ( ) ,
1051+ & env,
1052+ QueryMsg :: LatestHeight {
1053+ chain_id : CHAIN_ID . to_owned ( ) ,
1054+ } ,
1055+ & Some ( LatestHeight {
1056+ height : 2 ,
1057+ timestamp : Timestamp :: from_secs ( 1 ) ,
1058+ } ) ,
1059+ ) ;
1060+
1061+ reach_quorum (
1062+ & mut deps,
1063+ & env,
1064+ Attestation {
1065+ chain_id : CHAIN_ID . to_owned ( ) ,
1066+ height : u64:: MAX ,
1067+ timestamp : Timestamp :: from_secs ( 1 ) ,
1068+ key : b"key" . into ( ) ,
1069+ value : AttestationValue :: NonExistence ,
1070+ } ,
1071+ [ & * ATTESTOR_1 , & * ATTESTOR_2 ] ,
1072+ ) ;
1073+
1074+ assert_query_result (
1075+ deps. as_ref ( ) ,
1076+ & env,
1077+ QueryMsg :: LatestHeight {
1078+ chain_id : CHAIN_ID . to_owned ( ) ,
1079+ } ,
1080+ & Some ( LatestHeight {
1081+ height : u64:: MAX ,
1082+ timestamp : Timestamp :: from_secs ( 1 ) ,
1083+ } ) ,
1084+ ) ;
1085+ }
0 commit comments