Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: DeterminateSystems/flakehub-cache-action@main
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.23"
check-latest: true
- name: run lint
run: nix develop -c make lint
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: DeterminateSystems/flakehub-cache-action@main
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.23"
check-latest: true
cache: true
cache-dependency-path: store/go.sum
Expand Down
6 changes: 0 additions & 6 deletions .gitpod.yml

This file was deleted.

148 changes: 132 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,150 @@
version: "2"
run:
build-tags:
- rocksdb
concurrency: 4
sort-results: true
allow-parallel-runners: true
tests: true

allow-parallel-runners: true
linters:
disable-all: true
default: none
enable:
- copyloopvar
- dogsled
- dupl
- errcheck
- exportloopref
- errorlint
- goconst
- gocritic
- gofumpt
- revive
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- staticcheck
- stylecheck
- typecheck
- nolintlint
- revive
- staticcheck
- thelper
- unconvert
- unused
- nolintlint
settings:
dogsled:
max-blank-identifiers: 6
gocritic:
disabled-checks:
- regexpMust
- appendAssign
- ifElseChain
gosec:
excludes:
- G101
- G107
- G404
confidence: medium
misspell:
locale: US
nolintlint:
require-explanation: true
require-specific: false
allow-unused: false
revive:
rules:
- name: redefines-builtin-id
disabled: true
- name: exported
severity: error
disabled: false
staticcheck:
checks:
- all
unused:
local-variables-are-used: false
exclusions:
generated: lax
presets:
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- staticcheck
text: 'ST1000:'
- linters:
- revive
text: 'or be unexported' # don't report types that have no comments at all. there are way too many of these.
- linters:
- staticcheck
text: 'ST1003:'
- linters:
- staticcheck
text: 'ST1016:'
- linters:
- staticcheck
path: migrations
text: 'SA1019:'
- linters:
- staticcheck
text: 'SA1019: codec.NewAminoCodec is deprecated'
- linters:
- staticcheck
text: 'SA1019: legacybech32.MustMarshalPubKey'
- linters:
- staticcheck
text: 'SA1019: legacybech32.MarshalPubKey'
- linters:
- staticcheck
text: 'SA1019: legacybech32.UnmarshalPubKey'
- linters:
- staticcheck
text: 'SA1019: params.SendEnabled is deprecated'
- linters:
- gosec
text: 'G115: integer overflow conversion'
- linters:
- nolintlint
text: leading space
paths:
- server/grpc/gogoreflection/fix_registration.go
- fix_registration.go
- .*\.pb\.go$
- .*\.pb\.gw\.go$
- .*\.pulsar\.go$
- crypto/keys/secp256k1/internal/*
- types/coin_regex.go
- testutil/testdata
- x/params
- x/crisis
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 10000
max-same-issues: 10000
formatters:
enable:
- gci
- gofumpt
settings:
gci:
sections:
- standard
- default
- prefix(cosmossdk.io)
- prefix(github.com/cosmos/cosmos-sdk)
custom-order: true
gofumpt:
extra-rules: true
exclusions:

generated: lax
paths:
- server/grpc/gogoreflection/fix_registration.go
- fix_registration.go
- .*\.pb\.go$
- .*\.pb\.gw\.go$
- .*\.pulsar\.go$
- crypto/keys/secp256k1/internal/*
- types/coin_regex.go
- testutil/testdata
- x/params
- x/crisis
- third_party$
- builtin$
- examples$
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# Changelog

## [v1.1.2] - 2025-05-28

* Make `Iterator` and `Batch` interfaces more flexible by a type alias
* Update deps to the latest versions
* Update linter for general code cleanup

## [v1.1.1] - 2024-12-19

* [#120](https://github.com/cosmos/cosmos-db/pull/120) Skip unwanted logs from PebbleDB

## [v1.1.0] - 2024-11-22

* Allow full control in rocksdb opening
* Make `Iteractor` and `Batch` interfaces more flexible by a type alias
* Remove build tag for PebbleDB

## [v1.0.2] - 2024-02-26

* Downgrade Go version in go.mod to 1.19
* Downgrade Go version in `go.mod` to 1.19

## [v1.0.1] - 2024-02-25

Expand Down
18 changes: 8 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,20 @@ test-rocksdb:
@echo "--> Running go test"
@go test $(PACKAGES) -tags rocksdb -v

golangci_version=v1.55.0
golangci_version=v2.1.6

#? lint-install: Install golangci-lint
lint-install:
@echo "--> Installing golangci-lint $(golangci_version)"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(golangci_version)
.PHONY: lint-install

lint:
lint: lint-install
@echo "--> Running linter"
$(MAKE) lint-install
@golangci-lint run
@go mod verify
.PHONY: lint

format:
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofumpt -w -l .
find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs golangci-lint run --fix .
.PHONY: format
lint-fix: lint-install
@echo "--> Running linter"
@golangci-lint run --fix
.PHONY: lint lint-fix

45 changes: 28 additions & 17 deletions backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// Register a test backend for PrefixDB as well, with some unrelated junk data
func init() {
registerDBCreator("prefixdb", func(name, dir string, opts Options) (DB, error) {
mdb := NewMemDB()
mdb.Set([]byte("a"), []byte{1}) //nolint:errcheck
mdb.Set([]byte("b"), []byte{2}) //nolint:errcheck
mdb.Set([]byte("t"), []byte{20}) //nolint:errcheck
mdb.Set([]byte("test"), []byte{0}) //nolint:errcheck
mdb.Set([]byte("u"), []byte{21}) //nolint:errcheck
mdb.Set([]byte("z"), []byte{26}) //nolint:errcheck
_ = mdb.Set([]byte("a"), []byte{1})
_ = mdb.Set([]byte("b"), []byte{2})
_ = mdb.Set([]byte("t"), []byte{20})
_ = mdb.Set([]byte("test"), []byte{0})
_ = mdb.Set([]byte("u"), []byte{21})
_ = mdb.Set([]byte("z"), []byte{26})
return NewPrefixDB(mdb, []byte("test/")), nil
}, false)
}
Expand All @@ -33,6 +32,8 @@ func cleanupDBDir(dir, name string) {
}

func testBackendGetSetDelete(t *testing.T, backend BackendType) {
t.Helper()

// Default
dirname, err := os.MkdirTemp("", fmt.Sprintf("test_backend_%s_", backend))
require.Nil(t, err)
Expand Down Expand Up @@ -149,7 +150,7 @@ func TestGoLevelDBBackend(t *testing.T) {
defer cleanupDBDir("", name)

_, ok := db.(*GoLevelDB)
assert.True(t, ok)
require.True(t, ok)
}

func TestDBIterator(t *testing.T) {
Expand All @@ -161,6 +162,8 @@ func TestDBIterator(t *testing.T) {
}

func testDBIterator(t *testing.T, backend BackendType) {
t.Helper()

name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, backend, dir)
Expand Down Expand Up @@ -317,13 +320,15 @@ func testDBIterator(t *testing.T, backend BackendType) {
}

func verifyIterator(t *testing.T, itr Iterator, expected []int64, msg string) {
t.Helper()

var list []int64
for itr.Valid() {
key := itr.Key()
list = append(list, bytes2Int64(key))
itr.Next()
}
assert.Equal(t, expected, list, msg)
require.Equal(t, expected, list, msg)
}

func TestDBBatchGetByteSize(t *testing.T) {
Expand All @@ -335,6 +340,8 @@ func TestDBBatchGetByteSize(t *testing.T) {
}

func testDBBatchGetByteSize(t *testing.T, backend BackendType) {
t.Helper()

name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, backend, dir)
Expand All @@ -346,15 +353,15 @@ func testDBBatchGetByteSize(t *testing.T, backend BackendType) {
batchSize, err := batch.GetByteSize()
require.NoError(t, err)
// size of newly created batch should be 0 or negligible because of the metadata in the batch,
// for example peppble's batchHeaderLen is 12 so
// peppble's batch size will always be equal or greater than 12 even for empty batch
// for example, pebble's batchHeaderLen is 12, so
// pebble's batch size will always be equal or greater than 12 even for empty batches
require.LessOrEqual(t, batchSize, 32)

totalSizeOfKeyAndValue := 0
// set 100 random keys and values
for i := 0; i < 100; i++ {
keySize := rand.Intn(32) + 1 //nolint:gosec
valueSize := rand.Intn(32) + 1 //nolint:gosec
keySize := rand.Intn(32) + 1
valueSize := rand.Intn(32) + 1
totalSizeOfKeyAndValue += keySize + valueSize
require.NoError(t, batch.Set([]byte(randStr(keySize)), []byte(randStr(valueSize))))
}
Expand Down Expand Up @@ -382,6 +389,8 @@ func TestDBBatchOperations(t *testing.T) {
}

func testDBBatchOperations(t *testing.T, backend BackendType) {
t.Helper()

name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()
db, err := NewDB(name, backend, dir)
Expand Down Expand Up @@ -441,10 +450,10 @@ func testDBBatchOperations(t *testing.T, backend BackendType) {
require.NoError(t, err)
assertKeyValues(t, db, map[string][]byte{"a": {1}, "b": {2}})

// it should be possible to close an empty batch, and to re-close a closed batch
// it should be possible to close an empty batch and to re-close a closed batch
batch = db.NewBatch()
batch.Close()
batch.Close()
require.NoError(t, batch.Close())
require.NoError(t, batch.Close())

// all other operations on a closed batch should error
require.Error(t, batch.Set([]byte("a"), []byte{9}))
Expand All @@ -454,6 +463,8 @@ func testDBBatchOperations(t *testing.T, backend BackendType) {
}

func assertKeyValues(t *testing.T, db DB, expect map[string][]byte) {
t.Helper()

iter, err := db.Iterator(nil, nil)
require.NoError(t, err)
defer iter.Close()
Expand All @@ -464,5 +475,5 @@ func assertKeyValues(t *testing.T, db DB, expect map[string][]byte) {
actual[string(iter.Key())] = iter.Value()
}

assert.Equal(t, expect, actual)
require.Equal(t, expect, actual)
}
Loading
Loading