@@ -297,6 +297,12 @@ func TestCalcBaseFee(t *testing.T) {
297297 12000000 ,
298298 big .NewInt (1025000000 ),
299299 },
300+
301+ // Low parent baseFee tests
302+
303+ // parent gas usage >>>> parent gas limit
304+ // parent baseFee == 0
305+ // as expected, increment baseFee by 1
300306 {
301307 params .EIP1559ChainConfig ,
302308 big .NewInt (1000 ),
@@ -307,87 +313,75 @@ func TestCalcBaseFee(t *testing.T) {
307313 1000000000000000 ,
308314 big .NewInt (1 ),
309315 },
310-
311- // Low parent baseFee tests
316+ // parent gas usage <<<< parent gas limit
317+ // parent baseFee == 0
318+ // would normally expect decrement
319+ // but with parent baseFee == 0 the base fee calculation
320+ // reduces down to parent basefee + 0 = 0
321+ // this means the diff between parent and new basefee == 0 which is less than the minimum of |1|
322+ // so we default to incrementing by 1, it is a positive increment since the diff == 0 is non-negative
312323 {
313324 params .EIP1559ChainConfig ,
314325 big .NewInt (1000 ),
315326 1000 ,
316327 big .NewInt (2000 ),
317- big .NewInt (1 ),
328+ big .NewInt (0 ),
329+ 1000000000000000 ,
318330 1 ,
319- 8 ,
320- big .NewInt (2 ),
331+ big .NewInt (1 ),
321332 },
333+ // parent gas usage == parent gas limit
334+ // parent baseFee == 0
335+ // would normally expect decrement of 1
336+ // but that would go to negative numbers so it remains at 0
322337 {
323338 params .EIP1559ChainConfig ,
324339 big .NewInt (1000 ),
325340 1000 ,
326341 big .NewInt (2000 ),
327- big .NewInt (1 ),
342+ big .NewInt (0 ),
328343 1 ,
329- 9 ,
330- big .NewInt (2 ),
344+ 1 ,
345+ big .NewInt (0 ),
331346 },
347+ // parent gas usage >>>> parent gas limit
348+ // parent baseFee == 1
349+ // as expected, increment baseFee by 1
332350 {
333351 params .EIP1559ChainConfig ,
334352 big .NewInt (1000 ),
335353 1000 ,
336354 big .NewInt (2000 ),
337355 big .NewInt (1 ),
338- 100000000 ,
339- 899999999 ,
356+ 1 ,
357+ 1000000000000000 ,
340358 big .NewInt (2 ),
341359 },
360+ // parent gas usage <<<< parent gas limit
361+ // parent baseFee == 1
362+ // as expected, decrement by 1
342363 {
343364 params .EIP1559ChainConfig ,
344365 big .NewInt (1000 ),
345366 1000 ,
346367 big .NewInt (2000 ),
347368 big .NewInt (1 ),
348- 100000000 ,
349- 900000000 ,
350- big .NewInt (2 ),
351- },
352- {
353- params .EIP1559ChainConfig ,
354- big .NewInt (1000 ),
355- 1000 ,
356- big .NewInt (2000 ),
357- big .NewInt (2 ),
369+ 1000000000000000 ,
358370 1 ,
359- 4 ,
360- big .NewInt (3 ),
371+ big .NewInt (0 ),
361372 },
373+ // parent gas usage == parent gas limit
374+ // parent baseFee == 1
375+ // as expected, decrement by 1 when gas usage equals the gas target
362376 {
363377 params .EIP1559ChainConfig ,
364378 big .NewInt (1000 ),
365379 1000 ,
366380 big .NewInt (2000 ),
367- big .NewInt (2 ),
381+ big .NewInt (1 ),
368382 1 ,
369- 5 ,
370- big .NewInt (3 ),
371- },
372- {
373- params .EIP1559ChainConfig ,
374- big .NewInt (1000 ),
375- 1000 ,
376- big .NewInt (2000 ),
377- big .NewInt (2 ),
378- 100000000 ,
379- 499999999 ,
380- big .NewInt (3 ),
381- },
382- {
383- params .EIP1559ChainConfig ,
384- big .NewInt (1000 ),
385- 1000 ,
386- big .NewInt (2000 ),
387- big .NewInt (2 ),
388- 100000000 ,
389- 500000000 ,
390- big .NewInt (3 ),
383+ 1 ,
384+ big .NewInt (0 ),
391385 },
392386 }
393387 for i , test := range testConditions {
@@ -404,13 +398,13 @@ func TestCalcBaseFee(t *testing.T) {
404398 gasTarget := CalcBaseFee (& config , parent )
405399 if gasTarget != nil {
406400 if test .baseFee != nil && gasTarget .Cmp (test .baseFee ) != 0 {
407- t .Errorf ("test %d expected BaseFee %d got %d" , i + 1 , test .baseFee .Uint64 (), gasTarget .Uint64 ())
401+ t .Errorf ("test %d expected BaseFee %d got %d" , i + 1 , test .baseFee .Int64 (), gasTarget .Int64 ())
408402 }
409403 if test .baseFee == nil {
410- t .Errorf ("test %d expected nil BaseFee got %d" , i + 1 , gasTarget .Uint64 ())
404+ t .Errorf ("test %d expected nil BaseFee got %d" , i + 1 , gasTarget .Int64 ())
411405 }
412406 } else if test .baseFee != nil {
413- t .Errorf ("test %d expected BaseFee %d got nil" , i + 1 , test .baseFee .Uint64 ())
407+ t .Errorf ("test %d expected BaseFee %d got nil" , i + 1 , test .baseFee .Int64 ())
414408 }
415409 }
416410}
0 commit comments