From 6c5ef2128f6930cce14da82f80ce41ec328d8cdb Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 11 Aug 2023 02:38:00 +0000 Subject: [PATCH] `[BP: v4-ics <- #687]` feat(cosmos): Additional Helpers (#688) * feat(cosmos): Additional Helpers (#687) * injective / evm fixes * chain-id flag conditional (cherry picked from commit 5fdb1e8a62e5e8b53e4ee918915225745bf7065c) # Conflicts: # ibc/types.go * conflicts --------- Co-authored-by: Nikhil Vasan <97126437+nivasan1@users.noreply.github.com> Co-authored-by: Dan Kanefsky --- chain/cosmos/chain_node.go | 9 +++++++++ chain/cosmos/cosmos_chain.go | 4 ++++ chainspec.go | 5 +++++ ibc/types.go | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/chain/cosmos/chain_node.go b/chain/cosmos/chain_node.go index 4a9a37d49..2e200c196 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -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()) @@ -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 diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index 5577c7e14..b9903e023 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -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 diff --git a/chainspec.go b/chainspec.go index bcca6f36f..a975bc922 100644 --- a/chainspec.go +++ b/chainspec.go @@ -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 { diff --git a/ibc/types.go b/ibc/types.go index 885e8c16d..f546f0ed0 100644 --- a/ibc/types.go +++ b/ibc/types.go @@ -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" ) @@ -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 {