Skip to content

Commit

Permalink
Update write path of tmpnet subnet config
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald committed Aug 12, 2024
1 parent b181671 commit 86e48a3
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import (
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
)

const defaultSubnetDirName = "subnets"
const (
defaultSubnetDirName = "subnets"
jsonFileSuffix = ".json"
)

type Chain struct {
// Set statically
Expand Down Expand Up @@ -209,7 +212,7 @@ func (s *Subnet) Write(subnetDir string, chainDir string) error {
if err := os.MkdirAll(subnetDir, perms.ReadWriteExecute); err != nil {
return fmt.Errorf("failed to create subnet dir: %w", err)
}
tmpnetConfigPath := filepath.Join(subnetDir, s.Name+".json")
tmpnetConfigPath := filepath.Join(subnetDir, s.Name+jsonFileSuffix)

// Since subnets are expected to be serialized for the first time
// without their chains having been created (i.e. chains will have
Expand Down Expand Up @@ -249,13 +252,8 @@ func (s *Subnet) Write(subnetDir string, chainDir string) error {
return fmt.Errorf("failed to marshal avalanchego subnet config %s: %w", s.Name, err)
}

avgoConfigDir := filepath.Join(subnetDir, s.SubnetID.String())
if err := os.MkdirAll(avgoConfigDir, perms.ReadWriteExecute); err != nil {
return fmt.Errorf("failed to create avalanchego subnet config dir: %w", err)
}

avgoConfigPath := filepath.Join(avgoConfigDir, defaultConfigFilename)
if err := os.WriteFile(avgoConfigPath, bytes, perms.ReadWrite); err != nil {
subnetConfigPath := filepath.Join(subnetDir, s.SubnetID.String()+jsonFileSuffix)
if err := os.WriteFile(subnetConfigPath, bytes, perms.ReadWrite); err != nil {
return fmt.Errorf("failed to write avalanchego subnet config %s: %w", s.Name, err)
}
}
Expand Down Expand Up @@ -351,7 +349,7 @@ func readSubnets(subnetDir string) ([]*Subnet, error) {
// Looking only for files
continue
}
if filepath.Ext(entry.Name()) != ".json" {
if filepath.Ext(entry.Name()) != jsonFileSuffix {
// Subnet files should have a .json extension
continue
}
Expand Down

0 comments on commit 86e48a3

Please # to comment.