Skip to content

Commit

Permalink
fix(cosmosgen): fix tests (#2175)
Browse files Browse the repository at this point in the history
* fix(cosmosgen): fix tests

* fix module>proto pkg discovery

* Apply suggestions from code review
  • Loading branch information
ilgooz authored Mar 19, 2022
1 parent 797ec0b commit 420d0d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions integration/cosmosgen/cosmosgen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (

func TestCosmosGen(t *testing.T) {
var (
env = envtest.New(t)
path = env.Scaffold("blog")
env = envtest.New(t)
path = env.Scaffold("blog")
dirGenerated = filepath.Join(path, "vue/src/store/generated")
)

const (
withMsgModuleName = "withmsg"
withoutMsgModuleName = "withoutmsg"
Expand Down Expand Up @@ -91,6 +93,8 @@ func TestCosmosGen(t *testing.T) {
)),
))

require.NoError(t, os.RemoveAll(dirGenerated))

env.Must(env.Exec("generate vuex",
step.NewSteps(step.New(
step.Exec(
Expand All @@ -105,7 +109,6 @@ func TestCosmosGen(t *testing.T) {

var expectedCosmosModules = []string{
"cosmos.auth.v1beta1",
"cosmos.authz.v1beta1",
"cosmos.bank.v1beta1",
"cosmos.base.tendermint.v1beta1",
"cosmos.crisis.v1beta1",
Expand All @@ -128,7 +131,6 @@ func TestCosmosGen(t *testing.T) {
"test.blog.withoutmsg",
}

dirGenerated := filepath.Join(path, "vue/src/store/generated")
for _, chainModule := range expectedCustomModules {
_, statErr := os.Stat(filepath.Join(dirGenerated, "test/blog", chainModule))
require.False(t, os.IsNotExist(statErr), fmt.Sprintf("the %s vuex store should have be generated", chainModule))
Expand Down
12 changes: 12 additions & 0 deletions starport/pkg/cosmosanalysis/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,23 @@ func (d *moduleDiscoverer) pkgIsFromRegisteredModule(pkg protoanalysis.Package)
for i, rpcFunc := range s.RPCFuncs {
methods[i] = rpcFunc.Name
}

found, err := cosmosanalysis.DeepFindImplementation(implPath, methods)
if err != nil {
return false, err
}

// In some cases, the module registration is in another level of sub dir in the module.
// TODO: find the closest sub dir among proto packages.
if len(found) == 0 && strings.HasPrefix(rm, pkg.GoImportName) {
altImplRelPath := strings.TrimPrefix(pkg.GoImportName, d.basegopath)
altImplPath := filepath.Join(d.sourcePath, altImplRelPath)
found, err = cosmosanalysis.DeepFindImplementation(altImplPath, methods)
if err != nil {
return false, err
}
}

if len(found) > 0 {
return true, nil
}
Expand Down

0 comments on commit 420d0d7

Please sign in to comment.