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

chore: set e2e tests to run in parallel #729

Closed
wants to merge 13 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ endif
.PHONY: run-tests test test-all $(TEST_TARGETS)

test-e2e: build-docker-e2e
go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) -count=1 --tags=e2e
go test -mod=readonly -timeout=25m -v $(PACKAGES_E2E) --tags=e2e

test-sim-nondeterminism:
@echo "Running non-determinism test..."
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/btc_timestamping_phase2_hermes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ func (s *BTCTimestampingPhase2HermesTestSuite) Test1IbcCheckpointingPhase2Hermes
// BTC timestamps in Babylon contract
chainA.WaitUntilHeight(int64(endEpochNum*10 + 5))
babylonNode.FinalizeSealedEpochs(1, endEpochNum)
// wait another block to take effect
babylonNode.WaitForNextBlock()

// ensure endEpochNum has been finalised
endEpoch, err := babylonNode.QueryRawCheckpoint(endEpochNum)
s.NoError(err)
s.Equal(endEpoch.Status, ct.Finalized)
s.Equal(endEpoch.Status.String(), ct.Finalized.String())

// there should be 3 IBC packets sent (with sequence number 1, 2, 3).
// Thus, the next sequence number will eventually be 4
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/configurer/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (bc *baseConfigurer) RunIBCTransferChannel() error {
func (bc *baseConfigurer) runHermesIBCRelayer(chainConfigA *chain.Config, chainConfigB *chain.Config) error {
bc.t.Log("starting Hermes relayer container...")

tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-hermes-")
tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-hermes-*")
if err != nil {
return err
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (bc *baseConfigurer) runHermesIBCRelayer(chainConfigA *chain.Config, chainC
func (bc *baseConfigurer) runCosmosIBCRelayer(chainConfigA *chain.Config, chainConfigB *chain.Config) error {
bc.t.Log("Starting Cosmos relayer container...")

tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-cosmos-")
tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-cosmos-*")
if err != nil {
return err
}
Expand Down Expand Up @@ -309,10 +309,11 @@ func (bc *baseConfigurer) createBabylonPhase2Channel(chainA *chain.Config, chain
"--channel-version", chainA.IBCConfig.Version,
"--new-client-connection", "--yes",
}
_, _, err := bc.containerManager.ExecHermesCmd(bc.t, cmd, "SUCCESS")
out, errBuff, err := bc.containerManager.ExecHermesCmd(bc.t, cmd, "")
if err != nil {
return err
}
bc.t.Logf("bc.containerManager.ExecHermesCmd: out: %s, errBuf: %s", out.String(), errBuff.String())
bc.t.Logf("connected %s and %s chains via IBC", chainA.ChainMeta.Id, chainB.ChainMeta.Id)
bc.t.Logf("chainA's IBC config: %v", chainA.IBCConfig)
bc.t.Logf("chainB's IBC config: %v", chainB.IBCConfig)
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/configurer/chain/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
// This fails if unsuccessful.
_, err := n.QueryCurrentHeight()
if err != nil {
st, errRpc := n.rpcClient.Status(context.Background())
n.t.Logf("failed to query current height, status %+v: %s", st)

Check failure on line 72 in test/e2e/configurer/chain/node.go

View workflow job for this annotation

GitHub Actions / lint_test / integration-tests

(*testing.common).Logf format %s reads arg #2, but call has 1 arg

Check failure on line 72 in test/e2e/configurer/chain/node.go

View workflow job for this annotation

GitHub Actions / lint_test / lint

printf: (*testing.common).Logf format %s reads arg #2, but call has 1 arg (govet)

Check failure on line 72 in test/e2e/configurer/chain/node.go

View workflow job for this annotation

GitHub Actions / lint_test / unit-tests

(*testing.common).Logf format %s reads arg #2, but call has 1 arg
n.t.Logf("Logpath: %s", resource.Container.LogPath)
if errRpc != nil {
n.t.Logf("errRpc: %s", errRpc.Error())
}

stnode, errNode := n.Status()
n.t.Logf("failed to query current height, status node %+v: %s", stnode, err.Error())
if errNode != nil {
n.t.Logf("errNode: %s", errNode.Error())
}
return false
}
n.t.Logf("started node container: %s", n.Name)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/configurer/current.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (cb *CurrentBranchConfigurer) ConfigureChains() error {

func (cb *CurrentBranchConfigurer) ConfigureChain(chainConfig *chain.Config) error {
cb.t.Logf("starting e2e infrastructure from current branch for chain-id: %s", chainConfig.Id)
tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-")
tmpDir, err := os.MkdirTemp("", "bbn-e2e-testnet-*")
if err != nil {
return err
}
Expand Down
53 changes: 38 additions & 15 deletions test/e2e/configurer/factory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package configurer

import (
"fmt"
"testing"

"github.com/babylonchain/babylon/test/e2e/configurer/chain"
Expand Down Expand Up @@ -114,31 +115,33 @@ var (
// TODO currently only one configuration is available. Consider testing upgrades
// when necessary
func NewBTCTimestampingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) {
containerManager, err := containers.NewManager(isDebugLogEnabled, false, false)
identifier := "btc-timestamp"
containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false)
if err != nil {
return nil, err
}

return NewCurrentBranchConfigurer(t,
[]*chain.Config{
chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, ibcConfigChainA),
chain.New(t, containerManager, initialization.ChainBID, validatorConfigsChainB, ibcConfigChainB),
chain.New(t, containerManager, initialization.ChainAID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainA), ibcConfigChainA),
chain.New(t, containerManager, initialization.ChainBID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainB), ibcConfigChainB),
},
withIBC(baseSetup), // base set up with IBC
containerManager,
), nil
}

func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) {
containerManager, err := containers.NewManager(isDebugLogEnabled, false, false)
identifier := "ibc-transfer"
containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false)
if err != nil {
return nil, err
}

return NewCurrentBranchConfigurer(t,
[]*chain.Config{
chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, ibcConfigChainA),
chain.New(t, containerManager, initialization.ChainBID, validatorConfigsChainB, ibcConfigChainB),
chain.New(t, containerManager, initialization.ChainAID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainA), ibcConfigChainA),
chain.New(t, containerManager, initialization.ChainBID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainB), ibcConfigChainB),
},
withIBCTransferChannel(baseSetup), // base set up with IBC
containerManager,
Expand All @@ -147,15 +150,16 @@ func NewIBCTransferConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer,

// NewBTCTimestampingPhase2Configurer returns a new Configurer for BTC timestamping service (phase 2).
func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) {
containerManager, err := containers.NewManager(isDebugLogEnabled, false, false)
identifier := "btc-timestamping"
containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false)
if err != nil {
return nil, err
}

