@@ -41,8 +41,8 @@ func TestBlockHistoryEstimator_InvalidBlockHistorySize(t *testing.T) {
41
41
42
42
func TestBlockHistoryEstimator_LatestBlock (t * testing.T ) {
43
43
// Helper variables for tests
44
- min := uint64 (10 )
45
- max := uint64 (100_000 )
44
+ minPrice := uint64 (10 )
45
+ maxPrice := uint64 (100_000 )
46
46
defaultPrice := uint64 (100 )
47
47
depth := uint64 (1 ) // 1 is LatestBlockEstimator
48
48
pollPeriod := 100 * time .Millisecond
@@ -63,21 +63,21 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
63
63
t .Run ("Successful Estimation" , func (t * testing.T ) {
64
64
// Setup
65
65
cfg := cfgmock .NewConfig (t )
66
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
66
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
67
67
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
68
68
69
69
// Assert the computed price matches the expected price
70
70
require .NoError (t , estimator .calculatePrice (ctx ), "Failed to calculate price" )
71
- cfg .On ("ComputeUnitPriceMin" ).Return (min )
72
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
71
+ cfg .On ("ComputeUnitPriceMin" ).Return (minPrice )
72
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
73
73
assert .Equal (t , uint64 (lastBlockMedianPrice ), estimator .BaseComputeUnitPrice ())
74
74
})
75
75
76
76
t .Run ("Min Gate: Price Should Be Floored at Min" , func (t * testing.T ) {
77
77
// Setup
78
78
cfg := cfgmock .NewConfig (t )
79
79
tmpMin := uint64 (lastBlockMedianPrice ) + 100 // Set min higher than the median price
80
- setupConfigMock (cfg , defaultPrice , tmpMin , max , pollPeriod , depth )
80
+ setupConfigMock (cfg , defaultPrice , tmpMin , pollPeriod , depth )
81
81
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
82
82
83
83
// Call calculatePrice and ensure no error
@@ -91,14 +91,14 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
91
91
// Setup
92
92
cfg := cfgmock .NewConfig (t )
93
93
tmpMax := uint64 (lastBlockMedianPrice ) - 100 // Set max lower than the median price
94
- setupConfigMock (cfg , defaultPrice , min , tmpMax , pollPeriod , depth )
94
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
95
95
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
96
96
97
97
// Call calculatePrice and ensure no error
98
98
// Assert the compute unit price is capped at max
99
99
require .NoError (t , estimator .calculatePrice (ctx ), "Failed to calculate price with price above max" )
100
100
cfg .On ("ComputeUnitPriceMax" ).Return (tmpMax )
101
- cfg .On ("ComputeUnitPriceMin" ).Return (min )
101
+ cfg .On ("ComputeUnitPriceMin" ).Return (minPrice )
102
102
assert .Equal (t , tmpMax , estimator .BaseComputeUnitPrice (), "Price should be capped at max" )
103
103
})
104
104
@@ -109,13 +109,13 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
109
109
return rw , nil
110
110
})
111
111
cfg := cfgmock .NewConfig (t )
112
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
112
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
113
113
rw .On ("GetLatestBlock" , mock .Anything ).Return (nil , fmt .Errorf ("fail rpc call" )) // Mock GetLatestBlock returning error
114
114
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
115
115
116
116
// Ensure the price remains unchanged
117
117
require .Error (t , estimator .calculatePrice (ctx ), "Expected error when GetLatestBlock fails" )
118
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
118
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
119
119
assert .Equal (t , uint64 (100 ), estimator .BaseComputeUnitPrice (), "Price should not change when GetLatestBlock fails" )
120
120
})
121
121
@@ -126,13 +126,13 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
126
126
return rw , nil
127
127
})
128
128
cfg := cfgmock .NewConfig (t )
129
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
129
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
130
130
rw .On ("GetLatestBlock" , mock .Anything ).Return (nil , nil ) // Mock GetLatestBlock returning nil
131
131
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
132
132
133
133
// Ensure the price remains unchanged
134
134
require .Error (t , estimator .calculatePrice (ctx ), "Expected error when parsing fails" )
135
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
135
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
136
136
assert .Equal (t , uint64 (100 ), estimator .BaseComputeUnitPrice (), "Price should not change when parsing fails" )
137
137
})
138
138
@@ -143,13 +143,13 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
143
143
return rw , nil
144
144
})
145
145
cfg := cfgmock .NewConfig (t )
146
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
146
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
147
147
rw .On ("GetLatestBlock" , mock .Anything ).Return (& rpc.GetBlockResult {}, nil ) // Mock GetLatestBlock returning empty block
148
148
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
149
149
150
150
// Ensure the price remains unchanged
151
151
require .EqualError (t , estimator .calculatePrice (ctx ), errNoComputeUnitPriceCollected .Error (), "Expected error when no compute unit prices are collected" )
152
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
152
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
153
153
assert .Equal (t , uint64 (100 ), estimator .BaseComputeUnitPrice (), "Price should not change when median calculation fails" )
154
154
})
155
155
@@ -160,21 +160,21 @@ func TestBlockHistoryEstimator_LatestBlock(t *testing.T) {
160
160
return nil , fmt .Errorf ("fail client load" )
161
161
})
162
162
cfg := cfgmock .NewConfig (t )
163
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
163
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
164
164
estimator := initializeEstimator (ctx , t , rwFailLoader , cfg , logger .Test (t ))
165
165
166
166
// Call calculatePrice and expect an error
167
167
// Ensure the price remains unchanged
168
168
require .Error (t , estimator .calculatePrice (ctx ), "Expected error when getting client fails" )
169
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
169
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
170
170
assert .Equal (t , defaultPrice , estimator .BaseComputeUnitPrice (), "Price should remain at default when client fails" )
171
171
})
172
172
}
173
173
174
174
func TestBlockHistoryEstimator_MultipleBlocks (t * testing.T ) {
175
175
// helpers vars for tests
176
- min := uint64 (100 )
177
- max := uint64 (100_000 )
176
+ minPrice := uint64 (100 )
177
+ maxPrice := uint64 (100_000 )
178
178
depth := uint64 (3 )
179
179
defaultPrice := uint64 (100 )
180
180
pollPeriod := 3 * time .Second
@@ -220,20 +220,20 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
220
220
t .Run ("Successful Estimation" , func (t * testing.T ) {
221
221
// Setup
222
222
cfg := cfgmock .NewConfig (t )
223
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
223
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
224
224
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
225
225
226
226
// Calculated avg price should be equal to the one extracted manually from the blocks.
227
227
require .NoError (t , estimator .calculatePrice (ctx ))
228
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
228
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
229
229
assert .Equal (t , uint64 (multipleBlocksAvg ), estimator .BaseComputeUnitPrice ())
230
230
})
231
231
232
232
t .Run ("Min Gate: Price Should Be Floored at Min" , func (t * testing.T ) {
233
233
// Setup
234
234
cfg := cfgmock .NewConfig (t )
235
235
tmpMin := uint64 (multipleBlocksAvg ) + 100 // Set min higher than the avg price
236
- setupConfigMock (cfg , defaultPrice , tmpMin , max , pollPeriod , depth )
236
+ setupConfigMock (cfg , defaultPrice , tmpMin , pollPeriod , depth )
237
237
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
238
238
239
239
// Compute unit price should be floored at min
@@ -246,13 +246,13 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
246
246
// Setup
247
247
cfg := cfgmock .NewConfig (t )
248
248
tmpMax := uint64 (multipleBlocksAvg ) - 100 // Set tmpMax lower than the avg price
249
- setupConfigMock (cfg , defaultPrice , min , tmpMax , pollPeriod , depth )
249
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
250
250
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
251
251
252
252
// Compute unit price should be capped at max
253
253
require .NoError (t , estimator .calculatePrice (ctx ), "Failed to calculate price with price above max" )
254
254
cfg .On ("ComputeUnitPriceMax" ).Return (tmpMax )
255
- cfg .On ("ComputeUnitPriceMin" ).Return (min )
255
+ cfg .On ("ComputeUnitPriceMin" ).Return (minPrice )
256
256
assert .Equal (t , tmpMax , estimator .BaseComputeUnitPrice (), "Price should be capped at max" )
257
257
})
258
258
@@ -264,12 +264,12 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
264
264
return nil , fmt .Errorf ("fail client load" )
265
265
})
266
266
cfg := cfgmock .NewConfig (t )
267
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
267
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
268
268
estimator := initializeEstimator (ctx , t , rwFailLoader , cfg , logger .Test (t ))
269
269
270
270
// Price should remain unchanged
271
271
require .Error (t , estimator .calculatePrice (ctx ), "Expected error when getting client fails" )
272
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
272
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
273
273
assert .Equal (t , defaultPrice , estimator .BaseComputeUnitPrice ())
274
274
})
275
275
@@ -280,13 +280,13 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
280
280
return rw , nil
281
281
})
282
282
cfg := cfgmock .NewConfig (t )
283
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
283
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
284
284
rw .On ("SlotHeight" , mock .Anything ).Return (uint64 (0 ), fmt .Errorf ("failed to get current slot" )) // Mock SlotHeight returning error
285
285
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
286
286
287
287
// Price should remain unchanged
288
288
require .Error (t , estimator .calculatePrice (ctx ), "Expected error when getting current slot fails" )
289
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
289
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
290
290
assert .Equal (t , defaultPrice , estimator .BaseComputeUnitPrice ())
291
291
})
292
292
@@ -297,13 +297,13 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
297
297
return rw , nil
298
298
})
299
299
cfg := cfgmock .NewConfig (t )
300
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
300
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
301
301
rw .On ("SlotHeight" , mock .Anything ).Return (depth - 1 , nil ) // Mock SlotHeight returning less than desiredBlockCount
302
302
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
303
303
304
304
// Price should remain unchanged
305
305
require .Error (t , estimator .calculatePrice (ctx ), "Expected error when current slot is less than desired block count" )
306
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
306
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
307
307
assert .Equal (t , defaultPrice , estimator .BaseComputeUnitPrice ())
308
308
})
309
309
@@ -314,15 +314,15 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
314
314
return rw , nil
315
315
})
316
316
cfg := cfgmock .NewConfig (t )
317
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
317
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
318
318
rw .On ("SlotHeight" , mock .Anything ).Return (testSlots [len (testSlots )- 1 ], nil )
319
319
rw .On ("GetBlocksWithLimit" , mock .Anything , mock .Anything , mock .Anything ).
320
320
Return (nil , fmt .Errorf ("failed to get blocks with limit" )) // Mock GetBlocksWithLimit returning error
321
321
estimator := initializeEstimator (ctx , t , rwLoader , cfg , logger .Test (t ))
322
322
323
323
// Price should remain unchanged
324
324
require .Error (t , estimator .calculatePrice (ctx ), "Expected error when getting blocks with limit fails" )
325
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
325
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
326
326
assert .Equal (t , defaultPrice , estimator .BaseComputeUnitPrice ())
327
327
})
328
328
@@ -333,7 +333,7 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
333
333
return rw , nil
334
334
})
335
335
cfg := cfgmock .NewConfig (t )
336
- setupConfigMock (cfg , defaultPrice , min , max , pollPeriod , depth )
336
+ setupConfigMock (cfg , defaultPrice , minPrice , pollPeriod , depth )
337
337
rw .On ("SlotHeight" , mock .Anything ).Return (testSlots [len (testSlots )- 1 ], nil )
338
338
emptyBlocks := rpc.BlocksResult {} // No blocks with compute unit prices
339
339
rw .On ("GetBlocksWithLimit" , mock .Anything , mock .Anything , mock .Anything ).
@@ -342,15 +342,15 @@ func TestBlockHistoryEstimator_MultipleBlocks(t *testing.T) {
342
342
343
343
// Price should remain unchanged
344
344
require .EqualError (t , estimator .calculatePrice (ctx ), errNoComputeUnitPriceCollected .Error (), "Expected error when no compute unit prices are collected" )
345
- cfg .On ("ComputeUnitPriceMax" ).Return (max )
345
+ cfg .On ("ComputeUnitPriceMax" ).Return (maxPrice )
346
346
assert .Equal (t , defaultPrice , estimator .BaseComputeUnitPrice ())
347
347
})
348
348
}
349
349
350
350
// setupConfigMock configures the Config mock with necessary return values.
351
- func setupConfigMock (cfg * cfgmock.Config , defaultPrice uint64 , min , max uint64 , pollPeriod time.Duration , depth uint64 ) {
351
+ func setupConfigMock (cfg * cfgmock.Config , defaultPrice uint64 , minPrice uint64 , pollPeriod time.Duration , depth uint64 ) {
352
352
cfg .On ("ComputeUnitPriceDefault" ).Return (defaultPrice ).Once ()
353
- cfg .On ("ComputeUnitPriceMin" ).Return (min ).Once ()
353
+ cfg .On ("ComputeUnitPriceMin" ).Return (minPrice ).Once ()
354
354
cfg .On ("BlockHistoryPollPeriod" ).Return (pollPeriod ).Once ()
355
355
cfg .On ("BlockHistorySize" ).Return (depth )
356
356
}
0 commit comments