Skip to content

Commit 419952c

Browse files
authored
chore: refactor test library for middleware deployment (#390)
* chore: refactor middleware deployment for tests * chore: remove extra vm command * chore: refactor and cleanup naming * chore: retrigger ci
1 parent 4f75b3c commit 419952c

File tree

3 files changed

+281
-180
lines changed

3 files changed

+281
-180
lines changed

test/unit/InstantSlasher.t.sol

Lines changed: 39 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ import {StakeRegistry} from "../../src/StakeRegistry.sol";
5050
import {BLSApkRegistry} from "../../src/BLSApkRegistry.sol";
5151
import {IndexRegistry} from "../../src/IndexRegistry.sol";
5252
import {SocketRegistry} from "../../src/SocketRegistry.sol";
53+
import {MiddlewareDeployLib} from "../utils/MiddlewareDeployLib.sol";
5354

5455
contract InstantSlasherTest is Test {
5556
InstantSlasher public instantSlasher;
56-
InstantSlasher public instantSlasherImplementation;
5757
ProxyAdmin public proxyAdmin;
5858
EmptyContract public emptyContract;
5959
SlashingRegistryCoordinator public slashingRegistryCoordinator;
60-
SlashingRegistryCoordinator public slashingRegistryCoordinatorImplementation;
6160
CoreDeploymentLib.DeploymentData public coreDeployment;
6261
PauserRegistry public pauserRegistry;
6362
ERC20Mock public mockToken;
@@ -149,108 +148,51 @@ contract InstantSlasherTest is Test {
149148
IERC20(address(mockToken))
150149
)
151150
);
152-
153-
// Deploy empty proxies for all registries
154-
stakeRegistry = StakeRegistry(
155-
address(
156-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
157-
)
158-
);
159-
160-
blsApkRegistry = BLSApkRegistry(
161-
address(
162-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
163-
)
164-
);
165-
166-
indexRegistry = IndexRegistry(
167-
address(
168-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
169-
)
170-
);
171-
172-
socketRegistry = SocketRegistry(
173-
address(
174-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
175-
)
176-
);
177-
178-
slashingRegistryCoordinatorImplementation = new SlashingRegistryCoordinator(
179-
IStakeRegistry(address(stakeRegistry)),
180-
IBLSApkRegistry(address(blsApkRegistry)),
181-
IIndexRegistry(address(indexRegistry)),
182-
ISocketRegistry(address(socketRegistry)),
183-
IAllocationManager(coreDeployment.allocationManager),
184-
IPauserRegistry(address(pauserRegistry))
185-
);
186-
187-
slashingRegistryCoordinator = SlashingRegistryCoordinator(
188-
address(
189-
new TransparentUpgradeableProxy(
190-
address(slashingRegistryCoordinatorImplementation), address(proxyAdmin), ""
191-
)
192-
)
193-
);
194-
195-
// Deploy registry implementations pointing to the coordinator
196-
StakeRegistry stakeRegistryImplementation = new StakeRegistry(
197-
ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)),
198-
IDelegationManager(coreDeployment.delegationManager),
199-
IAVSDirectory(coreDeployment.avsDirectory),
200-
IAllocationManager(coreDeployment.allocationManager)
201-
);
202-
BLSApkRegistry blsApkRegistryImplementation =
203-
new BLSApkRegistry(ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)));
204-
IndexRegistry indexRegistryImplementation =
205-
new IndexRegistry(ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)));
206-
SocketRegistry socketRegistryImplementation =
207-
new SocketRegistry(IRegistryCoordinator(address(slashingRegistryCoordinator)));
208-
209-
// Upgrade all registry proxies
210-
proxyAdmin.upgrade(
211-
TransparentUpgradeableProxy(payable(address(stakeRegistry))),
212-
address(stakeRegistryImplementation)
213-
);
214-
proxyAdmin.upgrade(
215-
TransparentUpgradeableProxy(payable(address(blsApkRegistry))),
216-
address(blsApkRegistryImplementation)
217-
);
218-
proxyAdmin.upgrade(
219-
TransparentUpgradeableProxy(payable(address(indexRegistry))),
220-
address(indexRegistryImplementation)
221-
);
222-
proxyAdmin.upgrade(
223-
TransparentUpgradeableProxy(payable(address(socketRegistry))),
224-
address(socketRegistryImplementation)
225-
);
226-
227-
// Initialize the SlashingRegistryCoordinator first
228-
slashingRegistryCoordinator.initialize(
229-
proxyAdminOwner, churnApprover, ejector, 0, serviceManager
230-
);
231-
232151
vm.stopPrank();
233152

