Skip to content

Commit ec8341b

Browse files
committed
fixup: Use a private network
1 parent 1c0c176 commit ec8341b

File tree

3 files changed

+64
-29
lines changed

3 files changed

+64
-29
lines changed

tests/e2e/c/dynamic_fees.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ var _ = e2e.DescribeCChainSerial("[Dynamic Fees]", func() {
3939
gasTip := big.NewInt(1000 * params.GWei)
4040

4141
ginkgo.It("should ensure that the gas price is affected by load", func() {
42+
ginkgo.By("creating a new private network to ensure isolation from other tests")
43+
privateNetwork := e2e.Env.NewPrivateNetwork()
44+
4245
ginkgo.By("allocating a pre-funded key")
43-
key := e2e.Env.AllocateFundedKey()
46+
key := privateNetwork.GetConfig().FundedKeys[0]
4447
ethAddress := evm.GetEthAddress(key)
4548

4649
ginkgo.By("initializing a coreth client")
47-
ethClient := e2e.Env.NewEthClient(e2e.Env.GetRandomNodeURI())
50+
nodes := privateNetwork.GetNodes()
51+
nodeURI := nodes[0].GetProcessContext().URI
52+
ethClient := e2e.Env.NewEthClient(nodeURI)
4853

4954
ginkgo.By("initializing a transaction signer")
5055
cChainID, err := ethClient.ChainID(e2e.DefaultContext())
@@ -157,6 +162,6 @@ var _ = e2e.DescribeCChainSerial("[Dynamic Fees]", func() {
157162
e2e.SendEthTransaction(ethClient, signedTx)
158163
})
159164

160-
e2e.CheckBootstrapIsPossible(e2e.Env.GetNetwork())
165+
e2e.CheckBootstrapIsPossible(privateNetwork)
161166
})
162167
})

tests/e2e/e2e.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"math/rand"
1313
"os"
14+
"path/filepath"
1415
"strings"
1516
"time"
1617

