@@ -37,6 +37,14 @@ describe('Staking:Rebate', () => {
37
37
{ totalRewards : 1400 , fees : 0 , totalFees : 1400 , stake : 1200 , totalStake : 7300 } ,
38
38
]
39
39
40
+ // Edge case #1 - No closed allocations any query fees
41
+ const edgeCases1 : RebateTestCase [ ] = [
42
+ { totalRewards : 0 , fees : 0 , totalFees : 0 , stake : 5000 , totalStake : 7300 } ,
43
+ { totalRewards : 0 , fees : 0 , totalFees : 0 , stake : 600 , totalStake : 7300 } ,
44
+ { totalRewards : 0 , fees : 0 , totalFees : 0 , stake : 500 , totalStake : 7300 } ,
45
+ { totalRewards : 0 , fees : 0 , totalFees : 0 , stake : 1200 , totalStake : 7300 } ,
46
+ ]
47
+
40
48
// This function calculates the Cobb-Douglas formula in Typescript so we can compare against
41
49
// the Solidity implementation
42
50
// TODO: consider using bignumber.js to get extra precision
@@ -49,6 +57,9 @@ describe('Staking:Rebate', () => {
49
57
alphaNumerator : number ,
50
58
alphaDenominator : number ,
51
59
) {
60
+ if ( totalFees === 0 ) {
61
+ return 0
62
+ }
52
63
const feeRatio = fees / totalFees
53
64
const stakeRatio = stake / totalStake
54
65
const alpha = alphaNumerator / alphaDenominator
@@ -143,107 +154,73 @@ describe('Staking:Rebate', () => {
143
154
return rx . events [ 0 ] . args [ 0 ]
144
155
}
145
156
146
- beforeEach ( async function ( ) {
147
- ; [ deployer , other ] = await getAccounts ( )
148
- rebatePoolMock = ( ( await deployContract (
149
- 'RebatePoolMock' ,
150
- deployer . signer ,
151
- ) ) as unknown ) as RebatePoolMock
152
- } )
153
-
154
- describe ( 'should match cobb-douglas Solidity implementation' , function ( ) {
157
+ async function testAlphas ( fn , testCases ) {
155
158
// Typical alpha
156
159
it ( 'alpha 0.90' , async function ( ) {
157
160
const alpha : RebateRatio = [ 90 , 100 ]
158
- await shouldMatchFormulas ( testCases , alpha )
161
+ await fn ( testCases , alpha )
159
162
} )
160
163
161
164
// Typical alpha
162
165
it ( 'alpha 0.25' , async function ( ) {
163
166
const alpha : RebateRatio = [ 1 , 4 ]
164
- await shouldMatchFormulas ( testCases , alpha )
167
+ await fn ( testCases , alpha )
165
168
} )
166
169
167
170
// Periodic alpha
168
171
it ( 'alpha 0.33~' , async function ( ) {
169
172
const alpha : RebateRatio = [ 1 , 3 ]
170
- await shouldMatchFormulas ( testCases , alpha )
173
+ await fn ( testCases , alpha )
171
174
} )
172
175
173
176
// Small alpha
174
177
it ( 'alpha 0.005' , async function ( ) {
175
178
const alpha : RebateRatio = [ 1 , 200 ]
176
- await shouldMatchFormulas ( testCases , alpha )
179
+ await fn ( testCases , alpha )
177
180
} )
178
181
179
182
// Edge alpha
180
183
it ( 'alpha 1' , async function ( ) {
181
184
const alpha : RebateRatio = [ 1 , 1 ]
182
- await shouldMatchFormulas ( testCases , alpha )
185
+ await fn ( testCases , alpha )
183
186
} )
184
- } )
187
+ }
185
188
186
- describe ( 'should match rewards out from rebates' , function ( ) {
187
- // Typical alpha
188
- it ( 'alpha 0.90' , async function ( ) {
189
- const alpha : RebateRatio = [ 90 , 100 ]
190
- await shouldMatchOut ( testCases , alpha )
191
- } )
189
+ beforeEach ( async function ( ) {
190
+ ; [ deployer , other ] = await getAccounts ( )
191
+ rebatePoolMock = ( ( await deployContract (
192
+ 'RebatePoolMock' ,
193
+ deployer . signer ,
194
+ ) ) as unknown ) as RebatePoolMock
195
+ } )
192
196
193
- // Typical alpha
194
- it ( 'alpha 0.25' , async function ( ) {
195
- const alpha : RebateRatio = [ 1 , 4 ]
196
- await shouldMatchOut ( testCases , alpha )
197
+ describe ( 'should match cobb-douglas Solidity implementation' , function ( ) {
198
+ describe ( 'normal test case' , function ( ) {
199
+ testAlphas ( shouldMatchFormulas , testCases )
197
200
} )
198
201
199
- // Periodic alpha
200
- it ( 'alpha 0.33~' , async function ( ) {
201
- const alpha : RebateRatio = [ 1 , 3 ]
202
- await shouldMatchOut ( testCases , alpha )
202
+ describe ( 'edge #1 test case' , function ( ) {
203
+ testAlphas ( shouldMatchFormulas , edgeCases1 )
203
204
} )
205
+ } )
204
206
205
- // Small alpha
206
- it ( 'alpha 0.005' , async function ( ) {
207
- const alpha : RebateRatio = [ 1 , 200 ]
208
- await shouldMatchOut ( testCases , alpha )
207
+ describe ( 'should match rewards out from rebates' , function ( ) {
208
+ describe ( 'normal test case' , function ( ) {
209
+ testAlphas ( shouldMatchOut , testCases )
209
210
} )
210
211
211
- // Edge alpha
212
- it ( 'alpha 1' , async function ( ) {
213
- const alpha : RebateRatio = [ 1 , 1 ]
214
- await shouldMatchOut ( testCases , alpha )
212
+ describe ( 'edge #1 test case' , function ( ) {
213
+ testAlphas ( shouldMatchOut , edgeCases1 )
215
214
} )
216
215
} )
217
216
218
217
describe ( 'should always be that sum of rebate rewards obtained <= to total rewards' , function ( ) {
219
- // Typical alpha
220
- it ( 'alpha 0.90' , async function ( ) {
221
- const alpha : RebateRatio = [ 90 , 100 ]
222
- await shouldConserveBalances ( testCases , alpha )
218
+ describe ( 'normal test case' , function ( ) {
219
+ testAlphas ( shouldConserveBalances , testCases )
223
220
} )
224
221
225
- // Typical alpha
226
- it ( 'alpha 0.25' , async function ( ) {
227
- const alpha : RebateRatio = [ 1 , 4 ]
228
- await shouldConserveBalances ( testCases , alpha )
229
- } )
230
-
231
- // Periodic alpha
232
- it ( 'alpha 0.33~' , async function ( ) {
233
- const alpha : RebateRatio = [ 1 , 3 ]
234
- await shouldConserveBalances ( testCases , alpha )
235
- } )
236
-
237
- // Small alpha
238
- it ( 'alpha 0.005' , async function ( ) {
239
- const alpha : RebateRatio = [ 1 , 200 ]
240
- await shouldConserveBalances ( testCases , alpha )
241
- } )
242
-
243
- // Edge alpha
244
- it ( 'alpha 1' , async function ( ) {
245
- const alpha : RebateRatio = [ 1 , 1 ]
246
- await shouldConserveBalances ( testCases , alpha )
222
+ describe ( 'edge #1 test case' , function ( ) {
223
+ testAlphas ( shouldConserveBalances , edgeCases1 )
247
224
} )
248
225
} )
249
226
} )
0 commit comments