@@ -10,6 +10,7 @@ pub mod v7;
1010pub mod v8;
1111pub mod v9;
1212pub mod v10;
13+ pub mod v13;
1314
1415use base:: { ReportBase , ReportError } ;
1516
@@ -123,7 +124,7 @@ pub fn decode_full_report(payload: &[u8]) -> Result<(Vec<[u8; 32]>, Vec<u8>), Re
123124#[ cfg( test) ]
124125mod tests {
125126 use super :: * ;
126- use crate :: report:: { v1:: ReportDataV1 , v2:: ReportDataV2 , v3:: ReportDataV3 , v4:: ReportDataV4 , v5:: ReportDataV5 , v6:: ReportDataV6 , v7:: ReportDataV7 , v8:: ReportDataV8 , v9:: ReportDataV9 , v10:: ReportDataV10 } ;
127+ use crate :: report:: { v1:: ReportDataV1 , v2:: ReportDataV2 , v3:: ReportDataV3 , v4:: ReportDataV4 , v5:: ReportDataV5 , v6:: ReportDataV6 , v7:: ReportDataV7 , v8:: ReportDataV8 , v9:: ReportDataV9 , v10:: ReportDataV10 , v13 :: ReportDataV13 } ;
127128 use num_bigint:: BigInt ;
128129
129130 const V1_FEED_ID : ID = ID ( [
@@ -166,11 +167,20 @@ mod tests {
166167 00 , 10 , 107 , 74 , 167 , 229 , 124 , 167 , 182 , 138 , 225 , 191 , 69 , 101 , 63 , 86 , 182 , 86 , 253 , 58 ,
167168 163 , 53 , 239 , 127 , 174 , 105 , 107 , 102 , 63 , 27 , 132 , 114 ,
168169 ] ) ;
170+ const V13_FEED_ID : ID = ID ( [
171+ 00 , 13 , 19 , 169 , 185 , 197 , 227 , 122 , 9 , 159 , 55 , 78 , 146 , 195 , 121 , 20 , 175 , 92 , 38 , 143 ,
172+ 58 , 138 , 151 , 33 , 241 , 114 , 81 , 53 , 191 , 180 , 203 , 184 ,
173+ ] ) ;
169174
170175 pub const MOCK_TIMESTAMP : u32 = 1718885772 ;
171176 pub const MOCK_FEE : usize = 10 ;
172177 pub const MOCK_PRICE : isize = 100 ;
173178 pub const MARKET_STATUS_OPEN : u32 = 2 ;
179+ pub const MOCK_BEST_ASK : isize = 227 ;
180+ pub const MOCK_BEST_BID : isize = 229 ;
181+ pub const MOCK_ASK_VOLUME : u64 = 1500 ;
182+ pub const MOCK_BID_VOLUME : u64 = 1200 ;
183+ pub const MOCK_LAST_TRADED_PRICE : isize = 228 ;
174184
175185 pub fn generate_mock_report_data_v1 ( ) -> ReportDataV1 {
176186 let report_data = ReportDataV1 {
@@ -347,20 +357,18 @@ mod tests {
347357 report_data
348358 }
349359
350- pub fn generate_mock_report_data_v13 ( ) -> ReportDataV10 {
351- const MOCK_MULTIPLIER : isize = 1000000000000000000 ; // 1.0 with 18 decimals
352-
353- let report_data = ReportDataV10 {
354- feed_id : V10_FEED_ID ,
360+ pub fn generate_mock_report_data_v13 ( ) -> ReportDataV13 {
361+ let report_data = ReportDataV13 {
362+ feed_id : V13_FEED_ID ,
355363 valid_from_timestamp : MOCK_TIMESTAMP ,
356364 observations_timestamp : MOCK_TIMESTAMP ,
357365 native_fee : BigInt :: from ( MOCK_FEE ) ,
358366 link_fee : BigInt :: from ( MOCK_FEE ) ,
359367 expires_at : MOCK_TIMESTAMP + 100 ,
360368 best_ask : BigInt :: from ( MOCK_BEST_ASK ) ,
361369 best_bid : BigInt :: from ( MOCK_BEST_BID ) ,
362- ask_volume : MARKET_ASK_VOLUME ,
363- bid_volume : MARKET_BID_VOLUME ,
370+ ask_volume : MOCK_ASK_VOLUME ,
371+ bid_volume : MOCK_BID_VOLUME ,
364372 last_traded_price : BigInt :: from ( MOCK_LAST_TRADED_PRICE ) ,
365373 } ;
366374
@@ -716,4 +724,37 @@ mod tests {
716724
717725 assert_eq ! ( decoded_report. feed_id, V10_FEED_ID ) ;
718726 }
727+
728+ #[ test]
729+ fn test_decode_report_v13 ( ) {
730+ let report_data = generate_mock_report_data_v13 ( ) ;
731+ let encoded_report_data = report_data. abi_encode ( ) . unwrap ( ) ;
732+
733+ let report = generate_mock_report ( & encoded_report_data) ;
734+
735+ let ( _report_context, report_blob) = decode_full_report ( & report) . unwrap ( ) ;
736+
737+ let expected_report_blob = vec ! [
738+ "000d13a9b9c5e37a099f374e92c37914af5c268f3a8a9721f1725135bfb4cbb8" ,
739+ "0000000000000000000000000000000000000000000000000000000066741d8c" ,
740+ "0000000000000000000000000000000000000000000000000000000066741d8c" ,
741+ "000000000000000000000000000000000000000000000000000000000000000a" ,
742+ "000000000000000000000000000000000000000000000000000000000000000a" ,
743+ "0000000000000000000000000000000000000000000000000000000066741df0" ,
744+ "00000000000000000000000000000000000000000000000000000000000000e3" ,
745+ "00000000000000000000000000000000000000000000000000000000000000e5" ,
746+ "00000000000000000000000000000000000000000000000000000000000005dc" ,
747+ "00000000000000000000000000000000000000000000000000000000000004b0" ,
748+ "00000000000000000000000000000000000000000000000000000000000000e4" ,
749+ ] ;
750+
751+ let expected = bytes ( & format ! ( "0x{}" , expected_report_blob. join( "" ) ) ) ;
752+ println ! ( "Actual : {}" , hex:: encode( & report_blob) ) ;
753+ println ! ( "Expected: {}" , hex:: encode( & expected) ) ;
754+ assert_eq ! ( report_blob, expected) ;
755+
756+ let decoded_report = ReportDataV13 :: decode ( & report_blob) . unwrap ( ) ;
757+
758+ assert_eq ! ( decoded_report. feed_id, V13_FEED_ID ) ;
759+ }
719760}
0 commit comments