Skip to content

Commit

Permalink
[e2e] Enhance post-test bootstrap checks
Browse files Browse the repository at this point in the history
 - bootstrap all subnets (a request for hypersdk)
 - enable post-bootstrap interaction with the node by returning it
   from the check function and ensuring the node is only stopped at
   the end of the test (a request for hypersdk)
 - add bootstrap check to xsvm e2e
  • Loading branch information
maru-ava committed Jul 31, 2024
1 parent fdd4693 commit 6dee74f
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() {
_ = e2e.SendEthTransaction(ethClient, signedTx)
})

e2e.CheckBootstrapIsPossible(privateNetwork)
_ = e2e.CheckBootstrapIsPossible(privateNetwork, ginkgo.DeferCleanup)
})
})
2 changes: 1 addition & 1 deletion tests/e2e/c/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
require.Positive(balances[avaxAssetID])
})

e2e.CheckBootstrapIsPossible(e2e.Env.GetNetwork())
_ = e2e.CheckBootstrapIsPossible(e2e.Env.GetNetwork(), ginkgo.DeferCleanup)
})
})
2 changes: 1 addition & 1 deletion tests/e2e/p/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,6 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
ginkgo.By("stopping validator node to free up resources for a bootstrap check")
require.NoError(node.Stop(e2e.DefaultContext()))

e2e.CheckBootstrapIsPossible(network)
_ = e2e.CheckBootstrapIsPossible(network, ginkgo.DeferCleanup)
})
})
2 changes: 1 addition & 1 deletion tests/e2e/p/staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
ginkgo.By("stopping alpha to free up resources for a bootstrap check")
require.NoError(alphaNode.Stop(e2e.DefaultContext()))

e2e.CheckBootstrapIsPossible(network)
_ = e2e.CheckBootstrapIsPossible(network, ginkgo.DeferCleanup)
})
})
2 changes: 1 addition & 1 deletion tests/e2e/p/validator_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ var _ = e2e.DescribePChain("[Validator Sets]", func() {
}
})

e2e.CheckBootstrapIsPossible(network)
_ = e2e.CheckBootstrapIsPossible(network, ginkgo.DeferCleanup)
})
})
2 changes: 2 additions & 0 deletions tests/e2e/vms/xsvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ var _ = ginkgo.Describe("[XSVM]", func() {
destinationBalance, err := destinationClient.Balance(e2e.DefaultContext(), destinationKey.Address(), sourceChain.ChainID)
require.NoError(err)
require.Equal(units.Schmeckle, destinationBalance)

_ = e2e.CheckBootstrapIsPossible(network, ginkgo.DeferCleanup)
})
})

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/x/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ var _ = e2e.DescribeXChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
require.Positive(balances[avaxAssetID])
})

e2e.CheckBootstrapIsPossible(e2e.Env.GetNetwork())
_ = e2e.CheckBootstrapIsPossible(e2e.Env.GetNetwork(), ginkgo.DeferCleanup)
})
})
39 changes: 26 additions & 13 deletions tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ava-labs/coreth/interfaces"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
Expand Down Expand Up @@ -53,6 +54,11 @@ const (
PrivateNetworksDirName = "private_networks"
)

// RegisterCleanupFunc is a function that registers a function intended to be called at
// the end of a given test. A function that accepts this type can avoid a direct
// dependency on ginkgo's DeferCleanup function.
type RegisterCleanupFunc func(args ...interface{})

// Create a new wallet for the provided keychain against the specified node URI.
func NewWallet(keychain *secp256k1fx.Keychain, nodeURI tmpnet.NodeURI) primary.Wallet {
tests.Outf("{{blue}} initializing a new wallet for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI)
Expand Down Expand Up @@ -185,34 +191,41 @@ func WithSuggestedGasPrice(ethClient ethclient.Client) common.Option {
return common.WithBaseFee(baseFee)
}

// Verify that a new node can bootstrap into the network. This function is safe to call
// from `Teardown` by virtue of not depending on ginkgo.DeferCleanup.
func CheckBootstrapIsPossible(network *tmpnet.Network) {
// Verify that a new node can bootstrap into the network. If the check wasn't skipped,
// the node will be returned to the caller.
func CheckBootstrapIsPossible(network *tmpnet.Network, registerCleanup RegisterCleanupFunc) *tmpnet.Node {
require := require.New(ginkgo.GinkgoT())

if len(os.Getenv(SkipBootstrapChecksEnvName)) > 0 {
tests.Outf("{{yellow}}Skipping bootstrap check due to the %s env var being set", SkipBootstrapChecksEnvName)
return
return nil
}
ginkgo.By("checking if bootstrap is possible with the current network state")

ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancel()
// Ensure all subnets are bootstrapped
subnetIDs := make([]string, len(network.Subnets))
for i, subnet := range network.Subnets {
subnetIDs[i] = subnet.SubnetID.String()
}
flags := tmpnet.FlagsMap{
config.TrackSubnetsKey: strings.Join(subnetIDs, ","),
}

node := tmpnet.NewEphemeralNode(tmpnet.FlagsMap{})
require.NoError(network.StartNode(ctx, ginkgo.GinkgoWriter, node))
node := tmpnet.NewEphemeralNode(flags)
require.NoError(network.StartNode(DefaultContext(), ginkgo.GinkgoWriter, node))
// StartNode will initiate node stop if an error is encountered during start,
// so no further cleanup effort is required if an error is seen here.

// Ensure the node is always stopped at the end of the check
defer func() {
ctx, cancel = context.WithTimeout(context.Background(), DefaultTimeout)
// Register a cleanup to ensure the node is stopped after the check
registerCleanup(func() {
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancel()
require.NoError(node.Stop(ctx))
}()
})

// Check that the node becomes healthy within timeout
require.NoError(tmpnet.WaitForHealthy(ctx, node))
require.NoError(tmpnet.WaitForHealthy(DefaultContext(), node))
return node
}

// Start a temporary network with the provided avalanchego binary.
Expand Down
2 changes: 1 addition & 1 deletion tests/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ var _ = ginkgo.Describe("[Upgrade]", func() {
e2e.WaitForHealthy(node)
}

e2e.CheckBootstrapIsPossible(network)
_ = e2e.CheckBootstrapIsPossible(network, ginkgo.DeferCleanup)
})
})

0 comments on commit 6dee74f

Please # to comment.