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

chore: release v0.19.5 #2158

Merged
merged 10 commits into from
Mar 19, 2022
14 changes: 14 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [`v0.19.5`](https://github.com/tendermint/starport/pull/2158/commits)

### Features

- Enable client code and Vuex code generation for query only modules as well.
- Upgraded the Vue template to `v0.3.5`.

### Fixes:
- Fixed snake case in code generation.
- Fixed plugin installations for Go =>v1.18.

### Changes:
- Dropped transpilation of TS to JS. Code generation now only produces TS files.

## `v0.19.4`

### Features
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/tendermint/spn v0.1.1-0.20211210094128-4ca78a240c57
github.com/tendermint/tendermint v0.34.14
github.com/tendermint/tm-db v0.6.4
github.com/tendermint/vue v0.3.0
github.com/tendermint/vue v0.3.5
golang.org/x/mod v0.4.2
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1508,8 +1508,8 @@ github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs
github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8=
github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ=
github.com/tendermint/tm-db v0.6.4/go.mod h1:dptYhIpJ2M5kUuenLr+Yyf3zQOv1SgBZcl8/BmWlMBw=
github.com/tendermint/vue v0.3.0 h1:jllMEhdq3r7pIwLCNh7Aj7CXmOG3mqHCKeRMelohjwQ=
github.com/tendermint/vue v0.3.0/go.mod h1:Sg9MGPF+uY+SJ79sdZgtC2LnH+FDU2qWuiRxoZn5bmw=
github.com/tendermint/vue v0.3.5 h1:PTZaW0+7/4lRJyUtuZOxFzMCahNLowTadVoCZns2Wmw=
github.com/tendermint/vue v0.3.5/go.mod h1:Sg9MGPF+uY+SJ79sdZgtC2LnH+FDU2qWuiRxoZn5bmw=
github.com/tetafro/godot v1.4.9/go.mod h1:LR3CJpxDVGlYOWn3ZZg1PgNZdTUvzsZWu8xaEohUpn8=
github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
Expand Down
153 changes: 153 additions & 0 deletions integration/cosmosgen/cosmosgen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package cosmosgen_test

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
envtest "github.com/tendermint/starport/integration"
"github.com/tendermint/starport/starport/pkg/cmdrunner/step"
)

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

const (
withMsgModuleName = "withmsg"
withoutMsgModuleName = "withoutmsg"
)

env.Must(env.Exec("add custom module with message",
step.NewSteps(step.New(
step.Exec(
"starport",
"s",
"module",
withMsgModuleName,
),
step.Workdir(path),
)),
))

env.Must(env.Exec("create a message",
step.NewSteps(step.New(
step.Exec(
"starport",
"s",
"message",
"mymessage",
"myfield1",
"myfield2:bool",
"--module",
withMsgModuleName,
),
step.Workdir(path),
)),
))

env.Must(env.Exec("add custom module without message",
step.NewSteps(step.New(
step.Exec(
"starport",
"s",
"module",
withoutMsgModuleName,
),
step.Workdir(path),
)),
))

env.Must(env.Exec("create a type",
step.NewSteps(step.New(
step.Exec(
"starport",
"s",
"type",
"mytype",
"mytypefield",
"--module",
withoutMsgModuleName,
),
step.Workdir(path),
)),
))

env.Must(env.Exec("create a query",
step.NewSteps(step.New(
step.Exec(
"starport",
"s",
"query",
"myQuery",
"mytypefield",
"--module",
withoutMsgModuleName,
),
step.Workdir(path),
)),
))

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

env.Must(env.Exec("generate vuex",
step.NewSteps(step.New(
step.Exec(
"starport",
"g",
"vuex",
"--proto-all-modules",
),
step.Workdir(path),
)),
))

var expectedCosmosModules = []string{
"cosmos.auth.v1beta1",
"cosmos.bank.v1beta1",
"cosmos.base.tendermint.v1beta1",
"cosmos.crisis.v1beta1",
"cosmos.distribution.v1beta1",
"cosmos.evidence.v1beta1",
"cosmos.feegrant.v1beta1",
"cosmos.gov.v1beta1",
"cosmos.mint.v1beta1",
"cosmos.params.v1beta1",
"cosmos.slashing.v1beta1",
"cosmos.staking.v1beta1",
"cosmos.tx.v1beta1",
"cosmos.upgrade.v1beta1",
"cosmos.vesting.v1beta1",
}

var expectedCustomModules = []string{
"test.blog.blog",
"test.blog.withmsg",
"test.blog.withoutmsg",
}

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))
require.NoError(t, statErr)
}

chainDir, err := os.ReadDir(filepath.Join(dirGenerated, "test/blog"))
require.Equal(t, len(expectedCustomModules), len(chainDir), "no extra modules should have been generated for test/blog")
require.NoError(t, err)

for _, cosmosModule := range expectedCosmosModules {
_, statErr := os.Stat(filepath.Join(dirGenerated, "cosmos/cosmos-sdk", cosmosModule))
require.False(t, os.IsNotExist(statErr), fmt.Sprintf("the %s code generation for module should have be made", cosmosModule))
require.NoError(t, statErr)
}

