github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/gossip/state/config_test.go (about) 1 /* 2 Copyright hechain. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package state_test 8 9 import ( 10 "testing" 11 "time" 12 13 "github.com/hechain20/hechain/gossip/state" 14 "github.com/spf13/viper" 15 "github.com/stretchr/testify/require" 16 ) 17 18 func TestGlobalConfig(t *testing.T) { 19 viper.Reset() 20 viper.Set("peer.gossip.state.checkInterval", "1s") 21 viper.Set("peer.gossip.state.responseTimeout", "2s") 22 viper.Set("peer.gossip.state.batchSize", 3) 23 viper.Set("peer.gossip.state.maxRetries", 4) 24 viper.Set("peer.gossip.state.blockBufferSize", 5) 25 viper.Set("peer.gossip.state.channelSize", 6) 26 viper.Set("peer.gossip.state.enabled", true) 27 28 coreConfig := state.GlobalConfig() 29 30 expectedConfig := &state.StateConfig{ 31 StateCheckInterval: time.Second, 32 StateResponseTimeout: 2 * time.Second, 33 StateBatchSize: uint64(3), 34 StateMaxRetries: 4, 35 StateBlockBufferSize: 5, 36 StateChannelSize: 6, 37 StateEnabled: true, 38 } 39 40 require.Equal(t, expectedConfig, coreConfig) 41 } 42 43 func TestGlobalConfigDefaults(t *testing.T) { 44 viper.Reset() 45 46 coreConfig := state.GlobalConfig() 47 48 expectedConfig := &state.StateConfig{ 49 StateCheckInterval: 10 * time.Second, 50 StateResponseTimeout: 3 * time.Second, 51 StateBatchSize: uint64(10), 52 StateMaxRetries: 3, 53 StateBlockBufferSize: 20, 54 StateChannelSize: 100, 55 StateEnabled: false, 56 } 57 58 require.Equal(t, expectedConfig, coreConfig) 59 }