Skip to content

Commit ecbedc4

Browse files
authored
CI: Enable linting for tests (#1632)
* use linter for tests * fix lint * remove failing AddBlock(&genBlock) from TestDeleteTransactions
1 parent 6dce903 commit ecbedc4

18 files changed

+74
-68
lines changed

Diff for: .golangci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
run:
22
timeout: 5m
3-
tests: false
3+
tests: true
44

55
linters:
66
disable-all: true
@@ -66,4 +66,4 @@ issues:
6666

6767
# revive: ignore some rules
6868
- "^unused-parameter: parameter"
69-
- "^package-comments: should have a package comment"
69+
- "^package-comments: should have a package comment"

Diff for: api/app_boxes_fixtures_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import (
66
"fmt"
77
"testing"
88

9-
"github.com/algorand/indexer/v3/idb/postgres"
109
"github.com/stretchr/testify/require"
1110

1211
"github.com/algorand/avm-abi/apps"
12+
"github.com/algorand/indexer/v3/idb/postgres"
13+
"github.com/algorand/indexer/v3/util/test"
14+
1315
"github.com/algorand/go-algorand-sdk/v2/crypto"
1416
sdk "github.com/algorand/go-algorand-sdk/v2/types"
15-
"github.com/algorand/indexer/v3/util/test"
1617
)
1718

1819
func goalEncode(t *testing.T, s string) string {
@@ -23,7 +24,7 @@ func goalEncode(t *testing.T, s string) string {
2324
return string(b2)
2425
}
2526

26-
var goalEncodingExamples map[string]string = map[string]string{
27+
var goalEncodingExamples = map[string]string{
2728
"str": "str",
2829
"string": "string",
2930
"int": "42",

Diff for: api/handlers_e2e_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/stretchr/testify/assert"
2020
"github.com/stretchr/testify/require"
2121

22+
"github.com/algorand/avm-abi/apps"
2223
"github.com/algorand/indexer/v3/api/generated/v2"
2324
"github.com/algorand/indexer/v3/idb"
2425
"github.com/algorand/indexer/v3/idb/postgres"
@@ -27,7 +28,6 @@ import (
2728
"github.com/algorand/indexer/v3/util"
2829
"github.com/algorand/indexer/v3/util/test"
2930

30-
"github.com/algorand/avm-abi/apps"
3131
"github.com/algorand/go-algorand-sdk/v2/crypto"
3232
"github.com/algorand/go-algorand-sdk/v2/encoding/json"
3333
sdk "github.com/algorand/go-algorand-sdk/v2/types"
@@ -80,7 +80,7 @@ func setupIdb(t *testing.T, genesis sdk.Genesis) (*postgres.IndexerDb, func()) {
8080
Block: test.MakeGenesisBlock(),
8181
Delta: sdk.LedgerStateDelta{},
8282
}
83-
db.AddBlock(&vb)
83+
require.NoError(t, db.AddBlock(&vb))
8484
require.NoError(t, err)
8585

8686
return db, newShutdownFunc
@@ -1738,6 +1738,7 @@ func TestGetBlockWithCompression(t *testing.T) {
17381738
// we now make sure that compression flag works with other flags.
17391739
notCompressedBlock = getBlockFunc(t, true, false)
17401740
compressedBlock = getBlockFunc(t, true, true)
1741+
require.Equal(t, notCompressedBlock, compressedBlock)
17411742
require.Equal(t, len(*notCompressedBlock.Transactions), 0)
17421743
}
17431744

Diff for: api/handlers_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import (
1717
"github.com/stretchr/testify/mock"
1818
"github.com/stretchr/testify/require"
1919

20-
sdkcrypto "github.com/algorand/go-algorand-sdk/v2/crypto"
21-
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
22-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
2320
"github.com/algorand/indexer/v3/api/generated/v2"
2421
"github.com/algorand/indexer/v3/idb"
2522
"github.com/algorand/indexer/v3/idb/mocks"
2623
"github.com/algorand/indexer/v3/types"
24+
25+
sdkcrypto "github.com/algorand/go-algorand-sdk/v2/crypto"
26+
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
27+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
2728
)
2829

2930
func TestTransactionParamToTransactionFilter(t *testing.T) {
@@ -1187,7 +1188,7 @@ func TestBigNumbers(t *testing.T) {
11871188
c := e.NewContext(req, rec1)
11881189

11891190
// call handler
1190-
tc.callHandler(c, *si)
1191+
require.NoError(t, tc.callHandler(c, *si))
11911192
assert.Equal(t, http.StatusNotFound, rec1.Code)
11921193
bodyStr := rec1.Body.String()
11931194
require.Contains(t, bodyStr, tc.errString)
@@ -1234,7 +1235,7 @@ func TestRewindRoundParameterRejected(t *testing.T) {
12341235
c := e.NewContext(req, rec1)
12351236

12361237
// call handler
1237-
tc.callHandler(c, *si)
1238+
require.NoError(t, tc.callHandler(c, *si))
12381239
assert.Equal(t, http.StatusBadRequest, rec1.Code)
12391240
bodyStr := rec1.Body.String()
12401241
require.Contains(t, bodyStr, tc.errString)

Diff for: api/util_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"github.com/sirupsen/logrus/hooks/test"
1010
"github.com/stretchr/testify/require"
1111

12-
"github.com/algorand/go-algorand-sdk/v2/types"
13-
1412
"github.com/algorand/indexer/v3/idb"
13+
14+
"github.com/algorand/go-algorand-sdk/v2/types"
1515
)
1616

1717
func TestCallWithTimeoutTimesOut(t *testing.T) {

Diff for: cmd/algorand-indexer/daemon_test.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
log "github.com/sirupsen/logrus"
1313
"github.com/spf13/pflag"
1414
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
1516

1617
"github.com/algorand/indexer/v3/config"
1718
"github.com/algorand/indexer/v3/util"
@@ -23,7 +24,7 @@ func TestParameterConfigErrorWhenBothFileTypesArePresent(t *testing.T) {
2324
indexerDataDir := t.TempDir()
2425
for _, configFiletype := range config.FileTypes {
2526
autoloadPath := filepath.Join(indexerDataDir, autoLoadParameterConfigFileName+"."+configFiletype)
26-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
27+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
2728
}
2829

2930
daemonConfig := &daemonConfig{}
@@ -41,7 +42,7 @@ func TestIndexerConfigErrorWhenBothFileTypesArePresent(t *testing.T) {
4142
indexerDataDir := t.TempDir()
4243
for _, configFiletype := range config.FileTypes {
4344
autoloadPath := filepath.Join(indexerDataDir, autoLoadIndexerConfigFileName+"."+configFiletype)
44-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
45+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
4546
}
4647

4748
daemonConfig := &daemonConfig{}
@@ -59,7 +60,7 @@ func TestConfigWithEnableAllParamsExpectError(t *testing.T) {
5960
for _, configFiletype := range config.FileTypes {
6061
indexerDataDir := t.TempDir()
6162
autoloadPath := filepath.Join(indexerDataDir, autoLoadIndexerConfigFileName+"."+configFiletype)
62-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
63+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
6364
daemonConfig := &daemonConfig{}
6465
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
6566
daemonConfig.indexerDataDir = indexerDataDir
@@ -88,7 +89,7 @@ func TestConfigInvalidExpectError(t *testing.T) {
8889
b := bytes.NewBufferString("")
8990
indexerDataDir := t.TempDir()
9091
tempConfigFile := indexerDataDir + "/indexer-alt.yml"
91-
os.WriteFile(tempConfigFile, []byte(";;;"), fs.ModePerm)
92+
require.NoError(t, os.WriteFile(tempConfigFile, []byte(";;;"), fs.ModePerm))
9293
daemonConfig := &daemonConfig{}
9394
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
9495
daemonConfig.indexerDataDir = indexerDataDir
@@ -102,7 +103,7 @@ func TestConfigInvalidExpectError(t *testing.T) {
102103
func TestConfigSpecifiedTwiceExpectError(t *testing.T) {
103104
indexerDataDir := t.TempDir()
104105
tempConfigFile := indexerDataDir + "/indexer.yml"
105-
os.WriteFile(tempConfigFile, []byte{}, fs.ModePerm)
106+
require.NoError(t, os.WriteFile(tempConfigFile, []byte{}, fs.ModePerm))
106107
daemonConfig := &daemonConfig{}
107108
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
108109
daemonConfig.indexerDataDir = indexerDataDir
@@ -120,7 +121,7 @@ func TestLoadAPIConfigGivenAutoLoadAndUserSuppliedExpectError(t *testing.T) {
120121

121122
autoloadPath := filepath.Join(indexerDataDir, autoLoadParameterConfigFileName+"."+configFiletype)
122123
userSuppliedPath := filepath.Join(indexerDataDir, "foobar.yml")
123-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
124+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
124125
cfg := &daemonConfig{}
125126
cfg.indexerDataDir = indexerDataDir
126127
cfg.suppliedAPIConfigFile = userSuppliedPath
@@ -149,7 +150,7 @@ func TestLoadAPIConfigGivenAutoLoadExpectSuccess(t *testing.T) {
149150
indexerDataDir := t.TempDir()
150151

151152
autoloadPath := filepath.Join(indexerDataDir, autoLoadParameterConfigFileName+"."+configFiletype)
152-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
153+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
153154
cfg := &daemonConfig{}
154155
cfg.indexerDataDir = indexerDataDir
155156

@@ -180,7 +181,7 @@ func TestIndexerPidFileCreateFailExpectError(t *testing.T) {
180181
for _, configFiletype := range config.FileTypes {
181182
indexerDataDir := t.TempDir()
182183
autoloadPath := filepath.Join(indexerDataDir, autoLoadIndexerConfigFileName+"."+configFiletype)
183-
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
184+
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
184185

185186
invalidDir := filepath.Join(indexerDataDir, "foo", "bar")
186187
cfg := &daemonConfig{}

Diff for: cmd/validator/core/validator_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"github.com/jarcoal/httpmock"
88
"github.com/stretchr/testify/require"
99

10-
"github.com/algorand/go-algorand-sdk/v2/types"
11-
1210
"github.com/algorand/indexer/v3/api"
11+
12+
"github.com/algorand/go-algorand-sdk/v2/types"
1313
)
1414

1515
type mockProcessor struct {

Diff for: idb/idb_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"github.com/stretchr/testify/assert"
77
"github.com/stretchr/testify/require"
88

9-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
109
"github.com/algorand/indexer/v3/idb"
1110
"github.com/algorand/indexer/v3/util/test"
11+
12+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
1213
)
1314

1415
func TestTxnRowNext(t *testing.T) {

Diff for: idb/postgres/internal/encoding/encoding_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
8-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
9-
itypes "github.com/algorand/indexer/v3/types"
107
"github.com/stretchr/testify/assert"
118
"github.com/stretchr/testify/require"
129

1310
"github.com/algorand/indexer/v3/idb"
1411
"github.com/algorand/indexer/v3/idb/postgres/internal/types"
12+
itypes "github.com/algorand/indexer/v3/types"
13+
14+
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
15+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
1516
)
1617

1718
func TestEncodeSignedTxnWithAD(t *testing.T) {
@@ -42,7 +43,7 @@ func TestEncodeSignedTxnWithAD(t *testing.T) {
4243
var stxn sdk.SignedTxnWithAD
4344
for _, mt := range testTxns {
4445
t.Run(mt.name, func(t *testing.T) {
45-
msgpack.Decode(mt.msgpack, &stxn)
46+
require.NoError(t, msgpack.Decode(mt.msgpack, &stxn))
4647
js := EncodeSignedTxnWithAD(stxn)
4748
require.Equal(t, mt.json, string(js))
4849
})

Diff for: idb/postgres/internal/migrations/convert_account_data/m_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"testing"
77

8-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
98
"github.com/stretchr/testify/assert"
109
"github.com/stretchr/testify/require"
1110

@@ -16,6 +15,8 @@ import (
1615
cad "github.com/algorand/indexer/v3/idb/postgres/internal/migrations/convert_account_data"
1716
pgtest "github.com/algorand/indexer/v3/idb/postgres/internal/testing"
1817
pgutil "github.com/algorand/indexer/v3/idb/postgres/internal/util"
18+
19+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
1920
)
2021

2122
func makeAddress(i int) sdk.Address {

Diff for: idb/postgres/postgres_boxes_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
"github.com/stretchr/testify/require"
1212

1313
"github.com/algorand/avm-abi/apps"
14-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
1514
"github.com/algorand/indexer/v3/idb"
1615
"github.com/algorand/indexer/v3/idb/postgres/internal/encoding"
1716
"github.com/algorand/indexer/v3/idb/postgres/internal/writer"
1817
"github.com/algorand/indexer/v3/util/test"
1918

2019
"github.com/algorand/go-algorand-sdk/v2/protocol"
2120
"github.com/algorand/go-algorand-sdk/v2/protocol/config"
21+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
2222
)
2323

2424
type boxTestComparator func(t *testing.T, db *IndexerDb, appBoxes map[sdk.AppIndex]map[string]string,

Diff for: idb/postgres/postgres_integration_common_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"context"
55
"testing"
66

7-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
8-
"github.com/algorand/indexer/v3/types"
97
"github.com/jackc/pgx/v4/pgxpool"
108
"github.com/stretchr/testify/require"
119

1210
"github.com/algorand/indexer/v3/idb"
1311
pgtest "github.com/algorand/indexer/v3/idb/postgres/internal/testing"
12+
"github.com/algorand/indexer/v3/types"
1413
"github.com/algorand/indexer/v3/util/test"
14+
15+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
1516
)
1617

1718
func setupIdbWithConnectionString(t *testing.T, connStr string, genesis sdk.Genesis) *IndexerDb {
@@ -37,7 +38,7 @@ func setupIdb(t *testing.T, genesis sdk.Genesis) (*IndexerDb, func()) {
3738
Block: test.MakeGenesisBlock(),
3839
Delta: sdk.LedgerStateDelta{},
3940
}
40-
db.AddBlock(&vb)
41+
require.NoError(t, db.AddBlock(&vb))
4142

4243
return db, newShutdownFunc
4344
}

Diff for: idb/postgres/postgres_integration_test.go

+9-14
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/algorand/indexer/v3/types"
1514
"github.com/jackc/pgx/v4"
1615
"github.com/jackc/pgx/v4/pgxpool"
1716
"github.com/stretchr/testify/assert"
1817
"github.com/stretchr/testify/require"
1918

20-
crypto2 "github.com/algorand/go-algorand-sdk/v2/crypto"
21-
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
22-
sdk "github.com/algorand/go-algorand-sdk/v2/types"
19+
"github.com/algorand/go-codec/codec"
2320
"github.com/algorand/indexer/v3/api/generated/v2"
2421
"github.com/algorand/indexer/v3/idb"
2522
"github.com/algorand/indexer/v3/idb/postgres/internal/encoding"
2623
"github.com/algorand/indexer/v3/idb/postgres/internal/schema"
2724
pgtest "github.com/algorand/indexer/v3/idb/postgres/internal/testing"
2825
pgutil "github.com/algorand/indexer/v3/idb/postgres/internal/util"
26+
"github.com/algorand/indexer/v3/types"
2927
"github.com/algorand/indexer/v3/util"
3028
"github.com/algorand/indexer/v3/util/test"
3129

30+
crypto2 "github.com/algorand/go-algorand-sdk/v2/crypto"
3231
"github.com/algorand/go-algorand-sdk/v2/encoding/json"
32+
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
3333
"github.com/algorand/go-algorand-sdk/v2/protocol"
34-
"github.com/algorand/go-codec/codec"
34+
sdk "github.com/algorand/go-algorand-sdk/v2/types"
3535
)
3636

3737
// TestMaxRoundOnUninitializedDB makes sure we return 0 when getting the max round on a new DB.
@@ -1334,7 +1334,7 @@ func TestAddBlockIncrementsMaxRoundAccounted(t *testing.T) {
13341334
Block: block,
13351335
Delta: sdk.LedgerStateDelta{},
13361336
}
1337-
db.AddBlock(&vb)
1337+
require.NoError(t, db.AddBlock(&vb))
13381338

13391339
round, err = db.GetNextRoundToAccount()
13401340
require.NoError(t, err)
@@ -1347,7 +1347,7 @@ func TestAddBlockIncrementsMaxRoundAccounted(t *testing.T) {
13471347
Block: block,
13481348
Delta: sdk.LedgerStateDelta{},
13491349
}
1350-
db.AddBlock(&vb)
1350+
require.NoError(t, db.AddBlock(&vb))
13511351
require.NoError(t, err)
13521352

13531353
round, err = db.GetNextRoundToAccount()
@@ -1361,7 +1361,7 @@ func TestAddBlockIncrementsMaxRoundAccounted(t *testing.T) {
13611361
Block: block,
13621362
Delta: sdk.LedgerStateDelta{},
13631363
}
1364-
db.AddBlock(&vb)
1364+
require.NoError(t, db.AddBlock(&vb))
13651365

13661366
round, err = db.GetNextRoundToAccount()
13671367
require.NoError(t, err)
@@ -1626,7 +1626,7 @@ func TestSearchForInnerTransactionReturnsRootTransaction(t *testing.T) {
16261626
Block: test.MakeGenesisBlock(),
16271627
Delta: sdk.LedgerStateDelta{},
16281628
}
1629-
db.AddBlock(&genblk)
1629+
require.NoError(t, db.AddBlock(&genblk))
16301630
return db.AddBlock(&vb)
16311631
}, nil)
16321632
require.NoError(t, err)
@@ -2186,11 +2186,6 @@ func TestDeleteTransactions(t *testing.T) {
21862186

21872187
txns := []sdk.SignedTxn{}
21882188

2189-
genBlock := types.ValidatedBlock{
2190-
Block: test.MakeGenesisBlock(),
2191-
Delta: sdk.LedgerStateDelta{},
2192-
}
2193-
db.AddBlock(&genBlock)
21942189
// add 4 rounds of txns
21952190
// txnA := test.MakeCreateAppTxn(test.AccountA)
21962191
// txnB := test.MakeCreateAppTxn(test.AccountB)

0 commit comments

Comments
 (0)