From b802fa051a12944471540535ba0ce594d587c405 Mon Sep 17 00:00:00 2001 From: Manav Aggarwal Date: Thu, 18 May 2023 14:25:37 -0400 Subject: [PATCH] address comments --- pkg/shares/compact_shares_test.go | 2 +- pkg/shares/shares.go | 6 ++++-- test/util/testfactory/txs.go | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/shares/compact_shares_test.go b/pkg/shares/compact_shares_test.go index a605618fc8..2c2dde2842 100644 --- a/pkg/shares/compact_shares_test.go +++ b/pkg/shares/compact_shares_test.go @@ -118,7 +118,7 @@ func TestParseOutOfContextShares(t *testing.T) { require.NoError(t, err) for i := 0; i < 1000; i++ { - start, length := testfactory.GetRandomSlice(len(txShares)) + start, length := testfactory.GetRandomSubSlice(len(txShares)) resTxs, err := ParseTxs(txShares[start : start+length]) require.NoError(t, err) diff --git a/pkg/shares/shares.go b/pkg/shares/shares.go index e44bbf06c4..95f432954c 100644 --- a/pkg/shares/shares.go +++ b/pkg/shares/shares.go @@ -209,14 +209,16 @@ func (s *Share) RawDataUsingReserved() (rawData []byte, err error) { return s.data[rawDataStartIndexUsingReserved:], nil } +// rawDataStartIndexUsingReserved returns the start index of raw data while accounting for +// reserved bytes, if it exists in the share. func (s *Share) rawDataStartIndexUsingReserved() (int, error) { isStart, err := s.IsSequenceStart() if err != nil { - panic(err) + return 0, err } isCompact, err := s.IsCompactShare() if err != nil { - panic(err) + return 0, err } index := appconsts.NamespaceSize + appconsts.ShareInfoBytes diff --git a/test/util/testfactory/txs.go b/test/util/testfactory/txs.go index 8eefcc1295..e770d54e5d 100644 --- a/test/util/testfactory/txs.go +++ b/test/util/testfactory/txs.go @@ -33,7 +33,8 @@ func GenerateRandomTxs(count, size int) types.Txs { return txs } -func GetRandomSlice(size int) (start int, length int) { +// GetRandomSubSlice returns two integers representing a randomly sized range in the interval [0, size] +func GetRandomSubSlice(size int) (start int, length int) { length = rand.Intn(size + 1) start = rand.Intn(size - length + 1) return start, length