Skip to content

Commit

Permalink
tmpnet: Break config.go up into coherent parts
Browse files Browse the repository at this point in the history
- Move NetworkConfig functionality to Network
- Move NodeConfig functionality to Node
- Move FlagsMap to flags.go
- Move genesis helpers to genesis.go
- Move NodeURI and key generation to utils.go
- Remove redundant node_test.go
  • Loading branch information
maru-ava committed Dec 14, 2023
1 parent 111450b commit dab364e
Show file tree
Hide file tree
Showing 11 changed files with 516 additions and 529 deletions.
4 changes: 2 additions & 2 deletions tests/fixture/e2e/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewTestEnvironment(flagVars *FlagVars) *TestEnvironment {
network = StartNetwork(flagVars.AvalancheGoExecPath(), DefaultNetworkDir)
}

uris := network.GetURIs()
uris := tmpnet.GetNodeURIs(network.Nodes)
require.NotEmpty(uris, "network contains no nodes")
tests.Outf("{{green}}network URIs: {{/}} %+v\n", uris)

Expand All @@ -91,7 +91,7 @@ func NewTestEnvironment(flagVars *FlagVars) *TestEnvironment {
func (te *TestEnvironment) GetRandomNodeURI() tmpnet.NodeURI {
r := rand.New(rand.NewSource(time.Now().Unix())) //#nosec G404
nodeURI := te.URIs[r.Intn(len(te.URIs))]
tests.Outf("{{blue}} targeting node %s with URI: %s{{/}}\n", nodeURI.ID, nodeURI.URI)
tests.Outf("{{blue}} targeting node %s with URI: %s{{/}}\n", nodeURI.NodeID, nodeURI.URI)
return nodeURI
}

Expand Down
4 changes: 2 additions & 2 deletions tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (

// 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.ID, nodeURI.URI)
tests.Outf("{{blue}} initializing a new wallet for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI)
baseWallet, err := primary.MakeWallet(DefaultContext(), &primary.WalletConfig{
URI: nodeURI.URI,
AVAXKeychain: keychain,
Expand All @@ -81,7 +81,7 @@ func NewWallet(keychain *secp256k1fx.Keychain, nodeURI tmpnet.NodeURI) primary.W

// Create a new eth client targeting the specified node URI.
func NewEthClient(nodeURI tmpnet.NodeURI) ethclient.Client {
tests.Outf("{{blue}} initializing a new eth client for node %s with URI: %s {{/}}\n", nodeURI.ID, nodeURI.URI)
tests.Outf("{{blue}} initializing a new eth client for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI)
nodeAddress := strings.Split(nodeURI.URI, "//")[1]
uri := fmt.Sprintf("ws://%s/ext/bc/C/ws", nodeAddress)
client, err := ethclient.Dial(uri)
Expand Down
14 changes: 8 additions & 6 deletions tests/fixture/tmpnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ repositories.
The functionality in this package is grouped by logical purpose into
the following non-test files:

| Filename | Types | Purpose |
|:------------|:--------|:----------------------------------------------|
| defaults.go | <none> | Default configuration |
| network.go | Network | Network-level orchestration and configuration |
| node.go | Node | Node-level orchestration and configuration |
| util.go | <none> | Shared utility functions |
| Filename | Types | Purpose |
|:------------------|:------------|:-----------------------------------------------|
| defaults.go | | Defines common default configuration |
| flags.go | FlagsMap | Simplifies configuration of avalanchego flags |
| genesis.go | | Creates test genesis |
| network.go | Network | Orchestrates and configures temporary networks |
| node.go | Node | Orchestrates and configures nodes |
| utils.go | | Defines shared utility functions |

## Usage

Expand Down
Loading

0 comments on commit dab364e

Please sign in to comment.