234-
instantSlasherImplementation = new InstantSlasher(
235-
IAllocationManager(coreDeployment.allocationManager),
236-
ISlashingRegistryCoordinator(slashingRegistryCoordinator),
237-
slasher
238-
);
153+
MiddlewareDeployLib.MiddlewareDeployConfig memory middlewareConfig;
154+
middlewareConfig.instantSlasher.initialOwner = proxyAdminOwner;
155+
middlewareConfig.instantSlasher.slasher = slasher;
156+
middlewareConfig.slashingRegistryCoordinator.initialOwner = proxyAdminOwner;
157+
middlewareConfig.slashingRegistryCoordinator.churnApprover = churnApprover;
158+
middlewareConfig.slashingRegistryCoordinator.ejector = ejector;
159+
middlewareConfig.slashingRegistryCoordinator.initPausedStatus = 0;
160+
middlewareConfig.slashingRegistryCoordinator.serviceManager = serviceManager;
161+
middlewareConfig.socketRegistry.initialOwner = proxyAdminOwner;
162+
middlewareConfig.indexRegistry.initialOwner = proxyAdminOwner;
163+
middlewareConfig.stakeRegistry.initialOwner = proxyAdminOwner;
164+
middlewareConfig.stakeRegistry.minimumStake = 1 ether;
165+
middlewareConfig.stakeRegistry.strategyParams = 0;
166+
middlewareConfig.stakeRegistry.delegationManager = coreDeployment.delegationManager;
167+
middlewareConfig.stakeRegistry.avsDirectory = coreDeployment.avsDirectory;
168+
{
169+
IStakeRegistryTypes.StrategyParams[] memory stratParams =
170+
new IStakeRegistryTypes.StrategyParams[](1);
171+
stratParams[0] =
172+
IStakeRegistryTypes.StrategyParams({strategy: mockStrategy, multiplier: 1 ether});
173+
middlewareConfig.stakeRegistry.strategyParamsArray = stratParams;
174+
}
175+
middlewareConfig.stakeRegistry.lookAheadPeriod = 0;
176+
middlewareConfig.stakeRegistry.stakeType = IStakeRegistryTypes.StakeType(1);
177+
middlewareConfig.blsApkRegistry.initialOwner = proxyAdminOwner;
239178

