File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
mithril-common/src/test_utils Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,11 @@ impl CertificateChainFixture {
132132 & self . certificates_chained [ self . certificates_chained . len ( ) - 1 ]
133133 }
134134
135+ /// Return the latest certificate of this chain
136+ pub fn latest_certificate ( & self ) -> & Certificate {
137+ & self . certificates_chained [ 0 ]
138+ }
139+
135140 /// Return a copy of the chain but with reversed order (from genesis to last)
136141 pub fn reversed_chain ( & self ) -> Vec < Certificate > {
137142 self . certificates_chained . iter ( ) . rev ( ) . cloned ( ) . collect ( )
@@ -1065,6 +1070,22 @@ mod test {
10651070 assert ! ( chain_with_multiple_certificates. genesis_certificate( ) . is_genesis( ) ) ;
10661071 }
10671072
1073+ #[ test]
1074+ fn get_latest_certificate ( ) {
1075+ let chain_with_only_a_genesis = CertificateChainBuilder :: new ( )
1076+ . with_total_certificates ( 1 )
1077+ . build ( ) ;
1078+ assert ! ( chain_with_only_a_genesis. latest_certificate( ) . is_genesis( ) ) ;
1079+
1080+ let chain_with_multiple_certificates = CertificateChainBuilder :: new ( )
1081+ . with_total_certificates ( 10 )
1082+ . build ( ) ;
1083+ assert_eq ! (
1084+ chain_with_multiple_certificates. latest_certificate( ) ,
1085+ chain_with_multiple_certificates. first( ) . unwrap( )
1086+ ) ;
1087+ }
1088+
10681089 #[ test]
10691090 fn path_to_genesis_from_a_chain_with_one_certificate_per_epoch ( ) {
10701091 let chain = CertificateChainBuilder :: new ( )
You can’t perform that action at this time.
0 commit comments