@@ -9,7 +9,7 @@ import { bn, bootstrapWithStakedPool } from '../../bootstrap';
99import { delegateCollateral , declareDelegateIntent } from '../../../common' ;
1010import { fastForwardTo , getTime } from '@synthetixio/core-utils/utils/hardhat/rpc' ;
1111
12- describe ( 'VaultModule Two-step Delegation' , function ( ) {
12+ describe ( 'VaultModule Two-step Delegation timing ' , function ( ) {
1313 const {
1414 signers,
1515 systems,
@@ -224,6 +224,76 @@ describe('VaultModule Two-step Delegation', function () {
224224 } ) ;
225225 } ) ;
226226
227+ describe ( 'Delegation Timing failures with global params' , async ( ) => {
228+ let intentId : BigNumber ;
229+ let declareDelegateIntentTime : number ;
230+ before ( 'set global window times' , async ( ) => {
231+ await systems ( )
232+ . Core . connect ( owner )
233+ . setConfig (
234+ ethers . utils . formatBytes32String ( 'delegateCollateralDelay_min' ) ,
235+ ethers . utils . hexZeroPad ( bn ( 120 ) . toHexString ( ) , 32 )
236+ ) ; // use 120 as the global min delay
237+ await systems ( )
238+ . Core . connect ( owner )
239+ . setConfig (
240+ ethers . utils . formatBytes32String ( 'delegateCollateralWindow_max' ) ,
241+ ethers . utils . hexZeroPad ( bn ( 10 ) . toHexString ( ) , 32 )
242+ ) ; // use 10 as the global max window
243+ } ) ;
244+
245+ before ( 'set market window times' , async ( ) => {
246+ const previousConfiguration = await MockMarket . getDelegationCollateralConfiguration ( ) ;
247+ await MockMarket . setDelegationCollateralConfiguration (
248+ 10 ,
249+ 200 ,
250+ previousConfiguration [ 2 ] ,
251+ previousConfiguration [ 3 ]
252+ ) ;
253+ } ) ;
254+
255+ before ( 'declare intent to delegate' , async ( ) => {
256+ intentId = await declareDelegateIntent (
257+ systems ,
258+ owner ,
259+ user1 ,
260+ accountId ,
261+ poolId ,
262+ collateralAddress ( ) ,
263+ depositAmount . mul ( 2 ) ,
264+ ethers . utils . parseEther ( '1' )
265+ ) ;
266+
267+ declareDelegateIntentTime = await getTime ( provider ( ) ) ;
268+ } ) ;
269+
270+ after ( restore ) ;
271+
272+ it ( 'fails to execute a delegation if window is not open (too soon)' , async ( ) => {
273+ await fastForwardTo ( declareDelegateIntentTime + 115 , provider ( ) ) ;
274+
275+ await assertRevert (
276+ systems ( )
277+ . Core . connect ( user2 )
278+ . processIntentToDelegateCollateralByIntents ( accountId , [ intentId ] ) ,
279+ `DelegationIntentNotReady` ,
280+ systems ( ) . Core
281+ ) ;
282+ } ) ;
283+
284+ it ( 'fails to execute a delegation if window is already closed (too late)' , async ( ) => {
285+ await fastForwardTo ( declareDelegateIntentTime + 131 , provider ( ) ) ;
286+
287+ await assertRevert (
288+ systems ( )
289+ . Core . connect ( user2 )
290+ . processIntentToDelegateCollateralByIntents ( accountId , [ intentId ] ) ,
291+ `DelegationIntentExpired` ,
292+ systems ( ) . Core
293+ ) ;
294+ } ) ;
295+ } ) ;
296+
227297 describe ( 'Force Delete intents (only system owner)' , async ( ) => {
228298 let intentId : BigNumber ;
229299 before ( 'declare intent to delegate' , async ( ) => {
0 commit comments