240179
vm.startPrank(proxyAdminOwner);
241-
instantSlasher = InstantSlasher(
242-
address(
243-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
244-
)
245-
);
246-
247-
proxyAdmin.upgrade(
248-
TransparentUpgradeableProxy(payable(address(instantSlasher))),
249-
address(instantSlasherImplementation)
180+
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployments = MiddlewareDeployLib
181+
.deployMiddleware(
182+
address(proxyAdmin),
183+
coreDeployment.allocationManager,
184+
address(pauserRegistry),
185+
middlewareConfig
250186
);
251187
vm.stopPrank();
252188

253-
instantSlasher.initialize(slasher);
189+
instantSlasher = InstantSlasher(middlewareDeployments.instantSlasher);
190+
slashingRegistryCoordinator =
191+
SlashingRegistryCoordinator(middlewareDeployments.slashingRegistryCoordinator);
192+
stakeRegistry = StakeRegistry(middlewareDeployments.stakeRegistry);
193+
blsApkRegistry = BLSApkRegistry(middlewareDeployments.blsApkRegistry);
194+
indexRegistry = IndexRegistry(middlewareDeployments.indexRegistry);
195+
socketRegistry = SocketRegistry(middlewareDeployments.socketRegistry);
254196

255197
vm.startPrank(serviceManager);
256198
PermissionController(coreDeployment.permissionController).setAppointee(
@@ -295,12 +237,7 @@ contract InstantSlasherTest is Test {
295237
vm.stopPrank();
296238

297239
vm.label(address(instantSlasher), "InstantSlasher Proxy");
298-
vm.label(address(instantSlasherImplementation), "InstantSlasher Implementation");
299240
vm.label(address(slashingRegistryCoordinator), "SlashingRegistryCoordinator Proxy");
300-
vm.label(
301-
address(slashingRegistryCoordinatorImplementation),
302-
"SlashingRegistryCoordinator Implementation"
303-
);
304241
vm.label(address(proxyAdmin), "ProxyAdmin");
305242
vm.label(coreDeployment.allocationManager, "AllocationManager Proxy");
306243
}

test/unit/VetoableSlasher.t.sol

Lines changed: 40 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {IVetoableSlasherTypes} from "../../src/interfaces/IVetoableSlasher.sol";
5252
import {SocketRegistry} from "../../src/SocketRegistry.sol";
5353
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5454
import {IVetoableSlasherErrors} from "../../src/interfaces/IVetoableSlasher.sol";
55+
import {MiddlewareDeployLib} from "../utils/MiddlewareDeployLib.sol";
5556

5657
contract VetoableSlasherTest is Test {
5758
VetoableSlasher public vetoableSlasher;
@@ -155,87 +156,49 @@ contract VetoableSlasherTest is Test {
155156
)
156157
);
157158

158-
// Deploy empty proxies for all registries
159-
stakeRegistry = StakeRegistry(
160-
address(
161-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
162-
)
163-
);
164-
165-
blsApkRegistry = BLSApkRegistry(
166-
address(
167-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
168-
)
169-
);
170-
171-
indexRegistry = IndexRegistry(
172-
address(
173-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
174-
)
175-
);
176-
177-
socketRegistry = SocketRegistry(
178-
address(
179-
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
180-
)
181-
);
182-
183-
slashingRegistryCoordinatorImplementation = new SlashingRegistryCoordinator(
184-
IStakeRegistry(address(stakeRegistry)),
185-
IBLSApkRegistry(address(blsApkRegistry)),
186-
IIndexRegistry(address(indexRegistry)),
187-
ISocketRegistry(address(socketRegistry)),
188-
IAllocationManager(coreDeployment.allocationManager),
189-
IPauserRegistry(address(pauserRegistry))
190-
);
191-
192-
slashingRegistryCoordinator = SlashingRegistryCoordinator(
193-
address(
194-
new TransparentUpgradeableProxy(
195-
address(slashingRegistryCoordinatorImplementation), address(proxyAdmin), ""
196-
)
197-
)
198-
);
199-
200-
// Deploy registry implementations pointing to the coordinator
201-
StakeRegistry stakeRegistryImplementation = new StakeRegistry(
202-
ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)),
203-
IDelegationManager(coreDeployment.delegationManager),
204-
IAVSDirectory(coreDeployment.avsDirectory),
205-
IAllocationManager(coreDeployment.allocationManager)
206-
);
207-
BLSApkRegistry blsApkRegistryImplementation =
208-
new BLSApkRegistry(ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)));
209-
IndexRegistry indexRegistryImplementation =
210-
new IndexRegistry(ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)));
211-
SocketRegistry socketRegistryImplementation =
212-
new SocketRegistry(IRegistryCoordinator(address(slashingRegistryCoordinator)));
213-
214-
// Upgrade all registry proxies
215-
proxyAdmin.upgrade(
216-
TransparentUpgradeableProxy(payable(address(stakeRegistry))),
217-
address(stakeRegistryImplementation)
218-
);
219-
proxyAdmin.upgrade(
220-
TransparentUpgradeableProxy(payable(address(blsApkRegistry))),
221-
address(blsApkRegistryImplementation)
222-
);
223-
proxyAdmin.upgrade(
224-
TransparentUpgradeableProxy(payable(address(indexRegistry))),
225-
address(indexRegistryImplementation)
226-
);
227-
proxyAdmin.upgrade(
228-
TransparentUpgradeableProxy(payable(address(socketRegistry))),
229-
address(socketRegistryImplementation)
230-
);
159+
MiddlewareDeployLib.MiddlewareDeployConfig memory middlewareConfig;
160+
middlewareConfig.instantSlasher.initialOwner = proxyAdminOwner;
161+
middlewareConfig.instantSlasher.slasher = slasher;
162+
middlewareConfig.slashingRegistryCoordinator.initialOwner = proxyAdminOwner;
163+
middlewareConfig.slashingRegistryCoordinator.churnApprover = churnApprover;
164+
middlewareConfig.slashingRegistryCoordinator.ejector = ejector;
165+
middlewareConfig.slashingRegistryCoordinator.initPausedStatus = 0;
166+
middlewareConfig.slashingRegistryCoordinator.serviceManager = serviceManager;
167+
middlewareConfig.socketRegistry.initialOwner = proxyAdminOwner;
168+
middlewareConfig.indexRegistry.initialOwner = proxyAdminOwner;
169+
middlewareConfig.stakeRegistry.initialOwner = proxyAdminOwner;
170+
middlewareConfig.stakeRegistry.minimumStake = 1 ether;
171+
middlewareConfig.stakeRegistry.strategyParams = 0;
172+
middlewareConfig.stakeRegistry.delegationManager = coreDeployment.delegationManager;
173+
middlewareConfig.stakeRegistry.avsDirectory = coreDeployment.avsDirectory;
174+
{
175+
IStakeRegistryTypes.StrategyParams[] memory stratParams =
176+
new IStakeRegistryTypes.StrategyParams[](1);
177+
stratParams[0] =
178+
IStakeRegistryTypes.StrategyParams({strategy: mockStrategy, multiplier: 1 ether});
179+
middlewareConfig.stakeRegistry.strategyParamsArray = stratParams;
180+
}
181+
middlewareConfig.stakeRegistry.lookAheadPeriod = 0;
182+
middlewareConfig.stakeRegistry.stakeType = IStakeRegistryTypes.StakeType(1);
183+
middlewareConfig.blsApkRegistry.initialOwner = proxyAdminOwner;
231184

