-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathGovernancePowerStrategy.t.sol
214 lines (187 loc) · 5.98 KB
/
GovernancePowerStrategy.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import 'forge-std/Test.sol';
import {GovernancePowerStrategy} from '../src/contracts/GovernancePowerStrategy.sol';
import {IBaseVotingStrategy} from '../src/interfaces/IBaseVotingStrategy.sol';
import {IGovernancePowerDelegationToken} from '../src/contracts/dataHelpers/interfaces/IGovernancePowerDelegationToken.sol';
contract GovernancePowerStrategyTest is Test {
address public AAVE;
address public STK_AAVE;
address public A_AAVE;
uint128 public BASE_STORAGE_SLOT;
uint128 public A_AAVE_BASE_BALANCE_SLOT;
uint128 public A_AAVE_DELEGATED_STATE_SLOT;
GovernancePowerStrategy public governancePowerStrategy;
event VotingAssetAdd(address indexed asset, uint128[] storageSlots);
function setUp() public {
governancePowerStrategy = new GovernancePowerStrategy();
AAVE = IBaseVotingStrategy(address(governancePowerStrategy)).AAVE();
STK_AAVE = IBaseVotingStrategy(address(governancePowerStrategy)).STK_AAVE();
A_AAVE = IBaseVotingStrategy(address(governancePowerStrategy)).A_AAVE();
BASE_STORAGE_SLOT = IBaseVotingStrategy(address(governancePowerStrategy))
.BASE_BALANCE_SLOT();
A_AAVE_BASE_BALANCE_SLOT = IBaseVotingStrategy(
address(governancePowerStrategy)
).A_AAVE_BASE_BALANCE_SLOT();
A_AAVE_DELEGATED_STATE_SLOT = IBaseVotingStrategy(
address(governancePowerStrategy)
).A_AAVE_DELEGATED_STATE_SLOT();
}
function testConstructor() public {
uint128[] memory storageSlots = new uint128[](1);
storageSlots[0] = BASE_STORAGE_SLOT;
uint128[] memory storageSlotsAAve = new uint128[](2);
storageSlotsAAve[0] = A_AAVE_BASE_BALANCE_SLOT;
storageSlotsAAve[1] = A_AAVE_DELEGATED_STATE_SLOT;
vm.expectEmit(true, false, false, true);
emit VotingAssetAdd(AAVE, storageSlots);
vm.expectEmit(true, false, false, true);
emit VotingAssetAdd(STK_AAVE, storageSlots);
vm.expectEmit(true, false, false, true);
emit VotingAssetAdd(A_AAVE, storageSlotsAAve);
governancePowerStrategy = new GovernancePowerStrategy();
}
function testSetUp(address randomToken) public {
vm.assume(
randomToken != AAVE && randomToken != STK_AAVE && randomToken != A_AAVE
);
address[] memory tokenList = IBaseVotingStrategy(governancePowerStrategy)
.getVotingAssetList();
for (uint256 i; i < tokenList.length; i++) {
assertEq(tokenList[i] == randomToken, false);
}
}
function testGetVotingAssetList() public {
address[] memory votingAssets = governancePowerStrategy
.getVotingAssetList();
assertEq(votingAssets[0], AAVE);
assertEq(votingAssets[1], STK_AAVE);
}
function testGetVotingAssetConfig() public {
IBaseVotingStrategy.VotingAssetConfig
memory votingAssetConfigAave = governancePowerStrategy
.getVotingAssetConfig(AAVE);
assertEq(votingAssetConfigAave.storageSlots[0], uint128(0));
IBaseVotingStrategy.VotingAssetConfig
memory votingAssetConfigStk = governancePowerStrategy
.getVotingAssetConfig(STK_AAVE);
assertEq(votingAssetConfigStk.storageSlots[0], uint128(0));
address notAsset = address(1);
IBaseVotingStrategy.VotingAssetConfig
memory votingAssetConfigNull = governancePowerStrategy
.getVotingAssetConfig(notAsset);
assertEq(votingAssetConfigNull.storageSlots.length, 0);
}
function testGetFullVotingPower() public {
address user = address(2134);
uint256 aavePower = 123;
uint256 aAavePower = 13;
uint256 stkAavePower = 3;
vm.mockCall(
AAVE,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector
),
abi.encode(aavePower)
);
vm.expectCall(
AAVE,
0,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector,
user,
0
)
);
vm.mockCall(
A_AAVE,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector
),
abi.encode(aAavePower)
);
vm.expectCall(
A_AAVE,
0,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector,
user,
0
)
);
vm.mockCall(
STK_AAVE,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector
),
abi.encode(stkAavePower)
);
vm.expectCall(
STK_AAVE,
0,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector,
user,
0
)
);
uint256 fullPower = governancePowerStrategy.getFullVotingPower(user);
assertEq(fullPower, aavePower + stkAavePower + aAavePower);
}
function testGetFullPropositionPower() public {
address user = address(2134);
uint256 aavePower = 123;
uint256 aAavePower = 12;
uint256 stkAavePower = 3;
vm.mockCall(
AAVE,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector
),
abi.encode(aavePower)
);
vm.expectCall(
AAVE,
0,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector,
user,
1
)
);
vm.mockCall(
A_AAVE,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector
),
abi.encode(aAavePower)
);
vm.expectCall(
A_AAVE,
0,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector,
user,
1
)
);
vm.mockCall(
STK_AAVE,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector
),
abi.encode(stkAavePower)
);
vm.expectCall(
STK_AAVE,
0,
abi.encodeWithSelector(
IGovernancePowerDelegationToken.getPowerCurrent.selector,
user,
1
)
);
uint256 fullPower = governancePowerStrategy.getFullPropositionPower(user);
assertEq(fullPower, aavePower + stkAavePower + aAavePower);
}
}