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

feat: add integration tests for IBC chains #3820

Merged
merged 63 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
131c441
create a method to fill other methods
Dec 6, 2023
af20cba
add chain methods
Dec 6, 2023
72f9af8
simplify te logic
Dec 6, 2023
77b727c
spin up both chains
Dec 6, 2023
d3ffcc4
add reminder
Dec 6, 2023
434adb1
add relayers
Dec 8, 2023
138615d
create configs into the code and add a helper to setup and run chains
Dec 9, 2023
a1d0e9e
fix chain config
Dec 9, 2023
e839965
fix rpc ports
Dec 10, 2023
6d06da7
Merge branch 'main' into feat/ibc-integration-tests
Pantani Dec 10, 2023
25c53bd
fix wrong urls and missing relayer accounts
Dec 10, 2023
0cbcb5d
reset relayer config and avoid port conflicts
Dec 10, 2023
8ccd0f8
test relayer
Dec 10, 2023
3fa1f54
fix config port address
Dec 10, 2023
85e0036
draft check realyer
Dec 10, 2023
907bf75
Merge branch 'main' into feat/ibc-integration-tests
Pantani Dec 12, 2023
754e941
Merge branch 'main' into feat/ibc-integration-tests
Pantani Dec 12, 2023
4cb43fc
Merge remote-tracking branch 'origin/main' into feat/ibc-integration-…
Dec 12, 2023
f5da266
use hermes realyer instead ts relayer
Dec 13, 2023
a49364e
fix the default config values
Dec 13, 2023
abea944
fix the config flag
Dec 13, 2023
0af2b33
add missing tx.go file by default and enable cli if autocli not exist
Dec 19, 2023
543b08d
add changelog
Dec 19, 2023
2cf88c8
Merge branch 'fix/module-cli-tx-cmd' into feat/ibc-integration-tests
Dec 19, 2023
d5d7722
fix wrong error pkg
Dec 19, 2023
f5a059c
add missing imports
Dec 19, 2023
9e32d6e
Merge branch 'fix/module-cli-tx-cmd' into feat/ibc-integration-tests
Dec 19, 2023
d976cbd
only scaffold `cli/tx.go` if is a ibc module
Dec 19, 2023
f5b6e8a
Merge branch 'main' into fix/module-cli-tx-cmd
Pantani Dec 19, 2023
a43c274
move tx.go.plush to right place
Dec 19, 2023
e018eac
Merge branch 'fix/module-cli-tx-cmd' into feat/ibc-integration-tests
Dec 19, 2023
d968d93
add comment to cobra send packet command
Dec 19, 2023
3eddf13
add missing ibc interfaces to chain client
Dec 19, 2023
1d12cd0
Merge branch 'fix/missing-client-interfaces' into feat/ibc-integratio…
Dec 19, 2023
416b978
Merge branch 'main' into feat/ibc-integration-tests
Pantani Dec 20, 2023
211a7f4
Merge remote-tracking branch 'origin/main' into feat/ibc-integration-…
Dec 21, 2023
656a80c
Merge remote-tracking branch 'origin/main' into feat/ibc-integration-…
Dec 21, 2023
d5506e6
Merge branch 'main' into feat/ibc-integration-tests
Pantani Dec 23, 2023
fd34629
set port range
Dec 25, 2023
68c8e29
Revert "refactor(templates): add all ibc commands (#3858)"
Pantani Dec 25, 2023
9b4fac3
Merge branch 'revert-3858-julien/add-all-ibc-cmd' into feat/ibc-integ…
Dec 25, 2023
282423b
Merge remote-tracking branch 'origin/main' into feat/ibc-integration-…
Jan 16, 2024
fcc2186
fix changelog
Jan 16, 2024
aa8af90
fix ibc.go app
Jan 16, 2024
f67900b
query channels
Jan 17, 2024
e174df1
check balances
Jan 18, 2024
5188247
check ibc balance
Jan 18, 2024
cff30ea
improve test cleanup
Jan 18, 2024
f67bcb8
fix chain home and config paths
Jan 18, 2024
6b71b05
fix log typo
Jan 18, 2024
5fb4025
cerate the chain path before use
Jan 18, 2024
2bf6024
remove unused const
Jan 18, 2024
852e270
decrease cleanup time
Jan 18, 2024
ddf5f10
Merge branch 'main' into feat/ibc-integration-tests
Pantani Jan 22, 2024
50bcc66
setup the remote hermes app url
Jan 22, 2024
7e10443
use parser.ParseExpr instead parser.ParseExpr
Jan 26, 2024
a17b4eb
Merge branch 'main' into feat/ibc-integration-tests
Pantani Jan 26, 2024
0caca1f
Merge branch 'main' into feat/ibc-integration-tests
Pantani Jan 29, 2024
e77a8cb
Merge branch 'main' into feat/ibc-integration-tests
Pantani Jan 29, 2024
1a3672b
Merge branch 'main' into feat/ibc-integration-tests
Pantani Jan 29, 2024
e49050c
Merge branch 'main' into feat/ibc-integration-tests
Pantani Jan 29, 2024
2b02b9b
remove panic from assert error
Jan 31, 2024
69a5f69
improve error assert
Jan 31, 2024
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [#3839](https://github.com/ignite/cli/pull/3839) New structure for app scaffolding
- [#3835](https://github.com/ignite/cli/pull/3835) Add `--minimal` flag to `scaffold chain` to scaffold a chain with the least amount of sdk modules
- [#3820](https://github.com/ignite/cli/pull/3820) Add integration tests for IBC chains

### Changes

Expand Down
59 changes: 59 additions & 0 deletions ignite/pkg/goanalysis/goanalysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,62 @@ func createUnderscoreImport(imp string) *ast.ImportSpec {
},
}
}

// ReplaceCode replace a function implementation into a package path. The method will find
// the method signature and re-write the method implementation based in the new function.
func ReplaceCode(pkgPath, oldFunctionName, newFunction string) (err error) {
absPath, err := filepath.Abs(pkgPath)
if err != nil {
return err
}

fileSet := token.NewFileSet()
all, err := parser.ParseDir(fileSet, absPath, func(os.FileInfo) bool { return true }, parser.ParseComments)
if err != nil {
return err
}

for _, pkg := range all {
for _, f := range pkg.Files {
found := false
ast.Inspect(f, func(n ast.Node) bool {
if funcDecl, ok := n.(*ast.FuncDecl); ok {
// Check if the function has the name you want to replace.
if funcDecl.Name.Name == oldFunctionName {
// Replace the function body with the replacement code.
replacementExpr, err := parser.ParseExpr(newFunction)
if err != nil {
return false
}
funcDecl.Body = &ast.BlockStmt{List: []ast.Stmt{
&ast.ExprStmt{X: replacementExpr},
}}
found = true
return false
}
}
return true
})
if err != nil {
return err
}
if !found {
continue
}
filePath := fileSet.Position(f.Package).Filename
outFile, err := os.Create(filePath)
if err != nil {
return err
}

// Format and write the modified AST to the output file.
if err := format.Node(outFile, fileSet, f); err != nil {
return err
}
if err := outFile.Close(); err != nil {
return err
}
}
}
return nil
}
74 changes: 74 additions & 0 deletions ignite/pkg/goanalysis/goanalysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,77 @@ func TestUpdateInitImports(t *testing.T) {
})
}
}

