@@ -2,19 +2,36 @@ import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
2
2
import { loadFixture } from '@nomicfoundation/hardhat-toolbox/network-helpers'
3
3
import { expect } from 'chai'
4
4
import { ethers } from 'hardhat'
5
- import { RIFToken , StRIFToken } from '../typechain-types'
5
+ import {
6
+ ContractDoesNotSupportERC165andICollectiveRewardscheck ,
7
+ ContractDoesNotSupportICollectiveRewardsCheck ,
8
+ ContractSupportsERC165andICollectiveRewardscheck ,
9
+ ContractWithErrorInCanWithdraw ,
10
+ RIFToken ,
11
+ StRIFToken ,
12
+ } from '../typechain-types'
6
13
import { deployContracts } from './deployContracts'
7
14
8
15
describe ( 'stRIFToken' , ( ) => {
9
16
let owner : SignerWithAddress , holder : SignerWithAddress , voter : SignerWithAddress
10
17
let rif : RIFToken
11
18
let stRIF : StRIFToken
19
+ let ContractSupportsERC165andICollectiveRewardscheck : ContractSupportsERC165andICollectiveRewardscheck
20
+ let ContractDoesNotSupportERC165andICollectiveRewardscheck : ContractDoesNotSupportERC165andICollectiveRewardscheck
21
+ let ContractDoesNotSupportICollectiveRewardsCheck : ContractDoesNotSupportICollectiveRewardsCheck
22
+ let ContractWithErrorInCanWithdraw : ContractWithErrorInCanWithdraw
12
23
const votingPower = 10n * 10n ** 18n
13
24
14
25
// prettier-ignore
15
26
before ( async ( ) => {
16
27
; [ owner , holder , voter ] = await ethers . getSigners ( )
17
28
; ( { rif, stRIF } = await loadFixture ( deployContracts ) )
29
+ ContractDoesNotSupportERC165andICollectiveRewardscheck = await ethers . deployContract ( 'ContractDoesNotSupportERC165andICollectiveRewardscheck' )
30
+ ContractDoesNotSupportICollectiveRewardsCheck = await ethers . deployContract ( 'ContractDoesNotSupportICollectiveRewardsCheck' )
31
+ ContractSupportsERC165andICollectiveRewardscheck = await ethers . deployContract ( 'ContractSupportsERC165andICollectiveRewardscheck' , [
32
+ holder ,
33
+ ] )
34
+ ContractWithErrorInCanWithdraw = await ethers . deployContract ( 'ContractWithErrorInCanWithdraw' , [ voter ] )
18
35
} )
19
36
20
37
it ( 'Should assign the initial balance to the contract itself' , async ( ) => {
@@ -178,4 +195,98 @@ describe('stRIFToken', () => {
178
195
expect ( await stRIF . getVotes ( voter . address ) ) . to . equal ( votingPower )
179
196
} )
180
197
} )
198
+
199
+ describe ( 'CollectiveRewards Check to allow withdrawal' , ( ) => {
200
+ it ( 'blockedAddress should be set' , async ( ) => {
201
+ expect ( await ContractSupportsERC165andICollectiveRewardscheck . blockedAddress ( ) ) . to . be . properAddress
202
+ expect ( await ContractSupportsERC165andICollectiveRewardscheck . blockedAddress ( ) ) . to . equal ( holder . address )
203
+ } )
204
+
205
+ it ( 'only owner should be able to set CollectiveRewardsAddress' , async ( ) => {
206
+ const tx = stRIF
207
+ . connect ( holder )
208
+ . setCollectiveRewardsAddress ( ContractSupportsERC165andICollectiveRewardscheck )
209
+ await expect ( tx ) . to . be . revertedWithCustomError (
210
+ { interface : stRIF . interface } ,
211
+ 'OwnableUnauthorizedAccount' ,
212
+ )
213
+ } )
214
+
215
+ it ( 'setting CollectiveRewards address should fail if contract does not support ERC165 with STRIFSupportsICollectiveRewardsCheck' , async ( ) => {
216
+ const tx = stRIF . setCollectiveRewardsAddress (
217
+ await ContractDoesNotSupportERC165andICollectiveRewardscheck . getAddress ( ) ,
218
+ )
219
+ await expect ( tx ) . to . be . revertedWithCustomError (
220
+ { interface : stRIF . interface } ,
221
+ 'STRIFSupportsICollectiveRewardsCheck' ,
222
+ )
223
+ } )
224
+
225
+ it ( 'setting CollectiveRewards address should fail if contract does not support ICollectiveRewardsCheck with STRIFSupportsICollectiveRewardsCheck' , async ( ) => {
226
+ expect ( await ContractDoesNotSupportICollectiveRewardsCheck . supportsInterface ( '0x01ffc9a7' ) ) . to . be . true
227
+
228
+ const tx = stRIF . setCollectiveRewardsAddress (
229
+ await ContractDoesNotSupportERC165andICollectiveRewardscheck . getAddress ( ) ,
230
+ )
231
+ await expect ( tx ) . to . be . revertedWithCustomError (
232
+ { interface : stRIF . interface } ,
233
+ 'STRIFSupportsICollectiveRewardsCheck' ,
234
+ )
235
+ } )
236
+
237
+ it ( 'should set CollectiveRewards address if canWithdraw returns boolean' , async ( ) => {
238
+ const address = await ContractSupportsERC165andICollectiveRewardscheck . getAddress ( )
239
+ await stRIF . setCollectiveRewardsAddress ( address )
240
+
241
+ expect ( await stRIF . collectiveRewardsCheck ( ) ) . to . equal ( address )
242
+ } )
243
+
244
+ it ( 'should revert withdrawTo, _update with STRIFStakedInCollectiveRewardsCanWithdraw if bimCheck returns false' , async ( ) => {
245
+ expect ( await stRIF . balanceOf ( holder ) ) . to . equal ( votingPower )
246
+
247
+ const tx = stRIF . connect ( holder ) . withdrawTo ( holder . address , votingPower )
248
+ await expect ( tx ) . to . be . revertedWithCustomError (
249
+ { interface : stRIF . interface } ,
250
+ 'STRIFStakedInCollectiveRewardsCanWithdraw' ,
251
+ )
252
+
253
+ //runs _update under the hood
254
+ const transferTx = stRIF . connect ( holder ) . transfer ( voter , votingPower )
255
+ await expect ( transferTx ) . to . be . revertedWithCustomError (
256
+ { interface : stRIF . interface } ,
257
+ 'STRIFStakedInCollectiveRewardsCanWithdraw' ,
258
+ )
259
+ expect ( await stRIF . balanceOf ( holder ) ) . to . equal ( votingPower )
260
+ } )
261
+
262
+ it ( 'should allow withdrawTo if bimCheck returns true' , async ( ) => {
263
+ await ContractSupportsERC165andICollectiveRewardscheck . setBlockedAddress ( voter )
264
+ expect ( await stRIF . balanceOf ( holder ) ) . to . equal ( votingPower )
265
+
266
+ const value = votingPower / 2n
267
+ const tx = stRIF . connect ( holder ) . withdrawTo ( holder . address , value )
268
+ await expect ( tx ) . to . emit ( stRIF , 'Transfer' ) . withArgs ( holder . address , ethers . ZeroAddress , value )
269
+ } )
270
+
271
+ it ( 'should throw an error if _shouldSkipError is false' , async ( ) => {
272
+ const address = await ContractWithErrorInCanWithdraw . getAddress ( )
273
+ const setTX = stRIF . setCollectiveRewardsAddress ( address )
274
+ await expect ( setTX ) . to . emit ( stRIF , 'CollectiveRewardsAddressHasBeenChanged' ) . withArgs ( address )
275
+
276
+ const tx = stRIF . connect ( holder ) . withdrawTo ( holder . address , votingPower / 2n )
277
+ await expect ( tx ) . to . be . revertedWithCustomError (
278
+ { interface : stRIF . interface } ,
279
+ 'CollectiveRewardsErrored' ,
280
+ )
281
+ } )
282
+
283
+ it ( 'should ignore Collective Rewards error if _shouldSkipError is true' , async ( ) => {
284
+ const skipTX = stRIF . setCollectiveRewardsErrorSkipFlag ( true )
285
+ await expect ( skipTX ) . to . emit ( stRIF , 'STRIFCollectiveRewardsErrorSkipChangedTo' ) . withArgs ( true )
286
+
287
+ const value = votingPower / 2n
288
+ const tx = stRIF . connect ( holder ) . withdrawTo ( holder . address , value )
289
+ await expect ( tx ) . to . emit ( stRIF , 'Transfer' ) . withArgs ( holder . address , ethers . ZeroAddress , value )
290
+ } )
291
+ } )
181
292
} )
0 commit comments