Skip to content

Commit 98b900b

Browse files
committed
chore(all): Add nolint flags for conversions
Signed-off-by: Sophia Koehler <sophia@perun.network>
1 parent fd8bf8a commit 98b900b

26 files changed

+85
-65
lines changed

apps/payment/app_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestApp_ValidTransition(t *testing.T) {
9595
numParticipants := len(tt.from[0])
9696
for i := 0; i < numParticipants; i++ {
9797
// valid self-transition
98-
assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i)))
98+
assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i))) //nolint:gosec
9999
}
100100

101101
for _, tto := range tt.tos {
@@ -105,7 +105,7 @@ func TestApp_ValidTransition(t *testing.T) {
105105
test.WithBalances(asBalances(tto.alloc...)...),
106106
)
107107
for i := 0; i < numParticipants; i++ {
108-
err := app.ValidTransition(nil, from, to, channel.Index(i))
108+
err := app.ValidTransition(nil, from, to, channel.Index(i)) //nolint:gosec
109109
if i == tto.valid {
110110
assert.NoError(err)
111111
} else {

backend/sim/channel/asset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (a *Asset) UnmarshalBinary(data []byte) error {
5353
if len(data) != assetLen {
5454
return fmt.Errorf("unexpected length %d, want %d", len(data), assetLen) //nolint:goerr113 // We do not want to define this as constant error.
5555
}
56-
a.ID = int64(byteOrder.Uint64(data))
56+
a.ID = int64(byteOrder.Uint64(data)) //nolint:gosec
5757
return nil
5858
}
5959

channel/allocation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (a Allocation) Encode(w io.Writer) error {
325325
err, "invalid allocations cannot be encoded, got %v", a)
326326
}
327327
// encode dimensions
328-
if err := perunio.Encode(w, Index(len(a.Assets)), Index(len(a.Balances[0])), Index(len(a.Locked))); err != nil {
328+
if err := perunio.Encode(w, Index(len(a.Assets)), Index(len(a.Balances[0])), Index(len(a.Locked))); err != nil { //nolint:gosec
329329
return err
330330
}
331331
// encode assets
@@ -436,7 +436,7 @@ func (b Balances) Encode(w io.Writer) error {
436436
return errors.Errorf("expected maximum number of parts %d, got %d", MaxNumParts, numParts)
437437
}
438438

439-
if err := perunio.Encode(w, Index(numAssets), Index(numParts)); err != nil {
439+
if err := perunio.Encode(w, Index(numAssets), Index(numParts)); err != nil { //nolint:gosec
440440
return errors.WithMessage(err, "encoding dimensions")
441441
}
442442
for i := range b {
@@ -667,7 +667,7 @@ func (s SubAlloc) Encode(w io.Writer) error {
667667
err, "invalid sub-allocations cannot be encoded, got %v", s)
668668
}
669669
// encode ID and dimension
670-
if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil {
670+
if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil { //nolint:gosec
671671
return errors.WithMessagef(
672672
err, "encoding sub-allocation ID or dimension, id %v", s.ID)
673673
}
@@ -679,7 +679,7 @@ func (s SubAlloc) Encode(w io.Writer) error {
679679
}
680680
}
681681
// Encode IndexMap.
682-
if err := perunio.Encode(w, Index(len(s.IndexMap))); err != nil {
682+
if err := perunio.Encode(w, Index(len(s.IndexMap))); err != nil { //nolint:gosec
683683
return errors.WithMessage(err, "encoding length of index map")
684684
}
685685
for i, x := range s.IndexMap {

channel/machine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func newMachine(acc map[wallet.BackendID]wallet.Account, params Params) (*machin
151151
return &machine{
152152
phase: InitActing,
153153
acc: acc,
154-
idx: Index(idx),
154+
idx: Index(idx), //nolint:gosec
155155
params: params,
156156
Embedding: log.MakeEmbedding(log.WithField("ID", params.id)),
157157
}, nil
@@ -190,7 +190,7 @@ func (m *machine) Params() *Params {
190190

191191
// N returns the number of participants of the channel parameters of this machine.
192192
func (m *machine) N() Index {
193-
return Index(len(m.params.Parts))
193+
return Index(len(m.params.Parts)) //nolint:gosec
194194
}
195195

196196
// Phase returns the current phase.

channel/multi/funder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (f *Funder) SetEgoisticChain(l AssetID, id int, egoistic bool) {
6262
// channel. If any of the funder calls fails, the method returns an error.
6363
func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error {
6464
// Define funding timeout.
65-
d := time.Duration(request.Params.ChallengeDuration) * time.Second
65+
d := time.Duration(request.Params.ChallengeDuration) * time.Second //nolint:gosec
6666
ctx, cancel := context.WithTimeout(ctx, d)
6767
defer cancel()
6868

channel/params.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ func (ids *IDMap) Decode(r stdio.Reader) error {
112112

113113
func IDKey(ids IDMap) string {
114114
var buff strings.Builder
115-
length := int32(len(ids)) //nolint:gosec
116-
err := binary.Write(&buff, binary.BigEndian, length) //nolint:gosec
115+
length := int32(len(ids)) //nolint:gosec
116+
err := binary.Write(&buff, binary.BigEndian, length)
117117
if err != nil {
118118
log.Panic("could not encode map length in Key: ", err)
119119
}
120120
sortedKeys, sortedIDs := sortIDMap(ids)
121121
for i, id := range sortedIDs {
122-
if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil {
122+
if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil { //nolint:gosec
123123
log.Panicf("could not encode map key: " + err.Error())
124124
}
125125
if err := perunio.Encode(&buff, id); err != nil {

channel/persistence/statemachine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestStateMachine(t *testing.T) {
7676
sig, err = channel.Sign(acc, csm.StagingState(), b)
7777
require.NoError(err)
7878
}
79-
err = sm.AddSig(ctx, channel.Index(i), sig)
79+
err = sm.AddSig(ctx, channel.Index(i), sig) //nolint:gosec
8080
require.NoError(err)
8181
tpr.AssertEqual(csm)
8282
}
@@ -152,7 +152,7 @@ func TestStateMachine(t *testing.T) {
152152

153153
// Set Progressed
154154
timeout := ctest.NewRandomTimeout(rng)
155-
idx := channel.Index(rng.Intn(s.NumParts()))
155+
idx := channel.Index(rng.Intn(s.NumParts())) //nolint:gosec
156156
e := channel.NewProgressedEvent(s.ID[0], timeout, s, idx)
157157
err = sm.SetProgressed(ctx, e)
158158
require.NoError(err)

channel/test/randomizer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[wallet.Backen
269269
for _, b := range bIds {
270270
cId := [32]byte{}
271271
rng.Read(cId[:])
272-
id[wallet.BackendID(b)] = cId
272+
id[b] = cId
273273
}
274274
return
275275
}
@@ -281,7 +281,7 @@ func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[wallet.Backen
281281
} else {
282282
cId := [32]byte{}
283283
rng.Read(cId[:])
284-
id[wallet.BackendID(bId)] = cId
284+
id[bId] = cId
285285
}
286286
return
287287
}
@@ -299,7 +299,7 @@ func NewRandomChannelIDs(rng *rand.Rand, n int) (ids []map[wallet.BackendID]chan
299299
func NewRandomIndexMap(rng *rand.Rand, numParts int, numPartsParent int) (m []channel.Index) {
300300
m = make([]channel.Index, numParts)
301301
for i := range m {
302-
m[i] = channel.Index(rng.Intn(numPartsParent))
302+
m[i] = channel.Index(rng.Intn(numPartsParent)) //nolint:gosec
303303
}
304304
return
305305
}

client/channelconn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (c *channelConn) Close() error {
104104
func (c *channelConn) Send(ctx context.Context, msg wire.Msg) error {
105105
var eg errgroup.Group
106106
for i, peer := range c.peers {
107-
if channel.Index(i) == c.idx {
107+
if channel.Index(i) == c.idx { //nolint:gosec
108108
continue // skip own peer
109109
}
110110
c.log.WithField("peer", peer).Debugf("channelConn: publishing message: %v: %+v", msg.Type(), msg)
@@ -168,5 +168,5 @@ func (r *channelMsgRecv) Next(ctx context.Context) (channel.Index, ChannelMsg, e
168168
if !ok {
169169
return 0, nil, errors.Errorf("unexpected message type: expected ChannelMsg, got %T", env.Msg)
170170
}
171-
return channel.Index(idx), msg, nil // predicate must guarantee that the conversion is safe
171+
return channel.Index(idx), msg, nil //nolint:gosec
172172
}

client/restore_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func mkRndChan(rng *rand.Rand, bID wallet.BackendID) *persistence.Channel {
120120
parts[i] = map[wallet.BackendID]wallet.Address{bID: wallettest.NewRandomAccount(rng, bID).Address()}
121121
}
122122
ch := persistence.NewChannel()
123-
ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts))
123+
ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts)) //nolint:gosec
124124
ch.ParamsV = test.NewRandomParams(rng, test.WithParts(parts))
125125
sigs := make([]bool, channel.MaxNumParts)
126126
opts := test.WithParams(ch.ParamsV)

0 commit comments

Comments
 (0)