func TestReplaceCode(t *testing.T) {
var (
newFunction = `package test
func NewMethod1() {
n := "test new method"
bla := fmt.Sprintf("test new - %s", n)
fmt.Println(bla)
}`
rollback = `package test
func NewMethod1() {
foo := 100
bar := fmt.Sprintf("test - %d", foo)
fmt.Println(bar)
}`
)

type args struct {
path string
oldFunctionName string
newFunction string
}
tests := []struct {
name string
args args
err error
}{
{
name: "function fooTest",
args: args{
path: "testdata",
oldFunctionName: "fooTest",
newFunction: newFunction,
},
},
{
name: "function BazTest",
args: args{
path: "testdata",
oldFunctionName: "BazTest",
newFunction: newFunction,
},
},
{
name: "function invalidFunction",
args: args{
path: "testdata",
oldFunctionName: "invalidFunction",
newFunction: newFunction,
},
},
{
name: "invalid path",
args: args{
path: "invalid_path",
oldFunctionName: "invalidPath",
newFunction: newFunction,
},
err: os.ErrNotExist,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := goanalysis.ReplaceCode(tt.args.path, tt.args.oldFunctionName, tt.args.newFunction)
if tt.err != nil {
require.Error(t, err)
require.ErrorIs(t, err, tt.err)
return
}
require.NoError(t, err)
require.NoError(t, goanalysis.ReplaceCode(tt.args.path, tt.args.oldFunctionName, rollback))
})
}
}
16 changes: 16 additions & 0 deletions ignite/pkg/goanalysis/testdata/replace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package testdata

import "fmt"

func fooTest() {
n := "test new method"
bla := fmt.Sprintf("test new - %s", n)
fmt.
Println(bla)
}

func BazTest() {
foo := 100
bar := fmt.Sprintf("test - %d", foo)
fmt.Println(bar)
}
5 changes: 5 additions & 0 deletions ignite/pkg/goenv/goenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ func GoModCache() string {
}
return filepath.Join(build.Default.GOPATH, modDir)
}

// GoPath returns the go path.
func GoPath() string {
return os.Getenv(GOPATH)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be reverted. IBC commands are already added.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
ibccmd "github.com/cosmos/ibc-go/v8/modules/core/client/cli"
"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down Expand Up @@ -87,6 +88,7 @@ func queryCommand() *cobra.Command {
server.QueryBlocksCmd(),
authcmd.QueryTxCmd(),
server.QueryBlockResultsCmd(),
ibccmd.GetQueryCmd(),
)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

Expand All @@ -113,6 +115,7 @@ func txCommand() *cobra.Command {
authcmd.GetEncodeCommand(),
authcmd.GetDecodeCommand(),
authcmd.GetSimulateCmd(),
ibccmd.GetTxCmd(),
)
cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

var _ = strconv.Itoa(0)

// CmdSend<%= packetName.UpperCamel %>() returns the <%= packetName.UpperCamel %> send packet command.
// This command does not use AutoCLI because it gives a better UX to do not.
func CmdSend<%= packetName.UpperCamel %>() *cobra.Command {
flagPacketTimeoutTimestamp := "packet-timeout-timestamp"
Expand Down
4 changes: 4 additions & 0 deletions integration/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (a App) SourcePath() string {
return a.path
}

func (a *App) SetHomePath(homePath string) {
a.homePath = homePath
}

func (a *App) SetConfigPath(path string) {
a.configPath = path
}
Expand Down
Loading
Loading