Skip to content

Commit

Permalink
[BP: v4-ics <- #687] feat(cosmos): Additional Helpers (#688)
Browse files Browse the repository at this point in the history
* feat(cosmos): Additional Helpers (#687)

* injective / evm fixes

* chain-id flag conditional

(cherry picked from commit 5fdb1e8)

# Conflicts:
#	ibc/types.go

* conflicts

---------

Co-authored-by: Nikhil Vasan <97126437+nivasan1@users.noreply.github.com>
Co-authored-by: Dan Kanefsky <daniel.kanefsky@gmail.com>
  • Loading branch information
3 people authored Aug 11, 2023
1 parent ab3a123 commit 6c5ef21
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,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 @@ -640,6 +644,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 @@ -680,6 +680,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/v4/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

0 comments on commit 6c5ef21

Please sign in to comment.