Skip to content

Commit 24d75ae

Browse files
committed
fixup: Add ConfigMap type alias for map[string]any
1 parent 42ec341 commit 24d75ae

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

tests/fixture/subnet/xsvm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NewXSVMOrPanic(name string, key *secp256k1.PrivateKey, nodes ...*tmpnet.Nod
3333

3434
return &tmpnet.Subnet{
3535
Name: name,
36-
Config: map[string]any{
36+
Config: tmpnet.ConfigMap{
3737
// Reducing this from the 1s default speeds up tx acceptance
3838
"proposerMinBlockDelay": 0,
3939
},

tests/fixture/tmpnet/network.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func init() {
7979
}
8080
}
8181

82+
// Enables defining subnet and chain configuration in a format
83+
// appropriate for round-tripping through JSON to golang structs.
84+
type ConfigMap map[string]any
85+
8286
// Collects the configuration for running a temporary avalanchego network
8387
type Network struct {
8488
// Uniquely identifies the temporary network for metrics
@@ -107,10 +111,10 @@ type Network struct {
107111
Genesis *genesis.UnparsedConfig
108112

109113
// Configuration for primary subnets
110-
PrimarySubnetConfig map[string]any
114+
PrimarySubnetConfig ConfigMap
111115

112116
// Configuration for primary network chains (P, X, C)
113-
PrimaryChainConfigs map[string]ChainConfigMap
117+
PrimaryChainConfigs map[string]ConfigMap
114118

115119
// Default configuration to use when creating new nodes
116120
DefaultFlags FlagsMap
@@ -229,12 +233,12 @@ func (n *Network) EnsureDefaultConfig(log logging.Logger) error {
229233

230234
// Ensure primary chains are configured
231235
if n.PrimaryChainConfigs == nil {
232-
n.PrimaryChainConfigs = map[string]ChainConfigMap{}
236+
n.PrimaryChainConfigs = map[string]ConfigMap{}
233237
}
234238
defaultChainConfigs := DefaultChainConfigs()
235239
for alias, defaultChainConfig := range defaultChainConfigs {
236240
if _, ok := n.PrimaryChainConfigs[alias]; !ok {
237-
n.PrimaryChainConfigs[alias] = ChainConfigMap{}
241+
n.PrimaryChainConfigs[alias] = ConfigMap{}
238242
}
239243
primaryChainConfig := n.PrimaryChainConfigs[alias]
240244
for key, value := range defaultChainConfig {
@@ -806,7 +810,7 @@ func (n *Network) GetGenesisFileContent() (string, error) {
806810
// GetSubnetConfigContent returns the base64-encoded and
807811
// JSON-marshaled map of subnetID to subnet configuration.
808812
func (n *Network) GetSubnetConfigContent() (string, error) {
809-
subnetConfigs := map[ids.ID]map[string]any{}
813+
subnetConfigs := map[ids.ID]ConfigMap{}
810814

811815
if len(n.PrimarySubnetConfig) > 0 {
812816
subnetConfigs[constants.PrimaryNetworkID] = n.PrimarySubnetConfig

tests/fixture/tmpnet/network_config.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ func (n *Network) readConfig() error {
150150

151151
// The subset of network fields to store in the network config file.
152152
type serializedNetworkConfig struct {
153-
UUID string `json:"uuid,omitempty"`
154-
Owner string `json:"owner,omitempty"`
155-
PrimarySubnetConfig map[string]any `json:"primarySubnetConfig,omitempty"`
156-
PrimaryChainConfigs map[string]ChainConfigMap `json:"primaryChainConfigs,omitempty"`
157-
DefaultFlags FlagsMap `json:"defaultFlags,omitempty"`
158-
DefaultRuntimeConfig NodeRuntimeConfig `json:"defaultRuntimeConfig,omitempty"`
159-
PreFundedKeys []*secp256k1.PrivateKey `json:"preFundedKeys,omitempty"`
153+
UUID string `json:"uuid,omitempty"`
154+
Owner string `json:"owner,omitempty"`
155+
PrimarySubnetConfig ConfigMap `json:"primarySubnetConfig,omitempty"`
156+
PrimaryChainConfigs map[string]ConfigMap `json:"primaryChainConfigs,omitempty"`
157+
DefaultFlags FlagsMap `json:"defaultFlags,omitempty"`
158+
DefaultRuntimeConfig NodeRuntimeConfig `json:"defaultRuntimeConfig,omitempty"`
159+
PreFundedKeys []*secp256k1.PrivateKey `json:"preFundedKeys,omitempty"`
160160
}
161161

162162
func (n *Network) writeNetworkConfig() error {

tests/fixture/tmpnet/network_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestNetworkSerialization(t *testing.T) {
1818

1919
network := NewDefaultNetwork("testnet")
2020
// Validate round-tripping of primary subnet configuration
21-
network.PrimarySubnetConfig = map[string]any{
21+
network.PrimarySubnetConfig = ConfigMap{
2222
"validatorOnly": true,
2323
}
2424
require.NoError(network.EnsureDefaultConfig(logging.NoLog{}))

tests/fixture/tmpnet/subnet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Subnet struct {
5555
// networks (since the SubnetID will be different every time the subnet is created)
5656
Name string
5757

58-
Config map[string]any
58+
Config ConfigMap
5959

6060
// The ID of the transaction that created the subnet
6161
SubnetID ids.ID

0 commit comments

Comments
 (0)