return NewCurrentBranchConfigurer(t,
[]*chain.Config{
chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, ibcConfigChainA),
chain.New(t, containerManager, initialization.ChainBID, validatorConfigsChainB, ibcConfigChainB),
chain.New(t, containerManager, initialization.ChainAID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainA), ibcConfigChainA),
chain.New(t, containerManager, initialization.ChainBID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainB), ibcConfigChainB),
},
withPhase2IBC(baseSetup), // IBC setup (requires contract address)
containerManager,
Expand All @@ -164,15 +168,16 @@ func NewBTCTimestampingPhase2Configurer(t *testing.T, isDebugLogEnabled bool) (C

// NewBTCTimestampingPhase2RlyConfigurer returns a new Configurer for BTC timestamping service (phase 2), using the Go relayer (rly).
func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) {
containerManager, err := containers.NewManager(isDebugLogEnabled, true, false)
identifier := "btc-timestamping-rly"
containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, true, false)
if err != nil {
return nil, err
}

return NewCurrentBranchConfigurer(t,
[]*chain.Config{
chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, ibcConfigChainA),
chain.New(t, containerManager, initialization.ChainBID, validatorConfigsChainB, ibcConfigChainB),
chain.New(t, containerManager, initialization.ChainAID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainA), ibcConfigChainA),
chain.New(t, containerManager, initialization.ChainBID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainB), ibcConfigChainB),
},
withPhase2RlyIBC(baseSetup), // IBC setup with wasmd and Go relayer
containerManager,
Expand All @@ -181,15 +186,16 @@ func NewBTCTimestampingPhase2RlyConfigurer(t *testing.T, isDebugLogEnabled bool)

// NewBTCStakingConfigurer returns a new Configurer for BTC staking service
func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, error) {
containerManager, err := containers.NewManager(isDebugLogEnabled, false, false)
identifier := "btc-staking"
containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, false)
if err != nil {
return nil, err
}

