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

fix: restore runtime app API registered module discovery #3785

Merged
merged 21 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4f93cdb
fix: restore runtime app API registered modules
jeronimoalbi Nov 28, 2023
44dd09b
ci: fix lint issue with unused argument
jeronimoalbi Nov 28, 2023
a5ce718
tests: fix broken unit tests
jeronimoalbi Nov 28, 2023
46ee7bc
ci: fix linting issue
jeronimoalbi Nov 28, 2023
d54daf8
feat: add support for IBC modules discovery
jeronimoalbi Nov 30, 2023
d9d7c35
fix: correct issue that cause modules not to be discovered
jeronimoalbi Nov 30, 2023
f51da38
feat(pkg/xstrings): add `StringBetween` function
jeronimoalbi Dec 1, 2023
1080248
fix: discover "cosmossdk.io/x" based packages proto files
jeronimoalbi Dec 1, 2023
a8cbc62
feat(pkg/gocmd): add Go mod download support
jeronimoalbi Dec 1, 2023
2f64b04
feat(pkg/cosmosanalysis): add find module support
jeronimoalbi Dec 1, 2023
a708381
refactor(pkg/cosmosanalysis): change Cosmos SDK package path discovery
jeronimoalbi Dec 1, 2023
552cb96
Merge branch 'main' into fix/restore-api-module-discovery
Pantani Dec 1, 2023
8566506
Merge branch 'main' into fix/restore-api-module-discovery
Pantani Dec 1, 2023
ffaa1ec
refactor: add filter function to remove duplicated modules
jeronimoalbi Dec 1, 2023
ccebad7
Merge branch 'main' into fix/restore-api-module-discovery
Pantani Dec 2, 2023
af8086c
chore: TS template updates
clockworkgr Dec 2, 2023
e68e6a4
Merge branch 'main' into fix/restore-api-module-discovery
jeronimoalbi Dec 2, 2023
b9b090a
fix: correct TS imports for generated "cosmossdk.io" module packages
jeronimoalbi Dec 2, 2023
14137e3
tests: add unit tests for the new `pkg/gomodule` functions
jeronimoalbi Dec 3, 2023
0181c5f
refactor: add options to `pkg/cosmosanalysis` Discover function
jeronimoalbi Dec 3, 2023
4bb2cea
fix: Update package.json template
clockworkgr Dec 4, 2023
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
364 changes: 284 additions & 80 deletions ignite/pkg/cosmosanalysis/app/app.go

Large diffs are not rendered by default.

142 changes: 24 additions & 118 deletions ignite/pkg/cosmosanalysis/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func TestFindRegisteredModules(t *testing.T) {
"github.com/cosmos/cosmos-sdk/x/staking",
"github.com/cosmos/cosmos-sdk/x/gov",
"github.com/username/test/x/foo",
"github.com/cosmos/cosmos-sdk/x/auth/tx",
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice",
"github.com/cosmos/cosmos-sdk/client/grpc/node",
}

