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: Local-interchain cleanup #710

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion local-interchain/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build:

.PHONY: run
run:
../bin/local-ic $(filter-out $@,$(MAKECMDGOALS))
go run ./cmd/local-ic $(filter-out $@,$(MAKECMDGOALS))

.PHONY: install
install:
Expand Down
4 changes: 0 additions & 4 deletions local-interchain/cmd/local-ic/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,3 @@ func GetFiles() []string {

return fileNames
}

func init() {
rootCmd.AddCommand(chainsCmd)
}
4 changes: 4 additions & 0 deletions local-interchain/cmd/local-ic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
)

func main() {
rootCmd.AddCommand(chainsCmd)
rootCmd.AddCommand(newChainCmd)
rootCmd.AddCommand(startCmd)

if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "error while executing your CLI. Err: %v\n", err)
os.Exit(1)
Expand Down
4 changes: 0 additions & 4 deletions local-interchain/cmd/local-ic/new_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,3 @@ func getOrDefault[T any](output string, defaultVal T) T {

return any(text).(T)
}

func init() {
rootCmd.AddCommand(newChainCmd)
}
Comment on lines -184 to -186
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I avoid init() functions at all costs. Even though this is common in Viper and co-located with the subcommand file, I think it's an anti-pattern. It hides order of operations and hides functionality in the main() function. IOW, I want to look at main() and know exactly what's happening.

15 changes: 6 additions & 9 deletions local-interchain/cmd/local-ic/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"github.com/spf13/cobra"
)

var (
MakeFileInstallDirectory string
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoid global vars. In this case, wasn't needed at all.

Copy link
Member

@Reecepbcups Reecepbcups Aug 22, 2023

Choose a reason for hiding this comment

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

This is required for the ldflags in makefile to work I believe.
or does the var in get directory work properly when you make install. This is the reason it is a globalvar

ldflags = -X main.MakeFileInstallDirectory=$(CWD)

There are 3 install cases:

  1. the user make installs, it sets the current install location in the system
  2. ICTEST_HOME env is used
  3. neither of the above are true, and we set ictest to be at the user's $HOME/local-interchain location

This would remove the first which is the most common desire imo


var rootCmd = &cobra.Command{
Use: "local-ic",
Short: "Your local IBC interchain of nodes program",
Expand All @@ -28,24 +24,25 @@ var rootCmd = &cobra.Command{

func GetDirectory() string {
// Config variable override for the ICTEST_HOME
var makeInstalDir string
if res := os.Getenv("ICTEST_HOME"); res != "" {
MakeFileInstallDirectory = res
makeInstalDir = res
}

if MakeFileInstallDirectory == "" {
if makeInstalDir == "" {
dirname, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}

MakeFileInstallDirectory = path.Join(dirname, "local-interchain")
makeInstalDir = path.Join(dirname, "local-interchain")
}

if err := directoryRequirementChecks(MakeFileInstallDirectory, "configs", "chains"); err != nil {
if err := directoryRequirementChecks(makeInstalDir, "configs", "chains"); err != nil {
log.Fatal(err)
}

return MakeFileInstallDirectory
return makeInstalDir
}

func directoryRequirementChecks(parent string, subDirectories ...string) error {
Expand Down
4 changes: 0 additions & 4 deletions local-interchain/cmd/local-ic/start_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ var startCmd = &cobra.Command{
interchain.StartChain(parentDir, configPath)
},
}

func init() {
rootCmd.AddCommand(startCmd)
}
5 changes: 3 additions & 2 deletions local-interchain/interchain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"log"
"strings"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/strangelove-ventures/interchaintest/v7/chain/cosmos"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
types "github.com/strangelove-ventures/localinterchain/interchain/types"
"github.com/strangelove-ventures/localinterchain/interchain/types"
)

func AddGenesisKeysToKeyring(ctx context.Context, config *types.Config, chains []ibc.Chain) {
Expand Down Expand Up @@ -62,7 +63,7 @@ func SetupGenesisWallets(config *types.Config, chains []ibc.Chain) map[ibc.Chain
for _, coin := range amount {
additionalWallets[chainObj] = append(additionalWallets[chainObj], ibc.WalletAmount{
Address: acc.Address,
Amount: coin.Amount.Int64(),
Amount: math.NewInt(coin.Amount.Int64()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah nice. Yea this makes sense because this got merged first:

#679

Really surprised CI didn't catch this??

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh one more note... around backporting.
That PR is not backported yet: #685

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good catch. We should get that back ported. I can look at it.

Denom: coin.Denom,
})
}
Expand Down
Loading