From 1d88910b4bc0c0b21b180591caaee0dff2b2a406 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 11 Aug 2023 17:12:18 +0000 Subject: [PATCH] `[BP: v4 <- #687]` feat(cosmos): Additional Helpers (#689) * 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 e8bc45001..9b6f9c044 100644 --- a/chain/cosmos/chain_node.go +++ b/chain/cosmos/chain_node.go @@ -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()) @@ -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 diff --git a/chain/cosmos/cosmos_chain.go b/chain/cosmos/cosmos_chain.go index 9f8f9ce50..d1e6cb167 100644 --- a/chain/cosmos/cosmos_chain.go +++ b/chain/cosmos/cosmos_chain.go @@ -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 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 2adeee09a..4605dacfe 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/v3/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 {