Skip to content

Commit 2d2d89e

Browse files
jjeangalgithub-actions[bot]
authored andcommitted
Solve the latestBaseFee taking a Nil value (#878)
* check latest-base-fee for nil value + unit test * consolidate tests * change comment, trigger ci (cherry picked from commit 4b0acdb)
1 parent 1528844 commit 2d2d89e

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

espressotee/espresso_tee_helpers.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ func BaseFeeCheck(
8080
continue
8181
}
8282

83+
if latestBaseFee == nil {
84+
log.Error(msg, "base fee is nil", "delay", retryDelay, "attempt", attempt+1)
85+
if attempt < maxRetries-1 {
86+
time.Sleep(retryDelay)
87+
}
88+
continue
89+
}
90+
8391
if latestBaseFee.Uint64() > maxBaseFee {
8492
log.Error(
8593
msg,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package espressotee
2+
3+
import (
4+
"math/big"
5+
"testing"
6+
"time"
7+
)
8+
9+
func TestBaseFeeCheck_NilBaseFee(t *testing.T) {
10+
t.Run("retries when base fee is nil", func(t *testing.T) {
11+
attempts := 0
12+
fn := func() (*big.Int, error) {
13+
attempts++
14+
if attempts < 2 {
15+
return nil, nil
16+
}
17+
return big.NewInt(1000000), nil // Succeed on 3rd retry
18+
}
19+
20+
err := BaseFeeCheck(10000000, 3, 10*time.Millisecond, fn, "test")
21+
if err != nil {
22+
t.Errorf("Expected success after retry, got: %v", err)
23+
}
24+
if attempts != 2 {
25+
t.Errorf("Expected 2 attempts, got %d", attempts)
26+
}
27+
})
28+
29+
t.Run("fails when base fee always nil", func(t *testing.T) {
30+
attempts := 0
31+
fn := func() (*big.Int, error) {
32+
attempts++
33+
return nil, nil // Always nil
34+
}
35+
36+
err := BaseFeeCheck(10000000, 3, 10*time.Millisecond, fn, "test")
37+
if err == nil {
38+
t.Error("Expected error when base fee always nil")
39+
}
40+
if attempts != 3 {
41+
t.Errorf("Expected 3 attempts, got %d", attempts)
42+
}
43+
})
44+
}

0 commit comments

Comments
 (0)