@@ -21,7 +21,13 @@ contract('DynamicSynthRedeemer', async accounts => {
21
21
const [ , owner , , , account1 ] = accounts ;
22
22
23
23
let instance ;
24
- let addressResolver , dynamicSynthRedeemer , exchangeRates , issuer , proxysETH ;
24
+ let addressResolver ,
25
+ dynamicSynthRedeemer ,
26
+ exchangeRates ,
27
+ issuer ,
28
+ proxysETH ,
29
+ proxysUSD ,
30
+ proxySynthetix ;
25
31
26
32
before ( async ( ) => {
27
33
( {
@@ -30,6 +36,8 @@ contract('DynamicSynthRedeemer', async accounts => {
30
36
ExchangeRates : exchangeRates ,
31
37
Issuer : issuer ,
32
38
ProxyERC20sETH : proxysETH ,
39
+ ProxyERC20sUSD : proxysUSD ,
40
+ ProxySynthetix : proxySynthetix ,
33
41
} = await setupAllContracts ( {
34
42
accounts,
35
43
synths,
@@ -41,6 +49,7 @@ contract('DynamicSynthRedeemer', async accounts => {
41
49
'Issuer' ,
42
50
'Liquidator' ,
43
51
'LiquidatorRewards' ,
52
+ 'ProxyERC20' ,
44
53
'RewardEscrowV2' ,
45
54
] ,
46
55
} ) ) ;
@@ -55,7 +64,14 @@ contract('DynamicSynthRedeemer', async accounts => {
55
64
ensureOnlyExpectedMutativeFunctions ( {
56
65
abi : dynamicSynthRedeemer . abi ,
57
66
ignoreParents : [ 'Owned' , 'MixinResolver' ] ,
58
- expected : [ 'redeem' , 'redeemAll' , 'redeemPartial' , 'setDiscountRate' ] ,
67
+ expected : [
68
+ 'redeem' ,
69
+ 'redeemAll' ,
70
+ 'redeemPartial' ,
71
+ 'setDiscountRate' ,
72
+ 'resumeRedemption' ,
73
+ 'suspendRedemption' ,
74
+ ] ,
59
75
} ) ;
60
76
} ) ;
61
77
@@ -69,16 +85,101 @@ contract('DynamicSynthRedeemer', async accounts => {
69
85
assert . equal ( await instance . resolver ( ) , addressResolver . address ) ;
70
86
} ) ;
71
87
88
+ it ( 'should set default discount rate' , async ( ) => {
89
+ assert . bnEqual ( await instance . getDiscountRate ( ) , toUnit ( '1' ) ) ;
90
+ } ) ;
91
+
92
+ it ( 'should not be active for redemption' , async ( ) => {
93
+ assert . equal ( await instance . redemptionActive ( ) , false ) ;
94
+ } ) ;
95
+
72
96
it ( 'should access its dependencies via the address resolver' , async ( ) => {
73
97
assert . equal ( await addressResolver . getAddress ( toBytes32 ( 'Issuer' ) ) , issuer . address ) ;
74
98
assert . equal (
75
99
await addressResolver . getAddress ( toBytes32 ( 'ExchangeRates' ) ) ,
76
100
exchangeRates . address
77
101
) ;
78
102
} ) ;
103
+ } ) ;
79
104
80
- it ( 'should set default discount rate' , async ( ) => {
81
- assert . bnEqual ( await instance . getDiscountRate ( ) , toUnit ( '1' ) ) ;
105
+ describe ( 'suspendRedemption' , ( ) => {
106
+ describe ( 'failure modes' , ( ) => {
107
+ beforeEach ( async ( ) => {
108
+ // first resume redemptions
109
+ await instance . resumeRedemption ( { from : owner } ) ;
110
+ } ) ;
111
+
112
+ it ( 'reverts when not invoked by the owner' , async ( ) => {
113
+ await onlyGivenAddressCanInvoke ( {
114
+ fnc : instance . suspendRedemption ,
115
+ args : [ ] ,
116
+ accounts,
117
+ reason : 'Only the contract owner may perform this action' ,
118
+ address : owner ,
119
+ } ) ;
120
+ } ) ;
121
+
122
+ it ( 'reverts when redemption is already suspended' , async ( ) => {
123
+ await instance . suspendRedemption ( { from : owner } ) ;
124
+ await assert . revert ( instance . suspendRedemption ( { from : owner } ) , 'Redemption suspended' ) ;
125
+ } ) ;
126
+ } ) ;
127
+
128
+ describe ( 'when invoked by the owner' , ( ) => {
129
+ let txn ;
130
+ beforeEach ( async ( ) => {
131
+ // first resume redemptions
132
+ await instance . resumeRedemption ( { from : owner } ) ;
133
+ txn = await instance . suspendRedemption ( { from : owner } ) ;
134
+ } ) ;
135
+
136
+ it ( 'and redemptionActive is false' , async ( ) => {
137
+ assert . equal ( await instance . redemptionActive ( ) , false ) ;
138
+ } ) ;
139
+
140
+ it ( 'and a RedemptionSuspended event is emitted' , async ( ) => {
141
+ assert . eventEqual ( txn , 'RedemptionSuspended' , [ ] ) ;
142
+ } ) ;
143
+ } ) ;
144
+ } ) ;
145
+
146
+ describe ( 'resumeRedemption' , ( ) => {
147
+ describe ( 'failure modes' , ( ) => {
148
+ it ( 'reverts when not invoked by the owner' , async ( ) => {
149
+ await onlyGivenAddressCanInvoke ( {
150
+ fnc : instance . resumeRedemption ,
151
+ args : [ ] ,
152
+ accounts,
153
+ reason : 'Only the contract owner may perform this action' ,
154
+ address : owner ,
155
+ } ) ;
156
+ } ) ;
157
+
158
+ it ( 'reverts when redemption is not suspended' , async ( ) => {
159
+ await instance . resumeRedemption ( { from : owner } ) ;
160
+ await assert . revert ( instance . resumeRedemption ( { from : owner } ) , 'Redemption not suspended' ) ;
161
+ } ) ;
162
+ } ) ;
163
+
164
+ describe ( 'when redemption is suspended' , ( ) => {
165
+ it ( 'redemptionActive is false' , async ( ) => {
166
+ assert . equal ( await instance . redemptionActive ( ) , false ) ;
167
+ } ) ;
168
+
169
+ describe ( 'when invoked by the owner' , ( ) => {
170
+ let txn ;
171
+ beforeEach ( async ( ) => {
172
+ txn = await instance . resumeRedemption ( { from : owner } ) ;
173
+ } ) ;
174
+
175
+ it ( 'redemptions are active again' , async ( ) => {
176
+ assert . equal ( await instance . redemptionActive ( ) , true ) ;
177
+ } ) ;
178
+
179
+ it ( 'a RedemptionResumed event is emitted' , async ( ) => {
180
+ assert . eventEqual ( txn , 'RedemptionResumed' , [ ] ) ;
181
+ } ) ;
182
+ } ) ;
82
183
} ) ;
83
184
} ) ;
84
185
@@ -103,6 +204,20 @@ contract('DynamicSynthRedeemer', async accounts => {
103
204
104
205
describe ( 'redemption' , ( ) => {
105
206
describe ( 'redeem()' , ( ) => {
207
+ beforeEach ( async ( ) => {
208
+ await instance . resumeRedemption ( { from : owner } ) ;
209
+ } ) ;
210
+
211
+ it ( 'reverts when redemption is suspended' , async ( ) => {
212
+ await instance . suspendRedemption ( { from : owner } ) ;
213
+ await assert . revert (
214
+ instance . redeem ( proxysETH . address , {
215
+ from : account1 ,
216
+ } ) ,
217
+ 'Redemption deactivated'
218
+ ) ;
219
+ } ) ;
220
+
106
221
it ( 'reverts when discount rate is set to zero' , async ( ) => {
107
222
await instance . setDiscountRate ( toUnit ( '0' ) , { from : owner } ) ;
108
223
await assert . revert (
@@ -113,8 +228,7 @@ contract('DynamicSynthRedeemer', async accounts => {
113
228
) ;
114
229
} ) ;
115
230
116
- it ( 'redemption reverts when user has no balance' , async ( ) => {
117
- await instance . setDiscountRate ( toUnit ( '1' ) , { from : owner } ) ;
231
+ it ( 'reverts when user has no balance' , async ( ) => {
118
232
await assert . revert (
119
233
instance . redeem ( proxysETH . address , {
120
234
from : account1 ,
@@ -123,9 +237,29 @@ contract('DynamicSynthRedeemer', async accounts => {
123
237
) ;
124
238
} ) ;
125
239
240
+ it ( 'reverts when user attempts to redeem sUSD' , async ( ) => {
241
+ await assert . revert (
242
+ instance . redeem ( proxysUSD . address , {
243
+ from : account1 ,
244
+ } ) ,
245
+ 'Cannot redeem sUSD'
246
+ ) ;
247
+ } ) ;
248
+
249
+ it ( 'reverts when user attempts to redeem a non-synth token' , async ( ) => {
250
+ await assert . revert (
251
+ instance . redeem ( proxySynthetix . address , {
252
+ from : account1 ,
253
+ } )
254
+ ) ;
255
+ } ) ;
256
+
126
257
describe ( 'when the user has a synth balance' , ( ) => {
127
258
let userBalanceBefore ;
128
259
beforeEach ( async ( ) => {
260
+ // TODO: check owner ETH balance
261
+ // if got ETH, wrap it using ETH wrapper to get sETH and transfer to account1
262
+
129
263
// await proxysETH.transfer(account1, toUnit('5'), { from: owner });
130
264
userBalanceBefore = await proxysETH . balanceOf ( account1 ) ;
131
265
console . log ( userBalanceBefore ) ;
0 commit comments