1+ // SPDX-License-Identifier: BUSL-1.1
2+ pragma solidity ^ 0.8.12 ;
3+
4+ import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol " ;
5+
6+ import "src/contracts/strategies/StrategyFactory.sol " ;
7+ import "src/test/utils/EigenLayerUnitTestSetup.sol " ;
8+ import "../../contracts/permissions/PauserRegistry.sol " ;
9+
10+ /**
11+ * @notice Unit testing of the AVSDirectory contract. An AVSs' service manager contract will
12+ * call this to register an operator with the AVS.
13+ * Contracts tested: AVSDirectory
14+ * Contracts not mocked: DelegationManager
15+ */
16+ contract StrategyFactoryUnitTests is EigenLayerUnitTestSetup {
17+ // Contract under test
18+ StrategyFactory public strategyFactory;
19+ StrategyFactory public strategyFactoryImplementation;
20+
21+ // Contract dependencies
22+ StrategyBase public strategyImplementation;
23+ // eigenLayerProxyAdmin gets deployed in EigenLayerUnitTestSetup
24+ // ProxyAdmin eigenLayerProxyAdmin;
25+ ERC20PresetFixedSupply public underlyingToken;
26+
27+ uint256 initialSupply = 1e36 ;
28+ address initialOwner = address (this );
29+
30+ uint256 initialPausedStatus = 0 ;
31+
32+ function setUp () virtual override public {
33+ EigenLayerUnitTestSetup.setUp ();
34+
35+ address [] memory pausers = new address [](1 );
36+ pausers[0 ] = pauser;
37+ pauserRegistry = new PauserRegistry (pausers, unpauser);
38+
39+ underlyingToken = new ERC20PresetFixedSupply ("Test Token " , "TEST " , initialSupply, initialOwner);
40+
41+ strategyImplementation = new StrategyBase (strategyManagerMock);
42+
43+ strategyFactoryImplementation = new StrategyFactory (strategyManagerMock);
44+
45+ strategyFactory = StrategyFactory (
46+ address (
47+ new TransparentUpgradeableProxy (
48+ address (strategyFactoryImplementation),
49+ address (eigenLayerProxyAdmin),
50+ abi.encodeWithSelector (StrategyFactory.initialize.selector ,
51+ initialOwner,
52+ pauserRegistry,
53+ initialPausedStatus,
54+ strategyImplementation,
55+ eigenLayerProxyAdmin
56+ )
57+ )
58+ )
59+ );
60+ }
61+
62+ function test_initialization () public {
63+ assertEq (
64+ address (strategyFactory.strategyManager ()),
65+ address (strategyManagerMock),
66+ "constructor / initializer incorrect, strategyManager set wrong "
67+ );
68+ assertEq (
69+ address (strategyFactory.strategyImplementation ()),
70+ address (strategyImplementation),
71+ "constructor / initializer incorrect, strategyImplementation set wrong "
72+ );
73+ assertEq (
74+ address (strategyFactory.eigenLayerProxyAdmin ()),
75+ address (eigenLayerProxyAdmin),
76+ "constructor / initializer incorrect, eigenLayerProxyAdmin set wrong "
77+ );
78+ assertEq (
79+ address (strategyFactory.pauserRegistry ()),
80+ address (pauserRegistry),
81+ "constructor / initializer incorrect, pauserRegistry set wrong "
82+ );
83+ assertEq (strategyFactory.owner (), initialOwner, "constructor / initializer incorrect, owner set wrong " );
84+ assertEq (strategyFactory.paused (), initialPausedStatus, "constructor / initializer incorrect, paused status set wrong " );
85+ }
86+
87+ function test_initialize_revert_reinitialization () public {
88+ cheats.expectRevert ("Initializable: contract is already initialized " );
89+ strategyFactory.initialize (
90+ initialOwner,
91+ pauserRegistry,
92+ initialPausedStatus,
93+ strategyImplementation,
94+ eigenLayerProxyAdmin
95+ );
96+ }
97+
98+ function test_deployNewStrategy () public {
99+ StrategyBase newStrategy = StrategyBase (address (strategyFactory.deployNewStrategy (underlyingToken)));
100+
101+ require (strategyFactory.tokenStrategies (underlyingToken) == newStrategy, "tokenStrategies mapping not set correctly " );
102+ require (newStrategy.strategyManager () == strategyManagerMock, "strategyManager not set correctly " );
103+ require (eigenLayerProxyAdmin.getProxyImplementation (TransparentUpgradeableProxy (payable (address (newStrategy))))
104+ == address (strategyImplementation),
105+ "strategyImplementation not set correctly " );
106+ require (newStrategy.pauserRegistry () == pauserRegistry, "pauserRegistry not set correctly " );
107+ require (newStrategy.underlyingToken () == underlyingToken, "underlyingToken not set correctly " );
108+ require (strategyManagerMock.strategyIsWhitelistedForDeposit (newStrategy), "underlyingToken is not whitelisted " );
109+ require (! strategyManagerMock.thirdPartyTransfersForbidden (newStrategy), "newStrategy has 3rd party transfers forbidden " );
110+ }
111+
112+ function test_deployNewStrategy_revert_StrategyAlreadyExists () public {
113+ test_deployNewStrategy ();
114+ cheats.expectRevert ("StrategyFactory.deployNewStrategy: Strategy already exists for token " );
115+ strategyFactory.deployNewStrategy (underlyingToken);
116+ }
117+
118+ function test_whitelistStrategies () public {
119+ StrategyBase strategy = StrategyBase (
120+ address (
121+ new TransparentUpgradeableProxy (
122+ address (strategyImplementation),
123+ address (eigenLayerProxyAdmin),
124+ abi.encodeWithSelector (StrategyBase.initialize.selector , underlyingToken, pauserRegistry)
125+ )
126+ )
127+ );
128+
129+
130+ IStrategy[] memory strategiesToWhitelist = new IStrategy [](1 );
131+ bool [] memory thirdPartyTransfersForbiddenValues = new bool [](1 );
132+ strategiesToWhitelist[0 ] = strategy;
133+ thirdPartyTransfersForbiddenValues[0 ] = true ;
134+ strategyFactory.whitelistStrategies (strategiesToWhitelist, thirdPartyTransfersForbiddenValues);
135+
136+ require (strategyFactory.tokenStrategies (underlyingToken) == strategy, "tokenStrategies mapping not set correctly " );
137+ require (strategyManagerMock.thirdPartyTransfersForbidden (strategy), "3rd party transfers forbidden not set correctly " );
138+ }
139+ }
0 commit comments