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

[BP: v4 <- #687] feat(cosmos): Additional Helpers #689

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func (tn *ChainNode) Name() string {
return fmt.Sprintf("%s-%s-%d-%s", tn.Chain.Config().ChainID, nodeType, tn.Index, dockerutil.SanitizeContainerName(tn.TestName))
}

func (tn *ChainNode) ContainerID() string {
return tn.containerLifecycle.ContainerID()
}

// hostname of the test node container
func (tn *ChainNode) HostName() string {
return dockerutil.CondenseHostName(tn.Name())
Expand Down Expand Up @@ -620,6 +624,11 @@ func (tn *ChainNode) AddGenesisAccount(ctx context.Context, address string, gene
}

command = append(command, "add-genesis-account", address, amount)

if tn.Chain.Config().UsingChainIDFlagCLI {
command = append(command, "--chain-id", tn.Chain.Config().ChainID)
}

_, _, err := tn.ExecBin(ctx, command...)

return err
Expand Down
4 changes: 4 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,10 @@ func (c *CosmosChain) Start(testName string, ctx context.Context, additionalGene
Denom: chainCfg.Denom,
}

if chainCfg.ModifyGenesisAmounts != nil {
genesisAmount, genesisSelfDelegation = chainCfg.ModifyGenesisAmounts()
}

genesisAmounts := []types.Coin{genesisAmount}

configFileOverrides := chainCfg.ConfigFileOverrides
Expand Down
5 changes: 5 additions & 0 deletions chainspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ func (s *ChainSpec) applyConfigOverrides(cfg ibc.ChainConfig) (*ibc.ChainConfig,
if s.PreGenesis != nil {
cfg.PreGenesis = s.PreGenesis
}
if s.ModifyGenesisAmounts != nil {
cfg.ModifyGenesisAmounts = s.ModifyGenesisAmounts
}

cfg.UsingNewGenesisCommand = s.UsingNewGenesisCommand
cfg.UsingChainIDFlagCLI = s.UsingChainIDFlagCLI

// Set the version depending on the chain type.
switch cfg.Type {
Expand Down
5 changes: 5 additions & 0 deletions ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strconv"

simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
ibcexported "github.com/cosmos/ibc-go/v3/modules/core/03-connection/types"
)

Expand Down Expand Up @@ -40,12 +41,16 @@ type ChainConfig struct {
PreGenesis func(ChainConfig) error
// When provided, genesis file contents will be altered before sharing for genesis.
ModifyGenesis func(ChainConfig, []byte) ([]byte, error)
// Modify genesis-amounts
ModifyGenesisAmounts func() (sdk.Coin, sdk.Coin)
// Override config parameters for files at filepath.
ConfigFileOverrides map[string]any
// Non-nil will override the encoding config, used for cosmos chains only.
EncodingConfig *simappparams.EncodingConfig
// Required when the chain uses the new sub commands for genesis (https://github.com/cosmos/cosmos-sdk/pull/14149)
UsingNewGenesisCommand bool `yaml:"using-new-genesis-command"`
// Required when the chain requires the chain-id field to be populated for certain commands
UsingChainIDFlagCLI bool `yaml:"using-chain-id-flag-cli"`
}

func (c ChainConfig) Clone() ChainConfig {
Expand Down