232-
// Initialize the SlashingRegistryCoordinator first
233-
slashingRegistryCoordinator.initialize(
234-
proxyAdminOwner, churnApprover, ejector, 0, serviceManager
185+
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployments = MiddlewareDeployLib
186+
.deployMiddleware(
187+
address(proxyAdmin),
188+
coreDeployment.allocationManager,
189+
address(pauserRegistry),
190+
middlewareConfig
235191
);
236-
237192
vm.stopPrank();
238193

194+
vetoableSlasher = VetoableSlasher(middlewareDeployments.instantSlasher);
195+
slashingRegistryCoordinator =
196+
SlashingRegistryCoordinator(middlewareDeployments.slashingRegistryCoordinator);
197+
stakeRegistry = StakeRegistry(middlewareDeployments.stakeRegistry);
198+
blsApkRegistry = BLSApkRegistry(middlewareDeployments.blsApkRegistry);
199+
indexRegistry = IndexRegistry(middlewareDeployments.indexRegistry);
200+
socketRegistry = SocketRegistry(middlewareDeployments.socketRegistry);
201+
239202
vetoableSlasherImplementation = new VetoableSlasher(
240203
IAllocationManager(coreDeployment.allocationManager),
241204
ISlashingRegistryCoordinator(slashingRegistryCoordinator)
@@ -413,7 +376,6 @@ contract VetoableSlasherTest is Test {
413376
}
414377

415378
function test_fulfillSlashingRequest() public {
416-
vm.skip(false);
417379
vm.startPrank(operatorWallet.key.addr);
418380
IDelegationManager(coreDeployment.delegationManager).registerAsOperator(
419381
address(0), 1, "metadata"

0 commit comments

Comments
 (0)