Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Enable linting for tests #1632

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
timeout: 5m
tests: false
tests: true

linters:
disable-all: true
Expand Down Expand Up @@ -66,4 +66,4 @@ issues:

# revive: ignore some rules
- "^unused-parameter: parameter"
- "^package-comments: should have a package comment"
- "^package-comments: should have a package comment"
7 changes: 4 additions & 3 deletions api/app_boxes_fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"fmt"
"testing"

"github.com/algorand/indexer/v3/idb/postgres"
"github.com/stretchr/testify/require"

"github.com/algorand/avm-abi/apps"
"github.com/algorand/indexer/v3/idb/postgres"
"github.com/algorand/indexer/v3/util/test"

"github.com/algorand/go-algorand-sdk/v2/crypto"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
"github.com/algorand/indexer/v3/util/test"
)

func goalEncode(t *testing.T, s string) string {
Expand All @@ -23,7 +24,7 @@ func goalEncode(t *testing.T, s string) string {
return string(b2)
}

var goalEncodingExamples map[string]string = map[string]string{
var goalEncodingExamples = map[string]string{
"str": "str",
"string": "string",
"int": "42",
Expand Down
5 changes: 3 additions & 2 deletions api/handlers_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/algorand/avm-abi/apps"
"github.com/algorand/indexer/v3/api/generated/v2"
"github.com/algorand/indexer/v3/idb"
"github.com/algorand/indexer/v3/idb/postgres"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/algorand/indexer/v3/util"
"github.com/algorand/indexer/v3/util/test"

"github.com/algorand/avm-abi/apps"
"github.com/algorand/go-algorand-sdk/v2/crypto"
"github.com/algorand/go-algorand-sdk/v2/encoding/json"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
Expand Down Expand Up @@ -80,7 +80,7 @@ func setupIdb(t *testing.T, genesis sdk.Genesis) (*postgres.IndexerDb, func()) {
Block: test.MakeGenesisBlock(),
Delta: sdk.LedgerStateDelta{},
}
db.AddBlock(&vb)
require.NoError(t, db.AddBlock(&vb))
require.NoError(t, err)

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

Expand Down
11 changes: 6 additions & 5 deletions api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

sdkcrypto "github.com/algorand/go-algorand-sdk/v2/crypto"
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
"github.com/algorand/indexer/v3/api/generated/v2"
"github.com/algorand/indexer/v3/idb"
"github.com/algorand/indexer/v3/idb/mocks"
"github.com/algorand/indexer/v3/types"

sdkcrypto "github.com/algorand/go-algorand-sdk/v2/crypto"
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
)

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

// call handler
tc.callHandler(c, *si)
require.NoError(t, tc.callHandler(c, *si))
assert.Equal(t, http.StatusNotFound, rec1.Code)
bodyStr := rec1.Body.String()
require.Contains(t, bodyStr, tc.errString)
Expand Down Expand Up @@ -1234,7 +1235,7 @@ func TestRewindRoundParameterRejected(t *testing.T) {
c := e.NewContext(req, rec1)

// call handler
tc.callHandler(c, *si)
require.NoError(t, tc.callHandler(c, *si))
assert.Equal(t, http.StatusBadRequest, rec1.Code)
bodyStr := rec1.Body.String()
require.Contains(t, bodyStr, tc.errString)
Expand Down
4 changes: 2 additions & 2 deletions api/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"

"github.com/algorand/go-algorand-sdk/v2/types"

"github.com/algorand/indexer/v3/idb"

"github.com/algorand/go-algorand-sdk/v2/types"
)

func TestCallWithTimeoutTimesOut(t *testing.T) {
Expand Down
17 changes: 9 additions & 8 deletions cmd/algorand-indexer/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

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

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

daemonConfig := &daemonConfig{}
Expand All @@ -59,7 +60,7 @@ func TestConfigWithEnableAllParamsExpectError(t *testing.T) {
for _, configFiletype := range config.FileTypes {
indexerDataDir := t.TempDir()
autoloadPath := filepath.Join(indexerDataDir, autoLoadIndexerConfigFileName+"."+configFiletype)
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
daemonConfig := &daemonConfig{}
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
daemonConfig.indexerDataDir = indexerDataDir
Expand Down Expand Up @@ -88,7 +89,7 @@ func TestConfigInvalidExpectError(t *testing.T) {
b := bytes.NewBufferString("")
indexerDataDir := t.TempDir()
tempConfigFile := indexerDataDir + "/indexer-alt.yml"
os.WriteFile(tempConfigFile, []byte(";;;"), fs.ModePerm)
require.NoError(t, os.WriteFile(tempConfigFile, []byte(";;;"), fs.ModePerm))
daemonConfig := &daemonConfig{}
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
daemonConfig.indexerDataDir = indexerDataDir
Expand All @@ -102,7 +103,7 @@ func TestConfigInvalidExpectError(t *testing.T) {
func TestConfigSpecifiedTwiceExpectError(t *testing.T) {
indexerDataDir := t.TempDir()
tempConfigFile := indexerDataDir + "/indexer.yml"
os.WriteFile(tempConfigFile, []byte{}, fs.ModePerm)
require.NoError(t, os.WriteFile(tempConfigFile, []byte{}, fs.ModePerm))
daemonConfig := &daemonConfig{}
daemonConfig.flags = pflag.NewFlagSet("indexer", 0)
daemonConfig.indexerDataDir = indexerDataDir
Expand All @@ -120,7 +121,7 @@ func TestLoadAPIConfigGivenAutoLoadAndUserSuppliedExpectError(t *testing.T) {

autoloadPath := filepath.Join(indexerDataDir, autoLoadParameterConfigFileName+"."+configFiletype)
userSuppliedPath := filepath.Join(indexerDataDir, "foobar.yml")
os.WriteFile(autoloadPath, []byte{}, fs.ModePerm)
require.NoError(t, os.WriteFile(autoloadPath, []byte{}, fs.ModePerm))
cfg := &daemonConfig{}
cfg.indexerDataDir = indexerDataDir
cfg.suppliedAPIConfigFile = userSuppliedPath
Expand Down Expand Up @@ -149,7 +150,7 @@ func TestLoadAPIConfigGivenAutoLoadExpectSuccess(t *testing.T) {
indexerDataDir := t.TempDir()

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

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

invalidDir := filepath.Join(indexerDataDir, "foo", "bar")
cfg := &daemonConfig{}
Expand Down
4 changes: 2 additions & 2 deletions cmd/validator/core/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/require"

"github.com/algorand/go-algorand-sdk/v2/types"

"github.com/algorand/indexer/v3/api"

"github.com/algorand/go-algorand-sdk/v2/types"
)

type mockProcessor struct {
Expand Down
3 changes: 2 additions & 1 deletion idb/idb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

sdk "github.com/algorand/go-algorand-sdk/v2/types"
"github.com/algorand/indexer/v3/idb"
"github.com/algorand/indexer/v3/util/test"

sdk "github.com/algorand/go-algorand-sdk/v2/types"
)

func TestTxnRowNext(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions idb/postgres/internal/encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"fmt"
"testing"

"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
itypes "github.com/algorand/indexer/v3/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/algorand/indexer/v3/idb"
"github.com/algorand/indexer/v3/idb/postgres/internal/types"
itypes "github.com/algorand/indexer/v3/types"

"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
)

func TestEncodeSignedTxnWithAD(t *testing.T) {
Expand Down Expand Up @@ -42,7 +43,7 @@ func TestEncodeSignedTxnWithAD(t *testing.T) {
var stxn sdk.SignedTxnWithAD
for _, mt := range testTxns {
t.Run(mt.name, func(t *testing.T) {
msgpack.Decode(mt.msgpack, &stxn)
require.NoError(t, msgpack.Decode(mt.msgpack, &stxn))
js := EncodeSignedTxnWithAD(stxn)
require.Equal(t, mt.json, string(js))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"testing"

sdk "github.com/algorand/go-algorand-sdk/v2/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -16,6 +15,8 @@ import (
cad "github.com/algorand/indexer/v3/idb/postgres/internal/migrations/convert_account_data"
pgtest "github.com/algorand/indexer/v3/idb/postgres/internal/testing"
pgutil "github.com/algorand/indexer/v3/idb/postgres/internal/util"

sdk "github.com/algorand/go-algorand-sdk/v2/types"
)

func makeAddress(i int) sdk.Address {
Expand Down
2 changes: 1 addition & 1 deletion idb/postgres/postgres_boxes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"github.com/stretchr/testify/require"

"github.com/algorand/avm-abi/apps"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
"github.com/algorand/indexer/v3/idb"
"github.com/algorand/indexer/v3/idb/postgres/internal/encoding"
"github.com/algorand/indexer/v3/idb/postgres/internal/writer"
"github.com/algorand/indexer/v3/util/test"

"github.com/algorand/go-algorand-sdk/v2/protocol"
"github.com/algorand/go-algorand-sdk/v2/protocol/config"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
)

type boxTestComparator func(t *testing.T, db *IndexerDb, appBoxes map[sdk.AppIndex]map[string]string,
Expand Down
7 changes: 4 additions & 3 deletions idb/postgres/postgres_integration_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"testing"

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

"github.com/algorand/indexer/v3/idb"
pgtest "github.com/algorand/indexer/v3/idb/postgres/internal/testing"
"github.com/algorand/indexer/v3/types"
"github.com/algorand/indexer/v3/util/test"

sdk "github.com/algorand/go-algorand-sdk/v2/types"
)

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

return db, newShutdownFunc
}
Expand Down
23 changes: 9 additions & 14 deletions idb/postgres/postgres_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import (
"testing"
"time"

"github.com/algorand/indexer/v3/types"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

crypto2 "github.com/algorand/go-algorand-sdk/v2/crypto"
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
"github.com/algorand/go-codec/codec"
"github.com/algorand/indexer/v3/api/generated/v2"
"github.com/algorand/indexer/v3/idb"
"github.com/algorand/indexer/v3/idb/postgres/internal/encoding"
"github.com/algorand/indexer/v3/idb/postgres/internal/schema"
pgtest "github.com/algorand/indexer/v3/idb/postgres/internal/testing"
pgutil "github.com/algorand/indexer/v3/idb/postgres/internal/util"
"github.com/algorand/indexer/v3/types"
"github.com/algorand/indexer/v3/util"
"github.com/algorand/indexer/v3/util/test"

crypto2 "github.com/algorand/go-algorand-sdk/v2/crypto"
"github.com/algorand/go-algorand-sdk/v2/encoding/json"
"github.com/algorand/go-algorand-sdk/v2/encoding/msgpack"
"github.com/algorand/go-algorand-sdk/v2/protocol"
"github.com/algorand/go-codec/codec"
sdk "github.com/algorand/go-algorand-sdk/v2/types"
)

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

round, err = db.GetNextRoundToAccount()
require.NoError(t, err)
Expand All @@ -1347,7 +1347,7 @@ func TestAddBlockIncrementsMaxRoundAccounted(t *testing.T) {
Block: block,
Delta: sdk.LedgerStateDelta{},
}
db.AddBlock(&vb)
require.NoError(t, db.AddBlock(&vb))
require.NoError(t, err)

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

round, err = db.GetNextRoundToAccount()
require.NoError(t, err)
Expand Down Expand Up @@ -1626,7 +1626,7 @@ func TestSearchForInnerTransactionReturnsRootTransaction(t *testing.T) {
Block: test.MakeGenesisBlock(),
Delta: sdk.LedgerStateDelta{},
}
db.AddBlock(&genblk)
require.NoError(t, db.AddBlock(&genblk))
return db.AddBlock(&vb)
}, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -2186,11 +2186,6 @@ func TestDeleteTransactions(t *testing.T) {

txns := []sdk.SignedTxn{}

genBlock := types.ValidatedBlock{
Block: test.MakeGenesisBlock(),
Delta: sdk.LedgerStateDelta{},
}
db.AddBlock(&genBlock)
// add 4 rounds of txns
// txnA := test.MakeCreateAppTxn(test.AccountA)
// txnB := test.MakeCreateAppTxn(test.AccountB)
Expand Down
Loading
Loading