@@ -30,7 +30,7 @@ describe('Governable Contract', () => {
30
30
arbSigner = signers [ 2 ] ;
31
31
// create poseidon hasher
32
32
const govFactory = new Governable__factory ( wallet ) ;
33
- governableInstance = await govFactory . deploy ( sender . address , 0 , 0 ) ;
33
+ governableInstance = await govFactory . deploy ( sender . address , 0 , 2 ) ;
34
34
await governableInstance . deployed ( ) ;
35
35
} ) ;
36
36
@@ -81,26 +81,8 @@ describe('Governable Contract', () => {
81
81
'0x' + ethers . utils . keccak256 ( '0x' + dummyPubkey ) . slice ( - 40 )
82
82
) ;
83
83
84
- const refreshProposal = {
85
- voterMerkleRoot : ZERO_BYTES32 ,
86
- averageSessionLengthInMillisecs : '50000' ,
87
- voterCount : '1' ,
88
- nonce : '2' ,
89
- publicKey : `0x${ dummyPubkey } ` ,
90
- } ;
91
-
92
- const prehashed = solidityPack (
93
- [ 'bytes32' , 'uint64' , 'uint32' , 'uint32' , 'bytes' ] ,
94
- [
95
- refreshProposal . voterMerkleRoot ,
96
- refreshProposal . averageSessionLengthInMillisecs ,
97
- refreshProposal . voterCount ,
98
- refreshProposal . nonce ,
99
- refreshProposal . publicKey ,
100
- ]
101
- ) ;
102
-
103
- let msg = ethers . utils . arrayify ( ethers . utils . keccak256 ( prehashed ) ) ;
84
+ let newGovernorPublickKey = `0x${ dummyPubkey } ` ;
85
+ let msg = ethers . utils . arrayify ( ethers . utils . keccak256 ( newGovernorPublickKey ) ) ;
104
86
let signature = key . sign ( msg ) ;
105
87
let expandedSig = {
106
88
r : '0x' + signature . r . toString ( 'hex' ) ,
@@ -120,43 +102,23 @@ describe('Governable Contract', () => {
120
102
}
121
103
122
104
const tx = await governableInstance . transferOwnershipWithSignature (
123
- refreshProposal . voterMerkleRoot ,
124
- refreshProposal . averageSessionLengthInMillisecs ,
125
- refreshProposal . voterCount ,
126
- refreshProposal . nonce ,
127
- refreshProposal . publicKey ,
105
+ 2 ,
106
+ newGovernorPublickKey ,
128
107
sig
129
108
) ;
130
109
await tx . wait ( ) ;
131
110
132
111
assert . strictEqual ( await governableInstance . governor ( ) , nextGovernorAddress ) ;
133
- assert . strictEqual (
134
- ( await governableInstance . voterCount ( ) ) . toString ( ) ,
135
- refreshProposal . voterCount
136
- ) ;
137
- assert . strictEqual ( await governableInstance . voterMerkleRoot ( ) , refreshProposal . voterMerkleRoot ) ;
138
- assert . strictEqual ( ( await governableInstance . refreshNonce ( ) ) . toString ( ) , '2' ) ;
139
-
112
+ assert . strictEqual ( ( await governableInstance . jobId ( ) ) . toString ( ) , '2' ) ;
140
113
const filter = governableInstance . filters . GovernanceOwnershipTransferred ( ) ;
141
114
const events = await governableInstance . queryFilter ( filter ) ;
142
115
assert . strictEqual ( nextGovernorAddress , events [ 2 ] . args . newOwner ) ;
143
116
assert . strictEqual ( firstRotationKey , events [ 2 ] . args . previousOwner ) ;
144
117
} ) ;
145
118
146
119
it ( 'should vote validly and change the governor' , async ( ) => {
147
- const voteStruct = {
148
- nonce : await governableInstance . refreshNonce ( ) ,
149
- leafIndex : 0 ,
150
- siblingPathNodes : [ '0x0000000000000000000000000000000000000000000000000000000000000001' ] ,
151
- proposedGovernor : '0x1111111111111111111111111111111111111111' ,
152
- } ;
153
-
154
- await TruffleAssert . reverts (
155
- governableInstance . voteInFavorForceSetGovernor ( voteStruct ) ,
156
- 'Invalid time for vote'
157
- ) ;
158
-
159
- assert . strictEqual ( ( await governableInstance . refreshNonce ( ) ) . toString ( ) , '0' ) ;
120
+
121
+ assert . strictEqual ( ( await governableInstance . jobId ( ) ) . toString ( ) , '0' ) ;
160
122
const wallet = ethers . Wallet . createRandom ( ) ;
161
123
const key = ec . keyFromPrivate ( wallet . privateKey . slice ( 2 ) , 'hex' ) ;
162
124
const pubkey = key . getPublic ( ) . encode ( 'hex' ) . slice ( 2 ) ;
@@ -174,55 +136,13 @@ describe('Governable Contract', () => {
174
136
. encode ( 'hex' )
175
137
. slice ( 2 ) ;
176
138
177
- const nonce = 2 ;
178
-
139
+ const jobId = 2 ; // Job Id of the new governor.
140
+ let newGovernorPublickKey = `0x ${ dummyPubkey } ` ;
179
141
const signers = await ethers . getSigners ( ) ;
180
-
181
- const voter0Signer = signers [ 0 ] ;
182
- const voter0 = signers [ 0 ] . address ;
183
-
184
142
const voter1Signer = signers [ 1 ] ;
185
- const voter1 = signers [ 1 ] . address ;
186
-
187
143
const voter2Signer = signers [ 2 ] ;
188
- const voter2 = signers [ 2 ] . address ;
189
-
190
- const voter3 = signers [ 3 ] . address ;
191
-
192
- const hashVoter0 = ethers . utils . keccak256 ( voter0 ) ;
193
- const hashVoter1 = ethers . utils . keccak256 ( voter1 ) ;
194
- const hashVoter2 = ethers . utils . keccak256 ( voter2 ) ;
195
- const hashVoter3 = ethers . utils . keccak256 ( voter3 ) ;
196
-
197
- const hashVoter01 = ethers . utils . keccak256 ( hashVoter0 + hashVoter1 . slice ( 2 ) ) ;
198
- const hashVoter23 = ethers . utils . keccak256 ( hashVoter2 + hashVoter3 . slice ( 2 ) ) ;
199
-
200
- const hashVoter0123 = ethers . utils . keccak256 ( hashVoter01 + hashVoter23 . slice ( 2 ) ) ;
201
-
202
- const voterMerkleRoot = hashVoter0123 ;
203
- const averageSessionLengthInMillisecs = 50000 ;
204
- const voterCount = 4 ;
205
144
206
- const refreshProposal = {
207
- voterMerkleRoot,
208
- averageSessionLengthInMillisecs,
209
- voterCount,
210
- nonce,
211
- publicKey : `0x${ dummyPubkey } ` ,
212
- } ;
213
-
214
- const prehashed = solidityPack (
215
- [ 'bytes32' , 'uint64' , 'uint32' , 'uint32' , 'bytes' ] ,
216
- [
217
- refreshProposal . voterMerkleRoot ,
218
- refreshProposal . averageSessionLengthInMillisecs ,
219
- refreshProposal . voterCount ,
220
- refreshProposal . nonce ,
221
- refreshProposal . publicKey ,
222
- ]
223
- ) ;
224
-
225
- let msg = ethers . utils . arrayify ( ethers . utils . keccak256 ( prehashed ) ) ;
145
+ let msg = ethers . utils . arrayify ( ethers . utils . keccak256 ( newGovernorPublickKey ) ) ;
226
146
let signature = key . sign ( msg ) ;
227
147
let expandedSig = {
228
148
r : '0x' + signature . r . toString ( 'hex' ) ,
@@ -242,42 +162,18 @@ describe('Governable Contract', () => {
242
162
}
243
163
244
164
const tx = await governableInstance . transferOwnershipWithSignature (
245
- refreshProposal . voterMerkleRoot ,
246
- refreshProposal . averageSessionLengthInMillisecs ,
247
- refreshProposal . voterCount ,
248
- refreshProposal . nonce ,
249
- refreshProposal . publicKey ,
165
+ jobId ,
166
+ newGovernorPublickKey ,
250
167
sig
251
168
) ;
252
169
await tx . wait ( ) ;
253
170
254
- assert . strictEqual (
255
- ( await governableInstance . averageSessionLengthInMillisecs ( ) ) . toString ( ) ,
256
- averageSessionLengthInMillisecs . toString ( )
257
- ) ;
258
- assert . strictEqual ( ( await governableInstance . voterCount ( ) ) . toString ( ) , '4' ) ;
259
- assert . strictEqual ( await governableInstance . voterMerkleRoot ( ) , voterMerkleRoot ) ;
260
- assert . strictEqual ( ( await governableInstance . refreshNonce ( ) ) . toString ( ) , '2' ) ;
261
- await network . provider . send ( 'evm_increaseTime' , [ 600 ] ) ;
262
-
263
- const vote0 = {
264
- nonce : await governableInstance . refreshNonce ( ) ,
265
- leafIndex : 0 ,
266
- siblingPathNodes : [ hashVoter1 , hashVoter23 ] ,
267
- proposedGovernor : '0x1111111111111111111111111111111111111111' ,
268
- } ;
269
-
270
- await governableInstance . connect ( voter0Signer ) . voteInFavorForceSetGovernor ( vote0 ) ;
271
171
272
- assert . notEqual (
273
- await governableInstance . governor ( ) ,
274
- '0x1111111111111111111111111111111111111111'
275
- ) ;
172
+ assert . strictEqual ( ( await governableInstance . jobId ( ) ) . toString ( ) , '2' ) ;
173
+ await network . provider . send ( 'evm_increaseTime' , [ 600 ] ) ;
276
174
277
175
const vote1 = {
278
- nonce : await governableInstance . refreshNonce ( ) ,
279
- leafIndex : 1 ,
280
- siblingPathNodes : [ hashVoter0 , hashVoter23 ] ,
176
+ jobId : 3 ,
281
177
proposedGovernor : '0x1111111111111111111111111111111111111111' ,
282
178
} ;
283
179
@@ -289,10 +185,7 @@ describe('Governable Contract', () => {
289
185
) ;
290
186
291
187
const vote2 = {
292
- nonce : await governableInstance . refreshNonce ( ) ,
293
-
294
- leafIndex : 2 ,
295
- siblingPathNodes : [ hashVoter3 , hashVoter01 ] ,
188
+ jobId : 3 ,
296
189
proposedGovernor : '0x1111111111111111111111111111111111111111' ,
297
190
} ;
298
191
@@ -302,6 +195,12 @@ describe('Governable Contract', () => {
302
195
await governableInstance . governor ( ) ,
303
196
'0x1111111111111111111111111111111111111111'
304
197
) ;
305
- assert . strictEqual ( ( await governableInstance . refreshNonce ( ) ) . toString ( ) , '3' ) ;
198
+
199
+ const filter = governableInstance . filters . GovernanceOwnershipTransferred ( ) ;
200
+ const events = await governableInstance . queryFilter ( filter ) ;
201
+ assert . strictEqual ( 3 , events [ 3 ] . args . jobId ) ;
202
+ assert . strictEqual ( 2 , events [ 3 ] . args . previousOwnerJobId ) ;
203
+
204
+ assert . strictEqual ( ( await governableInstance . jobId ( ) ) . toString ( ) , '3' ) ;
306
205
} ) ;
307
206
} ) ;
0 commit comments