@@ -8,7 +8,7 @@ import express, { Express } from "express";
88import { StatusCodes } from "http-status-codes" ;
99import request from "supertest" ;
1010import { PriceInfo , PriceStore , VaaCache , VaaConfig } from "../listen" ;
11- import { RestAPI } from "../rest" ;
11+ import { RestAPI , VaaResponse } from "../rest" ;
1212
1313let priceInfo : PriceStore ;
1414let app : Express ;
@@ -52,10 +52,18 @@ function dummyPriceInfoPair(
5252 vaa : Buffer . from ( vaa , "hex" ) ,
5353 emitterChainId : 0 ,
5454 priceServiceReceiveTime : 0 ,
55+ lastAttestedPublishTime : 0 ,
5556 } ,
5657 ] ;
5758}
5859
60+ // Add some dummy data to the provided vaa cache.
61+ function addAbcdDataToCache ( id : string , cache : VaaCache ) {
62+ cache . set ( id , 10 , 9 , "abcd10" ) ;
63+ cache . set ( id , 20 , 19 , "abcd20" ) ;
64+ cache . set ( id , 30 , 29 , "abcd30" ) ;
65+ }
66+
5967beforeAll ( async ( ) => {
6068 priceInfoMap = new Map < string , PriceInfo > ( [
6169 dummyPriceInfoPair ( expandTo64Len ( "abcd" ) , 1 , "a1b2c3d4" ) ,
@@ -258,16 +266,14 @@ describe("Latest Vaa Bytes Endpoint", () => {
258266describe ( "Get VAA endpoint and Get VAA CCIP" , ( ) => {
259267 test ( "When called with valid id and timestamp in the cache returns the correct answer" , async ( ) => {
260268 const id = expandTo64Len ( "abcd" ) ;
261- vaasCache . set ( id , 10 , "abcd10" ) ;
262- vaasCache . set ( id , 20 , "abcd20" ) ;
263- vaasCache . set ( id , 30 , "abcd30" ) ;
269+ addAbcdDataToCache ( id , vaasCache ) ;
264270
265271 const resp = await request ( app ) . get ( "/api/get_vaa" ) . query ( {
266272 id,
267273 publish_time : 16 ,
268274 } ) ;
269275 expect ( resp . status ) . toBe ( StatusCodes . OK ) ;
270- expect ( resp . body ) . toEqual < VaaConfig > ( {
276+ expect ( resp . body ) . toEqual < VaaResponse > ( {
271277 vaa : "abcd20" ,
272278 publishTime : 20 ,
273279 } ) ;
@@ -286,9 +292,7 @@ describe("Get VAA endpoint and Get VAA CCIP", () => {
286292
287293 test ( "When called with valid id with leading 0x and timestamp in the cache returns the correct answer" , async ( ) => {
288294 const id = expandTo64Len ( "abcd" ) ;
289- vaasCache . set ( id , 10 , "abcd10" ) ;
290- vaasCache . set ( id , 20 , "abcd20" ) ;
291- vaasCache . set ( id , 30 , "abcd30" ) ;
295+ addAbcdDataToCache ( id , vaasCache ) ;
292296
293297 const resp = await request ( app )
294298 . get ( "/api/get_vaa" )
@@ -297,17 +301,15 @@ describe("Get VAA endpoint and Get VAA CCIP", () => {
297301 publish_time : 16 ,
298302 } ) ;
299303 expect ( resp . status ) . toBe ( StatusCodes . OK ) ;
300- expect ( resp . body ) . toEqual < VaaConfig > ( {
304+ expect ( resp . body ) . toEqual < VaaResponse > ( {
301305 vaa : "abcd20" ,
302306 publishTime : 20 ,
303307 } ) ;
304308 } ) ;
305309
306310 test ( "When called with target_chain, encodes resulting VAA in the right format" , async ( ) => {
307311 const id = expandTo64Len ( "abcd" ) ;
308- vaasCache . set ( id , 10 , "abcd10" ) ;
309- vaasCache . set ( id , 20 , "abcd20" ) ;
310- vaasCache . set ( id , 30 , "abcd30" ) ;
312+ addAbcdDataToCache ( id , vaasCache ) ;
311313
312314 const resp = await request ( app )
313315 . get ( "/api/get_vaa" )
@@ -317,7 +319,7 @@ describe("Get VAA endpoint and Get VAA CCIP", () => {
317319 target_chain : "evm" ,
318320 } ) ;
319321 expect ( resp . status ) . toBe ( StatusCodes . OK ) ;
320- expect ( resp . body ) . toEqual < VaaConfig > ( {
322+ expect ( resp . body ) . toEqual < VaaResponse > ( {
321323 vaa : "0x" + Buffer . from ( "abcd20" , "base64" ) . toString ( "hex" ) ,
322324 publishTime : 20 ,
323325 } ) ;
@@ -346,9 +348,7 @@ describe("Get VAA endpoint and Get VAA CCIP", () => {
346348
347349 test ( "When called with valid id and timestamp not in the cache without db returns vaa not found" , async ( ) => {
348350 const id = expandTo64Len ( "abcd" ) ;
349- vaasCache . set ( id , 10 , "abcd10" ) ;
350- vaasCache . set ( id , 20 , "abcd20" ) ;
351- vaasCache . set ( id , 30 , "abcd30" ) ;
351+ addAbcdDataToCache ( id , vaasCache ) ;
352352
353353 const resp = await request ( app )
354354 . get ( "/api/get_vaa" )
@@ -396,9 +396,7 @@ describe("Get VAA endpoint and Get VAA CCIP", () => {
396396 const appWithDb = await apiWithDb . createApp ( ) ;
397397
398398 const id = expandTo64Len ( "abcd" ) ;
399- vaasCache . set ( id , 10 , "abcd10" ) ;
400- vaasCache . set ( id , 20 , "abcd20" ) ;
401- vaasCache . set ( id , 30 , "abcd30" ) ;
399+ addAbcdDataToCache ( id , vaasCache ) ;
402400
403401 const resp = await request ( appWithDb )
404402 . get ( "/api/get_vaa" )
@@ -407,7 +405,7 @@ describe("Get VAA endpoint and Get VAA CCIP", () => {
407405 publish_time : 5 ,
408406 } ) ;
409407 expect ( resp . status ) . toBe ( StatusCodes . OK ) ;
410- expect ( resp . body ) . toEqual < VaaConfig > ( {
408+ expect ( resp . body ) . toEqual < VaaResponse > ( {
411409 vaa : `pythnet${ id } 5` ,
412410 publishTime : 5 ,
413411 } ) ;
@@ -451,9 +449,7 @@ describe("Get VAA endpoint and Get VAA CCIP", () => {
451449 const appWithDb = await apiWithDb . createApp ( ) ;
452450
453451 const id = expandTo64Len ( "abcd" ) ;
454- vaasCache . set ( id , 10 , "abcd10" ) ;
455- vaasCache . set ( id , 20 , "abcd20" ) ;
456- vaasCache . set ( id , 30 , "abcd30" ) ;
452+ addAbcdDataToCache ( id , vaasCache ) ;
457453
458454 const resp = await request ( appWithDb )
459455 . get ( "/api/get_vaa" )
@@ -493,9 +489,7 @@ describe("Get VAA endpoint and Get VAA CCIP", () => {
493489 const appWithDb = await apiWithDb . createApp ( ) ;
494490
495491 const id = expandTo64Len ( "abcd" ) ;
496- vaasCache . set ( id , 10 , "abcd10" ) ;
497- vaasCache . set ( id , 20 , "abcd20" ) ;
498- vaasCache . set ( id , 30 , "abcd30" ) ;
492+ addAbcdDataToCache ( id , vaasCache ) ;
499493
500494 const resp = await request ( appWithDb )
501495 . get ( "/api/get_vaa" )
0 commit comments