github.com/MetalBlockchain/metalgo@v1.11.9/vms/avm/config_test.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package avm
     5  
     6  import (
     7  	"testing"
     8  	"time"
     9  
    10  	"github.com/stretchr/testify/require"
    11  
    12  	"github.com/MetalBlockchain/metalgo/vms/avm/network"
    13  )
    14  
    15  func TestParseConfig(t *testing.T) {
    16  	tests := []struct {
    17  		name           string
    18  		configBytes    []byte
    19  		expectedConfig Config
    20  	}{
    21  		{
    22  			name:           "unspecified config",
    23  			configBytes:    nil,
    24  			expectedConfig: DefaultConfig,
    25  		},
    26  		{
    27  			name:        "manually specified checksums enabled",
    28  			configBytes: []byte(`{"checksums-enabled":true}`),
    29  			expectedConfig: Config{
    30  				Network:              network.DefaultConfig,
    31  				IndexTransactions:    DefaultConfig.IndexTransactions,
    32  				IndexAllowIncomplete: DefaultConfig.IndexAllowIncomplete,
    33  				ChecksumsEnabled:     true,
    34  			},
    35  		},
    36  		{
    37  			name:        "manually specified network value",
    38  			configBytes: []byte(`{"network":{"max-validator-set-staleness":1}}`),
    39  			expectedConfig: Config{
    40  				Network: network.Config{
    41  					MaxValidatorSetStaleness:                    time.Nanosecond,
    42  					TargetGossipSize:                            network.DefaultConfig.TargetGossipSize,
    43  					PushGossipPercentStake:                      network.DefaultConfig.PushGossipPercentStake,
    44  					PushGossipNumValidators:                     network.DefaultConfig.PushGossipNumValidators,
    45  					PushGossipNumPeers:                          network.DefaultConfig.PushGossipNumPeers,
    46  					PushRegossipNumValidators:                   network.DefaultConfig.PushRegossipNumValidators,
    47  					PushRegossipNumPeers:                        network.DefaultConfig.PushRegossipNumPeers,
    48  					PushGossipDiscardedCacheSize:                network.DefaultConfig.PushGossipDiscardedCacheSize,
    49  					PushGossipMaxRegossipFrequency:              network.DefaultConfig.PushGossipMaxRegossipFrequency,
    50  					PushGossipFrequency:                         network.DefaultConfig.PushGossipFrequency,
    51  					PullGossipPollSize:                          network.DefaultConfig.PullGossipPollSize,
    52  					PullGossipFrequency:                         network.DefaultConfig.PullGossipFrequency,
    53  					PullGossipThrottlingPeriod:                  network.DefaultConfig.PullGossipThrottlingPeriod,
    54  					PullGossipThrottlingLimit:                   network.DefaultConfig.PullGossipThrottlingLimit,
    55  					ExpectedBloomFilterElements:                 network.DefaultConfig.ExpectedBloomFilterElements,
    56  					ExpectedBloomFilterFalsePositiveProbability: network.DefaultConfig.ExpectedBloomFilterFalsePositiveProbability,
    57  					MaxBloomFilterFalsePositiveProbability:      network.DefaultConfig.MaxBloomFilterFalsePositiveProbability,
    58  				},
    59  				IndexTransactions:    DefaultConfig.IndexTransactions,
    60  				IndexAllowIncomplete: DefaultConfig.IndexAllowIncomplete,
    61  				ChecksumsEnabled:     DefaultConfig.ChecksumsEnabled,
    62  			},
    63  		},
    64  	}
    65  	for _, test := range tests {
    66  		t.Run(test.name, func(t *testing.T) {
    67  			require := require.New(t)
    68  
    69  			config, err := ParseConfig(test.configBytes)
    70  			require.NoError(err)
    71  			require.Equal(test.expectedConfig, config)
    72  		})
    73  	}
    74  }