@@ -236,6 +236,41 @@ describe('Deserialize', () => {
236236 expect ( Twap . deserialize ( TWAP_SERIALIZED ( twap . salt ) ) ) . toMatchObject ( twap )
237237 } )
238238
239+ test ( 'Deserializes correctly order with t0 set to an epoch' , ( ) => {
240+ const twap = Twap . deserialize (
241+ '0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000006cf1e9ca41f7611def408122793c358a3d11e5a541617665537761707065722d545741502d537761700000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001400000000000000000000000007fc66500c84a76ad7e9c93437bfc5ac33e2ddae9000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000003765a685a401622c060e5d700d9ad89413363a9100000000000000000000000000000000000000000000000009b6e64a8ec6000000000000000000000000000000000000000000000000000000000000055d4a800000000000000000000000000000000000000000000000000000000067f702df0000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000001518000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
242+ )
243+
244+ expect ( twap . handler ) . toEqual ( '0x6cF1e9cA41f7611dEf408122793c358a3d11E5a5' )
245+ expect ( twap . salt ) . toEqual ( '0x41617665537761707065722d545741502d537761700000000000000000000000' )
246+ expect ( twap . staticInput ) . toEqual ( {
247+ sellToken : '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9' ,
248+ buyToken : '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' ,
249+ partSellAmount : BigNumber . from ( 700000000000000000n ) ,
250+ minPartLimit : BigNumber . from ( 90000000 ) ,
251+ receiver : '0x3765A685a401622C060E5D700D9ad89413363a91' ,
252+ t0 : BigNumber . from ( 1744241375 ) ,
253+ n : BigNumber . from ( 5 ) ,
254+ t : BigNumber . from ( 86400 ) ,
255+ span : BigNumber . from ( 0 ) ,
256+ appData : '0x0000000000000000000000000000000000000000000000000000000000000000' ,
257+ } )
258+ expect ( twap . data ) . toEqual ( {
259+ sellToken : '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9' ,
260+ buyToken : '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' ,
261+ sellAmount : BigNumber . from ( 3500000000000000000n ) ,
262+ buyAmount : BigNumber . from ( 450000000 ) ,
263+ receiver : '0x3765A685a401622C060E5D700D9ad89413363a91' ,
264+ startTime : { startType : StartTimeValue . AT_EPOCH , epoch : BigNumber . from ( 1744241375 ) } ,
265+ numberOfParts : BigNumber . from ( 5 ) ,
266+ timeBetweenParts : BigNumber . from ( 86400 ) ,
267+ durationOfPart : { durationType : DurationType . AUTO } ,
268+ appData : '0x0000000000000000000000000000000000000000000000000000000000000000' ,
269+ } )
270+ expect ( twap . hasOffChainInput ) . toEqual ( false )
271+ expect ( twap . isSingleOrder ) . toEqual ( true )
272+ } )
273+
239274 test ( 'Throws if invalid' , ( ) => {
240275 expect ( ( ) => Twap . deserialize ( '0x' ) ) . toThrow ( 'InvalidSerializedConditionalOrder' )
241276 } )
@@ -317,8 +352,8 @@ describe('Poll Validate', () => {
317352 jest . resetAllMocks ( )
318353 } )
319354
320- test ( `Open TWAP, passes the validations` , async ( ) => {
321- // GIVEN: A TWAP that should be active (should start 1 second ago, should finish in 1 second)
355+ test ( `Open TWAP, passes the validations (t=0) ` , async ( ) => {
356+ // GIVEN: An active TWAP (creation was mined 1 second ago and should finish in 1 second)
322357 mockCabinet . mockReturnValue ( uint256Helper ( blockTimestamp - 1 ) )
323358 mockEndTimestamp . mockReturnValue ( blockTimestamp + 1 )
324359
@@ -332,6 +367,27 @@ describe('Poll Validate', () => {
332367 expect ( result ) . toEqual ( undefined )
333368 } )
334369
370+ test ( `Open TWAP, passes the validations (t0 set to an epoch)` , async ( ) => {
371+ // GIVEN: A TWAP that starts at a specific epoch (1 second ago)
372+ const twap = new MockTwap ( {
373+ handler : TWAP_ADDRESS ,
374+ data : {
375+ ...TWAP_PARAMS_TEST ,
376+ startTime : { startType : StartTimeValue . AT_EPOCH , epoch : BigNumber . from ( blockTimestamp - 1 ) } ,
377+ } ,
378+ } )
379+
380+ // GIVEN: A TWAP that is active (expires in 1 second)
381+ mockEndTimestamp . mockReturnValue ( blockTimestamp + 1 )
382+ mockCabinet . mockReturnValue ( uint256Helper ( 0 ) ) // No cabinet value is needed when t0=epoch
383+
384+ // WHEN: We poll
385+ const result = await twap . pollValidate ( { ...pollParams , blockInfo : { blockNumber, blockTimestamp } } )
386+
387+ // THEN: Successful validation
388+ expect ( result ) . toEqual ( undefined )
389+ } )
390+
335391 test ( `[TRY_AT_EPOCH] TWAP has not started` , async ( ) => {
336392 // GIVEN: A TWAP that hasn't started (should start in 1 second, should finish in 2 second)
337393 const startTime = blockTimestamp + 1
0 commit comments