cases := []struct {
Expand All @@ -110,6 +113,8 @@ func TestFindRegisteredModules(t *testing.T) {
"cosmossdk.io/x/evidence",
"cosmossdk.io/x/feegrant/module",
"cosmossdk.io/x/upgrade",
"github.com/cosmos/cosmos-sdk/x/auth",
"github.com/cosmos/cosmos-sdk/x/auth/tx",
"github.com/cosmos/cosmos-sdk/x/auth/tx/config",
"github.com/cosmos/cosmos-sdk/x/auth/vesting",
"github.com/cosmos/cosmos-sdk/x/authz/module",
Expand All @@ -125,6 +130,8 @@ func TestFindRegisteredModules(t *testing.T) {
"github.com/ignite/mars/x/mars",
"github.com/cosmos/cosmos-sdk/x/gov",
"github.com/username/test/x/foo",
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice",
"github.com/cosmos/cosmos-sdk/client/grpc/node",
},
},
{
Expand Down Expand Up @@ -191,6 +198,9 @@ func TestFindRegisteredModules(t *testing.T) {
path: "testdata/modules/spn",
expectedModules: []string{
"github.com/cosmos/cosmos-sdk/x/auth",
"github.com/cosmos/cosmos-sdk/x/auth/tx",
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice",
"github.com/cosmos/cosmos-sdk/client/grpc/node",
"github.com/cosmos/cosmos-sdk/x/bank",
"github.com/cosmos/cosmos-sdk/x/capability",
"github.com/cosmos/cosmos-sdk/x/staking",
Expand Down Expand Up @@ -239,6 +249,9 @@ func TestFindRegisteredModules(t *testing.T) {
"github.com/cosmos/cosmos-sdk/x/authz",
"github.com/CosmWasm/wasmd/x/wasm",
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts",
"github.com/cosmos/cosmos-sdk/x/auth/tx",
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice",
"github.com/cosmos/cosmos-sdk/client/grpc/node",
},
},
}
Expand All @@ -252,13 +265,16 @@ func TestFindRegisteredModules(t *testing.T) {
}
}

func TestFindKeepersModules(t *testing.T) {
func TestDiscoverModules(t *testing.T) {
basicModules := []string{
"github.com/cosmos/cosmos-sdk/x/auth",
"github.com/cosmos/cosmos-sdk/x/bank",
"github.com/cosmos/cosmos-sdk/x/staking",
"github.com/cosmos/cosmos-sdk/x/gov",
"github.com/username/test/x/foo",
"github.com/cosmos/cosmos-sdk/x/auth/tx",
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice",
"github.com/cosmos/cosmos-sdk/client/grpc/node",
}

cases := []struct {
Expand Down Expand Up @@ -343,6 +359,9 @@ func TestFindKeepersModules(t *testing.T) {
path: "testdata/modules/spn",
expectedModules: []string{
"github.com/cosmos/cosmos-sdk/x/auth",
"github.com/cosmos/cosmos-sdk/x/auth/tx",
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice",
"github.com/cosmos/cosmos-sdk/client/grpc/node",
"github.com/cosmos/cosmos-sdk/x/bank",
"github.com/cosmos/cosmos-sdk/x/capability",
"github.com/cosmos/cosmos-sdk/x/staking",
Expand Down Expand Up @@ -391,6 +410,9 @@ func TestFindKeepersModules(t *testing.T) {
"github.com/cosmos/cosmos-sdk/x/authz",
"github.com/CosmWasm/wasmd/x/wasm",
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts",
"github.com/cosmos/cosmos-sdk/x/auth/tx",
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice",
"github.com/cosmos/cosmos-sdk/client/grpc/node",
},
},
}
Expand All @@ -403,7 +425,7 @@ func TestFindKeepersModules(t *testing.T) {
got := make([]string, 0)
for _, f := range appPkg.Files {
fileImports := goanalysis.FormatImports(f)
modules, err := FindKeepersModules(f, fileImports)
modules, err := DiscoverModules(f, tt.path, fileImports)
require.NoError(t, err)
if modules != nil {
got = append(got, modules...)
Expand All @@ -414,122 +436,6 @@ func TestFindKeepersModules(t *testing.T) {
}
}

func Test_mergeImports(t *testing.T) {
tests := []struct {
name string
blankImports []string
discovered []string
want []string
}{
{
name: "test nil imports",
blankImports: nil,
discovered: nil,
want: nil,
},
{
name: "test empty imports",
blankImports: []string{},
discovered: []string{},
want: []string{},
},
{
name: "test only one blank import",
blankImports: []string{"github.com/cosmos/cosmos-sdk/x/auth"},
discovered: []string{},
want: []string{"github.com/cosmos/cosmos-sdk/x/auth"},
},
{
name: "test only one discovered import",
blankImports: []string{},
discovered: []string{"github.com/cosmos/cosmos-sdk/x/auth"},
want: []string{"github.com/cosmos/cosmos-sdk/x/auth"},
},
{
name: "test only one import",
blankImports: []string{"github.com/cosmos/cosmos-sdk/x/auth"},
discovered: []string{"github.com/cosmos/cosmos-sdk/x/auth/keeper"},
want: []string{"github.com/cosmos/cosmos-sdk/x/auth"},
},
{
name: "test only one keeper import",
blankImports: []string{"github.com/cosmos/cosmos-sdk/x/auth/module"},
discovered: []string{"github.com/cosmos/cosmos-sdk/x/auth/keeper"},
want: []string{"github.com/cosmos/cosmos-sdk/x/auth/module"},
},
{
name: "test two keeper import",
blankImports: []string{
"github.com/cosmos/cosmos-sdk/x/auth/module",
"github.com/cosmos/cosmos-sdk/x/bank/module",
},
discovered: []string{
"github.com/cosmos/cosmos-sdk/x/auth/keeper",
"github.com/cosmos/cosmos-sdk/x/bank/keeper",
},
want: []string{
"github.com/cosmos/cosmos-sdk/x/auth/module",
"github.com/cosmos/cosmos-sdk/x/bank/module",
},
},
{
name: "test two keeper import",
blankImports: []string{
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts",
},
discovered: []string{
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper",
"github.com/cosmos/cosmos-sdk/x/bank/keeper",
},
want: []string{
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts",
"github.com/cosmos/cosmos-sdk/x/bank/keeper",
},
},
{
name: "test keeper imports",
blankImports: []string{
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts",
"cosmossdk.io/x/feegrant/module",
},
discovered: []string{
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/controller/keeper",
"github.com/cosmos/cosmos-sdk/x/bank/keeper",
"cosmossdk.io/x/feegrant/types",
"cosmossdk.io/x/feegrant",
"cosmossdk.io/x/foo",
},
want: []string{
"github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts",
"github.com/cosmos/cosmos-sdk/x/bank/keeper",
"cosmossdk.io/x/feegrant/module",
"cosmossdk.io/x/foo",
},
},
{
name: "test three keeper import",
blankImports: []string{
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts",
"github.com/cosmos/ibc-go/modules/capability",
},
discovered: []string{
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts",
"github.com/cosmos/ibc-go/modules/capability",
},
want: []string{
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts",
"github.com/cosmos/ibc-go/modules/capability",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := mergeImports(tt.blankImports, tt.discovered)
require.ElementsMatch(t, tt.want, got)
})
}
}

func Test_removeKeeperPkgPath(t *testing.T) {
tests := []struct {
name string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module app

go 1.20

require (
cosmossdk.io/api v0.3.1
cosmossdk.io/core v0.5.1
cosmossdk.io/depinject v1.0.0-alpha.3
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.1
github.com/bufbuild/buf v1.23.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.3
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.55.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
google.golang.org/protobuf v1.31.0
)
11 changes: 0 additions & 11 deletions ignite/pkg/cosmosanalysis/app/testdata/modules/crescent/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"path/filepath"

storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/server"

"cosmossdk.io/client/v2/autocli"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -1031,13 +1030,3 @@ func (App) GetSubspace(moduleName string) paramstypes.Subspace {
func (App) SimulationManager() *module.SimulationManager {
return app.sm
}

// RegisterAPIRoutes registers all application module routes with the provided
// API server.
func (App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
app.App.RegisterAPIRoutes(apiSvr, apiConfig)
// register swagger API in app.go so that other applications can override easily
if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {
panic(err)
}
}
29 changes: 29 additions & 0 deletions ignite/pkg/cosmosanalysis/app/testdata/modules/crescent/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module github.com/crescent-network/crescent/v5

go 1.18

require (
github.com/cosmos/cosmos-sdk v0.45.10
github.com/cosmos/ibc-go/v3 v3.4.0
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/golangci/golangci-lint v1.50.1
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.13.0
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
github.com/tendermint/tendermint v0.34.22
github.com/tendermint/tm-db v0.6.7
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c
google.golang.org/grpc v1.50.1
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
)

12 changes: 0 additions & 12 deletions ignite/pkg/cosmosanalysis/app/testdata/modules/gaia/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/server"

"cosmossdk.io/client/v2/autocli"
sdkerrors "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -1096,13 +1094,3 @@ func (GaiaApp) GetSubspace(moduleName string) paramstypes.Subspace {
func (GaiaApp) SimulationManager() *module.SimulationManager {
return app.sm
}

// RegisterAPIRoutes registers all application module routes with the provided
// API server.
func (GaiaApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
app.App.RegisterAPIRoutes(apiSvr, apiConfig)
// register swagger API in app.go so that other applications can override easily
if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {
panic(err)
}
}
28 changes: 28 additions & 0 deletions ignite/pkg/cosmosanalysis/app/testdata/modules/gaia/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module github.com/cosmos/gaia/v14

go 1.20

require (
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.2.0
github.com/cosmos/cosmos-sdk v0.45.16
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4 v4.1.1
github.com/cosmos/ibc-go/v4 v4.4.2
github.com/cosmos/interchain-security/v2 v2.0.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.3
github.com/google/gofuzz v1.2.0
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/ory/dockertest/v3 v3.10.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/tendermint/tendermint v0.34.27
github.com/tendermint/tm-db v0.6.7
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb
google.golang.org/grpc v1.58.2
)
33 changes: 33 additions & 0 deletions ignite/pkg/cosmosanalysis/app/testdata/modules/juno/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module github.com/CosmosContracts/juno/v18

go 1.21

require (
cosmossdk.io/api v0.3.1
cosmossdk.io/errors v1.0.0
cosmossdk.io/log v1.2.1
cosmossdk.io/math v1.1.2
cosmossdk.io/tools/rosetta v0.2.1
github.com/CosmWasm/wasmd v0.45.0
github.com/CosmWasm/wasmvm v1.5.0
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.1
github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.0.0
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20230803181732-7c8f814d3b79
github.com/cosmos/ibc-go/v7 v7.3.1
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/prometheus/client_golang v1.16.0
github.com/skip-mev/pob v1.0.4
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98
google.golang.org/grpc v1.58.3
gopkg.in/yaml.v2 v2.4.0
)
Loading
Loading