From a15424a8e273e848830e8ca257608d2b5c256d38 Mon Sep 17 00:00:00 2001 From: rene <41963722+renaynay@users.noreply.github.com> Date: Mon, 4 Nov 2024 11:57:46 +0100 Subject: [PATCH] "readability"fix(store): Clearer range check (#227) This PR cleans up a sanity check on the range request in the private method of store to make it more readable. --- store/store.go | 6 ++---- store/store_test.go | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/store/store.go b/store/store.go index 0a0acaa..9488dfd 100644 --- a/store/store.go +++ b/store/store.go @@ -277,10 +277,8 @@ func (s *Store[H]) GetRange(ctx context.Context, from, to uint64) ([]H, error) { } func (s *Store[H]) getRangeByHeight(ctx context.Context, from, to uint64) ([]H, error) { - // as the requested range is non-inclusive in the end[from;to), we need to compare - // `from` with `to-1` - if from > to-1 { - return nil, fmt.Errorf("header/store: invalid range(%d,%d)", from, to-1) + if from >= to { + return nil, fmt.Errorf("header/store: invalid range(%d,%d)", from, to) } h, err := s.GetByHeight(ctx, to-1) if err != nil { diff --git a/store/store_test.go b/store/store_test.go index 7d123cf..13b3843 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -93,6 +93,10 @@ func TestStore(t *testing.T) { out, err = store.getRangeByHeight(ctx, 1, 13) require.NoError(t, err) assert.Len(t, out, 12) + + out, err = store.getRangeByHeight(ctx, 10, 11) + require.NoError(t, err) + assert.Len(t, out, 1) } // TestStore_GetRangeByHeight_ExpectedRange