-
Notifications
You must be signed in to change notification settings - Fork 656
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
tests: add option to dump genesis files in E2E tests #6100
Changes from 6 commits
65a41e2
c6266ac
9899bf4
7f44b73
a324846
f55d53f
f8f097b
934e2f0
fe24e23
8434b70
8a02d35
b9d9841
3a78f8c
06795b2
1cd3073
64b98a6
c8cc6b3
a46ca74
d37b961
3fb3d57
0261a22
63db86c
a6a6322
ecd0186
7d4b8d5
e6f5512
7c16d6b
495964b
d39df3b
ed2fcc9
c1a77c5
d6bbd8e
eba5cbc
35e3f74
e303ca0
c199f76
0846468
f70c7d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,9 @@ const ( | |
// defaultConfigFileName is the default filename for the config file that can be used to configure | ||
// e2e tests. See sample.config.yaml as an example for what this should look like. | ||
defaultConfigFileName = ".ibc-go-e2e-config.yaml" | ||
|
||
// defaultGenesisExportPath is the default path to which Genesis debug files will be exported to. | ||
defaultGenesisExportPath = "diagnostics/genesis.json" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we end up moving the GetE2EPath to internal, maybe we can move this constant there too. |
||
) | ||
|
||
func getChainImage(binary string) string { | ||
|
@@ -103,6 +106,10 @@ func (tc TestConfig) Validate() error { | |
if err := tc.validateRelayers(); err != nil { | ||
return fmt.Errorf("invalid relayer configuration: %w", err) | ||
} | ||
|
||
if err := tc.validateGenesisDebugConfig(); err != nil { | ||
return fmt.Errorf("invalid Genesis debug configuration: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
|
@@ -118,6 +125,10 @@ func (tc TestConfig) validateChains() error { | |
if cfg.Tag == "" { | ||
return fmt.Errorf("chain config missing tag: %+v", cfg) | ||
} | ||
// TODO: defaults? | ||
if cfg.Name == "" { | ||
return fmt.Errorf("chain config missing name: %+v", cfg) | ||
} | ||
|
||
// TODO: validate chainID in https://github.com/cosmos/ibc-go/issues/4697 | ||
// these are not passed in the CI at the moment. Defaults are used. | ||
|
@@ -163,6 +174,33 @@ func (tc TestConfig) validateRelayers() error { | |
return nil | ||
} | ||
|
||
func (tc TestConfig) GetChainIndex(name string) (int, error) { | ||
for i, chainCfg := range tc.ChainConfigs { | ||
if chainCfg.Name == name { | ||
return i, nil | ||
} | ||
} | ||
return -1, fmt.Errorf("chain %s not found in chain configs", name) | ||
} | ||
|
||
// validateGenesisDebugConfig validates configuration of Genesis debug options/ | ||
func (tc TestConfig) validateGenesisDebugConfig() error { | ||
cfg := tc.DebugConfig.GenesisDebug | ||
if !cfg.DumpGenesisDebugInfo { | ||
return nil | ||
} | ||
|
||
if cfg.ChainName == "" { | ||
// TODO create a default? | ||
return fmt.Errorf("genesis debug config missing chain name: %+v", cfg) | ||
} | ||
|
||
// Verify that the provided chain exists in our config | ||
_, err := tc.GetChainIndex(cfg.ChainName) | ||
|
||
return err | ||
} | ||
|
||
// GetActiveRelayerConfig returns the currently specified relayer config. | ||
func (tc TestConfig) GetActiveRelayerConfig() *relayer.Config { | ||
for _, r := range tc.RelayerConfigs { | ||
|
@@ -216,6 +254,7 @@ type UpgradeConfig struct { | |
// ChainConfig holds information about an individual chain used in the tests. | ||
type ChainConfig struct { | ||
ChainID string `yaml:"chainId"` | ||
Name string `yaml:"name"` | ||
Image string `yaml:"image"` | ||
Tag string `yaml:"tag"` | ||
Binary string `yaml:"binary"` | ||
|
@@ -227,9 +266,23 @@ type CometBFTConfig struct { | |
LogLevel string `yaml:"logLevel"` | ||
} | ||
|
||
type GenesisDebugConfig struct { | ||
// DumpGenesisDebugInfo enables the output of Genesis debug files. | ||
DumpGenesisDebugInfo bool `yaml:"dumpGenesisDebugInfo"` | ||
|
||
// ExportFilePath specifies which path to export Genesis debug files to. | ||
ExportFilePath string `yaml:"filePath"` | ||
|
||
// ChainName represent which chain to get Genesis debug info for. | ||
ChainName string `yaml:"chainName"` | ||
} | ||
|
||
type DebugConfig struct { | ||
// DumpLogs forces the logs to be collected before removing test containers. | ||
DumpLogs bool `yaml:"dumpLogs"` | ||
|
||
// GenesisDebug contains debug information specific to Genesis. | ||
GenesisDebug GenesisDebugConfig `yaml:"genesis"` | ||
} | ||
|
||
// LoadConfig attempts to load a atest configuration from the default file path. | ||
|
@@ -471,8 +524,8 @@ type ChainOptionConfiguration func(options *ChainOptions) | |
func DefaultChainOptions() ChainOptions { | ||
tc := LoadConfig() | ||
|
||
chainACfg := newDefaultSimappConfig(tc.ChainConfigs[0], "simapp-a", tc.GetChainAID(), "atoma", tc.CometBFTConfig) | ||
chainBCfg := newDefaultSimappConfig(tc.ChainConfigs[1], "simapp-b", tc.GetChainBID(), "atomb", tc.CometBFTConfig) | ||
chainACfg := newDefaultSimappConfig(tc.ChainConfigs[0], tc.ChainConfigs[0].Name, tc.GetChainAID(), "atoma", tc.CometBFTConfig) | ||
chainBCfg := newDefaultSimappConfig(tc.ChainConfigs[1], tc.ChainConfigs[1].Name, tc.GetChainBID(), "atomb", tc.CometBFTConfig) | ||
|
||
chainAVal, chainAFn := getValidatorsAndFullNodes(0) | ||
chainBVal, chainBFn := getValidatorsAndFullNodes(1) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,7 +4,10 @@ | |||||
"context" | ||||||
"errors" | ||||||
"fmt" | ||||||
"os" | ||||||
"path" | ||||||
"strings" | ||||||
"testing" | ||||||
|
||||||
dockerclient "github.com/docker/docker/client" | ||||||
interchaintest "github.com/strangelove-ventures/interchaintest/v8" | ||||||
|
@@ -67,6 +70,41 @@ | |||||
} | ||||||
} | ||||||
|
||||||
// ConfigureGenesisDebugExport sets, if needed, env variables to enable exporting of Genesis debug files. | ||||||
func (s *E2ETestSuite) ConfigureGenesisDebugExport(t *testing.T) { | ||||||
t.Helper() | ||||||
tc := LoadConfig() | ||||||
cfg := tc.DebugConfig.GenesisDebug | ||||||
if !cfg.DumpGenesisDebugInfo { | ||||||
return | ||||||
} | ||||||
|
||||||
exportPath := cfg.ExportFilePath | ||||||
if exportPath == "" { | ||||||
e2eDir, err := diagnostics.GetE2EDir(t) | ||||||
if err != nil { | ||||||
s.Fail("can't get e2edir: %w", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using - s.Fail("can't get e2edir: %w", err)
+ s.Require().NoError(err, "can't get e2edir") Committable suggestion
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you kind rabbit! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
} | ||||||
exportPath = path.Join(e2eDir, defaultGenesisExportPath) | ||||||
} | ||||||
|
||||||
if !path.IsAbs(exportPath) { | ||||||
wd, err := os.Getwd() | ||||||
if err != nil { | ||||||
s.Fail("can't get working directory: %w", err) | ||||||
} | ||||||
exportPath = path.Join(wd, exportPath) | ||||||
} | ||||||
|
||||||
t.Setenv("EXPORT_GENESIS_FILE_PATH", exportPath) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add a link to interchaintest code for where this is used |
||||||
chainIdx, err := tc.GetChainIndex(cfg.ChainName) | ||||||
if err != nil { | ||||||
s.Fail(err.Error()) | ||||||
} | ||||||
genesisChainName := fmt.Sprintf("%s-%d", cfg.ChainName, chainIdx+1) | ||||||
t.Setenv("EXPORT_GENESIS_CHAIN", genesisChainName) | ||||||
} | ||||||
|
||||||
// GetRelayerUsers returns two ibc.Wallet instances which can be used for the relayer users | ||||||
// on the two chains. | ||||||
func (s *E2ETestSuite) GetRelayerUsers(ctx context.Context, chainOpts ...ChainOptionConfiguration) (ibc.Wallet, ibc.Wallet) { | ||||||
|
@@ -173,7 +211,7 @@ | |||||
|
||||||
// generatePathName generates the path name using the test suites name | ||||||
func (s *E2ETestSuite) generatePathName() string { | ||||||
path := s.GetPathName(s.pathNameIndex) | ||||||
s.pathNameIndex++ | ||||||
return path | ||||||
} | ||||||
|
@@ -219,7 +257,7 @@ | |||||
s.paths = map[string]pathPair{} | ||||||
} | ||||||
|
||||||
path, ok := s.paths[s.T().Name()] | ||||||
if ok { | ||||||
return path.chainA, path.chainB | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be reverted before review. I had to do it as I don't have fzf available on github codespaces