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

tests: add option to dump genesis files in E2E tests #6100

Merged
merged 38 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
65a41e2
First test to export genesis debug files
bznein Apr 5, 2024
c6266ac
Allow for configuration on chainName and genesis debug info
bznein Apr 6, 2024
9899bf4
Better path handling - and linting
bznein Apr 6, 2024
7f44b73
Extend config to everything
bznein Apr 6, 2024
a324846
Merge branch 'main' into e2e-genesis
bznein Apr 6, 2024
f55d53f
Linter
bznein Apr 6, 2024
f8f097b
Default for chain names.
bznein Apr 6, 2024
934e2f0
Revert local hack
bznein Apr 6, 2024
fe24e23
Linter
bznein Apr 6, 2024
8434b70
Default genesis chain name
bznein Apr 6, 2024
8a02d35
Use genesischainame when validating
bznein Apr 6, 2024
b9d9841
Added comment.
bznein Apr 6, 2024
3a78f8c
Comments
bznein Apr 6, 2024
06795b2
Use s.Require().NoError() instead of s.Fail()
bznein Apr 6, 2024
1cd3073
Rename import
bznein Apr 6, 2024
64b98a6
Merge branch 'main' into e2e-genesis
bznein Apr 8, 2024
c8cc6b3
Moved init logic into SetupTest
Apr 8, 2024
a46ca74
Moved init logic into SetupTest
Apr 8, 2024
d37b961
Missed one revert
bznein Apr 8, 2024
3fb3d57
Merge branch 'main' into e2e-genesis
bznein Apr 8, 2024
0261a22
Refactoring.
bznein Apr 8, 2024
63db86c
PR Feedback
bznein Apr 8, 2024
a6a6322
Merge branch 'main' into e2e-genesis
chatton Apr 8, 2024
ecd0186
Merge branch 'main' into e2e-genesis
bznein Apr 8, 2024
7d4b8d5
Small refactoring.
bznein Apr 8, 2024
e6f5512
Fix typo in comment
bznein Apr 8, 2024
7c16d6b
Merge branch 'main' into e2e-genesis
bznein Apr 9, 2024
495964b
Merge branch 'main' into e2e-genesis
bznein Apr 9, 2024
d39df3b
Merge branch 'main' into e2e-genesis
bznein Apr 9, 2024
ed2fcc9
Merge branch 'main' into e2e-genesis
chatton Apr 9, 2024
c1a77c5
Merge branch 'main' into e2e-genesis
bznein Apr 9, 2024
d6bbd8e
Merge branch 'main' into e2e-genesis
bznein Apr 9, 2024
eba5cbc
Merge branch 'main' into e2e-genesis
bznein Apr 10, 2024
35e3f74
Rename path variable and un-alias path import.
bznein Apr 10, 2024
e303ca0
Fix missing rename
bznein Apr 10, 2024
c199f76
Merge branch 'main' into e2e-genesis
bznein Apr 10, 2024
0846468
Update e2e/testsuite/testsuite.go
bznein Apr 11, 2024
f70c7d9
Unexport method.
bznein Apr 11, 2024
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
2 changes: 1 addition & 1 deletion e2e/scripts/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ _verify_dependencies

# if the dev configs directory is present, enable fzf completion to select a test config file to use.
if [[ -d "dev-configs" ]]; then
export E2E_CONFIG_PATH="$(pwd)/dev-configs/$(_select_test_config)"
export E2E_CONFIG_PATH="/workspaces/ibc-go/e2e/dev-configs/config.yaml"
Copy link
Contributor Author

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

echo "Using configuration file at ${E2E_CONFIG_PATH}"
fi

Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/core/02-client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const (
)

