package config import ( "strings" "testing" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" "github.com/spf13/viper" "github.com/stretchr/testify/require" ) func TestConfig(t *testing.T) { t.Parallel() t.Run("all set", func(t *testing.T) { t.Parallel() file := strings.NewReader( ` fee: main_chain: 50000000 side_chain: 200000000 named_container_register: 2500000000 `, ) v := viper.New() v.SetConfigType("yaml") err := v.ReadConfig(file) require.NoError(t, err, "read config file failed") config := NewFeeConfig(v) require.Equal(t, fixedn.Fixed8(50000000), config.MainChainFee(), "main chain fee invalid") require.Equal(t, fixedn.Fixed8(200000000), config.SideChainFee(), "side chain fee invalid") require.Equal(t, fixedn.Fixed8(2500000000), config.NamedContainerRegistrationFee(), "named container register fee invalid") }) t.Run("nothing set", func(t *testing.T) { t.Parallel() file := strings.NewReader("") v := viper.New() v.SetConfigType("yaml") err := v.ReadConfig(file) require.NoError(t, err, "read config file failed") config := NewFeeConfig(v) require.Equal(t, fixedn.Fixed8(0), config.MainChainFee(), "main chain fee invalid") require.Equal(t, fixedn.Fixed8(0), config.SideChainFee(), "side chain fee invalid") require.Equal(t, fixedn.Fixed8(0), config.NamedContainerRegistrationFee(), "named container register fee invalid") }) t.Run("partially set", func(t *testing.T) { t.Parallel() file := strings.NewReader( ` fee: main_chain: 10 `, ) v := viper.New() v.SetConfigType("yaml") err := v.ReadConfig(file) require.NoError(t, err, "read config file failed") config := NewFeeConfig(v) require.Equal(t, fixedn.Fixed8(10), config.MainChainFee(), "main chain fee invalid") require.Equal(t, fixedn.Fixed8(0), config.SideChainFee(), "side chain fee invalid") require.Equal(t, fixedn.Fixed8(0), config.NamedContainerRegistrationFee(), "named container register fee invalid") }) }