Skip to content

Commit

Permalink
feat(core): add coretest package (#20487)
Browse files Browse the repository at this point in the history
Co-authored-by: unknown unknown <unknown@unknown>
  • Loading branch information
testinginprod and unknown unknown authored Jun 5, 2024
1 parent 80ba18e commit fe22e9a
Show file tree
Hide file tree
Showing 53 changed files with 641 additions and 375 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ updates:
labels:
- "A:automerge"
- dependencies
- package-ecosystem: gomod
directory: "/core/testing"
schedule:
interval: weekly
day: thursday
time: "01:30"
labels:
- "A:automerge"
- dependencies
- package-ecosystem: gomod
directory: "/depinject"
schedule:
Expand Down
2 changes: 2 additions & 0 deletions .github/pr_labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- store/**/*
"C:collections":
- collections/**/*
"C:core/testing":
- core/testing/**/*
"C:log":
- log/*
"C:orm":
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,36 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: core/
test-coretesting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
check-latest: true
cache: true
cache-dependency-path: core/testing/go.sum
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
core/testing/**/*.go
core/testing/go.mod
core/testing/go.sum
- name: tests
if: env.GIT_DIFF
run: |
cd core/testing
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: core/testing/

test-depinject:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ replace github.com/cosmos/cosmos-sdk => ./../../
replace (
cosmossdk.io/api => ./../../api
cosmossdk.io/core => ./../../core
cosmossdk.io/core/testing => ../../core/testing
cosmossdk.io/depinject => ./../../depinject
cosmossdk.io/log => ./../../log
cosmossdk.io/store => ./../../store
Expand Down
41 changes: 4 additions & 37 deletions collections/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,16 @@ import (
"math"
"testing"

db "github.com/cosmos/cosmos-db"
"github.com/stretchr/testify/require"

"cosmossdk.io/core/store"
"cosmossdk.io/core/testing"
)

type testStore struct {
db db.DB
}

func (t testStore) OpenKVStore(ctx context.Context) store.KVStore {
return t
}

func (t testStore) Get(key []byte) ([]byte, error) {
return t.db.Get(key)
}

func (t testStore) Has(key []byte) (bool, error) {
return t.db.Has(key)
}

func (t testStore) Set(key, value []byte) error {
return t.db.Set(key, value)
}

func (t testStore) Delete(key []byte) error {
return t.db.Delete(key)
}

func (t testStore) Iterator(start, end []byte) (store.Iterator, error) {
return t.db.Iterator(start, end)
}

func (t testStore) ReverseIterator(start, end []byte) (store.Iterator, error) {
return t.db.ReverseIterator(start, end)
}

var _ store.KVStore = testStore{}

func deps() (store.KVStoreService, context.Context) {
kv := db.NewMemDB()
return &testStore{kv}, context.Background()
ctx := coretesting.Context()
kv := coretesting.KVStoreService(ctx, "test")
return kv, ctx
}

func TestPrefix(t *testing.T) {
Expand Down
61 changes: 0 additions & 61 deletions collections/colltest/store.go

This file was deleted.

42 changes: 11 additions & 31 deletions collections/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,19 @@ module cosmossdk.io/collections
go 1.21

require (
cosmossdk.io/core v0.11.0
github.com/cosmos/cosmos-db v1.0.2
cosmossdk.io/core v0.12.0
cosmossdk.io/core/testing v0.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.9.0
pgregory.net/rapid v1.1.0
)

require (
cosmossdk.io/api v0.7.5 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/onsi/gomega v1.20.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/cosmos/gogoproto v1.4.12 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tidwall/btree v1.7.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
Expand All @@ -50,3 +25,8 @@ require (
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace (
cosmossdk.io/core => ../core
cosmossdk.io/core/testing => ../core/testing
)
Loading

0 comments on commit fe22e9a

Please sign in to comment.