Skip to content

Commit

Permalink
fix: remove "kvStoreKeys" check cosmosanalysis.go (#3871)
Browse files Browse the repository at this point in the history
* remove "kvStoreKeys" check cosmosanalysis.go

* add test case cosmosanalysis_test.go + update changelog

---------

Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
sashaduke and julienrbrt authored Jan 14, 2024
1 parent 1dce4e7 commit 3565187
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
### Fixes

- [#3878](https://github.com/ignite/cli/pull/3878) Support local forks of Cosmos SDK in scaffolded chain.
- [#3867](https://github.com/ignite/cli/pull/3867) Fix genesis export for ibc modules.
- [#3869](https://github.com/ignite/cli/pull/3869) Fix .git in parent dir
- [#3867](https://github.com/ignite/cli/pull/3867) Fix genesis export for ibc modules.
- [#3850](https://github.com/ignite/cli/pull/3871) Fix app.go file detection in apps scaffolded before v28.0.0

### Changes

Expand Down
1 change: 0 additions & 1 deletion ignite/pkg/cosmosanalysis/cosmosanalysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var AppImplementation = []string{
"AppCodec",
"GetKey",
"GetMemKey",
"kvStoreKeys",
"RegisterAPIRoutes",
}

Expand Down
60 changes: 45 additions & 15 deletions ignite/pkg/cosmosanalysis/cosmosanalysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R
func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
}
`)
appFileSDKv47 = []byte(`
package app
type App struct {}
func (app *App) Name() string { return app.BaseApp.Name() }
func (app *App) RegisterAPIRoutes() {}
func (app *App) RegisterTxService() {}
func (app *App) AppCodec() codec.Codec { return app.appCodec }
func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey { return nil }
func (app *App) GetMemKey(storeKey string) *storetypes.MemoryStoreKey { return nil }
func (app *App) GetSubspace(moduleName string) paramstypes.Subspace { return subspace }
func (app *App) TxConfig() client.TxConfig { return nil }
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
}
func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
return app.mm.EndBlock(ctx, req)
}
`)
)

Expand Down Expand Up @@ -177,50 +195,62 @@ func TestFindImplementationNotFound(t *testing.T) {
}

func TestFindAppFilePath(t *testing.T) {
tmpDir := t.TempDir()
tmpDir1 := t.TempDir()
tmpDir2 := t.TempDir()

appFolder := filepath.Join(tmpDir, "app")
secondaryAppFolder := filepath.Join(tmpDir, "myOwnAppDir")
err := os.Mkdir(appFolder, 0o700)
appFolder1 := filepath.Join(tmpDir1, "app")
appFolder2 := filepath.Join(tmpDir1, "myOwnAppDir")
appFolder3 := filepath.Join(tmpDir2, "sdk47AppDir")
err := os.Mkdir(appFolder1, 0o700)
require.NoError(t, err)
err = os.Mkdir(appFolder2, 0o700)
require.NoError(t, err)
err = os.Mkdir(secondaryAppFolder, 0o700)
err = os.Mkdir(appFolder3, 0o700)
require.NoError(t, err)

// No file
_, err = cosmosanalysis.FindAppFilePath(tmpDir)
_, err = cosmosanalysis.FindAppFilePath(tmpDir1)
require.Equal(t, "app.go file cannot be found", err.Error())

// Only one file with app implementation
myOwnAppFilePath := filepath.Join(secondaryAppFolder, "my_own_app.go")
myOwnAppFilePath := filepath.Join(appFolder2, "my_own_app.go")
err = os.WriteFile(myOwnAppFilePath, appFile, 0o644)
require.NoError(t, err)
pathFound, err := cosmosanalysis.FindAppFilePath(tmpDir)
pathFound, err := cosmosanalysis.FindAppFilePath(tmpDir1)
require.NoError(t, err)
require.Equal(t, myOwnAppFilePath, pathFound)

// With a test file added
appTestFilePath := filepath.Join(secondaryAppFolder, "my_own_app_test.go")
appTestFilePath := filepath.Join(appFolder2, "my_own_app_test.go")
err = os.WriteFile(appTestFilePath, appTestFile, 0o644)
require.NoError(t, err)
_, err = cosmosanalysis.FindAppFilePath(tmpDir)
_, err = cosmosanalysis.FindAppFilePath(tmpDir1)
require.Error(t, err)
require.Contains(t, err.Error(), "cannot locate your app.go")

// With an additional app file (that is app.go)
appFilePath := filepath.Join(appFolder, "app.go")
appFilePath := filepath.Join(appFolder1, "app.go")
err = os.WriteFile(appFilePath, appFile, 0o644)
require.NoError(t, err)
pathFound, err = cosmosanalysis.FindAppFilePath(tmpDir)
pathFound, err = cosmosanalysis.FindAppFilePath(tmpDir1)
require.NoError(t, err)
require.Equal(t, appFilePath, pathFound)

// With two app.go files
extraAppFilePath := filepath.Join(secondaryAppFolder, "app.go")
extraAppFilePath := filepath.Join(appFolder2, "app.go")
err = os.WriteFile(extraAppFilePath, appFile, 0o644)
require.NoError(t, err)
pathFound, err = cosmosanalysis.FindAppFilePath(tmpDir)
pathFound, err = cosmosanalysis.FindAppFilePath(tmpDir1)
require.NoError(t, err)
require.Equal(t, filepath.Join(appFolder1, "app.go"), pathFound)

// With an app.go file from a Cosmos SDK v0.47 app
sdk47AppFilePath := filepath.Join(appFolder3, "app_sdk_47.go")
err = os.WriteFile(sdk47AppFilePath, appFileSDKv47, 0o644)
require.NoError(t, err)
pathFound, err = cosmosanalysis.FindAppFilePath(tmpDir2)
require.NoError(t, err)
require.Equal(t, filepath.Join(appFolder, "app.go"), pathFound)
require.Equal(t, sdk47AppFilePath, pathFound)
}

func TestIsChainPath(t *testing.T) {
Expand Down

0 comments on commit 3565187

Please sign in to comment.