From 4164190a57d2925cdc16ba1d3fa552f33f7cd422 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Mon, 28 Apr 2025 16:40:05 -0400 Subject: [PATCH] chore: make format golines Signed-off-by: Chris Gianelloni --- ledger/slot.go | 19 ++++++++++++++----- ledger/slot_test.go | 33 +++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/ledger/slot.go b/ledger/slot.go index 928d48d6..b294b71c 100644 --- a/ledger/slot.go +++ b/ledger/slot.go @@ -41,17 +41,23 @@ func (ls *LedgerState) SlotToTime(slot uint64) (time.Time, error) { if epoch.StartSlot > math.MaxInt64 || epoch.LengthInSlots > math.MaxInt64 || epoch.SlotLength > math.MaxInt64 { - return time.Time{}, errors.New("epoch slot values are larger than time.Duration") + return time.Time{}, errors.New( + "epoch slot values are larger than time.Duration", + ) } if slot < epoch.StartSlot+uint64(epoch.LengthInSlots) { slotTime = slotTime.Add( - time.Duration(int64(slot)-int64(epoch.StartSlot)) * (time.Duration(epoch.SlotLength) * time.Millisecond), + time.Duration( + int64(slot)-int64(epoch.StartSlot), + ) * (time.Duration(epoch.SlotLength) * time.Millisecond), ) foundSlot = true break } slotTime = slotTime.Add( - time.Duration(epoch.LengthInSlots) * (time.Duration(epoch.SlotLength) * time.Millisecond), + time.Duration( + epoch.LengthInSlots, + ) * (time.Duration(epoch.SlotLength) * time.Millisecond), ) } if !foundSlot { @@ -76,7 +82,9 @@ func (ls *LedgerState) TimeToSlot(t time.Time) (uint64, error) { for _, epoch := range ls.epochCache { if epoch.LengthInSlots > math.MaxInt64 || epoch.SlotLength > math.MaxInt64 { - return 0, errors.New("epoch slot values are larger than time.Duration") + return 0, errors.New( + "epoch slot values are larger than time.Duration", + ) } slotDuration := time.Duration(epoch.SlotLength) * time.Millisecond if slotDuration < 0 { @@ -85,7 +93,8 @@ func (ls *LedgerState) TimeToSlot(t time.Time) (uint64, error) { epochEndTime := epochStartTime.Add( time.Duration(epoch.LengthInSlots) * slotDuration, ) - if (t.Equal(epochStartTime) || t.After(epochStartTime)) && t.Before(epochEndTime) { + if (t.Equal(epochStartTime) || t.After(epochStartTime)) && + t.Before(epochEndTime) { // Figure out how far into the epoch the specified time is timeDiff := t.Sub(epochStartTime) // nolint:gosec diff --git a/ledger/slot_test.go b/ledger/slot_test.go index f823920b..0382afc0 100644 --- a/ledger/slot_test.go +++ b/ledger/slot_test.go @@ -82,9 +82,18 @@ func TestSlotCalc(t *testing.T) { epoch: 0, }, { - slot: 86399, - slotTime: time.Date(2022, time.October, 25, 23, 59, 59, 0, time.UTC), - epoch: 0, + slot: 86399, + slotTime: time.Date( + 2022, + time.October, + 25, + 23, + 59, + 59, + 0, + time.UTC, + ), + epoch: 0, }, { slot: 86400, @@ -104,7 +113,11 @@ func TestSlotCalc(t *testing.T) { t.Errorf("unexpected error converting slot to time: %s", err) } if !tmpSlotToTime.Equal(testDef.slotTime) { - t.Errorf("did not get expected time from slot: got %s, wanted %s", tmpSlotToTime, testDef.slotTime) + t.Errorf( + "did not get expected time from slot: got %s, wanted %s", + tmpSlotToTime, + testDef.slotTime, + ) } // Time to slot tmpTimeToSlot, err := testLedgerState.TimeToSlot(testDef.slotTime) @@ -112,7 +125,11 @@ func TestSlotCalc(t *testing.T) { t.Errorf("unexpected error converting time to slot: %s", err) } if tmpTimeToSlot != testDef.slot { - t.Errorf("did not get expected slot from time: got %d, wanted %d", tmpTimeToSlot, testDef.slot) + t.Errorf( + "did not get expected slot from time: got %d, wanted %d", + tmpTimeToSlot, + testDef.slot, + ) } // Slot to epoch tmpSlotToEpoch, err := testLedgerState.SlotToEpoch(testDef.slot) @@ -120,7 +137,11 @@ func TestSlotCalc(t *testing.T) { t.Errorf("unexpected error getting epoch from slot: %s", err) } if tmpSlotToEpoch.EpochId != testDef.epoch { - t.Errorf("did not get expected epoch from slot: got %d, wanted %d", tmpSlotToEpoch.EpochId, testDef.epoch) + t.Errorf( + "did not get expected epoch from slot: got %d, wanted %d", + tmpSlotToEpoch.EpochId, + testDef.epoch, + ) } } }