Skip to content

Commit

Permalink
refactor: adjust to BaseVaultTest factoryMock changes
Browse files Browse the repository at this point in the history
  • Loading branch information
EndymionJkb committed Dec 30, 2024
1 parent 2a7e078 commit 6cbd390
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions pkg/vault/test/foundry/ProtocolFeePercentagesProvider.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { IVault } from "@balancer-labs/v3-interfaces/contracts/vault/IVault.sol"

import { ProtocolFeePercentagesProvider } from "../../contracts/ProtocolFeePercentagesProvider.sol";
import { BalancerContractRegistry } from "../../contracts/BalancerContractRegistry.sol";
import { PoolFactoryMock } from "../../contracts/test/PoolFactoryMock.sol";

import { BaseVaultTest } from "./utils/BaseVaultTest.sol";

Expand All @@ -42,7 +43,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
trustedContractRegistry = new BalancerContractRegistry(vault);
percentagesProvider = new ProtocolFeePercentagesProvider(vault, feeController, trustedContractRegistry);

// Mark the factoryMock as trusted, so that operations on it won't fail.
// Mark the poolFactory as trusted, so that operations on it won't fail.
authorizer.grantRole(
trustedContractRegistry.getActionId(BalancerContractRegistry.registerBalancerContract.selector),
admin
Expand All @@ -52,11 +53,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
admin
);
vm.prank(admin);
trustedContractRegistry.registerBalancerContract(
ContractType.POOL_FACTORY,
"MockFactory",
address(factoryMock)
);
trustedContractRegistry.registerBalancerContract(ContractType.POOL_FACTORY, "MockFactory", poolFactory);

percentagesProviderAuth = IAuthentication(address(percentagesProvider));
feeControllerAuth = IAuthentication(address(feeController));
Expand Down Expand Up @@ -94,7 +91,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
function testSetFactorySpecificProtocolFeePercentageNoPermission() public {
vm.expectRevert(IAuthentication.SenderNotAllowed.selector);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
maxSwapFeePercentage,
maxYieldFeePercentage
);
Expand All @@ -115,17 +112,15 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
_grantPermissions();

// Cause `isPoolFromFactory` to return "true" for address(0).
factoryMock.manualSetPoolFromFactory(address(0));
PoolFactoryMock(poolFactory).manualSetPoolFromFactory(address(0));

vm.prank(admin);
trustedContractRegistry.deprecateBalancerContract(address(factoryMock));
trustedContractRegistry.deprecateBalancerContract(poolFactory);

vm.expectRevert(
abi.encodeWithSelector(IProtocolFeePercentagesProvider.UnknownFactory.selector, address(factoryMock))
);
vm.expectRevert(abi.encodeWithSelector(IProtocolFeePercentagesProvider.UnknownFactory.selector, poolFactory));
vm.prank(admin);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
maxSwapFeePercentage,
maxYieldFeePercentage
);
Expand All @@ -137,7 +132,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
vm.expectRevert(IProtocolFeeController.ProtocolSwapFeePercentageTooHigh.selector);
vm.prank(admin);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
maxSwapFeePercentage + 1,
maxYieldFeePercentage
);
Expand All @@ -149,7 +144,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
vm.expectRevert(IVaultErrors.FeePrecisionTooHigh.selector);
vm.prank(admin);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
1e16 + 234234234,
maxYieldFeePercentage
);
Expand All @@ -161,7 +156,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
vm.expectRevert(IProtocolFeeController.ProtocolYieldFeePercentageTooHigh.selector);
vm.prank(admin);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
maxSwapFeePercentage,
maxYieldFeePercentage + 1
);
Expand All @@ -173,7 +168,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
vm.expectRevert(IProtocolFeeController.ProtocolYieldFeePercentageTooHigh.selector);
vm.prank(admin);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
1e16 + 234234234,
maxYieldFeePercentage + 1
);
Expand All @@ -187,20 +182,20 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {

vm.expectEmit();
emit IProtocolFeePercentagesProvider.FactorySpecificProtocolFeePercentagesSet(
address(factoryMock),
poolFactory,
maxSwapFeePercentage,
yieldFeePercentage
);

vm.prank(admin);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
maxSwapFeePercentage,
yieldFeePercentage
);

(uint256 actualSwapFeePercentage, uint256 actualYieldFeePercentage) = percentagesProvider
.getFactorySpecificProtocolFeePercentages(address(factoryMock));
.getFactorySpecificProtocolFeePercentages(poolFactory);
assertEq(actualSwapFeePercentage, maxSwapFeePercentage, "Wrong factory swap fee percentage");
assertEq(actualYieldFeePercentage, yieldFeePercentage, "Wrong factory swap fee percentage");
}
Expand All @@ -217,7 +212,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {

vm.prank(admin);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
maxSwapFeePercentage,
maxYieldFeePercentage
);
Expand All @@ -230,11 +225,11 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
abi.encodeWithSelector(
IProtocolFeePercentagesProvider.PoolNotFromFactory.selector,
INVALID_ADDRESS,
address(factoryMock)
poolFactory
)
);

percentagesProvider.setProtocolFeePercentagesForPools(address(factoryMock), pools);
percentagesProvider.setProtocolFeePercentagesForPools(poolFactory, pools);
}

function testSetProtocolFeePercentagesForPools() public {
Expand All @@ -246,7 +241,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {

vm.prank(admin);
percentagesProvider.setFactorySpecificProtocolFeePercentages(
address(factoryMock),
poolFactory,
expectedSwapFeePercentage,
expectedYieldFeePercentage
);
Expand All @@ -258,7 +253,7 @@ contract ProtocolFeePercentagesProviderTest is BaseVaultTest {
assertEq(originalYieldFeePercentage, 0, "Non-zero original yield fee percentage");

// Permissionless call to set fee percentages by factory.
percentagesProvider.setProtocolFeePercentagesForPools(address(factoryMock), pools);
percentagesProvider.setProtocolFeePercentagesForPools(poolFactory, pools);

(uint256 currentSwapFeePercentage, uint256 currentYieldFeePercentage) = IPoolInfo(pool)
.getAggregateFeePercentages();
Expand Down

0 comments on commit 6cbd390

Please sign in to comment.