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

Add support for genesis sub commands #384

Merged
merged 4 commits into from
Mar 14, 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
29 changes: 22 additions & 7 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,14 @@ func (tn *ChainNode) AddGenesisAccount(ctx context.Context, address string, gene
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()

_, _, err := tn.ExecBin(ctx, "add-genesis-account", address, amount)
var command []string
if tn.Chain.Config().UsingNewGenesisCommand {
command = append(command, "genesis")
}

command = append(command, "add-genesis-account", address, amount)
_, _, err := tn.ExecBin(ctx, command...)

return err
}

Expand All @@ -565,20 +572,28 @@ func (tn *ChainNode) Gentx(ctx context.Context, name string, genesisSelfDelegati
tn.lock.Lock()
defer tn.lock.Unlock()

_, _, err := tn.ExecBin(ctx,
"gentx", valKey, fmt.Sprintf("%d%s", genesisSelfDelegation.Amount.Int64(), genesisSelfDelegation.Denom),
var command []string
if tn.Chain.Config().UsingNewGenesisCommand {
command = append(command, "genesis")
}

command = append(command, "gentx", valKey, fmt.Sprintf("%d%s", genesisSelfDelegation.Amount.Int64(), genesisSelfDelegation.Denom),
"--keyring-backend", keyring.BackendTest,
"--chain-id", tn.Chain.Config().ChainID,
)
"--chain-id", tn.Chain.Config().ChainID)

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

// CollectGentxs runs collect gentxs on the node's home folders
func (tn *ChainNode) CollectGentxs(ctx context.Context) error {
command := []string{tn.Chain.Config().Bin, "collect-gentxs",
"--home", tn.HomeDir(),
command := []string{tn.Chain.Config().Bin}
if tn.Chain.Config().UsingNewGenesisCommand {
command = append(command, "genesis")
}

command = append(command, "collect-gentxs", "--home", tn.HomeDir())

tn.lock.Lock()
defer tn.lock.Unlock()

Expand Down
1 change: 1 addition & 0 deletions chainspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (s *ChainSpec) applyConfigOverrides(cfg ibc.ChainConfig) (*ibc.ChainConfig,
if s.ModifyGenesis != nil {
cfg.ModifyGenesis = s.ModifyGenesis
}
cfg.UsingNewGenesisCommand = s.UsingNewGenesisCommand

// Set the version depending on the chain type.
switch cfg.Type {
Expand Down
12 changes: 12 additions & 0 deletions chainspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ func TestChainSpec_Config(t *testing.T) {

require.Equal(t, m, cfg.NoHostMount)
})

t.Run("UsingNewGenesisCommand", func(t *testing.T) {
require.False(t, baseCfg.UsingNewGenesisCommand)

s := baseSpec
s.UsingNewGenesisCommand = true

cfg, err := s.Config(zaptest.NewLogger(t))
require.NoError(t, err)

require.True(t, cfg.UsingNewGenesisCommand)
})
})

t.Run("error cases", func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type ChainConfig struct {
ConfigFileOverrides map[string]any
// Non-nil will override the encoding config, used for cosmos chains only.
EncodingConfig *testutil.TestEncodingConfig
// 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"`
}

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