forked from ignite/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from likesToEatFish/dong/cmdignitetestnet
updates add command testnet inplace
- Loading branch information
Showing
9 changed files
with
219 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewTestNet returns a command that groups scaffolding related sub commands. | ||
func NewTestNet() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "testnet [command]", | ||
Short: "Start a testnet local", | ||
Long: `Start a testnet local | ||
`, | ||
Aliases: []string{"s"}, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
c.AddCommand( | ||
NewTestNetInPlace(), | ||
) | ||
|
||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"github.com/ignite/cli/v29/ignite/pkg/cliui" | ||
"github.com/ignite/cli/v29/ignite/services/chain" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewTestNetInPlace() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "in-place", | ||
Short: "Run simulation testing for the blockchain", | ||
Long: "Run simulation testing for the blockchain. It sends many randomized-input messages of each module to a simulated node and checks if invariants break", | ||
Args: cobra.NoArgs, | ||
RunE: testnetInPlaceHandler, | ||
} | ||
flagSetPath(c) | ||
flagSetClearCache(c) | ||
c.Flags().AddFlagSet(flagSetHome()) | ||
c.Flags().AddFlagSet(flagSetCheckDependencies()) | ||
c.Flags().AddFlagSet(flagSetSkipProto()) | ||
c.Flags().AddFlagSet(flagSetVerbose()) | ||
|
||
c.Flags().Bool(flagQuitOnFail, false, "quit program if the app fails to start") | ||
return c | ||
} | ||
|
||
func testnetInPlaceHandler(cmd *cobra.Command, _ []string) error { | ||
session := cliui.New( | ||
cliui.WithVerbosity(getVerbosity(cmd)), | ||
) | ||
defer session.End() | ||
|
||
// Otherwise run the serve command directly | ||
return chainInplace(cmd, session) | ||
} | ||
|
||
func chainInplace(cmd *cobra.Command, session *cliui.Session) error { | ||
chainOption := []chain.Option{ | ||
chain.WithOutputer(session), | ||
chain.CollectEvents(session.EventBus()), | ||
chain.CheckCosmosSDKVersion(), | ||
} | ||
|
||
if flagGetCheckDependencies(cmd) { | ||
chainOption = append(chainOption, chain.CheckDependencies()) | ||
} | ||
|
||
// check if custom config is defined | ||
config, _ := cmd.Flags().GetString(flagConfig) | ||
if config != "" { | ||
chainOption = append(chainOption, chain.ConfigFile(config)) | ||
} | ||
|
||
c, err := chain.NewWithHomeFlags(cmd, chainOption...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cfg, err := c.Config() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var acc string | ||
for _, i := range cfg.Accounts { | ||
acc = acc + "," + i.Address | ||
} | ||
|
||
chainID, err := c.ID() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
args := chain.InplaceArgs{ | ||
NewChainID: chainID, | ||
NewOperatorAddress: cfg.Validators[0].OperatorAddress, | ||
AcountsToFund: acc, | ||
} | ||
return c.TestNetInPlace(cmd.Context(), args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package chain | ||
|
||
import ( | ||
"context" | ||
chainconfig "github.com/ignite/cli/v29/ignite/config/chain" | ||
"os" | ||
) | ||
|
||
type InplaceArgs struct { | ||
NewChainID string | ||
NewOperatorAddress string | ||
PrvKeyValidator string | ||
AcountsToFund string | ||
} | ||
|
||
func (c Chain) TestNetInPlace(ctx context.Context, args InplaceArgs) error { | ||
commands, err := c.Commands(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// make sure that config.yml exists | ||
if c.options.ConfigFile != "" { | ||
if _, err := os.Stat(c.options.ConfigFile); err != nil { | ||
return err | ||
} | ||
} else if _, err := chainconfig.LocateDefault(c.app.Path); err != nil { | ||
return err | ||
} | ||
|
||
err = c.InPlace(ctx, commands, args) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters