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

tmpnet: Move tmpnet/local to tmpnet package #2457

Merged
merged 3 commits into from
Dec 15, 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
11 changes: 7 additions & 4 deletions scripts/tests.upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ if ! [[ "$0" =~ scripts/tests.upgrade.sh ]]; then
exit 255
fi

# 1.10.17 is the first version compatible with bls signing keys being
# included in the genesis. Attempting to upgrade from prior versions
# will result in nodes failing to boot due to the hash of the genesis
# not matching the hash of the committed genesis block.
# The AvalancheGo local network does not support long-lived
# backwards-compatible networks. When a breaking change is made to the
# local network, this flag must be updated to the last compatible
# version with the latest code.
#
# v1.10.17 includes the AWM activation on the C-Chain local network
# and the inclusion of BLS Public Keys in the network genesis.
DEFAULT_VERSION="1.10.17"

VERSION="${1:-${DEFAULT_VERSION}}"
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() {
privateNetwork := e2e.Env.NewPrivateNetwork()

ginkgo.By("allocating a pre-funded key")
key := privateNetwork.GetConfig().PreFundedKeys[0]
key := privateNetwork.PreFundedKeys[0]
ethAddress := evm.GetEthAddress(key)

ginkgo.By("initializing a coreth client")
node := privateNetwork.GetNodes()[0]
node := privateNetwork.Nodes[0]
nodeURI := tmpnet.NodeURI{
NodeID: node.GetID(),
URI: node.GetProcessContext().URI,
NodeID: node.NodeID,
URI: node.URI,
}
ethClient := e2e.NewEthClient(nodeURI)

Expand Down
18 changes: 8 additions & 10 deletions tests/e2e/faultinjection/duplicate_node_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ var _ = ginkgo.Describe("Duplicate node handling", func() {

ginkgo.It("should ensure that a given Node ID (i.e. staking keypair) can be used at most once on a network", func() {
network := e2e.Env.GetNetwork()
nodes := network.GetNodes()

ginkgo.By("creating new node")
node1 := e2e.AddEphemeralNode(network, tmpnet.FlagsMap{})
e2e.WaitForHealthy(node1)

ginkgo.By("checking that the new node is connected to its peers")
checkConnectedPeers(nodes, node1)
checkConnectedPeers(network.Nodes, node1)

ginkgo.By("creating a second new node with the same staking keypair as the first new node")
node1Flags := node1.GetConfig().Flags
node1Flags := node1.Flags
node2Flags := tmpnet.FlagsMap{
config.StakingTLSKeyContentKey: node1Flags[config.StakingTLSKeyContentKey],
config.StakingCertContentKey: node1Flags[config.StakingCertContentKey],
Expand All @@ -56,37 +55,36 @@ var _ = ginkgo.Describe("Duplicate node handling", func() {
e2e.WaitForHealthy(node2)

ginkgo.By("checking that the second new node is connected to its peers")
checkConnectedPeers(nodes, node2)
checkConnectedPeers(network.Nodes, node2)

// A bootstrap check was already performed by the second node.
})
})

// Check that a new node is connected to existing nodes and vice versa
func checkConnectedPeers(existingNodes []tmpnet.Node, newNode tmpnet.Node) {
func checkConnectedPeers(existingNodes []*tmpnet.Node, newNode *tmpnet.Node) {
require := require.New(ginkgo.GinkgoT())

// Collect the node ids of the new node's peers
infoClient := info.NewClient(newNode.GetProcessContext().URI)
infoClient := info.NewClient(newNode.URI)
peers, err := infoClient.Peers(e2e.DefaultContext())
require.NoError(err)
peerIDs := set.NewSet[ids.NodeID](len(existingNodes))
for _, peer := range peers {
peerIDs.Add(peer.ID)
}

newNodeID := newNode.GetID()
for _, existingNode := range existingNodes {
// Check that the existing node is a peer of the new node
require.True(peerIDs.Contains(existingNode.GetID()))
require.True(peerIDs.Contains(existingNode.NodeID))

// Check that the new node is a peer
infoClient := info.NewClient(existingNode.GetProcessContext().URI)
infoClient := info.NewClient(existingNode.URI)
peers, err := infoClient.Peers(e2e.DefaultContext())
require.NoError(err)
isPeer := false
for _, peer := range peers {
if peer.ID == newNodeID {
if peer.ID == newNode.NodeID {
isPeer = true
break
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/p/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
network := e2e.Env.GetNetwork()

ginkgo.By("checking that the network has a compatible minimum stake duration", func() {
minStakeDuration := cast.ToDuration(network.GetConfig().DefaultFlags[config.MinStakeDurationKey])
minStakeDuration := cast.ToDuration(network.DefaultFlags[config.MinStakeDurationKey])
require.Equal(tmpnet.DefaultMinStakeDuration, minStakeDuration)
})

Expand Down Expand Up @@ -91,7 +91,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
e2e.WaitForHealthy(node)

ginkgo.By("retrieving new node's id and pop")
infoClient := info.NewClient(node.GetProcessContext().URI)
infoClient := info.NewClient(node.URI)
nodeID, nodePOP, err := infoClient.GetNodeID(e2e.DefaultContext())
require.NoError(err)

Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/p/staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
network := e2e.Env.GetNetwork()

ginkgo.By("checking that the network has a compatible minimum stake duration", func() {
minStakeDuration := cast.ToDuration(network.GetConfig().DefaultFlags[config.MinStakeDurationKey])
minStakeDuration := cast.ToDuration(network.DefaultFlags[config.MinStakeDurationKey])
require.Equal(tmpnet.DefaultMinStakeDuration, minStakeDuration)
})

Expand Down Expand Up @@ -94,16 +94,16 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
pWallet := baseWallet.P()

ginkgo.By("retrieving alpha node id and pop")
alphaInfoClient := info.NewClient(alphaNode.GetProcessContext().URI)
alphaInfoClient := info.NewClient(alphaNode.URI)
alphaNodeID, alphaPOP, err := alphaInfoClient.GetNodeID(e2e.DefaultContext())
require.NoError(err)

ginkgo.By("retrieving beta node id and pop")
betaInfoClient := info.NewClient(betaNode.GetProcessContext().URI)
betaInfoClient := info.NewClient(betaNode.URI)
betaNodeID, betaPOP, err := betaInfoClient.GetNodeID(e2e.DefaultContext())
require.NoError(err)

pvmClient := platformvm.NewClient(alphaNode.GetProcessContext().URI)
pvmClient := platformvm.NewClient(alphaNode.URI)

const (
delegationPercent = 0.10 // 10%
Expand Down
17 changes: 8 additions & 9 deletions tests/fixture/e2e/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet/local"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/perms"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
Expand Down Expand Up @@ -60,14 +59,14 @@ func NewTestEnvironment(flagVars *FlagVars) *TestEnvironment {
networkDir := flagVars.NetworkDir()

// Load or create a test network
var network *local.LocalNetwork
var network *tmpnet.Network
if len(networkDir) > 0 {
var err error
network, err = local.ReadNetwork(networkDir)
network, err = tmpnet.ReadNetwork(networkDir)
require.NoError(err)
tests.Outf("{{yellow}}Using an existing network configured at %s{{/}}\n", network.Dir)
} else {
network = StartLocalNetwork(flagVars.AvalancheGoExecPath(), DefaultNetworkDir)
network = StartNetwork(flagVars.AvalancheGoExecPath(), DefaultNetworkDir)
}

uris := network.GetURIs()
Expand Down Expand Up @@ -97,8 +96,8 @@ func (te *TestEnvironment) GetRandomNodeURI() tmpnet.NodeURI {
}

// Retrieve the network to target for testing.
func (te *TestEnvironment) GetNetwork() tmpnet.Network {
network, err := local.ReadNetwork(te.NetworkDir)
func (te *TestEnvironment) GetNetwork() *tmpnet.Network {
network, err := tmpnet.ReadNetwork(te.NetworkDir)
te.require.NoError(err)
return network
}
Expand All @@ -123,15 +122,15 @@ func (te *TestEnvironment) NewKeychain(count int) *secp256k1fx.Keychain {
}

// Create a new private network that is not shared with other tests.
func (te *TestEnvironment) NewPrivateNetwork() tmpnet.Network {
func (te *TestEnvironment) NewPrivateNetwork() *tmpnet.Network {
// Load the shared network to retrieve its path and exec path
sharedNetwork, err := local.ReadNetwork(te.NetworkDir)
sharedNetwork, err := tmpnet.ReadNetwork(te.NetworkDir)
te.require.NoError(err)

// The private networks dir is under the shared network dir to ensure it
// will be included in the artifact uploaded in CI.
privateNetworksDir := filepath.Join(sharedNetwork.Dir, PrivateNetworksDirName)
te.require.NoError(os.MkdirAll(privateNetworksDir, perms.ReadWriteExecute))

return StartLocalNetwork(sharedNetwork.ExecPath, privateNetworksDir)
return StartNetwork(sharedNetwork.ExecPath, privateNetworksDir)
}
10 changes: 5 additions & 5 deletions tests/fixture/e2e/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"os"

"github.com/ava-labs/avalanchego/tests/fixture/tmpnet/local"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
)

type FlagVars struct {
Expand All @@ -24,7 +24,7 @@ func (v *FlagVars) NetworkDir() string {
if len(v.networkDir) > 0 {
return v.networkDir
}
return os.Getenv(local.NetworkDirEnvName)
return os.Getenv(tmpnet.NetworkDirEnvName)
}

func (v *FlagVars) AvalancheGoExecPath() string {
Expand All @@ -40,14 +40,14 @@ func RegisterFlags() *FlagVars {
flag.StringVar(
&vars.avalancheGoExecPath,
"avalanchego-path",
os.Getenv(local.AvalancheGoPathEnvName),
fmt.Sprintf("avalanchego executable path (required if not using an existing network). Also possible to configure via the %s env variable.", local.AvalancheGoPathEnvName),
os.Getenv(tmpnet.AvalancheGoPathEnvName),
fmt.Sprintf("avalanchego executable path (required if not using an existing network). Also possible to configure via the %s env variable.", tmpnet.AvalancheGoPathEnvName),
)
flag.StringVar(
&vars.networkDir,
"network-dir",
"",
fmt.Sprintf("[optional] the dir containing the configuration of an existing network to target for testing. Will only be used if --use-existing-network is specified. Also possible to configure via the %s env variable.", local.NetworkDirEnvName),
fmt.Sprintf("[optional] the dir containing the configuration of an existing network to target for testing. Will only be used if --use-existing-network is specified. Also possible to configure via the %s env variable.", tmpnet.NetworkDirEnvName),
)
flag.BoolVar(
&vars.useExistingNetwork,
Expand Down
21 changes: 10 additions & 11 deletions tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet/local"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
Expand Down Expand Up @@ -128,7 +127,7 @@ func Eventually(condition func() bool, waitFor time.Duration, tick time.Duration
// Add an ephemeral node that is only intended to be used by a single test. Its ID and
// URI are not intended to be returned from the Network instance to minimize
// accessibility from other tests.
func AddEphemeralNode(network tmpnet.Network, flags tmpnet.FlagsMap) tmpnet.Node {
func AddEphemeralNode(network *tmpnet.Network, flags tmpnet.FlagsMap) *tmpnet.Node {
require := require.New(ginkgo.GinkgoT())

node, err := network.AddEphemeralNode(ginkgo.GinkgoWriter, flags)
Expand All @@ -137,15 +136,15 @@ func AddEphemeralNode(network tmpnet.Network, flags tmpnet.FlagsMap) tmpnet.Node
// Ensure node is stopped on teardown. It's configuration is not removed to enable
// collection in CI to aid in troubleshooting failures.
ginkgo.DeferCleanup(func() {
tests.Outf("Shutting down ephemeral node %s\n", node.GetID())
tests.Outf("Shutting down ephemeral node %s\n", node.NodeID)
require.NoError(node.Stop())
})

return node
}

// Wait for the given node to report healthy.
func WaitForHealthy(node tmpnet.Node) {
func WaitForHealthy(node *tmpnet.Node) {
// Need to use explicit context (vs DefaultContext()) to support use with DeferCleanup
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
defer cancel()
Expand Down Expand Up @@ -197,7 +196,7 @@ func WithSuggestedGasPrice(ethClient ethclient.Client) common.Option {
}

// Verify that a new node can bootstrap into the network.
func CheckBootstrapIsPossible(network tmpnet.Network) {
func CheckBootstrapIsPossible(network *tmpnet.Network) {
require := require.New(ginkgo.GinkgoT())

if len(os.Getenv(SkipBootstrapChecksEnvName)) > 0 {
Expand All @@ -214,23 +213,23 @@ func CheckBootstrapIsPossible(network tmpnet.Network) {
require.NoError(err)

defer func() {
tests.Outf("Shutting down ephemeral node %s\n", node.GetID())
tests.Outf("Shutting down ephemeral node %s\n", node.NodeID)
require.NoError(node.Stop())
}()

WaitForHealthy(node)
}

// Start a local test-managed network with the provided avalanchego binary.
func StartLocalNetwork(avalancheGoExecPath string, networkDir string) *local.LocalNetwork {
// Start a temporary network with the provided avalanchego binary.
func StartNetwork(avalancheGoExecPath string, networkDir string) *tmpnet.Network {
require := require.New(ginkgo.GinkgoT())

network, err := local.StartNetwork(
network, err := tmpnet.StartNetwork(
DefaultContext(),
ginkgo.GinkgoWriter,
networkDir,
&local.LocalNetwork{
LocalConfig: local.LocalConfig{
&tmpnet.Network{
NodeRuntimeConfig: tmpnet.NodeRuntimeConfig{
ExecPath: avalancheGoExecPath,
},
},
Expand Down
Loading
Loading