cosmosDirs, err := os.ReadDir(filepath.Join(dirGenerated, "cosmos/cosmos-sdk"))
require.Equal(t, len(expectedCosmosModules), len(cosmosDirs), "no extra modules should have been generated for cosmos/cosmos-sdk")
require.NoError(t, err)
}
1 change: 0 additions & 1 deletion scripts/data/gen-nodetime/nodetime
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ main();
function main() {
switch (mode) {
case "ts-proto": require("ts-proto/protoc-gen-ts_proto"); return;
case "tsc": require("typescript/bin/tsc"); return;
case "sta": require("swagger-typescript-api/index"); return;
case "swagger-combine": require("swagger-combine/bin/swagger-combine"); return;
case "ibc-setup": require("@confio/relayer/build/binary/ibc-setup/index"); return;
Expand Down
160 changes: 160 additions & 0 deletions starport/pkg/cosmosanalysis/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go/token"

"github.com/tendermint/starport/starport/pkg/cosmosanalysis"
"github.com/tendermint/starport/starport/pkg/goanalysis"
)

var appImplementation = []string{
Expand Down Expand Up @@ -69,3 +70,162 @@ func CheckKeeper(path, keeperName string) error {
}
return nil
}

// FindRegisteredModules looks for all the registered modules in the App
// It finds activated modules by checking if imported modules are registered in the app and also checking if their query clients are registered
// It does so by:
// 1. Mapping out all the imports and named imports
// 2. Looking for the call to module.NewBasicManager and finds the modules registered there
// 3. Looking for the implementation of RegisterAPIRoutes and find the modules that call their RegisterGRPCGatewayRoutes
func FindRegisteredModules(chainRoot string) ([]string, error) {
appFilePath, err := cosmosanalysis.FindAppFilePath(chainRoot)
if err != nil {
return nil, err
}

fileSet := token.NewFileSet()
f, err := parser.ParseFile(fileSet, appFilePath, nil, 0)
if err != nil {
return []string{}, err
}

packages, err := goanalysis.FindImportedPackages(appFilePath)
if err != nil {
return nil, err
}

basicManagerModule, err := findBasicManagerModule(packages)
if err != nil {
return nil, err
}

var basicModules []string
ast.Inspect(f, func(n ast.Node) bool {
if pkgsReg := findBasicManagerRegistrations(n, basicManagerModule); pkgsReg != nil {
for _, rp := range pkgsReg {
importModule := packages[rp]
basicModules = append(basicModules, importModule)
}

return false
}

if pkgsReg := findRegisterAPIRoutersRegistrations(n); pkgsReg != nil {
for _, rp := range pkgsReg {
importModule := packages[rp]
if importModule == "" {
continue
}
basicModules = append(basicModules, importModule)
}

return false
}

return true
})

return basicModules, nil
}

func findBasicManagerRegistrations(n ast.Node, basicManagerModule string) []string {
callExprType, ok := n.(*ast.CallExpr)
if !ok {
return nil
}

selectorExprType, ok := callExprType.Fun.(*ast.SelectorExpr)
if !ok {
return nil
}

identExprType, ok := selectorExprType.X.(*ast.Ident)
if !ok || identExprType.Name != basicManagerModule || selectorExprType.Sel.Name != "NewBasicManager" {
return nil
}

packagesRegistered := make([]string, len(callExprType.Args))
for i, arg := range callExprType.Args {
argAsCompositeLitType, ok := arg.(*ast.CompositeLit)
if ok {
compositeTypeSelectorExpr, ok := argAsCompositeLitType.Type.(*ast.SelectorExpr)
if !ok {
continue
}

compositeTypeX, ok := compositeTypeSelectorExpr.X.(*ast.Ident)
if ok {
packagesRegistered[i] = compositeTypeX.Name
continue
}
}

argAsCallType, ok := arg.(*ast.CallExpr)
if ok {
argAsFunctionType, ok := argAsCallType.Fun.(*ast.SelectorExpr)
if !ok {
continue
}

argX, ok := argAsFunctionType.X.(*ast.Ident)
if ok {
packagesRegistered[i] = argX.Name
}
}
}

return packagesRegistered
}

func findBasicManagerModule(pkgs map[string]string) (string, error) {
for mod, pkg := range pkgs {
if pkg == "github.com/cosmos/cosmos-sdk/types/module" {
return mod, nil
}
}

return "", errors.New("no module for BasicManager was found")
}

func findRegisterAPIRoutersRegistrations(n ast.Node) []string {
funcLitType, ok := n.(*ast.FuncDecl)
if !ok {
return nil
}

if funcLitType.Name.Name != "RegisterAPIRoutes" {
return nil
}

var packagesRegistered []string
for _, stmt := range funcLitType.Body.List {
exprStmt, ok := stmt.(*ast.ExprStmt)
if !ok {
continue
}

exprCall, ok := exprStmt.X.(*ast.CallExpr)
if !ok {
continue
}

exprFun, ok := exprCall.Fun.(*ast.SelectorExpr)
if !ok || exprFun.Sel.Name != "RegisterGRPCGatewayRoutes" {
continue
}

identType, ok := exprFun.X.(*ast.Ident)
if !ok {
continue
}

pkgName := identType.Name
if pkgName == "" {
continue
}

packagesRegistered = append(packagesRegistered, identType.Name)
}

return packagesRegistered
}
Loading