Skip to content

Commit 6968d63

Browse files
authored
fix(deployment):turn on lint and fix issues (#71)
Enable lint in deployment package and fix lint issues. https://smartcontract-it.atlassian.net/browse/CLD-211
1 parent ee24199 commit 6968d63

15 files changed

+142
-45
lines changed

.github/workflows/pull-request-main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
with:
2121
only-new-issues: "false"
2222
golangci-lint-version: v2.0.2
23-
# Override the lint args because the detault ones are not compatible with golangci-lint v2
23+
# Override the lint args because the default ones are not compatible with golangci-lint v2
2424
golangci-lint-args: --output.checkstyle.path=golangci-lint-report.xml
2525

2626
ci-lint-misc:

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ linters:
132132
- third_party$
133133
- builtin$
134134
- examples$
135-
- deployment/*
136135
formatters:
137136
enable:
138137
- goimports

deployment/address_book.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package deployment
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67
"sync"
@@ -9,7 +10,6 @@ import (
910

1011
"github.com/Masterminds/semver/v3"
1112
"github.com/ethereum/go-ethereum/common"
12-
"github.com/pkg/errors"
1313
chainsel "github.com/smartcontractkit/chain-selectors"
1414
)
1515

@@ -39,6 +39,7 @@ func (tv TypeAndVersion) String() string {
3939

4040
// Use the LabelSet's String method for sorted labels
4141
sortedLabels := tv.Labels.String()
42+
4243
return fmt.Sprintf("%s %s %s",
4344
tv.Type,
4445
tv.Version.String(),
@@ -64,6 +65,7 @@ func MustTypeAndVersionFromString(s string) TypeAndVersion {
6465
if err != nil {
6566
panic(err)
6667
}
68+
6769
return tv
6870
}
6971

@@ -82,6 +84,7 @@ func TypeAndVersionFromString(s string) (TypeAndVersion, error) {
8284
if len(parts) > 2 {
8385
labels = NewLabelSet(parts[2:]...)
8486
}
87+
8588
return TypeAndVersion{
8689
Type: ContractType(parts[0]),
8790
Version: *v,
@@ -121,17 +124,17 @@ type AddressBookMap struct {
121124
func (m *AddressBookMap) save(chainSelector uint64, address string, typeAndVersion TypeAndVersion) error {
122125
family, err := chainsel.GetSelectorFamily(chainSelector)
123126
if err != nil {
124-
return errors.Wrapf(ErrInvalidChainSelector, "chain selector %d", chainSelector)
127+
return fmt.Errorf("%w: chain selector %d", ErrInvalidChainSelector, chainSelector)
125128
}
126129
if family == chainsel.FamilyEVM {
127130
if address == "" || address == common.HexToAddress("0x0").Hex() {
128-
return errors.Wrap(ErrInvalidAddress, "address cannot be empty")
131+
return fmt.Errorf("%w: address cannot be empty", ErrInvalidAddress)
129132
}
130133
if common.IsHexAddress(address) {
131134
// IMPORTANT: WE ALWAYS STANDARDIZE ETHEREUM ADDRESS STRINGS TO EIP55
132135
address = common.HexToAddress(address).Hex()
133136
} else {
134-
return errors.Wrapf(ErrInvalidAddress, "address %s is not a valid Ethereum address, only Ethereum addresses supported for EVM chains", address)
137+
return fmt.Errorf("%w: address %s is not a valid Ethereum address, only Ethereum addresses supported for EVM chains", ErrInvalidAddress, address)
135138
}
136139
}
137140

@@ -149,6 +152,7 @@ func (m *AddressBookMap) save(chainSelector uint64, address string, typeAndVersi
149152
return fmt.Errorf("address %s already exists for chain %d", address, chainSelector)
150153
}
151154
m.addressesByChain[chainSelector][address] = typeAndVersion
155+
152156
return nil
153157
}
154158

@@ -157,6 +161,7 @@ func (m *AddressBookMap) save(chainSelector uint64, address string, typeAndVersi
157161
func (m *AddressBookMap) Save(chainSelector uint64, address string, typeAndVersion TypeAndVersion) error {
158162
m.mtx.Lock()
159163
defer m.mtx.Unlock()
164+
160165
return m.save(chainSelector, address, typeAndVersion)
161166
}
162167

@@ -173,14 +178,14 @@ func (m *AddressBookMap) Addresses() (map[uint64]map[string]TypeAndVersion, erro
173178
func (m *AddressBookMap) AddressesForChain(chainSelector uint64) (map[string]TypeAndVersion, error) {
174179
_, err := chainsel.GetChainIDFromSelector(chainSelector)
175180
if err != nil {
176-
return nil, errors.Wrapf(ErrInvalidChainSelector, "chain selector %d", chainSelector)
181+
return nil, fmt.Errorf("%w: chain selector %d", ErrInvalidChainSelector, chainSelector)
177182
}
178183

179184
m.mtx.RLock()
180185
defer m.mtx.RUnlock()
181186

182187
if _, exists := m.addressesByChain[chainSelector]; !exists {
183-
return nil, errors.Wrapf(ErrChainNotFound, "chain selector %d", chainSelector)
188+
return nil, fmt.Errorf("%w: chain selector %d", ErrChainNotFound, chainSelector)
184189
}
185190

186191
// maps are mutable and pass via a pointer
@@ -207,6 +212,7 @@ func (m *AddressBookMap) Merge(ab AddressBook) error {
207212
}
208213
}
209214
}
215+
210216
return nil
211217
}
212218

@@ -246,6 +252,7 @@ func (m *AddressBookMap) cloneAddresses(input map[uint64]map[string]TypeAndVersi
246252
for chainSelector, chainAddresses := range input {
247253
result[chainSelector] = maps.Clone(chainAddresses)
248254
}
255+
249256
return result
250257
}
251258

@@ -340,6 +347,7 @@ func toTypeAndVersionMap(addrs map[string]TypeAndVersion) map[typeVersionKey][]s
340347
for k, v := range addrs {
341348
tvkMap[tvKey(v)] = append(tvkMap[tvKey(v)], k)
342349
}
350+
343351
return tvkMap
344352
}
345353

deployment/address_book_labels.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func NewLabelSet(labels ...string) LabelSet {
1414
for _, lb := range labels {
1515
set[lb] = struct{}{}
1616
}
17+
1718
return set
1819
}
1920

@@ -73,6 +74,7 @@ func (ls LabelSet) Equal(other LabelSet) bool {
7374
return false
7475
}
7576
}
77+
7678
return true
7779
}
7880

deployment/address_book_labels_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88

99
func TestNewLabelSet(t *testing.T) {
1010
t.Run("no labels", func(t *testing.T) {
11+
t.Parallel()
1112
ms := NewLabelSet()
1213
assert.Empty(t, ms, "expected empty set")
1314
})
14-
1515
t.Run("some labels", func(t *testing.T) {
16+
t.Parallel()
1617
ms := NewLabelSet("foo", "bar")
1718
assert.Len(t, ms, 2)
1819
assert.True(t, ms.Contains("foo"))
@@ -22,6 +23,7 @@ func TestNewLabelSet(t *testing.T) {
2223
}
2324

2425
func TestLabelSet_Add(t *testing.T) {
26+
t.Parallel()
2527
ms := NewLabelSet("initial")
2628
ms.Add("new")
2729

@@ -35,6 +37,7 @@ func TestLabelSet_Add(t *testing.T) {
3537
}
3638

3739
func TestLabelSet_Remove(t *testing.T) {
40+
t.Parallel()
3841
ms := NewLabelSet("remove_me", "keep")
3942
ms.Remove("remove_me")
4043

@@ -48,6 +51,7 @@ func TestLabelSet_Remove(t *testing.T) {
4851
}
4952

5053
func TestLabelSet_Contains(t *testing.T) {
54+
t.Parallel()
5155
ms := NewLabelSet("foo", "bar")
5256

5357
assert.True(t, ms.Contains("foo"))
@@ -56,7 +60,9 @@ func TestLabelSet_Contains(t *testing.T) {
5660
}
5761

5862
func TestLabelSet_List(t *testing.T) {
63+
t.Parallel()
5964
t.Run("list with items", func(t *testing.T) {
65+
t.Parallel()
6066
ms := NewLabelSet("foo", "bar", "baz")
6167

6268
labels := ms.List()
@@ -68,6 +74,7 @@ func TestLabelSet_List(t *testing.T) {
6874
})
6975

7076
t.Run("empty list", func(t *testing.T) {
77+
t.Parallel()
7178
ms := NewLabelSet()
7279

7380
labels := ms.List()
@@ -78,6 +85,7 @@ func TestLabelSet_List(t *testing.T) {
7885

7986
// TestLabelSet_String tests the String() method of the LabelSet type.
8087
func TestLabelSet_String(t *testing.T) {
88+
t.Parallel()
8189
tests := []struct {
8290
name string
8391
labels LabelSet
@@ -121,15 +129,16 @@ func TestLabelSet_String(t *testing.T) {
121129
}
122130

123131
for _, tt := range tests {
124-
tt := tt
125132
t.Run(tt.name, func(t *testing.T) {
133+
t.Parallel()
126134
result := tt.labels.String()
127135
assert.Equal(t, tt.expected, result, "LabelSet.String() should return the expected sorted string")
128136
})
129137
}
130138
}
131139

132140
func TestLabelSet_Equal(t *testing.T) {
141+
t.Parallel()
133142
tests := []struct {
134143
name string
135144
set1 LabelSet
@@ -193,7 +202,6 @@ func TestLabelSet_Equal(t *testing.T) {
193202
}
194203

195204
for _, tt := range tests {
196-
tt := tt
197205
t.Run(tt.name, func(t *testing.T) {
198206
t.Parallel()
199207

deployment/address_book_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var (
1919
)
2020

2121
func TestAddressBook_Save(t *testing.T) {
22+
t.Parallel()
2223
ab := NewMemoryAddressBook()
2324
onRamp100 := NewTypeAndVersion("OnRamp", Version1_0_0)
2425
onRamp110 := NewTypeAndVersion("OnRamp", Version1_1_0)
@@ -77,6 +78,7 @@ func TestAddressBook_Save(t *testing.T) {
7778
}
7879

7980
func TestAddressBook_Merge(t *testing.T) {
81+
t.Parallel()
8082
onRamp100 := NewTypeAndVersion("OnRamp", Version1_0_0)
8183
onRamp110 := NewTypeAndVersion("OnRamp", Version1_1_0)
8284
addr1 := common.HexToAddress("0x1").String()
@@ -130,6 +132,7 @@ func TestAddressBook_Merge(t *testing.T) {
130132
}
131133

132134
func TestAddressBook_Remove(t *testing.T) {
135+
t.Parallel()
133136
onRamp100 := NewTypeAndVersion("OnRamp", Version1_0_0)
134137
onRamp110 := NewTypeAndVersion("OnRamp", Version1_1_0)
135138
addr1 := common.HexToAddress("0x1").String()
@@ -157,7 +160,7 @@ func TestAddressBook_Remove(t *testing.T) {
157160
},
158161
})
159162
require.Error(t, baseAB.Remove(failAB))
160-
require.EqualValues(t, baseAB, copyOfBaseAB)
163+
require.Equal(t, baseAB, copyOfBaseAB)
161164

162165
// this Address book should be removed without error
163166
successAB := NewMemoryAddressBookFromMap(map[uint64]map[string]TypeAndVersion{
@@ -178,10 +181,11 @@ func TestAddressBook_Remove(t *testing.T) {
178181
})
179182

180183
require.NoError(t, baseAB.Remove(successAB))
181-
require.EqualValues(t, baseAB, expectingAB)
184+
require.Equal(t, baseAB, expectingAB)
182185
}
183186

184187
func TestAddressBook_ConcurrencyAndDeadlock(t *testing.T) {
188+
t.Parallel()
185189
onRamp100 := NewTypeAndVersion("OnRamp", Version1_0_0)
186190
onRamp110 := NewTypeAndVersion("OnRamp", Version1_1_0)
187191

@@ -207,9 +211,9 @@ func TestAddressBook_ConcurrencyAndDeadlock(t *testing.T) {
207211
}
208212

209213
// concurrent reads
210-
for i = 0; i < 100; i++ {
214+
for range 100 {
211215
wg.Add(1)
212-
go func(input int64) {
216+
go func() {
213217
addresses, err := baseAB.Addresses()
214218
if !assert.NoError(t, err) {
215219
return
@@ -229,7 +233,7 @@ func TestAddressBook_ConcurrencyAndDeadlock(t *testing.T) {
229233
}
230234
}
231235
wg.Done()
232-
}(i)
236+
}()
233237
}
234238

235239
// concurrent merges, starts from 1001 to avoid address conflicts
@@ -338,7 +342,6 @@ func Test_EnsureDeduped(t *testing.T) {
338342
}
339343

340344
for _, tt := range tests {
341-
tt := tt // capture range variable
342345
t.Run(tt.name, func(t *testing.T) {
343346
t.Parallel()
344347

@@ -349,6 +352,7 @@ func Test_EnsureDeduped(t *testing.T) {
349352
if tt.wantErrMsg != "" {
350353
require.Contains(t, gotErr.Error(), tt.wantErrMsg)
351354
}
355+
352356
return
353357
}
354358
require.NoError(t, gotErr, "did not expect an error but got one")
@@ -410,7 +414,6 @@ func TestTypeAndVersionFromString(t *testing.T) {
410414
}
411415

412416
for _, tt := range tests {
413-
tt := tt // capture range variable
414417
t.Run(tt.name, func(t *testing.T) {
415418
t.Parallel()
416419

@@ -470,7 +473,6 @@ func TestTypeAndVersion_AddLabels(t *testing.T) {
470473
}
471474

472475
for _, tt := range tests {
473-
tt := tt // capture range variable
474476
t.Run(tt.name, func(t *testing.T) {
475477
t.Parallel()
476478

@@ -499,6 +501,7 @@ func TestTypeAndVersion_AddLabels(t *testing.T) {
499501
}
500502

501503
func Test_toTypeAndVersionMap(t *testing.T) {
504+
t.Parallel()
502505
v100 := semver.MustParse("1.0.0")
503506

504507
tests := []struct {
@@ -540,8 +543,9 @@ func Test_toTypeAndVersionMap(t *testing.T) {
540543

541544
for _, tt := range tests {
542545
t.Run(tt.name, func(t *testing.T) {
546+
t.Parallel()
543547
got := toTypeAndVersionMap(tt.addrs)
544-
require.Equal(t, len(tt.want), len(got))
548+
require.Len(t, got, len(tt.want))
545549
for k, gotAddresses := range got {
546550
wantAddresses, ok := tt.want[k]
547551
require.True(t, ok)

deployment/changeset_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import (
55

66
"github.com/stretchr/testify/require"
77

8-
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
98
"github.com/smartcontractkit/chainlink-common/pkg/logger"
9+
10+
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
1011
)
1112

1213
type MyChangeSet struct{}
@@ -93,6 +94,7 @@ func TestChangeSetLegacyFunction(t *testing.T) {
9394
}
9495

9596
func NewNoopEnvironment(t *testing.T) Environment {
97+
t.Helper()
9698
return *NewEnvironment(
9799
"noop",
98100
logger.Test(t),

0 commit comments

Comments
 (0)