Skip to content

Commit 51ea520

Browse files
committed
Merge commit 'refs/pull/2758/head' of https://github.com/digitalbitbox/bitbox-wallet-app
2 parents 92bb536 + 433c5c9 commit 51ea520

32 files changed

+332
-347
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121
# https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images
2222
#
2323
# Keep this in sync with default in scripts/github-ci.sh.
24-
CI_IMAGE: ghcr.io/bitboxswiss/bitbox-wallet-app-ci:22
24+
CI_IMAGE: ghcr.io/bitboxswiss/bitbox-wallet-app-ci:23
2525
GITHUB_BUILD_DIR: ${{github.workspace}}
2626

2727
jobs:

.golangci.yml

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
# options for analysis running
55
run:
6-
go: 1.21
6+
go: "1.21"
77

88
# default concurrency is a available CPU number
99
concurrency: 4
1010

1111
# timeout for analysis, e.g. 30s, 5m, default is 1m
12-
deadline: 10m
12+
timeout: 10m
1313

1414
# exit code when at least one issue was found, default is 1
1515
issues-exit-code: 1
@@ -23,7 +23,9 @@ run:
2323
# output configuration options
2424
output:
2525
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
26-
format: colored-line-number
26+
formats:
27+
- format: colored-line-number
28+
path: stdout
2729

2830
# print lines of code with issue, default is true
2931
print-issued-lines: true
@@ -36,31 +38,10 @@ output:
3638
linters-settings:
3739
gocritic:
3840
enabled-checks:
39-
- assignOp
4041
- builtinShadow
41-
- captLocal
42-
- caseOrder
43-
- defaultCaseOrder
44-
- dupArg
45-
- dupBranchBody
46-
- dupCase
47-
- elseif
48-
- flagDeref
49-
- ifElseChain
5042
- nilValReturn
51-
- rangeExprCopy
5243
- rangeValCopy
53-
- regexpMust
54-
- sloppyLen
55-
- switchTrue
56-
- typeSwitchVar
5744
- typeUnparen
58-
- underef
59-
- unlambda
60-
- unslice
61-
maligned:
62-
# print struct with more effective memory layout or not, false by default
63-
suggest-new: true
6445
dupl:
6546
# tokens count to trigger issue, 150 by default
6647
threshold: 150
@@ -78,8 +59,6 @@ linters-settings:
7859
# max line length, lines longer will be reported. Default is 120.
7960
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
8061
line-length: 120
81-
# allow long comments.
82-
exclude: '//'
8362
revive:
8463
rules:
8564
- name: exported
@@ -88,22 +67,18 @@ linters-settings:
8867
linters:
8968
enable-all: true
9069
disable:
91-
- golint
92-
- scopelint
93-
- interfacer
9470
- gosec
9571
- bodyclose
9672
- dogsled
9773
- dupl
74+
- err113 # can't switch to errors.Is due to GopherJS still on go1.12
9875
- funlen
9976
- gochecknoglobals
10077
- gochecknoinits
10178
- gocognit
10279
- godox
103-
- goerr113 # can't switch to errors.Is due to GopherJS still on go1.12
10480
- gomnd
10581
- lll
106-
- maligned
10782
- nestif
10883
- prealloc
10984
- stylecheck
@@ -119,12 +94,10 @@ linters:
11994
- noctx
12095
- nlreturn
12196
- cyclop
122-
- ifshort
12397
- exhaustive
12498
- nilnil
12599
- nilerr
126100
- forcetypeassert
127-
- exhaustivestruct
128101
- exhaustruct
129102
- maintidx
130103
- errorlint
@@ -133,35 +106,49 @@ linters:
133106
- errname
134107
- forbidigo
135108
- makezero
109+
- mnd
136110
- nolintlint
137111
- gocyclo
138-
- nosnakecase
139112
- interfacebloat
140113
- musttag
141-
- structcheck
142-
- deadcode
143-
- varcheck
144114
- depguard
145115
- inamedparam
146116
- protogetter
117+
- perfsprint
147118
- gosmopolitan
148-
# todo: enable this, but there are a lot of hits
149-
- testifylint
119+
# TODO: enable this after merge https://github.com/karalabe/hid/pull/52
150120
- gomoddirectives
151121
disable-all: false
152122

153123
issues:
154-
# List of regexps of issue texts to exclude, empty list by default.
155-
# But independently from this option we use default exclude patterns,
156-
# it can be disabled by `exclude-use-default: false`. To list all
157-
# excluded by default patterns execute `golangci-lint run --help`
158-
exclude:
159-
# Use linters in their original configuration. golangci-linter changes the default config, for
160-
# example skipping the docstring comment checks of golint.
124+
# Independently of option `exclude` we use default exclude patterns,
125+
# it can be disabled by this option.
126+
# To list all excluded by default patterns execute `golangci-lint run --help`.
127+
# Default: true
161128
exclude-use-default: false
162129

