@@ -273,6 +273,41 @@ contract ActiveListingTest is DiscoveryTestBase {
273273 _assertProvidersExclude (lp);
274274 }
275275
276+ function test_WithdrawCollateral_SucceedsWhenRemoveProviderReverts ()
277+ public
278+ {
279+ deployDiscovery ();
280+ address lp = makeAddr ("revertCallbackLp " );
281+ _registerAndApprove (
282+ lp,
283+ "LP " ,
284+ Flyover.ProviderType.PegIn,
285+ MIN_COLLATERAL
286+ );
287+
288+ RemoveProviderRevertMock brokenDiscovery = new RemoveProviderRevertMock ();
289+ vm.prank (owner);
290+ collateralManagement.setFlyoverDiscovery (address (brokenDiscovery));
291+
292+ uint256 balanceBefore = lp.balance;
293+
294+ vm.prank (lp);
295+ collateralManagement.resign ();
296+ vm.roll (block .number + TEST_RESIGN_DELAY_BLOCKS);
297+
298+ vm.expectEmit (true , true , false , true );
299+ emit CollateralManagementContract.FlyoverDiscoveryError (
300+ abi.encodeWithSelector (
301+ RemoveProviderRevertMock.RemoveProviderFailed.selector
302+ )
303+ );
304+ vm.prank (lp);
305+ collateralManagement.withdrawCollateral ();
306+
307+ assertEq (lp.balance, balanceBefore + MIN_COLLATERAL);
308+ assertEq (collateralManagement.getPegInCollateral (lp), 0 );
309+ }
310+
276311 // ============ Initialization — FlyoverDiscovery ============
277312
278313 function test_InitializeV2_1_0_EmptyStateSucceeds () public {
@@ -411,6 +446,37 @@ contract ActiveListingTest is DiscoveryTestBase {
411446
412447 assertEq (discovery.getProviders ().length , 1 );
413448 _assertProvidersContain (keptLp);
449+
450+ assertEq (
451+ uint256 (discovery.getRegistrationState (pendingLp)),
452+ uint256 (IFlyoverDiscovery.RegistrationState.Pending),
453+ "pending-only slots must not be backfilled to Approved "
454+ );
455+
456+ assertEq (
457+ uint256 (discovery.getRegistrationState (resignedLp)),
458+ uint256 (IFlyoverDiscovery.RegistrationState.Approved),
459+ "resigned LPs with discovery records should be marked Approved "
460+ );
461+ assertEq (discovery.getProvider (resignedLp).providerAddress, resignedLp);
462+ assertFalse (
463+ discovery.isOperational (Flyover.ProviderType.PegIn, resignedLp)
464+ );
465+ _assertProvidersExclude (resignedLp);
466+
467+ assertEq (
468+ uint256 (discovery.getRegistrationState (withdrawnLp)),
469+ uint256 (IFlyoverDiscovery.RegistrationState.Approved),
470+ "withdrawn LPs with discovery records should be marked Approved "
471+ );
472+ assertEq (
473+ discovery.getProvider (withdrawnLp).providerAddress,
474+ withdrawnLp
475+ );
476+ assertFalse (
477+ discovery.isOperational (Flyover.ProviderType.PegIn, withdrawnLp)
478+ );
479+ _assertProvidersExclude (withdrawnLp);
414480 }
415481
416482 function test_InitializeV2_1_0_BackfillIgnoresInflatedLastProviderId ()
@@ -453,6 +519,11 @@ contract ActiveListingTest is DiscoveryTestBase {
453519 MIN_COLLATERAL
454520 );
455521
522+ vm.expectEmit (true , true , false , true );
523+ emit CollateralManagementContract.FlyoverDiscoverySet (
524+ address (0 ),
525+ address (discovery)
526+ );
456527 vm.prank (owner);
457528 collateralManagement.initializeV2_1_0 (address (discovery));
458529
@@ -537,6 +608,11 @@ contract ActiveListingTest is DiscoveryTestBase {
537608 cm.initializeV2_1_0 (address (discoveryA));
538609 discoveryA.initializeV2_1_0 ();
539610 cm.grantRole (cm.COLLATERAL_ADDER (), address (discoveryB));
611+ vm.expectEmit (true , true , false , true );
612+ emit CollateralManagementContract.FlyoverDiscoverySet (
613+ address (discoveryA),
614+ address (discoveryB)
615+ );
540616 cm.setFlyoverDiscovery (address (discoveryB));
541617 discoveryB.initializeV2_1_0 ();
542618 vm.stopPrank ();
@@ -677,3 +753,12 @@ contract ActiveListingTest is DiscoveryTestBase {
677753 assertEq (discovery.getProviders ().length , 0 );
678754 }
679755}
756+
757+ /// @dev Discovery stand-in that always reverts on removeProvider
758+ contract RemoveProviderRevertMock {
759+ error RemoveProviderFailed ();
760+
761+ function removeProvider (address ) external pure {
762+ revert RemoveProviderFailed ();
763+ }
764+ }
0 commit comments