From b3fdbafb5c9d80cb55836f5478e15e066a6501d2 Mon Sep 17 00:00:00 2001 From: Nikhil Vasan <97126437+nivasan1@users.noreply.github.com> Date: Thu, 10 Aug 2023 16:35:57 -0700 Subject: [PATCH] feat(cosmos): Additional Helpers (#687) * injective / evm fixes * chain-id flag conditional (cherry picked from commit 5fdb1e8a62e5e8b53e4ee918915225745bf7065c) # Conflicts: # ibc/types.go --- chain/cosmos/chain_node.go | 9 +++++++++ chain/cosmos/cosmos_chain.go | 4 ++++ chainspec.go | 5 +++++ ibc/types.go | 16 ++++++++++++++++ 4 files changed, 34 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..025fc9c17 100644 --- a/ibc/types.go +++ b/ibc/types.go @@ -4,8 +4,15 @@ import ( "reflect" "strconv" +<<<<<<< HEAD simappparams "github.com/cosmos/cosmos-sdk/simapp/params" ibcexported "github.com/cosmos/ibc-go/v4/modules/core/03-connection/types" +======= + "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/types/module/testutil" + ibcexported "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + sdk "github.com/cosmos/cosmos-sdk/types" +>>>>>>> 5fdb1e8 (feat(cosmos): Additional Helpers (#687)) ) // ChainConfig defines the chain parameters requires to run an interchaintest testnet for a chain. @@ -40,12 +47,21 @@ 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"` +<<<<<<< HEAD +======= + // Required when the chain requires the chain-id field to be populated for certain commands + UsingChainIDFlagCLI bool `yaml:"using-chain-id-flag-cli"` + // Configuration describing additional sidecar processes. + SidecarConfigs []SidecarConfig +>>>>>>> 5fdb1e8 (feat(cosmos): Additional Helpers (#687)) } func (c ChainConfig) Clone() ChainConfig {