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] Misc cleanup to support xsvm warp test PR #2903

Merged
merged 2 commits into from
Apr 3, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/fixture/tmpnet/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
type FlagsMap map[string]interface{}

// Utility function simplifying construction of a FlagsMap from a file.
func ReadFlagsMap(path string, description string) (*FlagsMap, error) {
func ReadFlagsMap(path string, description string) (FlagsMap, error) {
bytes, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read %s: %w", description, err)
}
flagsMap := &FlagsMap{}
if err := json.Unmarshal(bytes, flagsMap); err != nil {
flagsMap := FlagsMap{}
if err := json.Unmarshal(bytes, &flagsMap); err != nil {
return nil, fmt.Errorf("failed to unmarshal %s: %w", description, err)
}
return flagsMap, nil
Expand Down
6 changes: 5 additions & 1 deletion tests/fixture/tmpnet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ func (n *Network) EnsureDefaultConfig(w io.Writer, avalancheGoPath string, plugi

// Ensure nodes are created
if len(n.Nodes) == 0 {
n.Nodes = NewNodes(nodeCount)
nodes, err := NewNodes(nodeCount)
if err != nil {
return err
}
n.Nodes = nodes
}

// Ensure nodes are configured
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture/tmpnet/network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (n *Network) readChainConfigs() error {
if err != nil {
return err
}
n.ChainConfigs[chainAlias] = *chainConfig
n.ChainConfigs[chainAlias] = chainConfig
}

return nil
Expand Down
10 changes: 7 additions & 3 deletions tests/fixture/tmpnet/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ func NewNode(dataDir string) *Node {
}

// Initializes the specified number of nodes.
func NewNodes(count int) []*Node {
func NewNodes(count int) ([]*Node, error) {
nodes := make([]*Node, count)
for i := range nodes {
nodes[i] = NewNode("")
node := NewNode("")
if err := node.EnsureKeys(); err != nil {
return nil, err
}
nodes[i] = node
}
return nodes
return nodes, nil
}

// Reads a node's configuration from the specified directory.
Expand Down
16 changes: 4 additions & 12 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const defaultSubnetDirName = "subnets"
type Chain struct {
// Set statically
VMID ids.ID
Config FlagsMap
Genesis FlagsMap
Config string
Genesis []byte

// Set at runtime
ChainID ids.ID
Expand All @@ -50,12 +50,8 @@ func (c *Chain) WriteConfig(chainDir string) error {
return fmt.Errorf("failed to create chain config dir: %w", err)
}

bytes, err := DefaultJSONMarshal(c.Config)
if err != nil {
return fmt.Errorf("failed to marshal config for chain %s: %w", c.ChainID, err)
}
path := filepath.Join(chainConfigDir, defaultConfigFilename)
if err := os.WriteFile(path, bytes, perms.ReadWrite); err != nil {
if err := os.WriteFile(path, []byte(c.Config), perms.ReadWrite); err != nil {
return fmt.Errorf("failed to write chain config: %w", err)
}

Expand Down Expand Up @@ -138,13 +134,9 @@ func (s *Subnet) CreateChains(ctx context.Context, w io.Writer, uri string) erro
}

for _, chain := range s.Chains {
genesisBytes, err := DefaultJSONMarshal(chain.Genesis)
if err != nil {
return fmt.Errorf("failed to marshal genesis for chain %s: %w", chain.VMID, err)
}
createChainTx, err := pWallet.IssueCreateChainTx(
s.SubnetID,
genesisBytes,
chain.Genesis,
chain.VMID,
nil,
"",
Expand Down
8 changes: 8 additions & 0 deletions tests/fixture/tmpnet/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ func NewPrivateKeys(keyCount int) ([]*secp256k1.PrivateKey, error) {
}
return keys, nil
}

func NodesToIDs(nodes ...*Node) []ids.NodeID {
nodeIDs := make([]ids.NodeID, len(nodes))
for i, node := range nodes {
nodeIDs[i] = node.NodeID
}
return nodeIDs
}