-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathAlignedLayerServiceManager.t.sol
159 lines (130 loc) · 5.48 KB
/
AlignedLayerServiceManager.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.12;
import {stdStorage, StdStorage, Test} from "forge-std/Test.sol";
import "../src/core/AlignedLayerServiceManager.sol";
import {IAlignedLayerServiceManager} from "../src/core/IAlignedLayerServiceManager.sol";
import {IStakeRegistry} from "eigenlayer-middleware/interfaces/IStakeRegistry.sol";
import {IRegistryCoordinator} from "eigenlayer-middleware/interfaces/IRegistryCoordinator.sol";
import {IRewardsCoordinator} from "eigenlayer-contracts/src/contracts/interfaces/IRewardsCoordinator.sol";
import {BLSMockAVSDeployer} from "eigenlayer-middleware/../test/utils/BLSMockAVSDeployer.sol";
contract AlignedLayerServiceManagerTest is Test, BLSMockAVSDeployer {
AlignedLayerServiceManager alignedLayerServiceManager;
address initialOwner = address(0x123);
address aggregator = address(0x456);
using stdStorage for StdStorage;
event NewBatchV2(
bytes32 indexed batchMerkleRoot,
address senderAddress,
uint32 taskCreatedBlock,
string batchDataPointer
);
event NewBatchV3(
bytes32 indexed batchMerkleRoot,
address senderAddress,
uint32 taskCreatedBlock,
string batchDataPointer,
uint256 maxFeeToRespond
);
struct BatchIdentifier {
bytes32 batchMerkleRoot;
address senderAddress;
}
event BatchVerified(bytes32 batchMerkleRoot);
function setUp() public virtual {
_setUpBLSMockAVSDeployer();
alignedLayerServiceManager = new AlignedLayerServiceManager(
avsDirectory,
IRewardsCoordinator(address(rewardsCoordinatorMock)),
IRegistryCoordinator(address(registryCoordinator)),
IStakeRegistry(address(stakeRegistry))
);
// alignedLayerServiceManager.initialize(initialOwner, aggregator);
}
// function testInitialize() public {
// assertEq(alignedLayerServiceManager.owner(), initialOwner);
// assertEq(alignedLayerServiceManager.isAggregator(aggregator), true);
// }
function testCreateNewTask(
string memory root,
string memory batchDataPointer,
uint256 maxFeeToRespond
) public {
vm.assume(bytes(batchDataPointer).length > 50);
bytes32 batchMerkleRoot = keccak256(abi.encodePacked(root));
address batcher = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
hoax(batcher, maxFeeToRespond);
// transfer to serviceManager
address(alignedLayerServiceManager).call{value: maxFeeToRespond}("");
vm.expectEmit(true, true, true, true);
emit NewBatchV3(
batchMerkleRoot,
batcher,
uint32(block.number),
batchDataPointer,
maxFeeToRespond
);
vm.prank(batcher);
alignedLayerServiceManager.createNewTask(
batchMerkleRoot,
batchDataPointer,
maxFeeToRespond
);
bytes32 batchIdentifierHash = keccak256(
abi.encodePacked(batchMerkleRoot, batcher)
);
(
uint32 taskCreatedBlock,
bool responded,
uint256 _maxFeeToRespond
) = alignedLayerServiceManager.batchesState(batchIdentifierHash);
assertEq(taskCreatedBlock, uint32(block.number));
assertEq(responded, false);
assertEq(_maxFeeToRespond, maxFeeToRespond);
}
/* =============== Disabled verifiers tests =============== */
function test_SetVerifiersList_WorksAsExpected() public {
vm.prank(address(0));
uint256 newBitmap = 1234;
alignedLayerServiceManager.setDisabledVerifiers(newBitmap);
uint256 actualBitmap = alignedLayerServiceManager.disabledVerifiers();
assertEq(newBitmap, actualBitmap);
}
function test_DisabledAndEnableVerifier_WorksAsExpected() public {
uint8 verifierIdx = 28;
// make sure it is false by default
bool res = alignedLayerServiceManager.isVerifierDisabled(
verifierIdx
);
assertEq(res, false);
vm.expectEmit(true, true, true, true);
emit IAlignedLayerServiceManager.VerifierDisabled(verifierIdx);
// disable the verifier and check that it has been actually disable
vm.prank(address(0));
alignedLayerServiceManager.disableVerifier(verifierIdx);
res = alignedLayerServiceManager.isVerifierDisabled(verifierIdx);
assertEq(res, true);
// now whitelist the verifier again and make sure is not disabled anymore
vm.expectEmit(true, true, true, true);
emit IAlignedLayerServiceManager.VerifierEnabled(verifierIdx);
vm.prank(address(0));
alignedLayerServiceManager.enableVerifier(verifierIdx);
res = alignedLayerServiceManager.isVerifierDisabled(verifierIdx);
assertEq(res, false);
}
// here we test the filures
// test ownership
function test_SetVerifiersDisabled_FailsWhenNotOwner() public {
vm.expectRevert("Ownable: caller is not the owner");
alignedLayerServiceManager.setDisabledVerifiers(213);
}
function test_DisableVerifier_FailsWhenNotOwner() public {
uint8 newBitmap = 10;
vm.expectRevert("Ownable: caller is not the owner");
alignedLayerServiceManager.disableVerifier(newBitmap);
}
function test_EnabledVerifier_FailsWhenNotOwner() public {
uint8 newBitmap = 10;
vm.expectRevert("Ownable: caller is not the owner");
alignedLayerServiceManager.enableVerifier(newBitmap);
}
}