return NewCurrentBranchConfigurer(t,
[]*chain.Config{
// we only need 1 chain for testing BTC staking
chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil),
chain.New(t, containerManager, initialization.ChainAID, nodeCfgsWithIdentifier(identifier, validatorConfigsChainA), nil),
},
baseSetup, // base set up
containerManager,
Expand All @@ -198,7 +204,8 @@ func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer,

// NewSoftwareUpgradeConfigurer returns a new Configurer for Software Upgrade testing
func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradePath string) (Configurer, error) {
containerManager, err := containers.NewManager(isDebugLogEnabled, false, true)
identifier := "software-upgrade"
containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, true)
if err != nil {
return nil, err
}
Expand All @@ -214,3 +221,19 @@ func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradeP
0,
), nil
}

func nodeCfgsWithIdentifier(identifier string, cfgs []*initialization.NodeConfig) []*initialization.NodeConfig {
newCfgs := make([]*initialization.NodeConfig, len(cfgs))
for i, cfg := range cfgs {
newCfgs[i] = &initialization.NodeConfig{
Name: fmt.Sprintf("%s-%s", cfg.Name, identifier),
Pruning: cfg.Pruning,
PruningKeepRecent: cfg.PruningKeepRecent,
PruningInterval: cfg.PruningInterval,
SnapshotInterval: cfg.SnapshotInterval,
SnapshotKeepRecent: cfg.SnapshotKeepRecent,
IsValidator: cfg.IsValidator,
}
}
return newCfgs
}
39 changes: 29 additions & 10 deletions test/e2e/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,27 @@ type Manager struct {
network *dockertest.Network
resources map[string]*dockertest.Resource
isDebugLogEnabled bool
identifier string
}

