@@ -62,6 +62,7 @@ const flashLoanTestFixture = async (): Promise<FlashLoanContractsFixture> => {
6262 const result = await deployDiamond ( "" ) ;
6363 const unitroller = result . unitroller ;
6464 const comptroller = await ethers . getContractAt ( "ComptrollerMock" , unitroller . address ) ;
65+
6566 const comptrollerLens = await ComptrollerLensFactory . deploy ( ) ;
6667 await comptroller . _setAccessControl ( accessControlManager . address ) ;
6768 await comptroller . _setComptrollerLens ( comptrollerLens . address ) ;
@@ -185,6 +186,26 @@ describe("FlashLoan", async () => {
185186 await mockReceiverContract . deployed ( ) ;
186187 } ) ;
187188
189+ it ( "Should revert flash loan when paused system-wide" , async ( ) => {
190+ // Pause flash loans system-wide
191+ await comptroller . setFlashLoanPaused ( true ) ;
192+
193+ // Verify pause status
194+ expect ( await comptroller . flashLoanPaused ( ) ) . to . be . true ;
195+
196+ // Should revert when paused
197+ await expect (
198+ mockReceiverContract
199+ . connect ( alice )
200+ . requestFlashLoan (
201+ [ vTokenA . address , vTokenB . address ] ,
202+ [ flashLoanAmount1 , flashLoanAmount2 ] ,
203+ mockReceiverContract . address ,
204+ "0x" ,
205+ ) ,
206+ ) . to . be . revertedWithCustomError ( comptroller , "FlashLoanPausedSystemWide" ) ;
207+ } ) ;
208+
188209 it ( "Should revert if flashLoan is not enabled" , async ( ) => {
189210 expect ( await vTokenA . isFlashLoanEnabled ( ) ) . to . be . false ;
190211 expect ( await vTokenB . isFlashLoanEnabled ( ) ) . to . be . false ;
@@ -210,6 +231,33 @@ describe("FlashLoan", async () => {
210231 ) ;
211232 } ) ;
212233
234+ it ( "Should revert when onBehalf is address zero" , async ( ) => {
235+ await expect (
236+ comptroller . executeFlashLoan (
237+ ethers . constants . AddressZero , // ❌ Zero address
238+ mockReceiverContract . address ,
239+ [ vTokenA . address ] ,
240+ [ flashLoanAmount1 ] ,
241+ "0x" ,
242+ ) ,
243+ ) . to . be . revertedWith ( "can't be zero address" ) ;
244+ } ) ;
245+
246+ it ( "Should revert when too many assets are requested" , async ( ) => {
247+ await vTokenA . setFlashLoanEnabled ( true ) ;
248+ // Create array with more assets than MAX_FLASHLOAN_ASSETS
249+ const tooManyAssets = new Array ( 201 ) . fill ( vTokenA . address ) ; // Assuming MAX is 200
250+ const tooManyAmounts = new Array ( 201 ) . fill ( flashLoanAmount1 ) ;
251+
252+ await comptroller . setWhiteListFlashLoanAccount ( alice . address , true ) ;
253+
254+ await expect (
255+ comptroller . executeFlashLoan ( alice . address , mockReceiverContract . address , tooManyAssets , tooManyAmounts , "0x" ) ,
256+ )
257+ . to . be . revertedWithCustomError ( comptroller , "TooManyAssetsRequested" )
258+ . withArgs ( 201 , 200 ) ;
259+ } ) ;
260+
213261 it ( "Should revert if the market is not listed" , async ( ) => {
214262 await vTokenC . setFlashLoanEnabled ( true ) ;
215263 expect ( await vTokenC . isFlashLoanEnabled ( ) ) . to . be . true ;
@@ -314,6 +362,32 @@ describe("FlashLoan", async () => {
314362 ) . to . be . revertedWithCustomError ( comptroller , "ExecuteFlashLoanFailed" ) ;
315363 } ) ;
316364
365+ it ( "Should emit FlashLoanPauseChanged event when pause status changes" , async ( ) => {
366+ // Test pausing
367+ await expect ( comptroller . setFlashLoanPaused ( true ) )
368+ . to . emit ( comptroller , "FlashLoanPauseChanged" )
369+ . withArgs ( false , true ) ;
370+
371+ // Test unpausing
372+ await expect ( comptroller . setFlashLoanPaused ( false ) )
373+ . to . emit ( comptroller , "FlashLoanPauseChanged" )
374+ . withArgs ( true , false ) ;
375+ } ) ;
376+
377+ it ( "Should not emit event when setting same pause status" , async ( ) => {
378+ // Flash loans are not paused by default
379+ expect ( await comptroller . flashLoanPaused ( ) ) . to . be . false ;
380+
381+ // Setting to false again should not emit event (no change)
382+ await expect ( comptroller . setFlashLoanPaused ( false ) ) . to . not . emit ( comptroller , "FlashLoanPauseChanged" ) ;
383+
384+ // Pause first
385+ await comptroller . setFlashLoanPaused ( true ) ;
386+
387+ // Setting to true again should not emit event (no change)
388+ await expect ( comptroller . setFlashLoanPaused ( true ) ) . to . not . emit ( comptroller , "FlashLoanPauseChanged" ) ;
389+ } ) ;
390+
317391 it ( "User has not supplied in venus - Should not create debt position if receiver repays full amount + fee" , async ( ) => {
318392 await vTokenA . setFlashLoanEnabled ( true ) ;
319393 await vTokenB . setFlashLoanEnabled ( true ) ;
0 commit comments