Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions espressotee/espresso_tee_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ func BaseFeeCheck(
continue
}

if latestBaseFee == nil {
log.Error(msg, "base fee is nil", "delay", retryDelay, "attempt", attempt+1)
if attempt < maxRetries-1 {
time.Sleep(retryDelay)
}
continue
}

if latestBaseFee.Uint64() > maxBaseFee {
log.Error(
msg,
Expand Down
44 changes: 44 additions & 0 deletions espressotee/espresso_tee_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package espressotee

import (
"math/big"
"testing"
"time"
)

func TestBaseFeeCheck_NilBaseFee(t *testing.T) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we consolidate these tests and make them small, we should not have so many tests just for a nil check I think. Trying to keep our CI times less :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for sure, that's why I added a little comment on slack. I knew this concern would come up 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Run("retries when base fee is nil", func(t *testing.T) {
attempts := 0
fn := func() (*big.Int, error) {
attempts++
if attempts < 2 {
return nil, nil
}
return big.NewInt(1000000), nil // Succeed on 3rd retry
}

err := BaseFeeCheck(10000000, 3, 10*time.Millisecond, fn, "test")
if err != nil {
t.Errorf("Expected success after retry, got: %v", err)
}
if attempts != 2 {
t.Errorf("Expected 2 attempts, got %d", attempts)
}
})

t.Run("fails when base fee always nil", func(t *testing.T) {
attempts := 0
fn := func() (*big.Int, error) {
attempts++
return nil, nil // Always nil
}

err := BaseFeeCheck(10000000, 3, 10*time.Millisecond, fn, "test")
if err == nil {
t.Error("Expected error when base fee always nil")
}
if attempts != 3 {
t.Errorf("Expected 3 attempts, got %d", attempts)
}
})
}
Loading