@@ -22,13 +22,20 @@ BigNumberSetup.configure();
22
22
ChaiSetup . configure ( ) ;
23
23
const { expect, assert } = chai ;
24
24
25
+ import {
26
+ assertTokenBalance ,
27
+ expectInvalidOpcodeError ,
28
+ expectRevertError ,
29
+ } from "./utils/tokenAssertions" ;
25
30
import { INVALID_OPCODE , REVERT_ERROR } from "./constants/txn_error" ;
26
31
27
32
contract ( "{Set}" , ( accounts ) => {
28
33
let componentA : any ;
29
34
const unitsA : BigNumber = gWei ( 1 ) ;
30
35
let componentB : any ;
31
36
const unitsB : BigNumber = gWei ( 2 ) ;
37
+ let componentC : any ;
38
+ const unitsC : BigNumber = gWei ( 2 ) ;
32
39
33
40
const [ testAccount ] = accounts ;
34
41
let setToken : any ;
@@ -80,37 +87,25 @@ contract("{Set}", (accounts) => {
80
87
} ) ;
81
88
82
89
it ( "should not allow creation of a {Set} with mismatched quantity of units and tokens" , async ( ) => {
83
- await expect (
84
- SetToken . new (
85
- [ componentA . address , componentB . address ] ,
86
- [ unitsA ] ,
87
- TX_DEFAULTS ,
88
- ) ,
89
- ) . to . eventually . be . rejectedWith ( REVERT_ERROR ) ;
90
+ expectRevertError ( SetToken . new ( [ componentA . address , componentB . address ] , [ unitsA ] , TX_DEFAULTS ) ) ;
90
91
} ) ;
91
92
92
93
it ( "should not allow creation of a {Set} with no inputs" , async ( ) => {
93
- await expect (
94
- SetToken . new ( [ ] , [ ] , TX_DEFAULTS ) ,
95
- ) . to . eventually . be . rejectedWith ( REVERT_ERROR ) ;
94
+ expectRevertError ( SetToken . new ( [ ] , [ ] , TX_DEFAULTS ) ) ;
96
95
} ) ;
97
96
98
97
it ( "should not allow creation of a {Set} with units of 0 value" , async ( ) => {
99
98
const badUnit = 0 ;
100
99
101
- await expect (
102
- SetToken . new (
103
- [ componentA . address , componentB . address ] ,
104
- [ unitsA , badUnit ] ,
105
- TX_DEFAULTS ,
106
- ) ,
107
- ) . to . eventually . be . rejectedWith ( REVERT_ERROR ) ;
100
+ expectRevertError ( SetToken . new (
101
+ [ componentA . address , componentB . address ] ,
102
+ [ unitsA , badUnit ] ,
103
+ TX_DEFAULTS ,
104
+ ) ) ;
108
105
} ) ;
109
106
110
107
it ( "should not allow creation of a {Set} with address of 0" , async ( ) => {
111
- await expect (
112
- SetToken . new ( [ componentA . address , null ] , [ unitsA , unitsB ] , TX_DEFAULTS ) ,
113
- ) . to . eventually . be . rejectedWith ( REVERT_ERROR ) ;
108
+ expectRevertError ( SetToken . new ( [ componentA . address , null ] , [ unitsA , unitsB ] , TX_DEFAULTS ) ) ;
114
109
} ) ;
115
110
} ) ;
116
111
@@ -150,26 +145,9 @@ contract("{Set}", (accounts) => {
150
145
// The logs should have the right quantity
151
146
expect ( issuanceLog . _quantity ) . to . be . bignumber . equal ( quantity ) ;
152
147
153
- // User should have less A token
154
- const postIssueBalanceAofOwner = await componentA . balanceOf ( testAccount ) ;
155
- expect ( postIssueBalanceAofOwner ) . to . be . bignumber . equal (
156
- initialTokens . sub ( quantityA ) ,
157
- "Component A Balance" ,
158
- ) ;
159
-
160
- // User should have less B token
161
- const postIssueBalanceBofOwner = await componentB . balanceOf ( testAccount ) ;
162
- expect ( postIssueBalanceBofOwner ) . to . be . bignumber . equal (
163
- initialTokens . sub ( quantityB ) ,
164
- "Component B Balance" ,
165
- ) ;
166
-
167
- // User should have an/multiple Set tokens
168
- const postIssueBalanceIndexofOwner = await setToken . balanceOf ( testAccount ) ;
169
- expect ( postIssueBalanceIndexofOwner ) . to . be . bignumber . equal (
170
- quantity ,
171
- "Set Component Balance" ,
172
- ) ;
148
+ assertTokenBalance ( componentA , initialTokens . sub ( quantityA ) , testAccount ) ;
149
+ assertTokenBalance ( componentB , initialTokens . sub ( quantityB ) , testAccount ) ;
150
+ assertTokenBalance ( setToken , quantity , testAccount ) ;
173
151
} ) ;
174
152
175
153
it ( `should allow a user to redeem ${ quantity } token from the index fund` , async ( ) => {
@@ -187,17 +165,9 @@ contract("{Set}", (accounts) => {
187
165
// The logs should have the right quantity
188
166
expect ( redeemLog . _quantity ) . to . be . bignumber . equal ( quantity ) ;
189
167
190
- // User should have more A token
191
- const postRedeemBalanceAofOwner = await componentA . balanceOf ( testAccount ) ;
192
- expect ( postRedeemBalanceAofOwner ) . to . be . bignumber . equal ( initialTokens ) ;
193
-
194
- // User should have more B token
195
- const postRedeemBalanceBofOwner = await componentB . balanceOf ( testAccount ) ;
196
- expect ( postRedeemBalanceBofOwner ) . to . be . bignumber . equal ( initialTokens ) ;
197
-
198
- // User should have 0 Set token
199
- const postRedeemBalanceIndexofOwner = await setToken . balanceOf ( testAccount ) ;
200
- expect ( postRedeemBalanceIndexofOwner ) . to . be . bignumber . equal ( 0 ) ;
168
+ assertTokenBalance ( componentA , initialTokens , testAccount ) ;
169
+ assertTokenBalance ( componentB , initialTokens , testAccount ) ;
170
+ assertTokenBalance ( setToken , new BigNumber ( 0 ) , testAccount ) ;
201
171
} ) ;
202
172
}
203
173
} ) ;
@@ -222,23 +192,13 @@ contract("{Set}", (accounts) => {
222
192
223
193
await setToken . issue ( quantityInWei , TX_DEFAULTS ) ;
224
194
225
- // User should have less A token
226
- const postIssueBalanceAofOwner = await componentA . balanceOf ( testAccount ) ;
227
- expect ( postIssueBalanceAofOwner ) . to . be . bignumber . equal ( initialTokens . sub ( quantityA ) ) ;
228
-
229
- // User should have an/multiple Set tokens
230
- const postIssueBalanceIndexofOwner = await setToken . balanceOf ( testAccount ) ;
231
- expect ( postIssueBalanceIndexofOwner ) . to . be . bignumber . equal ( quantityInWei ) ;
195
+ assertTokenBalance ( componentA , initialTokens . sub ( quantityA ) , testAccount ) ;
196
+ assertTokenBalance ( setToken , quantityInWei , testAccount ) ;
232
197
233
198
await setToken . redeem ( quantityInWei , TX_DEFAULTS ) ;
234
199
235
- // User should have more A token
236
- const postRedeemBalanceAofOwner = await componentA . balanceOf ( testAccount ) ;
237
- expect ( postRedeemBalanceAofOwner ) . to . be . bignumber . equal ( initialTokens ) ;
238
-
239
- // User should have 0 Set token
240
- const postRedeemBalanceIndexofOwner = await setToken . balanceOf ( testAccount ) ;
241
- expect ( postRedeemBalanceIndexofOwner ) . to . be . bignumber . equal ( 0 ) ;
200
+ assertTokenBalance ( componentA , initialTokens , testAccount ) ;
201
+ assertTokenBalance ( setToken , new BigNumber ( 0 ) , testAccount ) ;
242
202
} ) ;
243
203
244
204
it ( "should disallow issuing a Set when the amount is too low" , async ( ) => {
@@ -258,9 +218,7 @@ contract("{Set}", (accounts) => {
258
218
259
219
await componentA . approve ( setToken . address , quantityA , TX_DEFAULTS ) ;
260
220
261
- await expect ( setToken . issue ( quantityInWei , TX_DEFAULTS ) ) . to . eventually . be . rejectedWith (
262
- INVALID_OPCODE ,
263
- ) ;
221
+ expectInvalidOpcodeError ( setToken . issue ( quantityInWei , TX_DEFAULTS ) ) ;
264
222
} ) ;
265
223
} ) ;
266
224
@@ -287,9 +245,7 @@ contract("{Set}", (accounts) => {
287
245
) ;
288
246
const quantityOverflow = overflow . plus ( quantity ) ;
289
247
290
- await expect ( setToken . issue ( quantityOverflow , TX_DEFAULTS ) ) . to . eventually . be . rejectedWith (
291
- INVALID_OPCODE ,
292
- ) ;
248
+ expectInvalidOpcodeError ( setToken . issue ( quantityOverflow , TX_DEFAULTS ) ) ;
293
249
} ) ;
294
250
} ) ;
295
251
} ) ;
@@ -298,25 +254,29 @@ contract("{Set}", (accounts) => {
298
254
const quantityIssued = ether ( 10 ) ;
299
255
let quantityA : BigNumber ;
300
256
let quantityB : BigNumber ;
257
+ let quantityC : BigNumber ;
301
258
302
259
// Create a Set two components with set tokens issued
303
260
beforeEach ( async ( ) => {
304
261
componentA = await StandardTokenMock . new ( testAccount , initialTokens , "Component A" , "A" ) ;
305
262
componentB = await StandardTokenMock . new ( testAccount , initialTokens , "Component B" , "B" ) ;
263
+ componentC = await StandardTokenMock . new ( testAccount , initialTokens , "Component C" , "C" ) ;
306
264
307
265
setToken = await SetToken . new (
308
- [ componentA . address , componentB . address ] ,
309
- [ unitsA , unitsB ] ,
266
+ [ componentA . address , componentB . address , componentC . address ] ,
267
+ [ unitsA , unitsB , unitsC ] ,
310
268
TX_DEFAULTS ,
311
269
) ;
312
270
313
271
// Expected Quantities of tokens moved are divided by a gWei
314
272
// to reflect the new units in set instantiation
315
273
quantityA = unitsA . mul ( quantityIssued ) . div ( gWei ( 1 ) ) ;
316
274
quantityB = unitsB . mul ( quantityIssued ) . div ( gWei ( 1 ) ) ;
275
+ quantityC = unitsC . mul ( quantityIssued ) . div ( gWei ( 1 ) ) ;
317
276
318
277
await componentA . approve ( setToken . address , quantityA , TX_DEFAULTS ) ;
319
278
await componentB . approve ( setToken . address , quantityB , TX_DEFAULTS ) ;
279
+ await componentC . approve ( setToken . address , quantityC , TX_DEFAULTS ) ;
320
280
321
281
await setToken . issue ( quantityIssued , TX_DEFAULTS ) ;
322
282
} ) ;
@@ -328,19 +288,22 @@ contract("{Set}", (accounts) => {
328
288
const postRedeemBalanceIndexofOwner = await setToken . balanceOf ( testAccount ) ;
329
289
expect ( postRedeemBalanceIndexofOwner ) . to . be . bignumber . equal ( 0 , "Post Balance Set" ) ;
330
290
331
- // The user should have 0 of TokenA
332
- const postRedeemBalanceAofOwner = await componentA . balanceOf ( testAccount ) ;
333
- expect ( postRedeemBalanceAofOwner ) . to . be . bignumber . equal (
334
- initialTokens . sub ( quantityA ) ) ;
291
+ assertTokenBalance ( componentA , initialTokens . sub ( quantityA ) , testAccount ) ;
335
292
336
293
// The user should have balance of Token A in excluded Tokens
337
294
const [ excludedBalanceAofOwner ] = await setToken . unredeemedComponents ( componentA . address , testAccount ) ;
338
295
expect ( excludedBalanceAofOwner ) . to . be . bignumber . equal (
339
296
quantityA ) ;
340
297
341
- // The user should have 10 token B
342
- const postRedeemBalanceBofOwner = await componentB . balanceOf ( testAccount ) ;
343
- expect ( postRedeemBalanceBofOwner ) . to . be . bignumber . equal ( initialTokens , "Post Balance B" ) ;
298
+ assertTokenBalance ( componentB , initialTokens , testAccount ) ;
299
+ } ) ;
300
+
301
+ it ( "should fail partial redeem with duplicate entries" , async ( ) => {
302
+ expectInvalidOpcodeError ( setToken . partialRedeem (
303
+ quantityIssued ,
304
+ [ componentA . address , componentA . address ] ,
305
+ TX_DEFAULTS ,
306
+ ) ) ;
344
307
} ) ;
345
308
} ) ;
346
309
@@ -377,9 +340,7 @@ contract("{Set}", (accounts) => {
377
340
it ( "should successfully redeem excluded a standard Set" , async ( ) => {
378
341
await setToken . redeemExcluded ( quantityA , componentA . address , TX_DEFAULTS ) ;
379
342
380
- // The user should have a balance of TokenA
381
- const postRedeemBalanceAofOwner = await componentA . balanceOf ( testAccount ) ;
382
- expect ( postRedeemBalanceAofOwner ) . to . be . bignumber . equal ( initialTokens ) ;
343
+ assertTokenBalance ( componentA , initialTokens , testAccount ) ;
383
344
384
345
// The user should have no balance of Token A in excluded Tokens
385
346
const [ excludedBalanceAofOwner ] = await setToken . unredeemedComponents ( componentA . address , testAccount ) ;
0 commit comments