163130
# Excluding configuration per-path, per-linter, per-text and per-source.
164131
exclude-rules:
132+
- linters:
133+
- gocritic
134+
text: "singleCaseSwitch: should rewrite switch statement to if statement"
135+
- linters:
136+
- gocritic
137+
text: "badCond: `ours == from && ours == to` condition is suspicious"
138+
- linters:
139+
- gocritic
140+
text: "builtinShadow: shadowing of predeclared identifier: max"
141+
- linters:
142+
- canonicalheader
143+
text: "non-canonical header \"X-API-KEY\", instead use: \"X-Api-Key\""
144+
- linters:
145+
- testifylint
146+
text: "go-require: require must only be used in the goroutine running the test function"
147+
- linters:
148+
- testifylint
149+
text: "go-require: do not use require in http handlers"
150+
- path: _test\.go
151+
text: "float-compare"
165152
# In addition to always disalbed linters above, exclude some more in tests.
166153
- path: _test\.go
167154
linters:

backend/accounts_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ func TestAccounts(t *testing.T) {
8787
b := newBackend(t, testnetDisabled, regtestDisabled)
8888
defer b.Close()
8989

90-
require.Len(t, b.Accounts(), 0)
91-
require.Len(t, b.Config().AccountsConfig().Accounts, 0)
90+
require.Empty(t, b.Accounts())
91+
require.Empty(t, b.Config().AccountsConfig().Accounts)
9292

9393
// 1) Registering a new keystore persists a set of initial default accounts.
9494
b.registerKeystore(ks)
@@ -670,7 +670,7 @@ func TestCreateAndPersistAccountConfig(t *testing.T) {
670670
)
671671
require.NoError(t, err)
672672
require.Nil(t, b.Config().AccountsConfig().Lookup("v0-55555555-eth-0"))
673-
require.Equal(t, accountsCount, len(b.Config().AccountsConfig().Accounts))
673+
require.Len(t, b.Config().AccountsConfig().Accounts, accountsCount)
674674

675675
// Try to add another Bitcoin account - can't, only one account supported.
676676
_, err = b.CreateAndPersistAccountConfig(
@@ -679,7 +679,7 @@ func TestCreateAndPersistAccountConfig(t *testing.T) {
679679
bitbox01LikeKeystore,
680680
)
681681
require.Equal(t, errAccountLimitReached, errp.Cause(err))
682-
require.Equal(t, accountsCount, len(b.Config().AccountsConfig().Accounts))
682+
require.Len(t, b.Config().AccountsConfig().Accounts, accountsCount)
683683

684684
// Try to add another Litecoin account - can't, only one account supported.
685685
_, err = b.CreateAndPersistAccountConfig(
@@ -688,7 +688,7 @@ func TestCreateAndPersistAccountConfig(t *testing.T) {
688688
bitbox01LikeKeystore,
689689
)
690690
require.Equal(t, errAccountLimitReached, errp.Cause(err))
691-
require.Equal(t, accountsCount, len(b.Config().AccountsConfig().Accounts))
691+
require.Len(t, b.Config().AccountsConfig().Accounts, accountsCount)
692692
})
693693

694694
// If the keystore cannot retrieve an xpub (e.g. USB communication error), no account should be
@@ -885,41 +885,41 @@ func TestInactiveAccount(t *testing.T) {
885885
checkShownAccountsLen(t, b, 3, 3)
886886
require.NotNil(t, b.Config().AccountsConfig().Lookup("v0-55555555-btc-0"))
887887
require.False(t, b.Config().AccountsConfig().Lookup("v0-55555555-btc-0").Inactive)
888-
require.True(t, !b.Accounts().lookup("v0-55555555-btc-0").Config().Config.Inactive)
888+
require.False(t, b.Accounts().lookup("v0-55555555-btc-0").Config().Config.Inactive)
889889
require.NotNil(t, b.Config().AccountsConfig().Lookup("v0-55555555-ltc-0"))
890890
require.False(t, b.Config().AccountsConfig().Lookup("v0-55555555-ltc-0").Inactive)
891-
require.True(t, !b.Accounts().lookup("v0-55555555-ltc-0").Config().Config.Inactive)
891+
require.False(t, b.Accounts().lookup("v0-55555555-ltc-0").Config().Config.Inactive)
892892
require.NotNil(t, b.Config().AccountsConfig().Lookup("v0-55555555-eth-0"))
893893
require.False(t, b.Config().AccountsConfig().Lookup("v0-55555555-eth-0").Inactive)
894-
require.True(t, !b.Accounts().lookup("v0-55555555-eth-0").Config().Config.Inactive)
894+
require.False(t, b.Accounts().lookup("v0-55555555-eth-0").Config().Config.Inactive)
895895

896896
// Deactive an account.
897897
require.NoError(t, b.SetAccountActive("v0-55555555-btc-0", false))
898898
checkShownAccountsLen(t, b, 3, 3)
899899
require.True(t, b.Config().AccountsConfig().Lookup("v0-55555555-btc-0").Inactive)
900-
require.False(t, !b.Accounts().lookup("v0-55555555-btc-0").Config().Config.Inactive)
900+
require.True(t, b.Accounts().lookup("v0-55555555-btc-0").Config().Config.Inactive)
901901

902902
// Reactivate.
903903
require.NoError(t, b.SetAccountActive("v0-55555555-btc-0", true))
904904
checkShownAccountsLen(t, b, 3, 3)
905905
require.False(t, b.Config().AccountsConfig().Lookup("v0-55555555-btc-0").Inactive)
906-
require.True(t, !b.Accounts().lookup("v0-55555555-btc-0").Config().Config.Inactive)
906+
require.False(t, b.Accounts().lookup("v0-55555555-btc-0").Config().Config.Inactive)
907907

908908
// Deactivating an ETH account with tokens also removes the tokens
909909
require.NoError(t, b.SetTokenActive("v0-55555555-eth-0", "eth-erc20-usdt", true))
910910
require.NoError(t, b.SetTokenActive("v0-55555555-eth-0", "eth-erc20-bat", true))
911911
checkShownAccountsLen(t, b, 5, 3)
912912
require.NoError(t, b.SetAccountActive("v0-55555555-eth-0", false))
913913
checkShownAccountsLen(t, b, 5, 3)
914-
require.False(t, !b.Accounts().lookup("v0-55555555-eth-0").Config().Config.Inactive)
915-
require.False(t, !b.Accounts().lookup("v0-55555555-eth-0-eth-erc20-usdt").Config().Config.Inactive)
916-
require.False(t, !b.Accounts().lookup("v0-55555555-eth-0-eth-erc20-bat").Config().Config.Inactive)
914+
require.True(t, b.Accounts().lookup("v0-55555555-eth-0").Config().Config.Inactive)
915+
require.True(t, b.Accounts().lookup("v0-55555555-eth-0-eth-erc20-usdt").Config().Config.Inactive)
916+
require.True(t, b.Accounts().lookup("v0-55555555-eth-0-eth-erc20-bat").Config().Config.Inactive)
917917
// Reactivating restores them again.
918918
require.NoError(t, b.SetAccountActive("v0-55555555-eth-0", true))
919919
checkShownAccountsLen(t, b, 5, 3)
920-
require.True(t, !b.Accounts().lookup("v0-55555555-eth-0").Config().Config.Inactive)
921-
require.True(t, !b.Accounts().lookup("v0-55555555-eth-0-eth-erc20-usdt").Config().Config.Inactive)
922-
require.True(t, !b.Accounts().lookup("v0-55555555-eth-0-eth-erc20-bat").Config().Config.Inactive)
920+
require.False(t, b.Accounts().lookup("v0-55555555-eth-0").Config().Config.Inactive)
921+
require.False(t, b.Accounts().lookup("v0-55555555-eth-0-eth-erc20-usdt").Config().Config.Inactive)
922+
require.False(t, b.Accounts().lookup("v0-55555555-eth-0-eth-erc20-bat").Config().Config.Inactive)
923923

924924
// Deactivate all accounts.
925925
require.NoError(t, b.SetAccountActive("v0-55555555-btc-0", false))

backend/aopp_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestAOPPSuccess(t *testing.T) {
154154
for _, test := range tests {
155155
test := test
156156
t.Run("", func(t *testing.T) {
157-
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
157+
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
158158
require.Equal(t, "POST", r.Method)
159159
require.Equal(t,
160160
[]string{"application/json"},
@@ -168,7 +168,8 @@ func TestAOPPSuccess(t *testing.T) {
168168
string(body),
169169
)
170170
w.WriteHeader(http.StatusNoContent)
171-
}))
171+
})
172+
server := httptest.NewServer(handler)
172173
defer server.Close()
173174

174175
b := newBackend(t, testnetDisabled, regtestDisabled)
@@ -313,7 +314,7 @@ func TestAOPPSuccess(t *testing.T) {
313314
params := defaultParams()
314315
b.registerKeystore(makeKeystore(t, scriptTypeRef(signing.ScriptTypeP2WPKH), keystoreHelper.ExtendedPublicKey))
315316
fingerprint, err := b.keystore.RootFingerprint()
316-
require.Nil(t, err)
317+
require.NoError(t, err)
317318
b.SetWatchonly(fingerprint, true)
318319
b.DeregisterKeystore()
319320

backend/backend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func TestRegisterKeystore(t *testing.T) {
403403
require.Equal(t, rootFingerprint1, []byte(b.Config().AccountsConfig().Keystores[0].RootFingerprint))
404404
// LastConnected might not be `time.Now()` anymore as some time may have passed in the unit
405405
// tests, but we check that it was set and recent.
406-
require.True(t, time.Since(b.Config().AccountsConfig().Keystores[0].LastConnected) < 10*time.Second)
406+
require.Less(t, time.Since(b.Config().AccountsConfig().Keystores[0].LastConnected), 10*time.Second)
407407

408408
// Deregistering the keystore leaves the loaded accounts (watchonly), and leaves the persisted
409409
// accounts and keystores.

backend/banners/banners_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,24 @@ import (
2525
)
2626

2727
func TestInit(t *testing.T) {
28-
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
28+
handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
2929
// Test request parameters
3030
_, err := rw.Write([]byte(`
31-
{
32-
"bitbox01": {
33-
"id": "some-id",
34-
"message": {
35-
"en": "some-msg"
36-
},
37-
"link": {
38-
"href": "some-link"
39-
}
40-
}
41-
}
31+
{
32+
"bitbox01": {
33+
"id": "some-id",
34+
"message": {
35+
"en": "some-msg"
36+
},
37+
"link": {
38+
"href": "some-link"
39+
}
40+
}
41+
}
4242
`))
4343
require.NoError(t, err)
44-
}))
44+
})
45+
server := httptest.NewServer(handler)
4546
defer server.Close()
4647