// NewManager creates a new Manager instance and initializes
// all Docker specific utilities. Returns an error if initialization fails.
func NewManager(isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (docker *Manager, err error) {
docker = &Manager{
func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer, isUpgrade bool) (m *Manager, err error) {
m = &Manager{
ImageConfig: NewImageConfig(isCosmosRelayer, isUpgrade),
resources: make(map[string]*dockertest.Resource),
isDebugLogEnabled: isDebugLogEnabled,
identifier: identifier,
}
docker.pool, err = dockertest.NewPool("")
m.pool, err = dockertest.NewPool("")
if err != nil {
return nil, err
}
docker.network, err = docker.pool.CreateNetwork("bbn-testnet")
m.network, err = m.pool.CreateNetwork(m.NetworkName())
if err != nil {
return nil, err
}
return docker, nil
return m, nil
}

// ExecTxCmd Runs ExecTxCmdWithSuccessString searching for `code: 0`
Expand All @@ -73,7 +75,7 @@ func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, conta

// ExecHermesCmd executes command on the hermes relaer container.
func (m *Manager) ExecHermesCmd(t *testing.T, command []string, success string) (bytes.Buffer, bytes.Buffer, error) {
return m.ExecCmd(t, hermesContainerName, command, success)
return m.ExecCmd(t, m.HermesContainerName(), command, success)
}

// ExecCmd executes command by running it on the node container (specified by containerName)
Expand Down Expand Up @@ -162,7 +164,7 @@ func (m *Manager) ExecCmd(t *testing.T, containerName string, command []string,
func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnemonic, chainBID, osmoBRelayerNodeName, osmoBValMnemonic string, hermesCfgPath string) (*dockertest.Resource, error) {
hermesResource, err := m.pool.RunWithOptions(
&dockertest.RunOptions{
Name: hermesContainerName,
Name: m.HermesContainerName(),
Repository: m.RelayerRepository,
Tag: m.RelayerTag,
NetworkID: m.network.Network.ID,
Expand Down Expand Up @@ -198,7 +200,7 @@ func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnem
if err != nil {
return nil, err
}
m.resources[hermesContainerName] = hermesResource
m.resources[m.HermesContainerName()] = hermesResource
return hermesResource, nil
}

Expand All @@ -207,7 +209,7 @@ func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnem
func (m *Manager) RunRlyResource(chainAID, osmoARelayerNodeName, osmoAValMnemonic, chainAIbcPort, chainBID, osmoBRelayerNodeName, osmoBValMnemonic, chainBIbcPort string, rlyCfgPath string) (*dockertest.Resource, error) {
rlyResource, err := m.pool.RunWithOptions(
&dockertest.RunOptions{
Name: cosmosRelayerContainerName,
Name: m.RelayerContainerName(),
Repository: m.RelayerRepository,
Tag: m.RelayerTag,
NetworkID: m.network.Network.ID,
Expand Down Expand Up @@ -239,7 +241,7 @@ func (m *Manager) RunRlyResource(chainAID, osmoARelayerNodeName, osmoAValMnemoni
if err != nil {
return nil, err
}
m.resources[cosmosRelayerContainerName] = rlyResource
m.resources[m.RelayerContainerName()] = rlyResource
return rlyResource, nil
}

Expand All @@ -255,12 +257,14 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st
Name: containerName,
Repository: m.CurrentRepository,
NetworkID: m.network.Network.ID,
Networks: []*dockertest.Network{m.network},
User: "root:root",
Entrypoint: []string{
"sh",
"-c",
"babylond start " + FlagHome,
},
// TODO: verify if exposed ports need to be dinamic, since e2e might run in parallel
ExposedPorts: []string{"26656", "26657", "1317", "9090"},
Mounts: []string{
fmt.Sprintf("%s/:%s", valCondifDir, BabylonHomePath),
Expand Down Expand Up @@ -346,6 +350,21 @@ func noRestart(config *docker.HostConfig) {
}
}

// RelayerContainerName returns the relayer container name with identifier of the manager.
func (m *Manager) RelayerContainerName() string {
return fmt.Sprintf("%s-%s", cosmosRelayerContainerName, m.identifier)
}

// HermesContainerName returns the hermes relayer container name with identifier of the manager.
func (m *Manager) HermesContainerName() string {
return fmt.Sprintf("%s-%s", hermesContainerName, m.identifier)
}

// NetworkName returns the network name with identifier of the manager.
func (m *Manager) NetworkName() string {
return fmt.Sprintf("bbn-testnet-%s", m.identifier)
}

// RunChainInitResource runs a chain init container to initialize genesis and configs for a chain with chainId.
// The chain is to be configured with chainVotingPeriod and validators deserialized from validatorConfigBytes.
// The genesis and configs are to be mounted on the init container as volume on mountDir path.
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,42 @@ import (
"github.com/stretchr/testify/suite"
)

// Each test suite can be run parallel, so it should not exist dependency
// between test different suite. However, inisde the suite itself, it can
// have dependency between Test1 and Test2, example:
// BTCStakingTestSuite has Test2SubmitCovenantSignature which
// depends on Test1CreateFinalityProviderAndDelegation for creating the
// finality provider used to query fp delegations and do its check.

// IBCTransferTestSuite tests IBC transfer end-to-end
func TestIBCTranferTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(IBCTransferTestSuite))
}

// TestBTCTimestampingTestSuite tests BTC timestamping protocol end-to-end
func TestBTCTimestampingTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(BTCTimestampingTestSuite))
}

// TestBTCTimestampingPhase2HermesTestSuite tests BTC timestamping phase 2 protocol end-to-end,
// with the Hermes relayer
func TestBTCTimestampingPhase2HermesTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(BTCTimestampingPhase2HermesTestSuite))
}

// TestBTCTimestampingPhase2RlyTestSuite tests BTC timestamping phase 2 protocol end-to-end,
// with the Go relayer
func TestBTCTimestampingPhase2RlyTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(BTCTimestampingPhase2RlyTestSuite))
}

// TestBTCStakingTestSuite tests BTC staking protocol end-to-end
func TestBTCStakingTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(BTCStakingTestSuite))
}

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/initialization/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestChainInit(t *testing.T) {
IsValidator: false,
},
}
dataDir, err = os.MkdirTemp("", "bbn-e2e-testnet-test")
dataDir, err = os.MkdirTemp("", "bbn-e2e-testnet-test-*")
)

chain, err := initialization.InitChain(id, dataDir, nodeConfigs, time.Second*3, time.Second, forkHeight)
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestSingleNodeInit(t *testing.T) {
SnapshotKeepRecent: 1,
IsValidator: false,
}
dataDir, err = os.MkdirTemp("", "bbn-e2e-testnet-test")
dataDir, err = os.MkdirTemp("", "bbn-e2e-testnet-test-*")
)

// Setup
Expand Down
Loading