Skip to content

Commit

Permalink
[tmpnet] Misc cleanup to support xsvm warp test PR
Browse files Browse the repository at this point in the history
- update tmpnet.ReadFlagsMap to avoid returning an unnecessary pointer

- add tmpnet.InterfaceToFlagsMap helper to simplify conversion of
subnet configuration to a FlagsMap for nicer serialization

- update tmpnet.NewNodes to initialize tls and signing keys so that
nodes returned by this method can be used to extract the validator IDs
for a subnet

- switch tmpnet.Chain.Genesis back to a byte array. A previous attempt
to improve the readability of tmpnet subnet configuration by
converting to FlagsMap ignored that genesis byte format is VM-specific.
  • Loading branch information
marun committed Apr 2, 2024
1 parent 9a0c852 commit 0184fa8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
22 changes: 19 additions & 3 deletions tests/fixture/tmpnet/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,34 @@ 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
}

// Round-trips the provided interface through JSON to convert to a
// FlagsMap. This allows for a cleaner serialization of embedded types
// such as chain configuration.
func InterfaceToFlagsMap(v interface{}) (FlagsMap, error) {
bytes, err := json.Marshal(v)
if err != nil {
return nil, err
}
flagsMap := FlagsMap{}
err = json.Unmarshal(bytes, &flagsMap)
if err != nil {
return nil, err
}
return flagsMap, nil
}

// SetDefaults ensures the effectiveness of flag overrides by only
// setting values supplied in the defaults map that are not already
// explicitly set.
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
4 changes: 3 additions & 1 deletion tests/fixture/tmpnet/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ func NewNode(dataDir string) *Node {
func NewNodes(count int) []*Node {
nodes := make([]*Node, count)
for i := range nodes {
nodes[i] = NewNode("")
node := NewNode("")
node.EnsureKeys()

Check failure on line 102 in tests/fixture/tmpnet/node.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `node.EnsureKeys` is not checked (errcheck)

Check failure on line 102 in tests/fixture/tmpnet/node.go

View workflow job for this annotation

GitHub Actions / Lint

unhandled-error: Unhandled error in call to function tmpnet.Node.EnsureKeys (revive)
nodes[i] = node
}
return nodes
}
Expand Down
8 changes: 2 additions & 6 deletions tests/fixture/tmpnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Chain struct {
// Set statically
VMID ids.ID
Config FlagsMap
Genesis FlagsMap
Genesis []byte

// Set at runtime
ChainID ids.ID
Expand Down Expand Up @@ -138,13 +138,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

0 comments on commit 0184fa8

Please sign in to comment.