func TestClientTestSuite(t *testing.T) {
testifysuite.Run(t, new(ClientTestSuite))
s := new(ClientTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type ClientTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/core/03-connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
)

func TestConnectionTestSuite(t *testing.T) {
testifysuite.Run(t, new(ConnectionTestSuite))
s := new(ConnectionTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type ConnectionTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/interchain_accounts/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ var orderMapping = map[channeltypes.Order][]string{
}

func TestInterchainAccountsTestSuite(t *testing.T) {
testifysuite.Run(t, new(InterchainAccountsTestSuite))
s := new(InterchainAccountsTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type InterchainAccountsTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/interchain_accounts/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import (
)

func TestInterchainAccountsGovTestSuite(t *testing.T) {
testifysuite.Run(t, new(InterchainAccountsGovTestSuite))
s := new(InterchainAccountsGovTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type InterchainAccountsGovTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/interchain_accounts/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const (
)

func TestInterchainAccountsGroupsTestSuite(t *testing.T) {
testifysuite.Run(t, new(InterchainAccountsGroupsTestSuite))
s := new(InterchainAccountsGroupsTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type InterchainAccountsGroupsTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/interchain_accounts/incentivized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import (
)

func TestIncentivizedInterchainAccountsTestSuite(t *testing.T) {
testifysuite.Run(t, new(IncentivizedInterchainAccountsTestSuite))
s := new(IncentivizedInterchainAccountsTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type IncentivizedInterchainAccountsTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/interchain_accounts/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (
)

func TestInterchainAccountsLocalhostTestSuite(t *testing.T) {
testifysuite.Run(t, new(LocalhostInterchainAccountsTestSuite))
s := new(LocalhostInterchainAccountsTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type LocalhostInterchainAccountsTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/interchain_accounts/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
)

func TestInterchainAccountsParamsTestSuite(t *testing.T) {
testifysuite.Run(t, new(InterchainAccountsParamsTestSuite))
s := new(InterchainAccountsParamsTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type InterchainAccountsParamsTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/interchain_accounts/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
)

func TestInterchainAccountsQueryTestSuite(t *testing.T) {
testifysuite.Run(t, new(InterchainAccountsQueryTestSuite))
s := new(InterchainAccountsQueryTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type InterchainAccountsQueryTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/interchain_accounts/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
)

func TestInterchainAccountsChannelUpgradesTestSuite(t *testing.T) {
testifysuite.Run(t, new(InterchainAccountsChannelUpgradesTestSuite))
s := new(InterchainAccountsChannelUpgradesTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type InterchainAccountsChannelUpgradesTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/transfer/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
)

func TestAuthzTransferTestSuite(t *testing.T) {
testifysuite.Run(t, new(AuthzTransferTestSuite))
s := new(AuthzTransferTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type AuthzTransferTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/transfer/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
)

func TestTransferTestSuite(t *testing.T) {
testifysuite.Run(t, new(TransferTestSuite))
suite := new(TransferTestSuite)
suite.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, suite)
}

type TransferTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/transfer/incentivized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ type IncentivizedTransferTestSuite struct {
}

func TestIncentivizedTransferTestSuite(t *testing.T) {
testifysuite.Run(t, new(IncentivizedTransferTestSuite))
s := new(IncentivizedTransferTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

func (s *IncentivizedTransferTestSuite) TestMsgPayPacketFee_AsyncSingleSender_Succeeds() {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/transfer/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
)

func TestTransferLocalhostTestSuite(t *testing.T) {
testifysuite.Run(t, new(LocalhostTransferTestSuite))
s := new(LocalhostTransferTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type LocalhostTransferTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/transfer/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
)

func TestTransferChannelUpgradesTestSuite(t *testing.T) {
testifysuite.Run(t, new(TransferChannelUpgradesTestSuite))
s := new(TransferChannelUpgradesTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type TransferChannelUpgradesTestSuite struct {
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/upgrades/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
)

func TestGenesisTestSuite(t *testing.T) {
suite.Run(t, new(GenesisTestSuite))
s := new(GenesisTestSuite)
s.ConfigureGenesisDebugExport(t)
suite.Run(t, s)
}

type GenesisTestSuite struct {
Expand Down
5 changes: 3 additions & 2 deletions e2e/tests/upgrades/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ func TestUpgradeTestSuite(t *testing.T) {
if testCfg.UpgradeConfig.Tag == "" || testCfg.UpgradeConfig.PlanName == "" {
t.Fatalf("%s and %s must be set when running an upgrade test", testsuite.ChainUpgradeTagEnv, testsuite.ChainUpgradePlanEnv)
}

testifysuite.Run(t, new(UpgradeTestSuite))
s := new(UpgradeTestSuite)
s.ConfigureGenesisDebugExport(t)
testifysuite.Run(t, s)
}

type UpgradeTestSuite struct {
Expand Down
6 changes: 3 additions & 3 deletions e2e/testsuite/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Collect(t *testing.T, dc *dockerclient.Client, debugModeEnabled bool, chain
t.Logf("writing logs for test: %s", t.Name())

ctx := context.TODO()
e2eDir, err := getE2EDir(t)
e2eDir, err := GetE2EDir(t)
if err != nil {
t.Logf("failed finding log directory: %s", err)
return
Expand Down Expand Up @@ -162,8 +162,8 @@ func relayerDiagnosticAbsoluteFilePaths() []string {
}
}

// getE2EDir finds the e2e directory above the test.
func getE2EDir(t *testing.T) (string, error) {
// GetE2EDir finds the e2e directory above the test.
func GetE2EDir(t *testing.T) (string, error) {
t.Helper()

wd, err := os.Getwd()
Expand Down
57 changes: 55 additions & 2 deletions e2e/testsuite/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Expand Down Expand Up @@ -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
}

Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"context"
"errors"
"fmt"
"os"
"path"
"strings"
"testing"

dockerclient "github.com/docker/docker/client"
interchaintest "github.com/strangelove-ventures/interchaintest/v8"
Expand Down Expand Up @@ -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)
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using s.Require().NoError(err) instead of s.Fail for error handling to immediately halt the test execution upon encountering an error, ensuring cleaner test failures and avoiding potential subsequent errors.

- s.Fail("can't get e2edir: %w", err)
+ s.Require().NoError(err, "can't get e2edir")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
s.Fail("can't get e2edir: %w", err)
s.Require().NoError(err, "can't get e2edir")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you kind rabbit!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bznein, you're very welcome! I'm here to help. 😊

(\__/) 
(•ㅅ•) CodeRabbit is happy to assist!
/   づ

If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

}
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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Expand Down Expand Up @@ -173,7 +211,7 @@

// generatePathName generates the path name using the test suites name
func (s *E2ETestSuite) generatePathName() string {
path := s.GetPathName(s.pathNameIndex)

Check warning on line 214 in e2e/testsuite/testsuite.go

View workflow job for this annotation

GitHub Actions / lint

import-shadowing: The name 'path' shadows an import name (revive)
s.pathNameIndex++
return path
}
Expand Down Expand Up @@ -219,7 +257,7 @@
s.paths = map[string]pathPair{}
}

path, ok := s.paths[s.T().Name()]

Check warning on line 260 in e2e/testsuite/testsuite.go

View workflow job for this annotation

GitHub Actions / lint

import-shadowing: The name 'path' shadows an import name (revive)
if ok {
return path.chainA, path.chainB
}
Expand Down
Loading