@@ -14,19 +14,17 @@ describe('Curation', () => {
14
14
let curation : Curation
15
15
let grt : GraphToken
16
16
17
+ // Test values
18
+ const shareAmountFor1000Tokens = toBN ( '3162277660168379331' )
19
+ const subgraphDeploymentID = randomHexBytes ( )
20
+
17
21
beforeEach ( async function ( ) {
18
22
// Deploy graph token
19
23
grt = await deployment . deployGRT ( governor . address , me )
20
24
21
25
// Deploy curation contract
22
26
curation = await deployment . deployCuration ( governor . address , grt . address , me )
23
27
await curation . connect ( governor ) . setStaking ( staking . address )
24
-
25
- // Randomize a test ID
26
- this . subgraphDeploymentID = randomHexBytes ( )
27
-
28
- // Test values
29
- this . shareAmountFor1000Tokens = toBN ( '3' )
30
28
} )
31
29
32
30
describe ( 'configuration' , function ( ) {
@@ -127,38 +125,35 @@ describe('Curation', () => {
127
125
} )
128
126
129
127
describe ( 'curation' , function ( ) {
128
+ const curatorTokens = toGRT ( '1000' )
129
+ const tokensToCollect = toGRT ( '1000' )
130
+
130
131
beforeEach ( async function ( ) {
131
132
// Give some funds to the curator and approve the curation contract
132
- this . curatorTokens = toGRT ( '1000' )
133
- await grt . connect ( governor ) . mint ( curator . address , this . curatorTokens )
134
- await grt . connect ( curator ) . approve ( curation . address , this . curatorTokens )
133
+ await grt . connect ( governor ) . mint ( curator . address , curatorTokens )
134
+ await grt . connect ( curator ) . approve ( curation . address , curatorTokens )
135
135
136
136
// Give some funds to the staking contract and approve the curation contract
137
- this . tokensToCollect = toGRT ( '1000' )
138
- await grt . connect ( governor ) . mint ( staking . address , this . tokensToCollect )
139
- await grt . connect ( staking ) . approve ( curation . address , this . curatorTokens )
137
+ await grt . connect ( governor ) . mint ( staking . address , tokensToCollect )
138
+ await grt . connect ( staking ) . approve ( curation . address , curatorTokens )
140
139
} )
141
140
142
141
context ( '> bonding curve' , function ( ) {
143
- beforeEach ( function ( ) {
144
- this . subgraphDeploymentID = randomHexBytes ( )
145
- } )
146
-
147
142
it ( 'convert shares to tokens' , async function ( ) {
148
143
// Curate
149
- await curation . connect ( curator ) . stake ( this . subgraphDeploymentID , this . curatorTokens )
144
+ await curation . connect ( curator ) . stake ( subgraphDeploymentID , curatorTokens )
150
145
151
146
// Conversion
152
- const shares = ( await curation . pools ( this . subgraphDeploymentID ) ) . shares
153
- const tokens = await curation . sharesToTokens ( this . subgraphDeploymentID , shares )
154
- expect ( tokens ) . to . eq ( this . curatorTokens )
147
+ const shares = ( await curation . pools ( subgraphDeploymentID ) ) . shares
148
+ const tokens = await curation . sharesToTokens ( subgraphDeploymentID , shares )
149
+ expect ( tokens ) . to . eq ( curatorTokens )
155
150
} )
156
151
157
152
it ( 'convert tokens to shares' , async function ( ) {
158
153
// Conversion
159
154
const tokens = toGRT ( '1000' )
160
- const shares = await curation . tokensToShares ( this . subgraphDeploymentID , tokens )
161
- expect ( shares ) . to . eq ( this . shareAmountFor1000Tokens )
155
+ const shares = await curation . tokensToShares ( subgraphDeploymentID , tokens )
156
+ expect ( shares ) . to . eq ( shareAmountFor1000Tokens )
162
157
} )
163
158
} )
164
159
@@ -168,27 +163,27 @@ describe('Curation', () => {
168
163
const curatorTokensBefore = await grt . balanceOf ( curator . address )
169
164
const curatorSharesBefore = await curation . getCuratorShares (
170
165
curator . address ,
171
- this . subgraphDeploymentID ,
166
+ subgraphDeploymentID ,
172
167
)
173
- const poolBefore = await curation . pools ( this . subgraphDeploymentID )
168
+ const poolBefore = await curation . pools ( subgraphDeploymentID )
174
169
const totalBalanceBefore = await grt . balanceOf ( curation . address )
175
170
176
171
// Curate
177
172
// Staking the minimum required = 1 share
178
173
const tokensToStake = defaults . curation . minimumCurationStake
179
- const sharesToReceive = toBN ( 1 )
180
- const tx = curation . connect ( curator ) . stake ( this . subgraphDeploymentID , tokensToStake )
174
+ const sharesToReceive = toGRT ( '1' )
175
+ const tx = curation . connect ( curator ) . stake ( subgraphDeploymentID , tokensToStake )
181
176
await expect ( tx )
182
177
. to . emit ( curation , 'Staked' )
183
- . withArgs ( curator . address , this . subgraphDeploymentID , tokensToStake , sharesToReceive )
178
+ . withArgs ( curator . address , subgraphDeploymentID , tokensToStake , sharesToReceive )
184
179
185
180
// After balances
186
181
const curatorTokensAfter = await grt . balanceOf ( curator . address )
187
182
const curatorSharesAfter = await curation . getCuratorShares (
188
183
curator . address ,
189
- this . subgraphDeploymentID ,
184
+ subgraphDeploymentID ,
190
185
)
191
- const poolAfter = await curation . pools ( this . subgraphDeploymentID )
186
+ const poolAfter = await curation . pools ( subgraphDeploymentID )
192
187
const totalBalanceAfter = await grt . balanceOf ( curation . address )
193
188
194
189
// Tokens transferred properly
@@ -207,44 +202,41 @@ describe('Curation', () => {
207
202
208
203
it ( 'reject stake below minimum tokens required' , async function ( ) {
209
204
const tokensToStake = defaults . curation . minimumCurationStake . sub ( toBN ( 1 ) )
210
- const tx = curation . connect ( curator ) . stake ( this . subgraphDeploymentID , tokensToStake )
205
+ const tx = curation . connect ( curator ) . stake ( subgraphDeploymentID , tokensToStake )
211
206
await expect ( tx ) . to . revertedWith ( 'Curation stake is below minimum required' )
212
207
} )
213
208
214
209
it ( 'reject redeem more than a curator owns' , async function ( ) {
215
- const tx = curation . connect ( me ) . redeem ( this . subgraphDeploymentID , 1 )
210
+ const tx = curation . connect ( me ) . redeem ( subgraphDeploymentID , 1 )
216
211
await expect ( tx ) . to . revertedWith ( 'Cannot redeem more shares than you own' )
217
212
} )
218
213
219
214
it ( 'reject collect tokens distributed as fees to the reserves' , async function ( ) {
220
215
// Source of tokens must be the staking for this to work
221
- const tx = curation . connect ( staking ) . collect ( this . subgraphDeploymentID , this . tokensToCollect )
216
+ const tx = curation . connect ( staking ) . collect ( subgraphDeploymentID , tokensToCollect )
222
217
await expect ( tx ) . to . revertedWith ( 'SubgraphDeployment must be curated to collect fees' )
223
218
} )
224
219
225
220
context ( '> when is curated' , function ( ) {
226
221
beforeEach ( async function ( ) {
227
- await curation . connect ( curator ) . stake ( this . subgraphDeploymentID , this . curatorTokens )
222
+ await curation . connect ( curator ) . stake ( subgraphDeploymentID , curatorTokens )
228
223
} )
229
224
230
225
it ( 'should create curation with default reserve ratio' , async function ( ) {
231
226
const defaultReserveRatio = await curation . defaultReserveRatio ( )
232
- const pool = await curation . pools ( this . subgraphDeploymentID )
227
+ const pool = await curation . pools ( subgraphDeploymentID )
233
228
expect ( pool . reserveRatio ) . to . eq ( defaultReserveRatio )
234
229
} )
235
230
236
231
it ( 'reject redeem zero shares' , async function ( ) {
237
- const tx = curation . redeem ( this . subgraphDeploymentID , 0 )
232
+ const tx = curation . redeem ( subgraphDeploymentID , 0 )
238
233
await expect ( tx ) . to . revertedWith ( 'Cannot redeem zero shares' )
239
234
} )
240
235
241
236
it ( 'should assign the right amount of shares according to bonding curve' , async function ( ) {
242
237
// Shares should be the ones bought with minimum stake (1) + more shares
243
- const curatorShares = await curation . getCuratorShares (
244
- curator . address ,
245
- this . subgraphDeploymentID ,
246
- )
247
- expect ( curatorShares ) . to . eq ( this . shareAmountFor1000Tokens )
238
+ const curatorShares = await curation . getCuratorShares ( curator . address , subgraphDeploymentID )
239
+ expect ( curatorShares ) . to . eq ( shareAmountFor1000Tokens )
248
240
} )
249
241
250
242
it ( 'should allow to redeem *partially*' , async function ( ) {
@@ -253,26 +245,23 @@ describe('Curation', () => {
253
245
const curatorTokensBefore = await grt . balanceOf ( curator . address )
254
246
const curatorSharesBefore = await curation . getCuratorShares (
255
247
curator . address ,
256
- this . subgraphDeploymentID ,
248
+ subgraphDeploymentID ,
257
249
)
258
- const poolBefore = await curation . pools ( this . subgraphDeploymentID )
250
+ const poolBefore = await curation . pools ( subgraphDeploymentID )
259
251
const totalTokensBefore = await grt . balanceOf ( curation . address )
260
252
261
253
// Redeem
262
254
const sharesToRedeem = toBN ( 1 ) // Curator want to sell 1 share
263
- const tokensToRedeem = await curation . sharesToTokens (
264
- this . subgraphDeploymentID ,
265
- sharesToRedeem ,
266
- )
255
+ const tokensToRedeem = await curation . sharesToTokens ( subgraphDeploymentID , sharesToRedeem )
267
256
const withdrawalFeePercentage = await curation . withdrawalFeePercentage ( )
268
257
const withdrawalFees = withdrawalFeePercentage . mul ( tokensToRedeem ) . div ( toBN ( MAX_PPM ) )
269
258
270
- const tx = curation . connect ( curator ) . redeem ( this . subgraphDeploymentID , sharesToRedeem )
259
+ const tx = curation . connect ( curator ) . redeem ( subgraphDeploymentID , sharesToRedeem )
271
260
await expect ( tx )
272
261
. to . emit ( curation , 'Redeemed' )
273
262
. withArgs (
274
263
curator . address ,
275
- this . subgraphDeploymentID ,
264
+ subgraphDeploymentID ,
276
265
tokensToRedeem ,
277
266
sharesToRedeem ,
278
267
withdrawalFees ,
@@ -283,9 +272,9 @@ describe('Curation', () => {
283
272
const curatorTokensAfter = await grt . balanceOf ( curator . address )
284
273
const curatorSharesAfter = await curation . getCuratorShares (
285
274
curator . address ,
286
- this . subgraphDeploymentID ,
275
+ subgraphDeploymentID ,
287
276
)
288
- const poolAfter = await curation . pools ( this . subgraphDeploymentID )
277
+ const poolAfter = await curation . pools ( subgraphDeploymentID )
289
278
const totalTokensAfter = await grt . balanceOf ( curation . address )
290
279
291
280
// Curator balance updated
@@ -306,20 +295,20 @@ describe('Curation', () => {
306
295
it ( 'should allow to redeem *fully*' , async function ( ) {
307
296
// Before balances
308
297
const tokenTotalSupplyBefore = await grt . totalSupply ( )
309
- const poolBefore = await curation . pools ( this . subgraphDeploymentID )
298
+ const poolBefore = await curation . pools ( subgraphDeploymentID )
310
299
311
300
// Redeem all shares
312
301
const sharesToRedeem = poolBefore . shares // we are selling all shares in the subgraph
313
302
const tokensToRedeem = poolBefore . tokens // we are withdrawing all funds
314
303
const withdrawalFeePercentage = await curation . withdrawalFeePercentage ( )
315
304
const withdrawalFees = withdrawalFeePercentage . mul ( tokensToRedeem ) . div ( toBN ( MAX_PPM ) )
316
305
317
- const tx = curation . connect ( curator ) . redeem ( this . subgraphDeploymentID , sharesToRedeem )
306
+ const tx = curation . connect ( curator ) . redeem ( subgraphDeploymentID , sharesToRedeem )
318
307
await expect ( tx )
319
308
. to . emit ( curation , 'Redeemed' )
320
309
. withArgs (
321
310
curator . address ,
322
- this . subgraphDeploymentID ,
311
+ subgraphDeploymentID ,
323
312
tokensToRedeem ,
324
313
sharesToRedeem ,
325
314
withdrawalFees ,
@@ -330,9 +319,9 @@ describe('Curation', () => {
330
319
const curatorTokensAfter = await grt . balanceOf ( curator . address )
331
320
const curatorSharesAfter = await curation . getCuratorShares (
332
321
curator . address ,
333
- this . subgraphDeploymentID ,
322
+ subgraphDeploymentID ,
334
323
)
335
- const poolAfter = await curation . pools ( this . subgraphDeploymentID )
324
+ const poolAfter = await curation . pools ( subgraphDeploymentID )
336
325
const totalTokensAfter = await grt . balanceOf ( curation . address )
337
326
338
327
// Curator balance updated
@@ -354,25 +343,23 @@ describe('Curation', () => {
354
343
it ( 'should collect tokens distributed as reserves for' , async function ( ) {
355
344
// Before balances
356
345
const totalBalanceBefore = await grt . balanceOf ( curation . address )
357
- const poolBefore = await curation . pools ( this . subgraphDeploymentID )
346
+ const poolBefore = await curation . pools ( subgraphDeploymentID )
358
347
359
348
// Source of tokens must be the staking for this to work
360
- const tx = curation
361
- . connect ( staking )
362
- . collect ( this . subgraphDeploymentID , this . tokensToCollect )
349
+ const tx = curation . connect ( staking ) . collect ( subgraphDeploymentID , tokensToCollect )
363
350
await expect ( tx )
364
351
. to . emit ( curation , 'Collected' )
365
- . withArgs ( this . subgraphDeploymentID , this . tokensToCollect )
352
+ . withArgs ( subgraphDeploymentID , tokensToCollect )
366
353
367
354
// After balances
368
355
const totalBalanceAfter = await grt . balanceOf ( curation . address )
369
- const poolAfter = await curation . pools ( this . subgraphDeploymentID )
356
+ const poolAfter = await curation . pools ( subgraphDeploymentID )
370
357
371
358
// Curation balance updated
372
- expect ( poolAfter . tokens ) . to . eq ( poolBefore . tokens . add ( this . tokensToCollect ) )
359
+ expect ( poolAfter . tokens ) . to . eq ( poolBefore . tokens . add ( tokensToCollect ) )
373
360
374
361
// Contract balance updated
375
- expect ( totalBalanceAfter ) . to . eq ( totalBalanceBefore . add ( this . tokensToCollect ) )
362
+ expect ( totalBalanceAfter ) . to . eq ( totalBalanceBefore . add ( tokensToCollect ) )
376
363
} )
377
364
} )
378
365
} )
0 commit comments