4748
banners := NewBanners()

backend/bitsurance/bitsurance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ func TestBitsuranceGetId(t *testing.T) {
5757
},
5858
}
5959
id, err := GetBitsuranceId(mockedInterface)
60-
assert.NoError(t, err)
60+
require.NoError(t, err)
6161
assert.Equal(t, expectedId, id)
6262
}

backend/coins/btc/account_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ func TestInsuredAccountAddresses(t *testing.T) {
164164
require.NoError(t, account.Initialize())
165165

166166
// check the number of available addresses for native and wrapped segwit.
167-
require.Equal(t, len(account.GetUnusedReceiveAddresses()[0].Addresses), 20)
168-
require.Equal(t, *account.GetUnusedReceiveAddresses()[0].ScriptType, signing.ScriptTypeP2WPKHP2SH)
169-
require.Equal(t, len(account.GetUnusedReceiveAddresses()[1].Addresses), 20)
170-
require.Equal(t, *account.GetUnusedReceiveAddresses()[1].ScriptType, signing.ScriptTypeP2WPKH)
167+
require.Len(t, account.GetUnusedReceiveAddresses()[0].Addresses, 20)
168+
require.Equal(t, signing.ScriptTypeP2WPKHP2SH, *account.GetUnusedReceiveAddresses()[0].ScriptType)
169+
require.Len(t, account.GetUnusedReceiveAddresses()[1].Addresses, 20)
170+
require.Equal(t, signing.ScriptTypeP2WPKH, *account.GetUnusedReceiveAddresses()[1].ScriptType)
171171

172172
// Create a new insured account.
173173
account2 := mockAccount(t, &config.Account{
@@ -180,9 +180,9 @@ func TestInsuredAccountAddresses(t *testing.T) {
180180
require.NoError(t, account2.Initialize())
181181

182182
// native segwit is the only address type available.
183-
require.Equal(t, len(account2.GetUnusedReceiveAddresses()), 1)
184-
require.Equal(t, len(account2.GetUnusedReceiveAddresses()[0].Addresses), 20)
185-
require.Equal(t, *account2.GetUnusedReceiveAddresses()[0].ScriptType, signing.ScriptTypeP2WPKH)
183+
require.Len(t, account2.GetUnusedReceiveAddresses(), 1)
184+
require.Len(t, account2.GetUnusedReceiveAddresses()[0].Addresses, 20)
185+
require.Equal(t, signing.ScriptTypeP2WPKH, *account2.GetUnusedReceiveAddresses()[0].ScriptType)
186186

187187
}
188188

0 commit comments

Comments
 (0)