@@ -30,6 +31,7 @@ import (
3031
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
3132
"github.com/ava-labs/avalanchego/tests/fixture/testnet/local"
3233
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
34+
"github.com/ava-labs/avalanchego/utils/perms"
3335
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
3436
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
3537
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
@@ -62,6 +64,14 @@ const (
6264
// checks. Useful for speeding up iteration during test
6365
// development.
6466
SkipBootstrapChecksEnvName = "E2E_SKIP_BOOTSTRAP_CHECKS"
67+
68+
// An empty string prompts the use of the default path which ensures a
69+
// predictable target for github's upload-artifact action.
70+
DefaultNetworkDir = ""
71+
72+
// Directory used to store private networks (specific to a single test)
73+
// under the shared network dir.
74+
PrivateNetworksDirName = "private_networks"
6575
)
6676

6777
// Env is used to access shared test fixture. Intended to be
@@ -127,6 +137,7 @@ func (te *TestEnvironment) NewKeychain(count int) *secp256k1fx.Keychain {
127137
}
128138

129139
// Create a new wallet for the provided keychain against the specified node URI.
140+
// TODO(marun) Make this a regular function.
130141
func (te *TestEnvironment) NewWallet(keychain *secp256k1fx.Keychain, uri string) primary.Wallet {
131142
tests.Outf("{{blue}} initializing a new wallet for URI: %s {{/}}\n", uri)
132143
wallet, err := primary.MakeWallet(DefaultContext(), &primary.WalletConfig{
@@ -139,6 +150,7 @@ func (te *TestEnvironment) NewWallet(keychain *secp256k1fx.Keychain, uri string)
139150
}
140151

141152
// Create a new eth client targeting the specified node URI.
153+
// TODO(marun) Make this a regular function.
142154
func (te *TestEnvironment) NewEthClient(nodeURI string) ethclient.Client {
143155
tests.Outf("{{blue}} initializing a new eth client for URI: %s {{/}}\n", nodeURI)
144156
nodeAddress := strings.Split(nodeURI, "//")[1]
@@ -148,6 +160,20 @@ func (te *TestEnvironment) NewEthClient(nodeURI string) ethclient.Client {
148160
return client
149161
}
150162

163+
// Create a new private network that is not shared with other tests.
164+
func (te *TestEnvironment) NewPrivateNetwork() testnet.Network {
165+
// Load the shared network to retrieve its path and exec path
166+
sharedNetwork, err := local.ReadNetwork(te.NetworkDir)
167+
te.require.NoError(err)
168+
169+
// The private networks dir is under the shared network dir to ensure it
170+
// will be included in the artifact uploaded in CI.
171+
privateNetworksDir := filepath.Join(sharedNetwork.Dir, PrivateNetworksDirName)
172+
te.require.NoError(os.MkdirAll(privateNetworksDir, perms.ReadWriteExecute))
173+
174+
return StartLocalNetwork(sharedNetwork.ExecPath, privateNetworksDir)
175+
}
176+
151177
// Helper simplifying use of a timed context by canceling the context on ginkgo teardown.
152178
func ContextWithTimeout(duration time.Duration) context.Context {
153179
ctx, cancel := context.WithTimeout(context.Background(), duration)
@@ -267,3 +293,32 @@ func CheckBootstrapIsPossible(network testnet.Network) {
267293
node := AddEphemeralNode(network, testnet.FlagsMap{})
268294
WaitForHealthy(node)
269295
}
296+
297+
// Start a local test-managed network with the provided avalanchego binary.
298+
func StartLocalNetwork(avalancheGoExecPath string, networkDir string) *local.LocalNetwork {
299+
require := require.New(ginkgo.GinkgoT())
300+
301+
tests.Outf("{{magenta}}Starting network with %q{{/}}\n", avalancheGoExecPath)
302+
303+
network, err := local.StartNetwork(
304+
DefaultContext(),
305+
ginkgo.GinkgoWriter,
306+
networkDir,
307+
&local.LocalNetwork{
308+
LocalConfig: local.LocalConfig{
309+
ExecPath: avalancheGoExecPath,
310+
},
311+
},
312+
testnet.DefaultNodeCount,
313+
testnet.DefaultFundedKeyCount,
314+
)
315+
require.NoError(err)
316+
ginkgo.DeferCleanup(func() {
317+
tests.Outf("Shutting down network\n")
318+
require.NoError(network.Stop())
319+
})
320+
321+
tests.Outf("{{green}}Successfully started network{{/}}\n")
322+
323+
return network
324+
}

tests/e2e/e2e_test.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package e2e_test
55

66
import (
7-
"context"
87
"encoding/json"
98
"flag"
109
"fmt"
@@ -20,7 +19,6 @@ import (
2019
"github.com/ava-labs/avalanchego/tests"
2120
"github.com/ava-labs/avalanchego/tests/e2e"
2221
"github.com/ava-labs/avalanchego/tests/fixture"
23-
"github.com/ava-labs/avalanchego/tests/fixture/testnet"
2422
"github.com/ava-labs/avalanchego/tests/fixture/testnet/local"
2523

2624
// ensure test packages are scanned by ginkgo
@@ -83,30 +81,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
8381
network, err = local.ReadNetwork(persistentNetworkDir)
8482
require.NoError(err)
8583
} else {
86-
tests.Outf("{{magenta}}Starting network with %q{{/}}\n", avalancheGoExecPath)
87-
88-
ctx, cancel := context.WithTimeout(context.Background(), local.DefaultNetworkStartTimeout)
89-
defer cancel()
90-
var err error
91-
network, err = local.StartNetwork(
92-
ctx,
93-
ginkgo.GinkgoWriter,
94-
"", // Use the default path to ensure a predictable target for github's upload-artifact action
95-
&local.LocalNetwork{
96-
LocalConfig: local.LocalConfig{
97-
ExecPath: avalancheGoExecPath,
98-
},
99-
},
100-
testnet.DefaultNodeCount,
101-
testnet.DefaultFundedKeyCount,
102-
)
103-
require.NoError(err)
104-
ginkgo.DeferCleanup(func() {
105-
tests.Outf("Shutting down network\n")
106-
require.NoError(network.Stop())
107-
})
108-
109-
tests.Outf("{{green}}Successfully started network{{/}}\n")
84+
network = e2e.StartLocalNetwork(avalancheGoExecPath, e2e.DefaultNetworkDir)
11085
}
11186

11287
uris := network.GetURIs()

0 commit comments

Comments
 (0)